Refactor email query and controller endpoints
Refactored `FetchEmailsQuery` to encapsulate filtering and retrieval parameters (`UnseenOnly` and `MaxCount`) within a nested `MailQuery` record for better organization. Updated `FetchEmailsQueryHandler` to use the new structure.
Simplified `EmailController` endpoints:
- Replaced multiple query parameters in `FetchEmails` with a single `FetchEmailsQuery` object.
- Replaced multiple parameters in `MarkAsSeen` with a `MarkEmailAsSeenCommand` object.
- Adjusted the HTTP route for `MarkAsSeen` from `"{uid}/seen"` to `"seen"`.
Updated XML documentation to reflect these changes, improving maintainability and scalability.
This commit is contained in:
@@ -22,14 +22,22 @@ public record FetchEmailsQuery : IRequest<IEnumerable<ReceivedEmailContext>>
|
||||
public string Folder { get; init; } = "INBOX";
|
||||
|
||||
/// <summary>
|
||||
/// When <see langword="true"/> returns only unread messages.
|
||||
/// Mail query used to filter and limit the emails retrieved.
|
||||
/// </summary>
|
||||
public bool UnseenOnly { get; init; } = false;
|
||||
public MailQuery Mail { get; init; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of messages to retrieve (most-recent first). 0 = unlimited.
|
||||
/// </summary>
|
||||
public int MaxCount { get; init; } = 50;
|
||||
public record MailQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// When <see langword="true"/> returns only unread messages.
|
||||
/// </summary>
|
||||
public bool UnseenOnly { get; init; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of messages to retrieve (most-recent first). 0 = unlimited.
|
||||
/// </summary>
|
||||
public int MaxCount { get; init; } = 50;
|
||||
}
|
||||
}
|
||||
|
||||
public class FetchEmailsQueryHandler(
|
||||
@@ -49,8 +57,8 @@ public class FetchEmailsQueryHandler(
|
||||
return await ImapService.FetchEmailsAsync(
|
||||
account,
|
||||
request.Folder,
|
||||
request.UnseenOnly,
|
||||
request.MaxCount,
|
||||
request.Mail.UnseenOnly,
|
||||
request.Mail.MaxCount,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user