mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 08:10:07 +01:00
57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
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)
|
|
{
|
|
|
|
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
|
|
};
|
|
}
|
|
|
|
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
|
|
};
|
|
}
|
|
}
|