Refactor ReadEmailQuery to return structured response

Updated ReadEmailQuery to return a new response type,
ReadEmailQueryResponse, which includes both email data
and metadata (e.g., LastSync). Added the Account property
to ReadEmailQuery for specifying the email account.

Refactored ReadEmailQueryHandler to:
- Use IImapEmailService to fetch LastSync metadata.
- Return ReadEmailQueryResponse instead of a collection
  of ReceivedEmailDto.

Introduced ReadEmailQueryResponse class to encapsulate
LastSync and Emails properties.

Updated EmailController to handle the new response
structure, ensuring compatibility with the updated
ReadEmailQuery and its handler.
This commit is contained in:
2026-08-17 01:13:14 +02:00
parent d01a0ceaa6
commit 6c698c95be
3 changed files with 33 additions and 9 deletions

View File

@@ -94,22 +94,22 @@ public class EmailController(IMediator mediator) : ControllerBase
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> FetchEmails([FromQuery] ReadEmailQuery query, [FromQuery] OnlyFilter? only = null, CancellationToken cancellationToken = default)
{
var emails = await mediator.Send(query, cancellationToken);
var res = await mediator.Send(query, cancellationToken);
if(!emails.Any())
if(!res.Emails.Any())
return NotFound("No emails found matching the specified criteria.");
if (only == OnlyFilter.HtmlBody)
{
if (emails.FirstOrDefault()?.HtmlBody is string htmlBody)
if (res.Emails.FirstOrDefault()?.HtmlBody is string htmlBody)
return Content(htmlBody, "text/html");
else
return NotFound();
}
else if (only == OnlyFilter.Uid)
return Ok(emails.Select(e => e.Uid).ToList());
return Ok(res.Emails.Select(e => e.Uid).ToList());
else
return Ok(emails);
return Ok(res);
}
#endregion Receive
}