Files
emall-api/FutureMailAPI/DTOs/MailDTOs.cs
2025-10-18 16:18:20 +08:00

318 lines
12 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace FutureMailAPI.DTOs
{
public class SentMailCreateDto
{
[Required(ErrorMessage = "标题是必填项")]
[StringLength(200, ErrorMessage = "标题长度不能超过200个字符")]
public string Title { get; set; } = string.Empty;
[Required(ErrorMessage = "内容是必填项")]
public string Content { get; set; } = string.Empty;
// 收件人类型: 0-自己, 1-指定用户, 2-公开时间胶囊
[Required(ErrorMessage = "收件人类型是必填项")]
[Range(0, 2, ErrorMessage = "收件人类型必须是0、1或2")]
public int RecipientType { get; set; }
// 如果是指定用户,提供用户邮箱
public string? RecipientEmail { get; set; }
[Required(ErrorMessage = "投递时间是必填项")]
public DateTime DeliveryTime { get; set; }
// 触发条件类型: 0-时间, 1-地点, 2-事件
[Required(ErrorMessage = "触发条件类型是必填项")]
[Range(0, 2, ErrorMessage = "触发条件类型必须是0、1或2")]
public int TriggerType { get; set; } = 0;
// 触发条件详情(JSON格式)
public string? TriggerDetails { get; set; }
// 附件路径(JSON数组格式)
public string? Attachments { get; set; }
// 是否加密
public bool IsEncrypted { get; set; } = false;
// 加密密钥(如果使用端到端加密)
public string? EncryptionKey { get; set; }
// 邮件主题/胶囊皮肤
[StringLength(50, ErrorMessage = "主题长度不能超过50个字符")]
public string? Theme { get; set; }
}
// 兼容前端请求格式的DTO
public class SentMailCreateCompatDto
{
[Required(ErrorMessage = "标题是必填项")]
[StringLength(200, ErrorMessage = "标题长度不能超过200个字符")]
public string title { get; set; } = string.Empty;
[Required(ErrorMessage = "内容是必填项")]
public string content { get; set; } = string.Empty;
[Required(ErrorMessage = "收件人类型是必填项")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public RecipientTypeEnum recipientType { get; set; }
public string? recipientEmail { get; set; }
[Required(ErrorMessage = "投递时间是必填项")]
public DateTime sendTime { get; set; }
[Required(ErrorMessage = "触发条件类型是必填项")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public TriggerTypeEnum triggerType { get; set; }
public object? triggerCondition { get; set; }
public List<object>? attachments { get; set; }
public bool isEncrypted { get; set; } = false;
public string capsuleStyle { get; set; } = "default";
// 转换为内部DTO
public SentMailCreateDto ToInternalDto()
{
var dto = new SentMailCreateDto
{
Title = this.title,
Content = this.content,
RecipientType = (int)this.recipientType,
RecipientEmail = this.recipientEmail,
DeliveryTime = this.sendTime,
TriggerType = (int)this.triggerType,
IsEncrypted = this.isEncrypted,
Theme = this.capsuleStyle
};
// 处理触发条件
if (this.triggerCondition != null)
{
dto.TriggerDetails = System.Text.Json.JsonSerializer.Serialize(this.triggerCondition);
}
// 处理附件
if (this.attachments != null && this.attachments.Count > 0)
{
dto.Attachments = System.Text.Json.JsonSerializer.Serialize(this.attachments);
}
return dto;
}
}
public enum RecipientTypeEnum
{
SELF = 0,
SPECIFIC = 1,
PUBLIC = 2
}
public enum TriggerTypeEnum
{
TIME = 0,
LOCATION = 1,
EVENT = 2
}
public class SentMailUpdateDto
{
[StringLength(200, ErrorMessage = "标题长度不能超过200个字符")]
public string? Title { get; set; }
public string? Content { get; set; }
public DateTime? DeliveryTime { get; set; }
public string? TriggerDetails { get; set; }
public string? Attachments { get; set; }
public string? Theme { get; set; }
}
public class SentMailResponseDto
{
public int Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;
public int SenderId { get; set; }
public string SenderUsername { get; set; } = string.Empty;
public int RecipientType { get; set; }
public int? RecipientId { get; set; }
public string? RecipientUsername { get; set; }
public DateTime SentAt { get; set; }
public DateTime DeliveryTime { get; set; }
public int Status { get; set; }
public int TriggerType { get; set; }
public string? TriggerDetails { get; set; }
public string? Attachments { get; set; }
public bool IsEncrypted { get; set; }
public string? Theme { get; set; }
// 计算属性
public string StatusText { get; set; } = string.Empty;
public string RecipientTypeText { get; set; } = string.Empty;
public string TriggerTypeText { get; set; } = string.Empty;
public int DaysUntilDelivery { get; set; }
}
public class ReceivedMailResponseDto
{
public int Id { get; set; }
public int SentMailId { get; set; }
public string Title { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;
public string SenderUsername { get; set; } = string.Empty;
public DateTime SentAt { get; set; }
public DateTime ReceivedAt { get; set; }
public bool IsRead { get; set; }
public DateTime? ReadAt { get; set; }
public bool IsReplied { get; set; }
public int? ReplyMailId { get; set; }
public string? Theme { get; set; }
}
public class MailListQueryDto
{
public int PageIndex { get; set; } = 1;
public int PageSize { get; set; } = 10;
public int? Status { get; set; }
public int? RecipientType { get; set; }
public string? Keyword { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
}
// 存入胶囊请求DTO
public class SaveToCapsuleDto
{
[Required(ErrorMessage = "标题是必填项")]
[StringLength(200, ErrorMessage = "标题长度不能超过200个字符")]
public string Title { get; set; } = string.Empty;
[Required(ErrorMessage = "内容是必填项")]
public string Content { get; set; } = string.Empty;
[Required(ErrorMessage = "收件人类型是必填项")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public RecipientTypeEnum RecipientType { get; set; }
public string? RecipientEmail { get; set; }
public DateTime? SendTime { get; set; }
[Required(ErrorMessage = "触发条件类型是必填项")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public TriggerTypeEnum TriggerType { get; set; } = TriggerTypeEnum.TIME;
public object? TriggerCondition { get; set; }
public List<object>? Attachments { get; set; }
public bool IsEncrypted { get; set; } = false;
[Required(ErrorMessage = "胶囊样式是必填项")]
public string CapsuleStyle { get; set; } = "default";
}
// 存入胶囊响应DTO
public class SaveToCapsuleResponseDto
{
public int Id { get; set; }
public string MailId { get; set; } = string.Empty;
public string CapsuleId { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public DateTime CreatedAt { get; set; }
}
// 胶囊邮件列表响应DTO
public class CapsuleMailListResponseDto
{
public string MailId { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public UserInfoDto Sender { get; set; } = new();
public UserInfoDto Recipient { get; set; } = new();
public DateTime SendTime { get; set; }
public DateTime? DeliveryTime { get; set; }
public string Status { get; set; } = string.Empty;
public bool HasAttachments { get; set; }
public bool IsEncrypted { get; set; }
public string CapsuleStyle { get; set; } = string.Empty;
public int? Countdown { get; set; } // 倒计时秒数仅status=PENDING时返回
}
// 胶囊邮件详情响应DTO
public class CapsuleMailDetailResponseDto
{
public string MailId { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;
public UserInfoDto Sender { get; set; } = new();
public UserInfoDto Recipient { get; set; } = new();
public DateTime SendTime { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? DeliveryTime { get; set; }
public string Status { get; set; } = string.Empty;
public string TriggerType { get; set; } = string.Empty;
public object? TriggerCondition { get; set; }
public List<AttachmentDto> Attachments { get; set; } = new();
public bool IsEncrypted { get; set; }
public string CapsuleStyle { get; set; } = string.Empty;
public bool CanEdit { get; set; } // 是否可编辑(仅草稿状态)
public bool CanRevoke { get; set; } // 是否可撤销(仅待投递状态)
}
// 附件DTO
public class AttachmentDto
{
public string Id { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public string Url { get; set; } = string.Empty;
public string? Thumbnail { get; set; }
public long Size { get; set; }
}
// 更新胶囊邮件DTO
public class UpdateCapsuleMailDto
{
public string? Title { get; set; }
public string? Content { get; set; }
public RecipientTypeEnum? RecipientType { get; set; }
public string? RecipientEmail { get; set; }
public DateTime? SendTime { get; set; }
public TriggerTypeEnum? TriggerType { get; set; }
public object? TriggerCondition { get; set; }
public List<object>? Attachments { get; set; }
public bool? IsEncrypted { get; set; }
public string? CapsuleStyle { get; set; }
}
// 发送至未来请求DTO
public class SendToFutureDto
{
[Required(ErrorMessage = "邮件ID是必填项")]
public int MailId { get; set; }
[Required(ErrorMessage = "投递时间是必填项")]
public DateTime DeliveryTime { get; set; }
}
// 发送至未来响应DTO
public class SendToFutureResponseDto
{
public int MailId { get; set; }
public string Title { get; set; } = string.Empty;
public DateTime DeliveryTime { get; set; }
public string Status { get; set; } = string.Empty;
public DateTime SentAt { get; set; }
}
}