mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 23:00:07 +01:00
fix: db model fixes and quote mapping
This commit is contained in:
32
Mapping/QuoteMapping.cs
Normal file
32
Mapping/QuoteMapping.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using QuotifyBE.Data;
|
||||
using QuotifyBE.DTOs;
|
||||
using QuotifyBE.Entities;
|
||||
|
||||
namespace QuotifyBE.Mapping;
|
||||
|
||||
public static class QuoteMapping
|
||||
{
|
||||
|
||||
public static QuoteShortDTO ToQuoteShortDTO(this Quote quote, ApplicationDbContext db)
|
||||
{
|
||||
|
||||
List<string> categoryNames = [];
|
||||
if (quote.QuoteCategories != null)
|
||||
{
|
||||
foreach (QuoteCategory quoteCategory in quote.QuoteCategories)
|
||||
{
|
||||
categoryNames.Add(quoteCategory.Category!.Name ?? $"Unnamed category {quoteCategory.CategoryId}");
|
||||
}
|
||||
}
|
||||
|
||||
return new QuoteShortDTO
|
||||
{
|
||||
Id = quote.Id,
|
||||
Text = quote.Text,
|
||||
Author = quote.Author,
|
||||
ImageUrl = quote.Image?.Url,
|
||||
Categories = categoryNames
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user