refactor: Refactor Get connections

This commit is contained in:
2024-12-26 14:23:50 +01:00
parent feb47b1f8e
commit e33c270fde
11 changed files with 431 additions and 145 deletions

View File

@@ -1,55 +0,0 @@
namespace ConnectionsAPI.Models
{
public class ConnectionsPuzzleDTO
{
public static ConnectionsPuzzleDTO FromEntity(Database.Entities.ConnectionsPuzzle dbPuzzle) =>
new()
{
PuzzleNumber = dbPuzzle.Index,
PrintDate = dbPuzzle.PrintDate,
Editor = dbPuzzle.EditorName,
NextPuzzle = dbPuzzle.NextPrintDate ?? string.Empty,
PreviousPuzzle = dbPuzzle.PrevPrintDate ?? string.Empty,
Categories = dbPuzzle.Categories.OrderBy(x => (int)x.Color).Select(PuzzleCategoryDTO.FromEntity).ToList(),
};
public int PuzzleNumber { get; set; }
public string PrintDate { get; set; } = string.Empty;
public string PreviousPuzzle { get; set; } = string.Empty;
public string NextPuzzle { get; set; } = string.Empty;
public string Editor { get; set; } = string.Empty;
public ICollection<PuzzleCategoryDTO> Categories { get; set; } = [];
}
public class PuzzleCategoryDTO
{
public static PuzzleCategoryDTO FromEntity(Database.Entities.ConnectionsCategory dbCategory) =>
new()
{
Title = dbCategory.Name,
Cards = dbCategory.Cards.OrderBy(x => x.Content).Select(PuzzleCardDTO.FromEntity).ToList(),
Color = dbCategory.Color.ToString().ToLower(),
OrderingKey = (int)dbCategory.Color
};
public string Title { get; set; } = string.Empty;
public string Color { get; set; } = string.Empty;
public int OrderingKey { get; set; }
public ICollection<PuzzleCardDTO> Cards { get; set; } = [];
}
public class PuzzleCardDTO
{
public static PuzzleCardDTO FromEntity(Database.Entities.ConnectionsCard dbCard) =>
new()
{
Content = dbCard.Content,
Position = dbCard.Position,
};
public string Content { get; set; } = string.Empty;
public int Position { get; set; }
}
}

View File

@@ -0,0 +1,3 @@
namespace ConnectionsAPI.Models.Request;
public record GetPuzzleRequest(string PrintDate);

View File

@@ -0,0 +1,53 @@
namespace ConnectionsAPI.Models.Response;
public class ConnectionsPuzzleDTO
{
public static ConnectionsPuzzleDTO FromEntity(Database.Entities.ConnectionsPuzzle dbPuzzle) =>
new()
{
PuzzleNumber = dbPuzzle.Index,
PrintDate = dbPuzzle.PrintDate,
Editor = dbPuzzle.EditorName,
NextPuzzle = dbPuzzle.NextPrintDate ?? string.Empty,
PreviousPuzzle = dbPuzzle.PrevPrintDate ?? string.Empty,
Categories = dbPuzzle.Categories.OrderBy(x => (int)x.Color).Select(PuzzleCategoryDTO.FromEntity).ToList(),
};
public int PuzzleNumber { get; set; }
public string PrintDate { get; set; } = string.Empty;
public string PreviousPuzzle { get; set; } = string.Empty;
public string NextPuzzle { get; set; } = string.Empty;
public string Editor { get; set; } = string.Empty;
public ICollection<PuzzleCategoryDTO> Categories { get; set; } = [];
}
public class PuzzleCategoryDTO
{
public static PuzzleCategoryDTO FromEntity(Database.Entities.ConnectionsCategory dbCategory) =>
new()
{
Title = dbCategory.Name,
Cards = dbCategory.Cards.OrderBy(x => x.Content).Select(PuzzleCardDTO.FromEntity).ToList(),
Color = dbCategory.Color.ToString().ToLower(),
OrderingKey = (int)dbCategory.Color
};
public string Title { get; set; } = string.Empty;
public string Color { get; set; } = string.Empty;
public int OrderingKey { get; set; }
public ICollection<PuzzleCardDTO> Cards { get; set; } = [];
}
public class PuzzleCardDTO
{
public static PuzzleCardDTO FromEntity(Database.Entities.ConnectionsCard dbCard) =>
new()
{
Content = dbCard.Content,
Position = dbCard.Position,
};
public string Content { get; set; } = string.Empty;
public int Position { get; set; }
}