mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 16:00:06 +01:00
feat: return creation/update time
This commit is contained in:
@@ -94,7 +94,7 @@ public class CategoryController : ControllerBase
|
||||
[HttpGet]
|
||||
[EnableCors]
|
||||
[ProducesResponseType(typeof(List<CategoryShortDTO>), 200)]
|
||||
public async Task<IActionResult> GetQuotePage()
|
||||
public async Task<IActionResult> GetEveryCategory()
|
||||
{
|
||||
// The following seems to be a bad idea, so I leave it as is. ~eee4
|
||||
//
|
||||
|
||||
@@ -46,7 +46,7 @@ public class QuotesController : ControllerBase
|
||||
/// <response code="404">Returned when requested page is invalid (page_no <= 0)</response>
|
||||
[HttpGet("page/{page_no}")]
|
||||
[EnableCors]
|
||||
[ProducesResponseType(typeof(List<QuoteShortDTO>), 200)]
|
||||
[ProducesResponseType(typeof(List<QuoteCompleteDTO>), 200)]
|
||||
[ProducesResponseType(typeof(ErrorDTO), 404)]
|
||||
public async Task<IActionResult> GetQuotePage(int page_no = 1, string? sort = "desc", [FromQuery] string? category_id = null)
|
||||
{
|
||||
@@ -113,7 +113,7 @@ public class QuotesController : ControllerBase
|
||||
}
|
||||
|
||||
var result = pageQuotes
|
||||
.Select(q => q.ToQuoteShortDTO())
|
||||
.Select(q => q.ToQuoteCompleteDTO())
|
||||
.ToList();
|
||||
|
||||
return Ok(result);
|
||||
@@ -132,7 +132,7 @@ public class QuotesController : ControllerBase
|
||||
/// <response code="200">Returned on valid request</response>
|
||||
/// <response code="404">Returned when quote id is invalid or simply doesn't exist</response>
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(QuoteShortDTO), 200)]
|
||||
[ProducesResponseType(typeof(QuoteCompleteDTO), 200)]
|
||||
[ProducesResponseType(typeof(ErrorDTO), 404)]
|
||||
public async Task<IActionResult> GetQuoteById(int id)
|
||||
{
|
||||
@@ -147,7 +147,7 @@ public class QuotesController : ControllerBase
|
||||
if (quote == null)
|
||||
return NotFound(new { status = "error", error_msg = "Quote not found" });
|
||||
|
||||
return Ok(quote.ToQuoteShortDTO());
|
||||
return Ok(quote.ToQuoteCompleteDTO());
|
||||
}
|
||||
|
||||
// POST /api/v1/quotes/new
|
||||
|
||||
14
DTOs/QuoteCompleteDTO.cs
Normal file
14
DTOs/QuoteCompleteDTO.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace QuotifyBE.DTOs;
|
||||
|
||||
public record class QuoteCompleteDTO
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Author { get; set; } = string.Empty;
|
||||
public string? ImageUrl { get; set; }
|
||||
public List<string>? Categories { get; set; } = new();
|
||||
public DateTime? createDate { get; set; }
|
||||
public DateTime? updateDate { get; set; }
|
||||
|
||||
};
|
||||
|
||||
@@ -29,4 +29,28 @@ public static class QuoteMapping
|
||||
Categories = categoryNames
|
||||
};
|
||||
}
|
||||
|
||||
public static QuoteCompleteDTO ToQuoteCompleteDTO(this Quote quote)
|
||||
{
|
||||
|
||||
List<string> categoryNames = [];
|
||||
if (quote.QuoteCategories != null)
|
||||
{
|
||||
foreach (QuoteCategory quoteCategory in quote.QuoteCategories)
|
||||
{
|
||||
categoryNames.Add(quoteCategory.Category!.Name ?? $"Unnamed category {quoteCategory.CategoryId}");
|
||||
}
|
||||
}
|
||||
|
||||
return new QuoteCompleteDTO
|
||||
{
|
||||
Id = quote.Id,
|
||||
Text = quote.Text,
|
||||
Author = quote.Author,
|
||||
ImageUrl = quote.Image?.Url,
|
||||
Categories = categoryNames,
|
||||
createDate = quote.CreatedAt,
|
||||
updateDate = quote.LastUpdatedAt
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user