GuestLog - StayEntry detail view and improvements:

- Added detail view for StayEntries.
- Added button to delete StayEntries.
- Improve queries of StayEntries using a "query config" record.
- Enabled LazyLoading for all database relations. This will make easier to find cases where required relations aren't explicitly loaded.
This commit is contained in:
2026-08-17 21:28:26 +02:00
parent 3e0ef34f66
commit 67845e250f
15 changed files with 229 additions and 45 deletions
@@ -12,7 +12,7 @@ public class StayEntryDTO
public string? PaymentMethod { get; set; }
public List<GuestDocumentDTO> GuestDocuments { get; set; } = [];
public List<GuestDocumentDTO>? GuestDocuments { get; set; } = null;
public DateTime? CreateTime { get; set; }
+2 -2
View File
@@ -33,7 +33,7 @@ internal static class EntityMapping
};
}
public static StayEntryDTO MapStayEntryEntityToDTO(StayEntry entity)
public static StayEntryDTO MapStayEntryEntityToDTO(StayEntry entity, bool includeGuests)
{
return new()
{
@@ -45,7 +45,7 @@ internal static class EntityMapping
PaymentMethod = entity.PaymentMethod,
CreateTime = entity.CreateTime,
UpdateTime = entity.UpdateTime,
GuestDocuments = [.. entity.GuestDocuments.Select(e => MapGuestDocumentEntityToDTO(e))],
GuestDocuments = includeGuests ? [.. entity.GuestDocuments.Select(e => MapGuestDocumentEntityToDTO(e))] : null,
};
}
@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using Somnia.GuestLog.Models.Entities;
namespace Somnia.GuestLog.Models.QueryConfigs;
public record StayEntryQueryConfig(bool IncludeGuests = false, bool UseSplitQueries = true, bool DisableTracking = false)
{
public readonly static StayEntryQueryConfig DefaultQueryConfig = new();
}
public static class StayEntryQueryExtensions
{
public static IQueryable<StayEntry> AddQueryConfig(this IQueryable<StayEntry> query, StayEntryQueryConfig? config)
{
config ??= StayEntryQueryConfig.DefaultQueryConfig;
if (config.IncludeGuests)
{
query = query.Include(e => e.GuestDocuments);
}
if (config.UseSplitQueries)
{
query = query.AsSplitQuery();
}
if (config.DisableTracking)
{
query = query.AsNoTracking();
}
return query;
}
}