mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 19:00:07 +01:00
33 lines
804 B
C#
33 lines
804 B
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
|
|
};
|
|
}
|
|
}
|