From 07b18aa9f44c20518c4f38387685eafd6c4c31c5 Mon Sep 17 00:00:00 2001 From: Mads Heimdal Thy Date: Fri, 4 Dec 2026 12:59:24 +0100 Subject: [PATCH 1/5] Add food administration, pickup and exchange --- .../Controllers/FoodController.cs | 191 + .../Controllers/FoodOperationsController.cs | 176 + .../Controllers/ResourcesControllers.cs | 34 - .../src/Fastasys.ApiService/Data/DbSeeder.cs | 6 +- .../Data/Entities/FoodServing.cs | 47 + .../Data/Entities/Resources.cs | 5 + .../Data/InfosysDbContext.cs | 13 + ...20261204115334_AddFoodServings.Designer.cs | 3863 +++++++++++++++++ .../20261204115334_AddFoodServings.cs | 182 + .../InfosysDbContextModelSnapshot.cs | 179 + backend/src/Fastasys.ApiService/Program.cs | 9 +- .../Services/FoodOrders.cs | 57 + backend/tests/Fastasys.Tests/FoodTests.cs | 113 + frontend/public/assets/i18n/da.json | 86 + frontend/public/assets/i18n/en.json | 86 + frontend/src/app/app.routes.ts | 5 +- .../app/features/resources/food/food-api.ts | 141 + .../features/resources/food/food-pickup.html | 107 + .../resources/food/food-pickup.spec.ts | 107 + .../features/resources/food/food-pickup.ts | 158 + .../src/app/features/resources/food/food.html | 336 +- .../src/app/features/resources/food/food.scss | 161 +- .../src/app/features/resources/food/food.ts | 278 +- .../components/toolbar/toolbar-navigation.ts | 19 +- .../src/app/shared/types/resources.types.ts | 5 + 25 files changed, 6243 insertions(+), 121 deletions(-) create mode 100644 backend/src/Fastasys.ApiService/Controllers/FoodController.cs create mode 100644 backend/src/Fastasys.ApiService/Controllers/FoodOperationsController.cs create mode 100644 backend/src/Fastasys.ApiService/Data/Entities/FoodServing.cs create mode 100644 backend/src/Fastasys.ApiService/Data/Migrations/20261204115334_AddFoodServings.Designer.cs create mode 100644 backend/src/Fastasys.ApiService/Data/Migrations/20261204115334_AddFoodServings.cs create mode 100644 backend/src/Fastasys.ApiService/Services/FoodOrders.cs create mode 100644 backend/tests/Fastasys.Tests/FoodTests.cs create mode 100644 frontend/src/app/features/resources/food/food-api.ts create mode 100644 frontend/src/app/features/resources/food/food-pickup.html create mode 100644 frontend/src/app/features/resources/food/food-pickup.spec.ts create mode 100644 frontend/src/app/features/resources/food/food-pickup.ts diff --git a/backend/src/Fastasys.ApiService/Controllers/FoodController.cs b/backend/src/Fastasys.ApiService/Controllers/FoodController.cs new file mode 100644 index 0000000..dd6b497 --- /dev/null +++ b/backend/src/Fastasys.ApiService/Controllers/FoodController.cs @@ -0,0 +1,191 @@ +using System.ComponentModel.DataAnnotations; +using Fastasys.ApiService.Data; +using Fastasys.ApiService.Data.Entities; +using Fastasys.ApiService.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Npgsql; + +namespace Fastasys.ApiService.Controllers; + +public record FoodTypeRequest([Required, MaxLength(256)] string Name, [Required, MaxLength(256)] string NameEnglish, + [Required] decimal? Price, [Required] MealPeriod? MealPeriod, [Required] FoodDiet? Diet); + +public record FoodServingRequest([Required] DateOnly? Date, [Required] MealPeriod? MealPeriod, + [Required] TimeOnly? StartsAt, [Required] TimeOnly? EndsAt, [Required] int[] FoodTypeIds); + +public record FoodServingDto(int Id, DateOnly Date, MealPeriod MealPeriod, TimeOnly StartsAt, TimeOnly EndsAt, int[] FoodTypeIds, bool IsCurrent); + +public record FoodServingCount(int FoodTypeId, int Ordered, int HandedOut); + +public record OrderFoodDto(int ParticipantId, int FoodTypeId, DateTime Date, int Quantity = 1); + +public record SetFoodOrderDto(int ParticipantId, int FoodTypeId, [Required, Range(0, int.MaxValue)] int? Quantity); + +[ApiController] +[Authorize] +[Route("api/food")] +public class FoodController(InfosysDbContext db) : ControllerBase +{ + [AllowAnonymous] + [HttpGet("types")] + public Task> GetTypes(CancellationToken ct) => + db.FoodTypes.AsNoTracking().Where(food => food.IsActive).OrderBy(food => food.Name).ToListAsync(ct); + + [HttpPost("types")] + [Authorize(Policy = "FoodManagement")] + public async Task> CreateType(FoodTypeRequest request, CancellationToken ct) + { + var food = new FoodType(); + if (!ApplyType(food, request)) return BadRequest(new { code = "invalidType" }); + db.FoodTypes.Add(food); + await db.SaveChangesAsync(ct); + return StatusCode(StatusCodes.Status201Created, food); + } + + [HttpPut("types/{id:int}")] + [Authorize(Policy = "FoodManagement")] + public async Task> UpdateType(int id, FoodTypeRequest request, CancellationToken ct) + { + await using var transaction = await FoodOrders.LockTypes(db, [id], ct); + var food = await db.FoodTypes.FindAsync([id], ct); + if (food is null) return NotFound(new { code = "typeNotFound" }); + if (food.MealPeriod != request.MealPeriod && await db.FoodServings.AnyAsync(serving => serving.FoodTypes.Any(type => type.Id == id), ct)) + return Conflict(new { code = "typeAssigned" }); + if (!ApplyType(food, request)) return BadRequest(new { code = "invalidType" }); + + await db.SaveChangesAsync(ct); + if (transaction is not null) await transaction.CommitAsync(ct); + return food; + } + + [HttpGet("servings")] + [Authorize(Policy = "FoodServingView")] + public async Task> GetServings(CancellationToken ct) + { + var now = FoodOrders.LocalNow(); + var servings = await db.FoodServings.AsNoTracking().Include(s => s.FoodTypes) + .OrderBy(s => s.Date).ThenBy(s => s.StartsAt).ToListAsync(ct); + return servings.Select(s => MapServing(s, now)).ToArray(); + } + + [HttpPost("servings")] + [Authorize(Policy = "FoodManagement")] + public async Task> CreateServing(FoodServingRequest request, CancellationToken ct) + { + if (request.Date is not DateOnly date || request.MealPeriod is not MealPeriod period || !Enum.IsDefined(period) || + request.StartsAt is not TimeOnly starts || request.EndsAt is not TimeOnly ends || ends <= starts) + return BadRequest(new { code = "invalidServing" }); + + var ids = request.FoodTypeIds.Distinct().ToArray(); + if (ids.Length == 0) return BadRequest(new { code = "invalidServingTypes" }); + await using var transaction = await FoodOrders.LockTypes(db, ids, ct); + var types = await db.FoodTypes.Where(food => ids.Contains(food.Id) && food.IsActive && food.MealPeriod == period).ToListAsync(ct); + if (ids.Length != types.Count) return BadRequest(new { code = "invalidServingTypes" }); + if (await db.FoodServings.AnyAsync(s => s.Date == date && s.MealPeriod == period, ct)) + return Conflict(new { code = "servingExists" }); + + var serving = new FoodServing { Date = date, MealPeriod = period, StartsAt = starts, EndsAt = ends, FoodTypes = types }; + db.FoodServings.Add(serving); + try + { + await db.SaveChangesAsync(ct); + if (transaction is not null) await transaction.CommitAsync(ct); + } + catch (DbUpdateException e) when (e.InnerException is PostgresException { SqlState: PostgresErrorCodes.UniqueViolation }) + { + return Conflict(new { code = "servingExists" }); + } + return StatusCode(StatusCodes.Status201Created, MapServing(serving, FoodOrders.LocalNow())); + } + + [HttpGet("servings/{id:int}/counts")] + [Authorize(Policy = "FoodServingView")] + public async Task>> GetCounts(int id, CancellationToken ct) + { + var serving = await FoodOrders.GetServing(db, id, ct); + if (serving is null) return NotFound(new { code = "servingNotFound" }); + var counts = await FoodOrders.ForServing(db, serving).AsNoTracking() + .Select(order => new FoodServingCount(order.FoodTypeId, order.Quantity, order.Handouts.Count(h => h.UndoneAt == null))) + .ToListAsync(ct); + var byType = counts.ToLookup(row => row.FoodTypeId); + return Ok(serving.FoodTypes.Select(type => new FoodServingCount(type.Id, byType[type.Id].Sum(row => row.Ordered), byType[type.Id].Sum(row => row.HandedOut)))); + } + + [HttpPut("servings/{id:int}/order")] + [Authorize(Policy = "FoodOrdering")] + public async Task SetOrder(int id, SetFoodOrderDto request, CancellationToken ct) + { + await using var transaction = await FoodOrders.LockServing(db, id, ct); + var serving = await FoodOrders.GetServing(db, id, ct); + if (serving is null) return NotFound(new { code = "servingNotFound" }); + if (!serving.FoodTypes.Any(type => type.Id == request.FoodTypeId) || request.Quantity is not int quantity || quantity < 0) + return BadRequest(new { code = "invalidOrder" }); + if (!await db.Participants.AnyAsync(p => p.Id == request.ParticipantId && !p.IsAnnulled, ct)) + return NotFound(new { code = "participantNotFound" }); + + var date = FoodOrders.OrderDate(serving.Date); + var order = await db.ParticipantFoods.FindAsync([request.ParticipantId, request.FoodTypeId, date], ct); + if (order is null) + { + if (quantity > 0) + db.ParticipantFoods.Add(new ParticipantFood { ParticipantId = request.ParticipantId, FoodTypeId = request.FoodTypeId, Date = date, Quantity = quantity }); + } + else + { + if (quantity < await FoodOrders.AllocatedQuantity(db, order, ct)) return Conflict(new { code = "orderAlreadyAllocated" }); + order.Quantity = quantity; + } + + await db.SaveChangesAsync(ct); + if (transaction is not null) await transaction.CommitAsync(ct); + return NoContent(); + } + + [HttpPost("order")] + [Authorize(Policy = "FoodOrdering")] + public async Task OrderFood(OrderFoodDto request, CancellationToken ct) + { + if (request.Quantity <= 0) return BadRequest(new { code = "invalidOrder" }); + if (!await db.FoodTypes.AnyAsync(food => food.Id == request.FoodTypeId && food.IsActive, ct)) + return NotFound(new { code = "typeNotFound" }); + if (!await db.Participants.AnyAsync(p => p.Id == request.ParticipantId && !p.IsAnnulled, ct)) + return NotFound(new { code = "participantNotFound" }); + + var date = FoodOrders.OrderDate(DateOnly.FromDateTime(request.Date)); + if (await db.ParticipantFoods.AnyAsync(o => o.ParticipantId == request.ParticipantId && o.FoodTypeId == request.FoodTypeId && o.Date == date, ct)) + return Conflict(new { code = "orderExists" }); + db.ParticipantFoods.Add(new ParticipantFood { ParticipantId = request.ParticipantId, FoodTypeId = request.FoodTypeId, Date = date, Quantity = request.Quantity }); + try + { + await db.SaveChangesAsync(ct); + } + catch (DbUpdateException e) when (e.InnerException is PostgresException { SqlState: PostgresErrorCodes.UniqueViolation }) + { + return Conflict(new { code = "orderExists" }); + } + return Ok(new { message = "Food ordered successfully" }); + } + + private static bool ApplyType(FoodType food, FoodTypeRequest request) + { + if (string.IsNullOrWhiteSpace(request.Name) || string.IsNullOrWhiteSpace(request.NameEnglish) || + request.Price is not decimal price || price < 0 || price != decimal.Round(price, 2) || + request.MealPeriod is not MealPeriod period || !Enum.IsDefined(period) || + request.Diet is not FoodDiet diet || !Enum.IsDefined(diet)) return false; + + food.Name = request.Name.Trim(); + food.NameEnglish = request.NameEnglish.Trim(); + food.Price = price; + food.MealPeriod = period; + food.Diet = diet; + return true; + } + + private static FoodServingDto MapServing(FoodServing serving, DateTime now) => new( + serving.Id, serving.Date, serving.MealPeriod, serving.StartsAt, serving.EndsAt, + serving.FoodTypes.Select(type => type.Id).Order().ToArray(), + DateOnly.FromDateTime(now) == serving.Date && TimeOnly.FromDateTime(now) >= serving.StartsAt && TimeOnly.FromDateTime(now) < serving.EndsAt + ); +} diff --git a/backend/src/Fastasys.ApiService/Controllers/FoodOperationsController.cs b/backend/src/Fastasys.ApiService/Controllers/FoodOperationsController.cs new file mode 100644 index 0000000..d3c5569 --- /dev/null +++ b/backend/src/Fastasys.ApiService/Controllers/FoodOperationsController.cs @@ -0,0 +1,176 @@ +using Fastasys.ApiService.Data; +using Fastasys.ApiService.Data.Entities; +using Fastasys.ApiService.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Fastasys.ApiService.Controllers; + +public record FoodPortionRequest(Guid RequestId, int ParticipantId, int FoodTypeId); +public record FoodTransferRequest(int BuyerId); +public record FoodParticipantDto(int Id, string Name, IReadOnlyList Orders); +public record FoodParticipantOrder(int FoodTypeId, int Ordered, int HandedOut, int Offered) +{ + public int Remaining => Ordered - HandedOut - Offered; +} + +public record FoodOfferDto(Guid Id, int ParticipantId, string ParticipantName, int FoodTypeId); + +[ApiController] +[Route("api/food/servings/{servingId:int}")] +public class FoodOperationsController(InfosysDbContext db) : ControllerBase +{ + [HttpGet("participants/{lookup}")] + [Authorize(Policy = "FoodParticipantLookup")] + public async Task> GetParticipant(int servingId, string lookup, CancellationToken ct) + { + var serving = await FoodOrders.GetServing(db, servingId, ct); + if (serving is null) return NotFound(new { code = "servingNotFound" }); + + var number = ParticipantRules.IdFromBarcode(lookup, serving.Date.Year) ?? + (int.TryParse(lookup, out var participantId) ? participantId : 0); + if (number is <= 0 or > int.MaxValue) return NotFound(new { code = "participantNotFound" }); + var participant = await db.Participants.AsNoTracking().SingleOrDefaultAsync(p => p.Id == number && !p.IsAnnulled, ct); + if (participant is null) return NotFound(new { code = "participantNotFound" }); + + var orders = await FoodOrders.ForServing(db, serving) + .Where(item => item.ParticipantId == number && item.Quantity > 0) + .OrderBy(item => item.FoodTypeId) + .Select(item => new FoodParticipantOrder(item.FoodTypeId, item.Quantity, + item.Handouts.Count(h => h.UndoneAt == null), item.Offers.Count(o => o.ClosedAt == null))) + .ToListAsync(ct); + return new FoodParticipantDto(participant.Id, participant.DisplayName(), orders); + } + + [HttpPost("handouts")] + [Authorize(Policy = "FoodDistribution")] + public async Task HandOut(int servingId, FoodPortionRequest request, CancellationToken ct) + { + if (request.RequestId == Guid.Empty) return BadRequest(new { code = "invalidOrder" }); + await using var transaction = await FoodOrders.LockServing(db, servingId, ct); + var serving = await FoodOrders.GetServing(db, servingId, ct); + if (serving is null) return NotFound(new { code = "servingNotFound" }); + + var existing = await db.FoodHandouts.FindAsync([request.RequestId], ct); + if (existing is not null) + return existing.ServingId == servingId && existing.ParticipantId == request.ParticipantId && + existing.FoodTypeId == request.FoodTypeId && existing.UndoneAt is null + ? Ok(new { id = existing.Id }) + : Conflict(new { code = "portionUnavailable" }); + + var order = await FindOrder(serving, request, ct); + if (order is null || order.Quantity <= await FoodOrders.AllocatedQuantity(db, order, ct)) + return Conflict(new { code = "portionUnavailable" }); + + var handout = new FoodHandout { Id = request.RequestId, ServingId = servingId, Order = order, HandedOutAt = DateTime.UtcNow }; + db.FoodHandouts.Add(handout); + await db.SaveChangesAsync(ct); + if (transaction is not null) await transaction.CommitAsync(ct); + return Ok(new { id = handout.Id }); + } + + [HttpPut("handouts/{id:guid}/undo")] + [Authorize(Policy = "FoodDistribution")] + public async Task UndoHandout(int servingId, Guid id, CancellationToken ct) + { + await using var transaction = await FoodOrders.LockServing(db, servingId, ct); + var handout = await db.FoodHandouts.SingleOrDefaultAsync(h => h.ServingId == servingId && h.Id == id, ct); + if (handout is null) return NotFound(new { code = "handoutNotFound" }); + handout.UndoneAt ??= DateTime.UtcNow; + await db.SaveChangesAsync(ct); + if (transaction is not null) await transaction.CommitAsync(ct); + return NoContent(); + } + + [HttpGet("offers")] + [Authorize(Policy = "FoodMarketplaceView")] + public async Task> GetOffers(int servingId, CancellationToken ct) + { + var offers = await db.FoodOffers.AsNoTracking().Include(offer => offer.Order.Participant) + .Where(o => o.ServingId == servingId && o.ClosedAt == null && !o.Order.Participant.IsAnnulled) + .OrderBy(o => o.OfferedAt).ToListAsync(ct); + return offers.Select(o => new FoodOfferDto(o.Id, o.ParticipantId, o.Order.Participant.DisplayName(), o.FoodTypeId)).ToArray(); + } + + [HttpPost("offers")] + [Authorize(Policy = "FoodMarketplace")] + public async Task CreateOffer(int servingId, FoodPortionRequest request, CancellationToken ct) + { + if (request.RequestId == Guid.Empty) return BadRequest(new { code = "invalidOrder" }); + await using var transaction = await FoodOrders.LockServing(db, servingId, ct); + var serving = await FoodOrders.GetServing(db, servingId, ct); + if (serving is null) return NotFound(new { code = "servingNotFound" }); + + var existing = await db.FoodOffers.FindAsync([request.RequestId], ct); + if (existing is not null) + return existing.ServingId == servingId && existing.ParticipantId == request.ParticipantId && + existing.FoodTypeId == request.FoodTypeId && existing.ClosedAt is null + ? NoContent() + : Conflict(new { code = "offerClosed" }); + + var order = await FindOrder(serving, request, ct); + if (order is null || order.Quantity <= await FoodOrders.AllocatedQuantity(db, order, ct)) + return Conflict(new { code = "portionUnavailable" }); + + db.FoodOffers.Add(new FoodOffer { Id = request.RequestId, ServingId = servingId, Order = order, OfferedAt = DateTime.UtcNow }); + await db.SaveChangesAsync(ct); + if (transaction is not null) await transaction.CommitAsync(ct); + return NoContent(); + } + + [HttpPut("offers/{id:guid}/transfer")] + [Authorize(Policy = "FoodMarketplace")] + public async Task TransferOffer(int servingId, Guid id, FoodTransferRequest request, CancellationToken ct) + { + await using var transaction = await FoodOrders.LockServing(db, servingId, ct); + var offer = await db.FoodOffers.Include(o => o.Order.Participant).SingleOrDefaultAsync(o => o.ServingId == servingId && o.Id == id, ct); + if (offer is null) return NotFound(new { code = "offerNotFound" }); + if (offer.ClosedAt is not null) return offer.BuyerId == request.BuyerId ? NoContent() : Conflict(new { code = "offerClosed" }); + if (offer.ParticipantId == request.BuyerId) return BadRequest(new { code = "sameParticipant" }); + if (offer.Order.Participant.IsAnnulled || offer.Order.Quantity <= 0) return Conflict(new { code = "portionUnavailable" }); + if (!await db.Participants.AnyAsync(p => p.Id == request.BuyerId && !p.IsAnnulled, ct)) + return NotFound(new { code = "participantNotFound" }); + + var order = await db.ParticipantFoods.FindAsync([request.BuyerId, offer.FoodTypeId, offer.OrderDate], ct); + if (order?.Quantity == int.MaxValue) return Conflict(new { code = "invalidOrder" }); + if (order is null) + { + db.ParticipantFoods.Add(new ParticipantFood + { + ParticipantId = request.BuyerId, + Date = offer.OrderDate, + FoodTypeId = offer.FoodTypeId, + Quantity = 1 + }); + } + else + { + order.Quantity++; + } + + offer.Order.Quantity--; + offer.BuyerId = request.BuyerId; + offer.ClosedAt = DateTime.UtcNow; + await db.SaveChangesAsync(ct); + if (transaction is not null) await transaction.CommitAsync(ct); + return NoContent(); + } + + [HttpDelete("offers/{id:guid}")] + [Authorize(Policy = "FoodMarketplace")] + public async Task CancelOffer(int servingId, Guid id, CancellationToken ct) + { + await using var transaction = await FoodOrders.LockServing(db, servingId, ct); + var offer = await db.FoodOffers.SingleOrDefaultAsync(o => o.ServingId == servingId && o.Id == id, ct); + if (offer is null) return NotFound(new { code = "offerNotFound" }); + if (offer.BuyerId is not null) return Conflict(new { code = "offerClosed" }); + offer.ClosedAt ??= DateTime.UtcNow; + await db.SaveChangesAsync(ct); + if (transaction is not null) await transaction.CommitAsync(ct); + return NoContent(); + } + + private Task FindOrder(FoodServing serving, FoodPortionRequest request, CancellationToken ct) => + FoodOrders.ForServing(db, serving).SingleOrDefaultAsync(o => o.ParticipantId == request.ParticipantId && o.FoodTypeId == request.FoodTypeId, ct); +} diff --git a/backend/src/Fastasys.ApiService/Controllers/ResourcesControllers.cs b/backend/src/Fastasys.ApiService/Controllers/ResourcesControllers.cs index d0b446d..77129b8 100644 --- a/backend/src/Fastasys.ApiService/Controllers/ResourcesControllers.cs +++ b/backend/src/Fastasys.ApiService/Controllers/ResourcesControllers.cs @@ -6,44 +6,10 @@ namespace Fastasys.ApiService.Controllers; -public record OrderFoodDto(int ParticipantId, int FoodTypeId, DateTime Date, int Quantity = 1); - public record OrderWearDto(int ParticipantId, int WearItemId, int Quantity = 1); public record CreateRoomDto(string Name, string Location, int Capacity, string Description); -[ApiController] -[Route("api/[controller]")] -public class FoodController(InfosysDbContext db) : ControllerBase -{ - [HttpGet("types")] - public async Task GetTypes() - { - var types = await db.FoodTypes.AsNoTracking().Where(f => f.IsActive).ToListAsync(); - return Ok(types); - } - - [HttpPost("order")] - public async Task OrderFood([FromBody] OrderFoodDto dto) - { - var food = await db.FoodTypes.FindAsync(dto.FoodTypeId); - if (food == null) - return NotFound(new { message = "Food type not found" }); - - var participantFood = new ParticipantFood - { - ParticipantId = dto.ParticipantId, - FoodTypeId = dto.FoodTypeId, - Date = dto.Date.Date, - Quantity = dto.Quantity, - }; - - db.ParticipantFoods.Add(participantFood); - await db.SaveChangesAsync(); - return Ok(new { message = "Food ordered successfully" }); - } -} - [ApiController] [Route("api/[controller]")] public class WearController(InfosysDbContext db) : ControllerBase diff --git a/backend/src/Fastasys.ApiService/Data/DbSeeder.cs b/backend/src/Fastasys.ApiService/Data/DbSeeder.cs index 99b23ff..a710839 100644 --- a/backend/src/Fastasys.ApiService/Data/DbSeeder.cs +++ b/backend/src/Fastasys.ApiService/Data/DbSeeder.cs @@ -252,9 +252,9 @@ public static void Seed(InfosysDbContext db) // Demo Food Types db.FoodTypes.AddRange( - new FoodType { Name = "Morgenmad", NameEnglish = "Breakfast", Price = 45.00m, IsActive = true }, - new FoodType { Name = "Aftensmad (Kød)", NameEnglish = "Dinner (Meat)", Price = 85.00m, IsActive = true }, - new FoodType { Name = "Aftensmad (Vegansk)", NameEnglish = "Dinner (Vegan)", Price = 85.00m, IsActive = true } + new FoodType { Name = "Morgenmad", NameEnglish = "Breakfast", Price = 45.00m, IsActive = true, MealPeriod = MealPeriod.Breakfast, Diet = FoodDiet.Standard }, + new FoodType { Name = "Aftensmad (Kød)", NameEnglish = "Dinner (Meat)", Price = 85.00m, IsActive = true, MealPeriod = MealPeriod.Dinner, Diet = FoodDiet.Standard }, + new FoodType { Name = "Aftensmad (Vegansk)", NameEnglish = "Dinner (Vegan)", Price = 85.00m, IsActive = true, MealPeriod = MealPeriod.Dinner, Diet = FoodDiet.Vegan } ); // Demo Wear Items diff --git a/backend/src/Fastasys.ApiService/Data/Entities/FoodServing.cs b/backend/src/Fastasys.ApiService/Data/Entities/FoodServing.cs new file mode 100644 index 0000000..886e05b --- /dev/null +++ b/backend/src/Fastasys.ApiService/Data/Entities/FoodServing.cs @@ -0,0 +1,47 @@ +using System.Text.Json.Serialization; + +namespace Fastasys.ApiService.Data.Entities; + +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum MealPeriod { Breakfast, Lunch, Dinner } + +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum FoodDiet { Standard, Vegetarian, Vegan } + +// Times are local to the convention, in Europe/Copenhagen. A food order already identifies the day and dish. +public class FoodServing +{ + public int Id { get; set; } + public DateOnly Date { get; set; } + public MealPeriod MealPeriod { get; set; } + public TimeOnly StartsAt { get; set; } + public TimeOnly EndsAt { get; set; } + public ICollection FoodTypes { get; set; } = new List(); +} + +public class FoodHandout +{ + public Guid Id { get; set; } + public int ServingId { get; set; } + public FoodServing Serving { get; set; } = null!; + public int ParticipantId { get; set; } + public int FoodTypeId { get; set; } + public DateTime OrderDate { get; set; } + public ParticipantFood Order { get; set; } = null!; + public DateTime HandedOutAt { get; set; } + public DateTime? UndoneAt { get; set; } +} + +public class FoodOffer +{ + public Guid Id { get; set; } + public int ServingId { get; set; } + public FoodServing Serving { get; set; } = null!; + public int ParticipantId { get; set; } + public int FoodTypeId { get; set; } + public DateTime OrderDate { get; set; } + public ParticipantFood Order { get; set; } = null!; + public DateTime OfferedAt { get; set; } + public DateTime? ClosedAt { get; set; } + public int? BuyerId { get; set; } +} diff --git a/backend/src/Fastasys.ApiService/Data/Entities/Resources.cs b/backend/src/Fastasys.ApiService/Data/Entities/Resources.cs index 99872bd..7abe399 100644 --- a/backend/src/Fastasys.ApiService/Data/Entities/Resources.cs +++ b/backend/src/Fastasys.ApiService/Data/Entities/Resources.cs @@ -18,6 +18,8 @@ public class FoodType public string NameEnglish { get; set; } = string.Empty; public decimal Price { get; set; } public bool IsActive { get; set; } = true; + public MealPeriod? MealPeriod { get; set; } + public FoodDiet? Diet { get; set; } public virtual ICollection ParticipantFoodOrders { get; set; } = new List(); } @@ -30,6 +32,9 @@ public class ParticipantFood public virtual FoodType FoodType { get; set; } = null!; public DateTime Date { get; set; } public int Quantity { get; set; } = 1; + + public ICollection Handouts { get; set; } = new List(); + public ICollection Offers { get; set; } = new List(); } public class WearItem diff --git a/backend/src/Fastasys.ApiService/Data/InfosysDbContext.cs b/backend/src/Fastasys.ApiService/Data/InfosysDbContext.cs index 13ce6bc..d8cbe2e 100644 --- a/backend/src/Fastasys.ApiService/Data/InfosysDbContext.cs +++ b/backend/src/Fastasys.ApiService/Data/InfosysDbContext.cs @@ -36,6 +36,9 @@ public class InfosysDbContext(DbContextOptions options) : DbCo public DbSet Rooms => Set(); public DbSet FoodTypes => Set(); public DbSet ParticipantFoods => Set(); + public DbSet FoodServings => Set(); + public DbSet FoodHandouts => Set(); + public DbSet FoodOffers => Set(); public DbSet WearItems => Set(); public DbSet ParticipantWears => Set(); public DbSet EntranceTypes => Set(); @@ -203,6 +206,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) pf.Date, }); + modelBuilder.Entity().Property(food => food.MealPeriod).HasConversion(); + modelBuilder.Entity().Property(food => food.Diet).HasConversion(); + modelBuilder.Entity().Property(serving => serving.MealPeriod).HasConversion(); + modelBuilder.Entity().HasIndex(serving => new { serving.Date, serving.MealPeriod }).IsUnique(); + modelBuilder.Entity().HasMany(serving => serving.FoodTypes).WithMany().UsingEntity("FoodServingTypes"); + modelBuilder.Entity().HasOne(handout => handout.Order).WithMany(order => order.Handouts) + .HasForeignKey(handout => new { handout.ParticipantId, handout.FoodTypeId, handout.OrderDate }); + modelBuilder.Entity().HasOne(offer => offer.Order).WithMany(order => order.Offers) + .HasForeignKey(offer => new { offer.ParticipantId, offer.FoodTypeId, offer.OrderDate }); + modelBuilder.Entity().HasKey(pw => new { pw.ParticipantId, pw.WearItemId }); } } diff --git a/backend/src/Fastasys.ApiService/Data/Migrations/20261204115334_AddFoodServings.Designer.cs b/backend/src/Fastasys.ApiService/Data/Migrations/20261204115334_AddFoodServings.Designer.cs new file mode 100644 index 0000000..9f09859 --- /dev/null +++ b/backend/src/Fastasys.ApiService/Data/Migrations/20261204115334_AddFoodServings.Designer.cs @@ -0,0 +1,3863 @@ +// +using System; +using Fastasys.ApiService.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Fastasys.ApiService.Data.Migrations +{ + [DbContext(typeof(InfosysDbContext))] + [Migration("20261204115334_AddFoodServings")] + partial class AddFoodServings + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.15") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Activity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("AutoSignupCategory") + .IsRequired() + .HasColumnType("text"); + + b.Property("CanSignUp") + .HasColumnType("boolean"); + + b.Property("DescriptionDanish") + .IsRequired() + .HasColumnType("text"); + + b.Property("DescriptionEnglish") + .IsRequired() + .HasColumnType("text"); + + b.Property("DurationHours") + .HasPrecision(5, 2) + .HasColumnType("numeric(5,2)"); + + b.Property("GameMasterLanguage") + .IsRequired() + .HasColumnType("text"); + + b.Property("GameMastersPerTeam") + .HasColumnType("integer"); + + b.Property("IsHidden") + .HasColumnType("boolean"); + + b.Property("IsReplayable") + .HasColumnType("boolean"); + + b.Property("IsRoomExclusive") + .HasColumnType("boolean"); + + b.Property("IsTimeExclusive") + .HasColumnType("boolean"); + + b.Property("KarmaType") + .HasColumnType("integer"); + + b.Property("MaxPlayersPerTeam") + .HasColumnType("integer"); + + b.Property("MaxSignups") + .HasColumnType("integer"); + + b.Property("MinAge") + .HasColumnType("integer"); + + b.Property("MinPlayersPerTeam") + .HasColumnType("integer"); + + b.Property("Note") + .IsRequired() + .HasColumnType("text"); + + b.Property("PlayerLanguage") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("integer"); + + b.Property("TeaserDanish") + .IsRequired() + .HasColumnType("text"); + + b.Property("TeaserEnglish") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("TitleEnglish") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("WordPressId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("activities"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ActivitySettings", b => + { + b.Property("Id") + .HasColumnType("integer"); + + b.Property("BigKarma") + .HasColumnType("integer"); + + b.Property("MediumKarma") + .HasColumnType("integer"); + + b.Property("SmallKarma") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("activity_settings"); + + b.HasData( + new + { + Id = 1, + BigKarma = 10, + MediumKarma = 0, + SmallKarma = 7 + }); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Boardgame", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("text"); + + b.Property("Barcode") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsPresent") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("MinPlayers") + .HasColumnType("integer"); + + b.Property("PlayingTimeMinutes") + .HasColumnType("integer"); + + b.Property("Publisher") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Boardgames"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.BoardgameLoan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BoardgameId") + .HasColumnType("integer"); + + b.Property("LoanedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("ReturnedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("BoardgameId"); + + b.HasIndex("ParticipantId"); + + b.ToTable("BoardgameLoans"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Country", b => + { + b.Property("Code") + .HasMaxLength(2) + .HasColumnType("character varying(2)"); + + b.Property("NameDanish") + .IsRequired() + .HasColumnType("text"); + + b.Property("NameEnglish") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Code"); + + b.ToTable("countries"); + + b.HasData( + new + { + Code = "AF", + NameDanish = "Afghanistan", + NameEnglish = "Afghanistan" + }, + new + { + Code = "AL", + NameDanish = "Albanien", + NameEnglish = "Albania" + }, + new + { + Code = "DZ", + NameDanish = "Algeriet", + NameEnglish = "Algeria" + }, + new + { + Code = "AS", + NameDanish = "Amerikansk Samoa", + NameEnglish = "American Samoa" + }, + new + { + Code = "AD", + NameDanish = "Andorra", + NameEnglish = "Andorra" + }, + new + { + Code = "AO", + NameDanish = "Angola", + NameEnglish = "Angola" + }, + new + { + Code = "AI", + NameDanish = "Anguilla", + NameEnglish = "Anguilla" + }, + new + { + Code = "AG", + NameDanish = "Antigua og Barbuda", + NameEnglish = "Antigua & Barbuda" + }, + new + { + Code = "AR", + NameDanish = "Argentina", + NameEnglish = "Argentina" + }, + new + { + Code = "AM", + NameDanish = "Armenien", + NameEnglish = "Armenia" + }, + new + { + Code = "AW", + NameDanish = "Aruba", + NameEnglish = "Aruba" + }, + new + { + Code = "AU", + NameDanish = "Australien", + NameEnglish = "Australia" + }, + new + { + Code = "AT", + NameDanish = "Østrig", + NameEnglish = "Austria" + }, + new + { + Code = "AZ", + NameDanish = "Aserbajdsjan", + NameEnglish = "Azerbaijan" + }, + new + { + Code = "BS", + NameDanish = "Bahamas", + NameEnglish = "Bahamas" + }, + new + { + Code = "BH", + NameDanish = "Bahrain", + NameEnglish = "Bahrain" + }, + new + { + Code = "BD", + NameDanish = "Bangladesh", + NameEnglish = "Bangladesh" + }, + new + { + Code = "BB", + NameDanish = "Barbados", + NameEnglish = "Barbados" + }, + new + { + Code = "BY", + NameDanish = "Hviderusland", + NameEnglish = "Belarus" + }, + new + { + Code = "BE", + NameDanish = "Belgien", + NameEnglish = "Belgium" + }, + new + { + Code = "BZ", + NameDanish = "Belize", + NameEnglish = "Belize" + }, + new + { + Code = "BJ", + NameDanish = "Benin", + NameEnglish = "Benin" + }, + new + { + Code = "BM", + NameDanish = "Bermuda", + NameEnglish = "Bermuda" + }, + new + { + Code = "BT", + NameDanish = "Bhutan", + NameEnglish = "Bhutan" + }, + new + { + Code = "BO", + NameDanish = "Bolivia", + NameEnglish = "Bolivia" + }, + new + { + Code = "BA", + NameDanish = "Bosnien-Hercegovina", + NameEnglish = "Bosnia & Herzegovina" + }, + new + { + Code = "BW", + NameDanish = "Botswana", + NameEnglish = "Botswana" + }, + new + { + Code = "BR", + NameDanish = "Brasilien", + NameEnglish = "Brazil" + }, + new + { + Code = "IO", + NameDanish = "Det Britiske Territorium i Det Indiske Ocean", + NameEnglish = "British Indian Ocean Territory" + }, + new + { + Code = "VG", + NameDanish = "De Britiske Jomfruøer", + NameEnglish = "British Virgin Islands" + }, + new + { + Code = "BN", + NameDanish = "Brunei", + NameEnglish = "Brunei" + }, + new + { + Code = "BG", + NameDanish = "Bulgarien", + NameEnglish = "Bulgaria" + }, + new + { + Code = "BF", + NameDanish = "Burkina Faso", + NameEnglish = "Burkina Faso" + }, + new + { + Code = "BI", + NameDanish = "Burundi", + NameEnglish = "Burundi" + }, + new + { + Code = "KH", + NameDanish = "Cambodja", + NameEnglish = "Cambodia" + }, + new + { + Code = "CM", + NameDanish = "Cameroun", + NameEnglish = "Cameroon" + }, + new + { + Code = "CA", + NameDanish = "Canada", + NameEnglish = "Canada" + }, + new + { + Code = "IC", + NameDanish = "Kanariske øer", + NameEnglish = "Canary Islands" + }, + new + { + Code = "CV", + NameDanish = "Kap Verde", + NameEnglish = "Cape Verde" + }, + new + { + Code = "BQ", + NameDanish = "De tidligere Nederlandske Antiller", + NameEnglish = "Caribbean Netherlands" + }, + new + { + Code = "KY", + NameDanish = "Caymanøerne", + NameEnglish = "Cayman Islands" + }, + new + { + Code = "CF", + NameDanish = "Den Centralafrikanske Republik", + NameEnglish = "Central African Republic" + }, + new + { + Code = "EA", + NameDanish = "Ceuta og Melilla", + NameEnglish = "Ceuta & Melilla" + }, + new + { + Code = "TD", + NameDanish = "Tchad", + NameEnglish = "Chad" + }, + new + { + Code = "CL", + NameDanish = "Chile", + NameEnglish = "Chile" + }, + new + { + Code = "CN", + NameDanish = "Kina", + NameEnglish = "China" + }, + new + { + Code = "CX", + NameDanish = "Juleøen", + NameEnglish = "Christmas Island" + }, + new + { + Code = "CC", + NameDanish = "Cocosøerne", + NameEnglish = "Cocos (Keeling) Islands" + }, + new + { + Code = "CO", + NameDanish = "Colombia", + NameEnglish = "Colombia" + }, + new + { + Code = "KM", + NameDanish = "Comorerne", + NameEnglish = "Comoros" + }, + new + { + Code = "CG", + NameDanish = "Congo-Brazzaville", + NameEnglish = "Congo - Brazzaville" + }, + new + { + Code = "CD", + NameDanish = "Congo-Kinshasa", + NameEnglish = "Congo - Kinshasa" + }, + new + { + Code = "CK", + NameDanish = "Cookøerne", + NameEnglish = "Cook Islands" + }, + new + { + Code = "CR", + NameDanish = "Costa Rica", + NameEnglish = "Costa Rica" + }, + new + { + Code = "HR", + NameDanish = "Kroatien", + NameEnglish = "Croatia" + }, + new + { + Code = "CU", + NameDanish = "Cuba", + NameEnglish = "Cuba" + }, + new + { + Code = "CW", + NameDanish = "Curaçao", + NameEnglish = "Curaçao" + }, + new + { + Code = "CY", + NameDanish = "Cypern", + NameEnglish = "Cyprus" + }, + new + { + Code = "CZ", + NameDanish = "Tjekkiet", + NameEnglish = "Czechia" + }, + new + { + Code = "CI", + NameDanish = "Elfenbenskysten", + NameEnglish = "Côte d’Ivoire" + }, + new + { + Code = "DK", + NameDanish = "Danmark", + NameEnglish = "Denmark" + }, + new + { + Code = "DG", + NameDanish = "Diego Garcia", + NameEnglish = "Diego Garcia" + }, + new + { + Code = "DJ", + NameDanish = "Djibouti", + NameEnglish = "Djibouti" + }, + new + { + Code = "DM", + NameDanish = "Dominica", + NameEnglish = "Dominica" + }, + new + { + Code = "DO", + NameDanish = "Den Dominikanske Republik", + NameEnglish = "Dominican Republic" + }, + new + { + Code = "EC", + NameDanish = "Ecuador", + NameEnglish = "Ecuador" + }, + new + { + Code = "EG", + NameDanish = "Egypten", + NameEnglish = "Egypt" + }, + new + { + Code = "SV", + NameDanish = "El Salvador", + NameEnglish = "El Salvador" + }, + new + { + Code = "GQ", + NameDanish = "Ækvatorialguinea", + NameEnglish = "Equatorial Guinea" + }, + new + { + Code = "ER", + NameDanish = "Eritrea", + NameEnglish = "Eritrea" + }, + new + { + Code = "EE", + NameDanish = "Estland", + NameEnglish = "Estonia" + }, + new + { + Code = "SZ", + NameDanish = "Eswatini", + NameEnglish = "Eswatini" + }, + new + { + Code = "ET", + NameDanish = "Etiopien", + NameEnglish = "Ethiopia" + }, + new + { + Code = "FK", + NameDanish = "Falklandsøerne", + NameEnglish = "Falkland Islands" + }, + new + { + Code = "FO", + NameDanish = "Færøerne", + NameEnglish = "Faroe Islands" + }, + new + { + Code = "FJ", + NameDanish = "Fiji", + NameEnglish = "Fiji" + }, + new + { + Code = "FI", + NameDanish = "Finland", + NameEnglish = "Finland" + }, + new + { + Code = "FR", + NameDanish = "Frankrig", + NameEnglish = "France" + }, + new + { + Code = "GF", + NameDanish = "Fransk Guyana", + NameEnglish = "French Guiana" + }, + new + { + Code = "PF", + NameDanish = "Fransk Polynesien", + NameEnglish = "French Polynesia" + }, + new + { + Code = "GA", + NameDanish = "Gabon", + NameEnglish = "Gabon" + }, + new + { + Code = "GM", + NameDanish = "Gambia", + NameEnglish = "Gambia" + }, + new + { + Code = "GE", + NameDanish = "Georgien", + NameEnglish = "Georgia" + }, + new + { + Code = "DE", + NameDanish = "Tyskland", + NameEnglish = "Germany" + }, + new + { + Code = "GH", + NameDanish = "Ghana", + NameEnglish = "Ghana" + }, + new + { + Code = "GI", + NameDanish = "Gibraltar", + NameEnglish = "Gibraltar" + }, + new + { + Code = "GR", + NameDanish = "Grækenland", + NameEnglish = "Greece" + }, + new + { + Code = "GL", + NameDanish = "Grønland", + NameEnglish = "Greenland" + }, + new + { + Code = "GD", + NameDanish = "Grenada", + NameEnglish = "Grenada" + }, + new + { + Code = "GP", + NameDanish = "Guadeloupe", + NameEnglish = "Guadeloupe" + }, + new + { + Code = "GU", + NameDanish = "Guam", + NameEnglish = "Guam" + }, + new + { + Code = "GT", + NameDanish = "Guatemala", + NameEnglish = "Guatemala" + }, + new + { + Code = "GG", + NameDanish = "Guernsey", + NameEnglish = "Guernsey" + }, + new + { + Code = "GN", + NameDanish = "Guinea", + NameEnglish = "Guinea" + }, + new + { + Code = "GW", + NameDanish = "Guinea-Bissau", + NameEnglish = "Guinea-Bissau" + }, + new + { + Code = "GY", + NameDanish = "Guyana", + NameEnglish = "Guyana" + }, + new + { + Code = "HT", + NameDanish = "Haiti", + NameEnglish = "Haiti" + }, + new + { + Code = "HN", + NameDanish = "Honduras", + NameEnglish = "Honduras" + }, + new + { + Code = "HK", + NameDanish = "SAR Hongkong", + NameEnglish = "Hong Kong SAR China" + }, + new + { + Code = "HU", + NameDanish = "Ungarn", + NameEnglish = "Hungary" + }, + new + { + Code = "IS", + NameDanish = "Island", + NameEnglish = "Iceland" + }, + new + { + Code = "IN", + NameDanish = "Indien", + NameEnglish = "India" + }, + new + { + Code = "ID", + NameDanish = "Indonesien", + NameEnglish = "Indonesia" + }, + new + { + Code = "IR", + NameDanish = "Iran", + NameEnglish = "Iran" + }, + new + { + Code = "IQ", + NameDanish = "Irak", + NameEnglish = "Iraq" + }, + new + { + Code = "IE", + NameDanish = "Irland", + NameEnglish = "Ireland" + }, + new + { + Code = "IM", + NameDanish = "Isle of Man", + NameEnglish = "Isle of Man" + }, + new + { + Code = "IL", + NameDanish = "Israel", + NameEnglish = "Israel" + }, + new + { + Code = "IT", + NameDanish = "Italien", + NameEnglish = "Italy" + }, + new + { + Code = "JM", + NameDanish = "Jamaica", + NameEnglish = "Jamaica" + }, + new + { + Code = "JP", + NameDanish = "Japan", + NameEnglish = "Japan" + }, + new + { + Code = "JE", + NameDanish = "Jersey", + NameEnglish = "Jersey" + }, + new + { + Code = "JO", + NameDanish = "Jordan", + NameEnglish = "Jordan" + }, + new + { + Code = "KZ", + NameDanish = "Kasakhstan", + NameEnglish = "Kazakhstan" + }, + new + { + Code = "KE", + NameDanish = "Kenya", + NameEnglish = "Kenya" + }, + new + { + Code = "KI", + NameDanish = "Kiribati", + NameEnglish = "Kiribati" + }, + new + { + Code = "XK", + NameDanish = "Kosovo", + NameEnglish = "Kosovo" + }, + new + { + Code = "KW", + NameDanish = "Kuwait", + NameEnglish = "Kuwait" + }, + new + { + Code = "KG", + NameDanish = "Kirgisistan", + NameEnglish = "Kyrgyzstan" + }, + new + { + Code = "LA", + NameDanish = "Laos", + NameEnglish = "Laos" + }, + new + { + Code = "LV", + NameDanish = "Letland", + NameEnglish = "Latvia" + }, + new + { + Code = "LB", + NameDanish = "Libanon", + NameEnglish = "Lebanon" + }, + new + { + Code = "LS", + NameDanish = "Lesotho", + NameEnglish = "Lesotho" + }, + new + { + Code = "LR", + NameDanish = "Liberia", + NameEnglish = "Liberia" + }, + new + { + Code = "LY", + NameDanish = "Libyen", + NameEnglish = "Libya" + }, + new + { + Code = "LI", + NameDanish = "Liechtenstein", + NameEnglish = "Liechtenstein" + }, + new + { + Code = "LT", + NameDanish = "Litauen", + NameEnglish = "Lithuania" + }, + new + { + Code = "LU", + NameDanish = "Luxembourg", + NameEnglish = "Luxembourg" + }, + new + { + Code = "MO", + NameDanish = "SAR Macao", + NameEnglish = "Macao SAR China" + }, + new + { + Code = "MG", + NameDanish = "Madagaskar", + NameEnglish = "Madagascar" + }, + new + { + Code = "MW", + NameDanish = "Malawi", + NameEnglish = "Malawi" + }, + new + { + Code = "MY", + NameDanish = "Malaysia", + NameEnglish = "Malaysia" + }, + new + { + Code = "ML", + NameDanish = "Mali", + NameEnglish = "Mali" + }, + new + { + Code = "MT", + NameDanish = "Malta", + NameEnglish = "Malta" + }, + new + { + Code = "MH", + NameDanish = "Marshalløerne", + NameEnglish = "Marshall Islands" + }, + new + { + Code = "MQ", + NameDanish = "Martinique", + NameEnglish = "Martinique" + }, + new + { + Code = "MR", + NameDanish = "Mauretanien", + NameEnglish = "Mauritania" + }, + new + { + Code = "MU", + NameDanish = "Mauritius", + NameEnglish = "Mauritius" + }, + new + { + Code = "YT", + NameDanish = "Mayotte", + NameEnglish = "Mayotte" + }, + new + { + Code = "MX", + NameDanish = "Mexico", + NameEnglish = "Mexico" + }, + new + { + Code = "FM", + NameDanish = "Mikronesien", + NameEnglish = "Micronesia" + }, + new + { + Code = "MD", + NameDanish = "Moldova", + NameEnglish = "Moldova" + }, + new + { + Code = "MC", + NameDanish = "Monaco", + NameEnglish = "Monaco" + }, + new + { + Code = "MN", + NameDanish = "Mongoliet", + NameEnglish = "Mongolia" + }, + new + { + Code = "ME", + NameDanish = "Montenegro", + NameEnglish = "Montenegro" + }, + new + { + Code = "MS", + NameDanish = "Montserrat", + NameEnglish = "Montserrat" + }, + new + { + Code = "MA", + NameDanish = "Marokko", + NameEnglish = "Morocco" + }, + new + { + Code = "MZ", + NameDanish = "Mozambique", + NameEnglish = "Mozambique" + }, + new + { + Code = "MM", + NameDanish = "Myanmar (Burma)", + NameEnglish = "Myanmar (Burma)" + }, + new + { + Code = "NA", + NameDanish = "Namibia", + NameEnglish = "Namibia" + }, + new + { + Code = "NR", + NameDanish = "Nauru", + NameEnglish = "Nauru" + }, + new + { + Code = "NP", + NameDanish = "Nepal", + NameEnglish = "Nepal" + }, + new + { + Code = "NL", + NameDanish = "Holland", + NameEnglish = "Netherlands" + }, + new + { + Code = "NC", + NameDanish = "Ny Kaledonien", + NameEnglish = "New Caledonia" + }, + new + { + Code = "NZ", + NameDanish = "New Zealand", + NameEnglish = "New Zealand" + }, + new + { + Code = "NI", + NameDanish = "Nicaragua", + NameEnglish = "Nicaragua" + }, + new + { + Code = "NE", + NameDanish = "Niger", + NameEnglish = "Niger" + }, + new + { + Code = "NG", + NameDanish = "Nigeria", + NameEnglish = "Nigeria" + }, + new + { + Code = "NU", + NameDanish = "Niue", + NameEnglish = "Niue" + }, + new + { + Code = "NF", + NameDanish = "Norfolk Island", + NameEnglish = "Norfolk Island" + }, + new + { + Code = "KP", + NameDanish = "Nordkorea", + NameEnglish = "North Korea" + }, + new + { + Code = "MK", + NameDanish = "Nordmakedonien", + NameEnglish = "North Macedonia" + }, + new + { + Code = "MP", + NameDanish = "Nordmarianerne", + NameEnglish = "Northern Mariana Islands" + }, + new + { + Code = "NO", + NameDanish = "Norge", + NameEnglish = "Norway" + }, + new + { + Code = "OM", + NameDanish = "Oman", + NameEnglish = "Oman" + }, + new + { + Code = "PK", + NameDanish = "Pakistan", + NameEnglish = "Pakistan" + }, + new + { + Code = "PW", + NameDanish = "Palau", + NameEnglish = "Palau" + }, + new + { + Code = "PS", + NameDanish = "De palæstinensiske områder", + NameEnglish = "Palestinian Territories" + }, + new + { + Code = "PA", + NameDanish = "Panama", + NameEnglish = "Panama" + }, + new + { + Code = "PG", + NameDanish = "Papua Ny Guinea", + NameEnglish = "Papua New Guinea" + }, + new + { + Code = "PY", + NameDanish = "Paraguay", + NameEnglish = "Paraguay" + }, + new + { + Code = "PE", + NameDanish = "Peru", + NameEnglish = "Peru" + }, + new + { + Code = "PH", + NameDanish = "Filippinerne", + NameEnglish = "Philippines" + }, + new + { + Code = "PN", + NameDanish = "Pitcairn", + NameEnglish = "Pitcairn Islands" + }, + new + { + Code = "PL", + NameDanish = "Polen", + NameEnglish = "Poland" + }, + new + { + Code = "PT", + NameDanish = "Portugal", + NameEnglish = "Portugal" + }, + new + { + Code = "PR", + NameDanish = "Puerto Rico", + NameEnglish = "Puerto Rico" + }, + new + { + Code = "QA", + NameDanish = "Qatar", + NameEnglish = "Qatar" + }, + new + { + Code = "RO", + NameDanish = "Rumænien", + NameEnglish = "Romania" + }, + new + { + Code = "RU", + NameDanish = "Rusland", + NameEnglish = "Russia" + }, + new + { + Code = "RW", + NameDanish = "Rwanda", + NameEnglish = "Rwanda" + }, + new + { + Code = "RE", + NameDanish = "Réunion", + NameEnglish = "Réunion" + }, + new + { + Code = "WS", + NameDanish = "Samoa", + NameEnglish = "Samoa" + }, + new + { + Code = "SM", + NameDanish = "San Marino", + NameEnglish = "San Marino" + }, + new + { + Code = "SA", + NameDanish = "Saudi-Arabien", + NameEnglish = "Saudi Arabia" + }, + new + { + Code = "SN", + NameDanish = "Senegal", + NameEnglish = "Senegal" + }, + new + { + Code = "RS", + NameDanish = "Serbien", + NameEnglish = "Serbia" + }, + new + { + Code = "SC", + NameDanish = "Seychellerne", + NameEnglish = "Seychelles" + }, + new + { + Code = "SL", + NameDanish = "Sierra Leone", + NameEnglish = "Sierra Leone" + }, + new + { + Code = "SG", + NameDanish = "Singapore", + NameEnglish = "Singapore" + }, + new + { + Code = "SX", + NameDanish = "Sint Maarten", + NameEnglish = "Sint Maarten" + }, + new + { + Code = "SK", + NameDanish = "Slovakiet", + NameEnglish = "Slovakia" + }, + new + { + Code = "SI", + NameDanish = "Slovenien", + NameEnglish = "Slovenia" + }, + new + { + Code = "SB", + NameDanish = "Salomonøerne", + NameEnglish = "Solomon Islands" + }, + new + { + Code = "SO", + NameDanish = "Somalia", + NameEnglish = "Somalia" + }, + new + { + Code = "ZA", + NameDanish = "Sydafrika", + NameEnglish = "South Africa" + }, + new + { + Code = "KR", + NameDanish = "Sydkorea", + NameEnglish = "South Korea" + }, + new + { + Code = "SS", + NameDanish = "Sydsudan", + NameEnglish = "South Sudan" + }, + new + { + Code = "ES", + NameDanish = "Spanien", + NameEnglish = "Spain" + }, + new + { + Code = "LK", + NameDanish = "Sri Lanka", + NameEnglish = "Sri Lanka" + }, + new + { + Code = "BL", + NameDanish = "Saint Barthélemy", + NameEnglish = "St. Barthélemy" + }, + new + { + Code = "SH", + NameDanish = "St. Helena", + NameEnglish = "St. Helena" + }, + new + { + Code = "KN", + NameDanish = "Saint Kitts og Nevis", + NameEnglish = "St. Kitts & Nevis" + }, + new + { + Code = "LC", + NameDanish = "Saint Lucia", + NameEnglish = "St. Lucia" + }, + new + { + Code = "MF", + NameDanish = "Saint Martin", + NameEnglish = "St. Martin" + }, + new + { + Code = "PM", + NameDanish = "Saint Pierre og Miquelon", + NameEnglish = "St. Pierre & Miquelon" + }, + new + { + Code = "VC", + NameDanish = "Saint Vincent og Grenadinerne", + NameEnglish = "St. Vincent & Grenadines" + }, + new + { + Code = "SD", + NameDanish = "Sudan", + NameEnglish = "Sudan" + }, + new + { + Code = "SR", + NameDanish = "Surinam", + NameEnglish = "Suriname" + }, + new + { + Code = "SJ", + NameDanish = "Svalbard og Jan Mayen", + NameEnglish = "Svalbard & Jan Mayen" + }, + new + { + Code = "SE", + NameDanish = "Sverige", + NameEnglish = "Sweden" + }, + new + { + Code = "CH", + NameDanish = "Schweiz", + NameEnglish = "Switzerland" + }, + new + { + Code = "SY", + NameDanish = "Syrien", + NameEnglish = "Syria" + }, + new + { + Code = "ST", + NameDanish = "São Tomé og Príncipe", + NameEnglish = "São Tomé & Príncipe" + }, + new + { + Code = "TW", + NameDanish = "Taiwan", + NameEnglish = "Taiwan" + }, + new + { + Code = "TJ", + NameDanish = "Tadsjikistan", + NameEnglish = "Tajikistan" + }, + new + { + Code = "TZ", + NameDanish = "Tanzania", + NameEnglish = "Tanzania" + }, + new + { + Code = "TH", + NameDanish = "Thailand", + NameEnglish = "Thailand" + }, + new + { + Code = "TL", + NameDanish = "Timor-Leste", + NameEnglish = "Timor-Leste" + }, + new + { + Code = "TG", + NameDanish = "Togo", + NameEnglish = "Togo" + }, + new + { + Code = "TK", + NameDanish = "Tokelau", + NameEnglish = "Tokelau" + }, + new + { + Code = "TO", + NameDanish = "Tonga", + NameEnglish = "Tonga" + }, + new + { + Code = "TT", + NameDanish = "Trinidad og Tobago", + NameEnglish = "Trinidad & Tobago" + }, + new + { + Code = "TN", + NameDanish = "Tunesien", + NameEnglish = "Tunisia" + }, + new + { + Code = "TR", + NameDanish = "Tyrkiet", + NameEnglish = "Turkey" + }, + new + { + Code = "TM", + NameDanish = "Turkmenistan", + NameEnglish = "Turkmenistan" + }, + new + { + Code = "TC", + NameDanish = "Turks- og Caicosøerne", + NameEnglish = "Turks & Caicos Islands" + }, + new + { + Code = "TV", + NameDanish = "Tuvalu", + NameEnglish = "Tuvalu" + }, + new + { + Code = "UM", + NameDanish = "Amerikanske oversøiske øer", + NameEnglish = "U.S. Outlying Islands" + }, + new + { + Code = "VI", + NameDanish = "De Amerikanske Jomfruøer", + NameEnglish = "U.S. Virgin Islands" + }, + new + { + Code = "UG", + NameDanish = "Uganda", + NameEnglish = "Uganda" + }, + new + { + Code = "UA", + NameDanish = "Ukraine", + NameEnglish = "Ukraine" + }, + new + { + Code = "AE", + NameDanish = "De Forenede Arabiske Emirater", + NameEnglish = "United Arab Emirates" + }, + new + { + Code = "GB", + NameDanish = "Storbritannien", + NameEnglish = "United Kingdom" + }, + new + { + Code = "US", + NameDanish = "USA", + NameEnglish = "United States" + }, + new + { + Code = "UY", + NameDanish = "Uruguay", + NameEnglish = "Uruguay" + }, + new + { + Code = "UZ", + NameDanish = "Usbekistan", + NameEnglish = "Uzbekistan" + }, + new + { + Code = "VU", + NameDanish = "Vanuatu", + NameEnglish = "Vanuatu" + }, + new + { + Code = "VA", + NameDanish = "Vatikanstaten", + NameEnglish = "Vatican City" + }, + new + { + Code = "VE", + NameDanish = "Venezuela", + NameEnglish = "Venezuela" + }, + new + { + Code = "VN", + NameDanish = "Vietnam", + NameEnglish = "Vietnam" + }, + new + { + Code = "WF", + NameDanish = "Wallis og Futuna", + NameEnglish = "Wallis & Futuna" + }, + new + { + Code = "EH", + NameDanish = "Vestsahara", + NameEnglish = "Western Sahara" + }, + new + { + Code = "YE", + NameDanish = "Yemen", + NameEnglish = "Yemen" + }, + new + { + Code = "ZM", + NameDanish = "Zambia", + NameEnglish = "Zambia" + }, + new + { + Code = "ZW", + NameDanish = "Zimbabwe", + NameEnglish = "Zimbabwe" + }, + new + { + Code = "AX", + NameDanish = "Åland", + NameEnglish = "Åland Islands" + }); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.EntranceType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("EntranceTypes"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodHandout", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("FoodTypeId") + .HasColumnType("integer"); + + b.Property("HandedOutAt") + .HasColumnType("timestamp with time zone"); + + b.Property("OrderDate") + .HasColumnType("timestamp with time zone"); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("ServingId") + .HasColumnType("integer"); + + b.Property("UndoneAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ServingId"); + + b.HasIndex("ParticipantId", "FoodTypeId", "OrderDate"); + + b.ToTable("FoodHandouts"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodOffer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("BuyerId") + .HasColumnType("integer"); + + b.Property("ClosedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("FoodTypeId") + .HasColumnType("integer"); + + b.Property("OfferedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("OrderDate") + .HasColumnType("timestamp with time zone"); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("ServingId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ServingId"); + + b.HasIndex("ParticipantId", "FoodTypeId", "OrderDate"); + + b.ToTable("FoodOffers"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodServing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("EndsAt") + .HasColumnType("time without time zone"); + + b.Property("MealPeriod") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartsAt") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("Date", "MealPeriod") + .IsUnique(); + + b.ToTable("FoodServings"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Diet") + .HasColumnType("text"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("MealPeriod") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("NameEnglish") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.ToTable("FoodTypes"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.HeroForceCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ColorHex") + .IsRequired() + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("HeroForceCategories"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.HeroForceShift", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("EndTime") + .HasColumnType("timestamp with time zone"); + + b.Property("MaxParticipants") + .HasColumnType("integer"); + + b.Property("StartTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("HeroForceShifts"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.HeroForceShiftParticipant", b => + { + b.Property("ShiftId") + .HasColumnType("integer"); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("Id") + .HasColumnType("integer"); + + b.Property("SignedUpAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("ShiftId", "ParticipantId"); + + b.ToTable("HeroForceShiftParticipants"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.IdCardTemplate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Background") + .HasColumnType("bytea"); + + b.Property("BackgroundContentType") + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("id_card_templates"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.IdCardTemplateItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DataSource") + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("Rotation") + .HasColumnType("integer"); + + b.Property("TemplateId") + .HasColumnType("integer"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.Property("Width") + .HasColumnType("integer"); + + b.Property("X") + .HasColumnType("integer"); + + b.Property("Y") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TemplateId"); + + b.ToTable("id_card_template_items"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.LoanItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AvailableQuantity") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("TotalQuantity") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("LoanItems"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Newsletter", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Body") + .IsRequired() + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("RecipientCount") + .HasColumnType("integer"); + + b.Property("SentAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Newsletters"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.OrganizerArea", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("NameDanish") + .IsRequired() + .HasColumnType("text"); + + b.Property("NameEnglish") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("organizer_areas"); + + b.HasData( + new + { + Id = 1, + NameDanish = "Scenarieforfatter" + }, + new + { + Id = 2, + NameDanish = "Brætspilsdesigner" + }, + new + { + Id = 3, + NameDanish = "Arrangørkærlighed" + }, + new + { + Id = 4, + NameDanish = "Arrangørmessen" + }, + new + { + Id = 5, + NameDanish = "AV & Tech" + }, + new + { + Id = 6, + NameDanish = "Bar" + }, + new + { + Id = 7, + NameDanish = "Brætspilscafé" + }, + new + { + Id = 8, + NameDanish = "Brætspilsdesignansvarlig" + }, + new + { + Id = 9, + NameDanish = "Opsætning/nedpilning" + }, + new + { + Id = 10, + NameDanish = "Butikker" + }, + new + { + Id = 11, + NameDanish = "DirtBuster" + }, + new + { + Id = 12, + NameDanish = "Brætspilsdommer" + }, + new + { + Id = 13, + NameDanish = "Scenariedommer" + }, + new + { + Id = 14, + NameDanish = "Fastafamily" + }, + new + { + Id = 15, + NameDanish = "FastaQuests" + }, + new + { + Id = 16, + NameDanish = "Fastaval Junior" + }, + new + { + Id = 17, + NameDanish = "FTTF (Fastaval-translator-task-force)" + }, + new + { + Id = 18, + NameDanish = "Game Rush" + }, + new + { + Id = 19, + NameDanish = "TV" + }, + new + { + Id = 20, + NameDanish = "Heltestyrken" + }, + new + { + Id = 21, + NameDanish = "Holdlægning" + }, + new + { + Id = 22, + NameDanish = "Hovedarrangørgruppe" + }, + new + { + Id = 23, + NameDanish = "Indkøb & Transport" + }, + new + { + Id = 24, + NameDanish = "Infoen" + }, + new + { + Id = 25, + NameDanish = "International" + }, + new + { + Id = 26, + NameDanish = "IT" + }, + new + { + Id = 27, + NameDanish = "Kaffekro" + }, + new + { + Id = 28, + NameDanish = "Kiosk" + }, + new + { + Id = 29, + NameDanish = "Kommunikation" + }, + new + { + Id = 30, + NameDanish = "Køkken" + }, + new + { + Id = 31, + NameDanish = "Levnedsmiddel" + }, + new + { + Id = 32, + NameDanish = "Madudlevering" + }, + new + { + Id = 33, + NameDanish = "Miljø/affaldshåndtering" + }, + new + { + Id = 34, + NameDanish = "Morgenmad" + }, + new + { + Id = 35, + NameDanish = "Økonomi" + }, + new + { + Id = 36, + NameDanish = "Opvask" + }, + new + { + Id = 37, + NameDanish = "Otto-produktion" + }, + new + { + Id = 38, + NameDanish = "Ottofest" + }, + new + { + Id = 39, + NameDanish = "Ottos stue" + }, + new + { + Id = 40, + NameDanish = "Receptioner" + }, + new + { + Id = 41, + NameDanish = "Regelformidleransvarlig" + }, + new + { + Id = 42, + NameDanish = "Scenarieansvarlig" + }, + new + { + Id = 43, + NameDanish = "Sildesalat" + }, + new + { + Id = 44, + NameDanish = "SoMe" + }, + new + { + Id = 45, + NameDanish = "Spillederansvarlig" + }, + new + { + Id = 46, + NameDanish = "Spilstart (scenarier + brætspil)" + }, + new + { + Id = 47, + NameDanish = "Streaming (under Fastaval)" + }, + new + { + Id = 48, + NameDanish = "Streaming (under Ottoshow)" + }, + new + { + Id = 49, + NameDanish = "Super Søndag" + }, + new + { + Id = 50, + NameDanish = "Synopseakademiet" + }, + new + { + Id = 51, + NameDanish = "Tema og Wear" + }, + new + { + Id = 52, + NameDanish = "Tryghed & Tryghedsvært" + }, + new + { + Id = 53, + NameDanish = "Ungdom og Efterskolerne" + }, + new + { + Id = 54, + NameDanish = "Æresgæst" + }, + new + { + Id = 55, + NameDanish = "Æresotto" + }, + new + { + Id = 56, + NameDanish = "Grafik" + }); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Participant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.PrimitiveCollection("ActivityLanguages") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("AddressLine1") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("AddressLine2") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("AdminNote") + .IsRequired() + .HasColumnType("text"); + + b.Property("AmountPaid") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("date"); + + b.Property("CategoryId") + .HasColumnType("integer"); + + b.Property("CheckedInAt") + .HasColumnType("timestamp with time zone"); + + b.Property("City") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("CommentNote") + .HasColumnType("text"); + + b.Property("CountryCode") + .IsRequired() + .HasMaxLength(2) + .HasColumnType("character varying(2)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DesiredActivities") + .HasColumnType("integer"); + + b.Property("DesiredHeroTasks") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.Property("ExtraVouchers") + .HasColumnType("integer"); + + b.Property("FinancialSupport") + .HasColumnType("boolean"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("GameActivityId") + .HasColumnType("integer"); + + b.Property("HeroForceNote") + .HasColumnType("text"); + + b.Property("IdCardTemplateId") + .HasColumnType("integer"); + + b.Property("IsActivityLocked") + .HasColumnType("boolean"); + + b.Property("IsAnnulled") + .HasColumnType("boolean"); + + b.Property("IsAuthorOrDesigner") + .HasColumnType("boolean"); + + b.Property("IsNoShow") + .HasColumnType("boolean"); + + b.Property("JuniorComment") + .HasColumnType("text"); + + b.Property("JuniorContact") + .HasColumnType("text"); + + b.Property("JuniorGameMaster") + .HasColumnType("boolean"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("MaxGameMasterRuns") + .HasColumnType("integer"); + + b.Property("MaxRulesGuideGames") + .HasColumnType("integer"); + + b.Property("MessageToParticipant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Nickname") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("OrganizerAreaId") + .HasColumnType("integer"); + + b.Property("PaymentNote") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("PhotoConsent") + .HasColumnType("boolean"); + + b.Property("PreferredLanguage") + .IsRequired() + .HasColumnType("text"); + + b.Property("Pronouns") + .IsRequired() + .HasMaxLength(4) + .HasColumnType("character varying(4)"); + + b.Property("SetupHelpMonday") + .HasColumnType("boolean"); + + b.Property("SetupHelpTuesday") + .HasColumnType("boolean"); + + b.Property("SignedUpAt") + .HasColumnType("timestamp with time zone"); + + b.PrimitiveCollection("SleepingAreas") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("SleepingNote") + .HasColumnType("text"); + + b.Property("SmsSignup") + .HasColumnType("boolean"); + + b.Property("SuperGameMaster") + .HasColumnType("boolean"); + + b.Property("SuperHero") + .HasColumnType("boolean"); + + b.Property("SuperRulesGuide") + .HasColumnType("boolean"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("YouthClub") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("ZipCode") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CountryCode"); + + b.HasIndex("GameActivityId"); + + b.HasIndex("IdCardTemplateId"); + + b.HasIndex("OrganizerAreaId"); + + b.ToTable("participants"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.Property("IdCardTemplateId") + .HasColumnType("integer"); + + b.Property("IsOrganizer") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("IdCardTemplateId"); + + b.ToTable("participant_categories"); + + b.HasData( + new + { + Id = 1, + IsOrganizer = false, + Name = "Deltager" + }, + new + { + Id = 2, + IsOrganizer = true, + Name = "Arrangør" + }, + new + { + Id = 3, + IsOrganizer = false, + Name = "Junior" + }, + new + { + Id = 4, + IsOrganizer = false, + Name = "Forældre" + }, + new + { + Id = 5, + IsOrganizer = false, + Name = "Freeloader" + }); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantFood", b => + { + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("FoodTypeId") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Quantity") + .HasColumnType("integer"); + + b.HasKey("ParticipantId", "FoodTypeId", "Date"); + + b.HasIndex("FoodTypeId"); + + b.ToTable("ParticipantFoods"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantPhoto", b => + { + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("Cropped") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("CroppedContentType") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("Original") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("OriginalContentType") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("ParticipantId"); + + b.ToTable("participant_photos"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantWear", b => + { + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("WearItemId") + .HasColumnType("integer"); + + b.Property("Quantity") + .HasColumnType("integer"); + + b.HasKey("ParticipantId", "WearItemId"); + + b.HasIndex("WearItemId"); + + b.ToTable("ParticipantWears"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Payment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("CallbackData") + .HasColumnType("text"); + + b.Property("CompletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Currency") + .IsRequired() + .HasColumnType("text"); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("PaymentProvider") + .IsRequired() + .HasColumnType("text"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TransactionId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ParticipantId"); + + b.ToTable("Payments"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Privilege", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Key") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("privileges"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Category") + .IsRequired() + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("numeric"); + + b.Property("Stock") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("roles"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.RolePrivilege", b => + { + b.Property("RoleId") + .HasColumnType("integer"); + + b.Property("PrivilegeId") + .HasColumnType("integer"); + + b.HasKey("RoleId", "PrivilegeId"); + + b.HasIndex("PrivilegeId"); + + b.ToTable("role_privileges"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Room", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Capacity") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Rooms"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Run", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Number") + .HasColumnType("integer"); + + b.Property("RoomId") + .HasColumnType("integer"); + + b.Property("ScheduleId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RoomId"); + + b.HasIndex("ScheduleId", "Number") + .IsUnique(); + + b.ToTable("runs"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.RunSeat", b => + { + b.Property("RunId") + .HasColumnType("integer"); + + b.Property("SeatNumber") + .HasColumnType("integer"); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("Role") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("RunId", "SeatNumber"); + + b.HasIndex("ParticipantId"); + + b.HasIndex("RunId", "ParticipantId") + .IsUnique(); + + b.ToTable("run_seats"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.Property("Quantity") + .HasColumnType("integer"); + + b.Property("SaleDate") + .HasColumnType("timestamp with time zone"); + + b.Property("TotalAmount") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.HasIndex("ParticipantId"); + + b.HasIndex("ProductId"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Schedule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActivityId") + .HasColumnType("integer"); + + b.Property("CancelledAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EndTime") + .HasColumnType("timestamp with time zone"); + + b.Property("RoomId") + .HasColumnType("integer"); + + b.Property("StartTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ActivityId"); + + b.HasIndex("RoomId"); + + b.ToTable("schedule"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ScheduleSignup", b => + { + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("ScheduleId") + .HasColumnType("integer"); + + b.Property("Role") + .HasColumnType("text"); + + b.Property("Priority") + .HasColumnType("integer"); + + b.HasKey("ParticipantId", "ScheduleId", "Role"); + + b.HasIndex("ScheduleId"); + + b.ToTable("schedule_signups"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.SignupConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConfigKey") + .IsRequired() + .HasColumnType("text"); + + b.Property("ConfigValue") + .IsRequired() + .HasColumnType("text"); + + b.Property("Module") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("SignupConfigs"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.SignupPage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderIndex") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("SignupPages"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.SignupPageElement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ElementType") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsRequired") + .HasColumnType("boolean"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("OptionsJson") + .HasColumnType("text"); + + b.Property("OrderIndex") + .HasColumnType("integer"); + + b.Property("PageId") + .HasColumnType("integer"); + + b.Property("ValidationRules") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("PageId"); + + b.ToTable("SignupPageElements"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.SignupSubmission", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConfirmationToken") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FormDataJson") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsConfirmed") + .HasColumnType("boolean"); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("SubmittedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ParticipantId"); + + b.ToTable("SignupSubmissions"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.SmsLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ErrorMessage") + .HasColumnType("text"); + + b.Property("Message") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.Property("SentAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Success") + .HasColumnType("boolean"); + + b.HasKey("Id"); + + b.ToTable("SmsLogs"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Ticket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedById") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("ResolvedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.ToTable("Tickets"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.TicketMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("TicketId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TicketId"); + + b.HasIndex("UserId"); + + b.ToTable("TicketMessages"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("LastLoginAt") + .HasColumnType("timestamp with time zone"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("Username") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("users"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.UserRole", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("user_roles"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.WearItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("numeric"); + + b.Property("Size") + .IsRequired() + .HasColumnType("text"); + + b.Property("Stock") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("WearItems"); + }); + + modelBuilder.Entity("FoodServingTypes", b => + { + b.Property("FoodServingId") + .HasColumnType("integer"); + + b.Property("FoodTypesId") + .HasColumnType("integer"); + + b.HasKey("FoodServingId", "FoodTypesId"); + + b.HasIndex("FoodTypesId"); + + b.ToTable("FoodServingTypes"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.BoardgameLoan", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Boardgame", "Boardgame") + .WithMany("Loans") + .HasForeignKey("BoardgameId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.Participant", "Participant") + .WithMany() + .HasForeignKey("ParticipantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Boardgame"); + + b.Navigation("Participant"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodHandout", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.FoodServing", "Serving") + .WithMany() + .HasForeignKey("ServingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.ParticipantFood", "Order") + .WithMany("Handouts") + .HasForeignKey("ParticipantId", "FoodTypeId", "OrderDate") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Serving"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodOffer", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.FoodServing", "Serving") + .WithMany() + .HasForeignKey("ServingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.ParticipantFood", "Order") + .WithMany("Offers") + .HasForeignKey("ParticipantId", "FoodTypeId", "OrderDate") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Serving"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.HeroForceShift", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.HeroForceCategory", "Category") + .WithMany("Shifts") + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.HeroForceShiftParticipant", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.HeroForceShift", "Shift") + .WithMany("Participants") + .HasForeignKey("ShiftId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shift"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.IdCardTemplateItem", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.IdCardTemplate", "Template") + .WithMany("Items") + .HasForeignKey("TemplateId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Template"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Participant", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.ParticipantCategory", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.Country", "Country") + .WithMany() + .HasForeignKey("CountryCode") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.Activity", "GameActivity") + .WithMany() + .HasForeignKey("GameActivityId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Fastasys.ApiService.Data.Entities.IdCardTemplate", "IdCardTemplate") + .WithMany() + .HasForeignKey("IdCardTemplateId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Fastasys.ApiService.Data.Entities.OrganizerArea", "OrganizerArea") + .WithMany() + .HasForeignKey("OrganizerAreaId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Category"); + + b.Navigation("Country"); + + b.Navigation("GameActivity"); + + b.Navigation("IdCardTemplate"); + + b.Navigation("OrganizerArea"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantCategory", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.IdCardTemplate", "IdCardTemplate") + .WithMany() + .HasForeignKey("IdCardTemplateId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("IdCardTemplate"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantFood", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.FoodType", "FoodType") + .WithMany("ParticipantFoodOrders") + .HasForeignKey("FoodTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.Participant", "Participant") + .WithMany("Foods") + .HasForeignKey("ParticipantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FoodType"); + + b.Navigation("Participant"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantPhoto", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Participant", "Participant") + .WithOne() + .HasForeignKey("Fastasys.ApiService.Data.Entities.ParticipantPhoto", "ParticipantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Participant"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantWear", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Participant", "Participant") + .WithMany("Wears") + .HasForeignKey("ParticipantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.WearItem", "WearItem") + .WithMany("ParticipantWearItems") + .HasForeignKey("WearItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Participant"); + + b.Navigation("WearItem"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Payment", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Participant", "Participant") + .WithMany("Payments") + .HasForeignKey("ParticipantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Participant"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.RolePrivilege", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Privilege", "Privilege") + .WithMany("RolePrivileges") + .HasForeignKey("PrivilegeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.Role", "Role") + .WithMany("RolePrivileges") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Privilege"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Run", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Room", "Room") + .WithMany() + .HasForeignKey("RoomId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.Schedule", "Schedule") + .WithMany("Runs") + .HasForeignKey("ScheduleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Room"); + + b.Navigation("Schedule"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.RunSeat", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Participant", "Participant") + .WithMany() + .HasForeignKey("ParticipantId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.Run", "Run") + .WithMany("Seats") + .HasForeignKey("RunId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Participant"); + + b.Navigation("Run"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Sale", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Participant", "Participant") + .WithMany() + .HasForeignKey("ParticipantId"); + + b.HasOne("Fastasys.ApiService.Data.Entities.Product", "Product") + .WithMany("Sales") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Participant"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Schedule", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Activity", "Activity") + .WithMany("Schedules") + .HasForeignKey("ActivityId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.Room", "Room") + .WithMany("Schedules") + .HasForeignKey("RoomId"); + + b.Navigation("Activity"); + + b.Navigation("Room"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ScheduleSignup", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Participant", "Participant") + .WithMany("Signups") + .HasForeignKey("ParticipantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.Schedule", "Schedule") + .WithMany("Signups") + .HasForeignKey("ScheduleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Participant"); + + b.Navigation("Schedule"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.SignupPageElement", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.SignupPage", "Page") + .WithMany("Elements") + .HasForeignKey("PageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Page"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.SignupSubmission", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Participant", "Participant") + .WithMany() + .HasForeignKey("ParticipantId"); + + b.Navigation("Participant"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Ticket", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CreatedBy"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.TicketMessage", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Ticket", "Ticket") + .WithMany("Messages") + .HasForeignKey("TicketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ticket"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.UserRole", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.Role", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("FoodServingTypes", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.FoodServing", null) + .WithMany() + .HasForeignKey("FoodServingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.FoodType", null) + .WithMany() + .HasForeignKey("FoodTypesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Activity", b => + { + b.Navigation("Schedules"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Boardgame", b => + { + b.Navigation("Loans"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodType", b => + { + b.Navigation("ParticipantFoodOrders"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.HeroForceCategory", b => + { + b.Navigation("Shifts"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.HeroForceShift", b => + { + b.Navigation("Participants"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.IdCardTemplate", b => + { + b.Navigation("Items"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Participant", b => + { + b.Navigation("Foods"); + + b.Navigation("Payments"); + + b.Navigation("Signups"); + + b.Navigation("Wears"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantFood", b => + { + b.Navigation("Handouts"); + + b.Navigation("Offers"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Privilege", b => + { + b.Navigation("RolePrivileges"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Product", b => + { + b.Navigation("Sales"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Role", b => + { + b.Navigation("RolePrivileges"); + + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Room", b => + { + b.Navigation("Schedules"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Run", b => + { + b.Navigation("Seats"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Schedule", b => + { + b.Navigation("Runs"); + + b.Navigation("Signups"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.SignupPage", b => + { + b.Navigation("Elements"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Ticket", b => + { + b.Navigation("Messages"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.User", b => + { + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.WearItem", b => + { + b.Navigation("ParticipantWearItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/backend/src/Fastasys.ApiService/Data/Migrations/20261204115334_AddFoodServings.cs b/backend/src/Fastasys.ApiService/Data/Migrations/20261204115334_AddFoodServings.cs new file mode 100644 index 0000000..b07d4c5 --- /dev/null +++ b/backend/src/Fastasys.ApiService/Data/Migrations/20261204115334_AddFoodServings.cs @@ -0,0 +1,182 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Fastasys.ApiService.Data.Migrations +{ + /// + public partial class AddFoodServings : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Diet", + table: "FoodTypes", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "MealPeriod", + table: "FoodTypes", + type: "text", + nullable: true); + + migrationBuilder.CreateTable( + name: "FoodServings", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "date", nullable: false), + MealPeriod = table.Column(type: "text", nullable: false), + StartsAt = table.Column(type: "time without time zone", nullable: false), + EndsAt = table.Column(type: "time without time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_FoodServings", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "FoodHandouts", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + ServingId = table.Column(type: "integer", nullable: false), + ParticipantId = table.Column(type: "integer", nullable: false), + FoodTypeId = table.Column(type: "integer", nullable: false), + OrderDate = table.Column(type: "timestamp with time zone", nullable: false), + HandedOutAt = table.Column(type: "timestamp with time zone", nullable: false), + UndoneAt = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_FoodHandouts", x => x.Id); + table.ForeignKey( + name: "FK_FoodHandouts_FoodServings_ServingId", + column: x => x.ServingId, + principalTable: "FoodServings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FoodHandouts_ParticipantFoods_ParticipantId_FoodTypeId_Orde~", + columns: x => new { x.ParticipantId, x.FoodTypeId, x.OrderDate }, + principalTable: "ParticipantFoods", + principalColumns: new[] { "ParticipantId", "FoodTypeId", "Date" }, + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "FoodOffers", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + ServingId = table.Column(type: "integer", nullable: false), + ParticipantId = table.Column(type: "integer", nullable: false), + FoodTypeId = table.Column(type: "integer", nullable: false), + OrderDate = table.Column(type: "timestamp with time zone", nullable: false), + OfferedAt = table.Column(type: "timestamp with time zone", nullable: false), + ClosedAt = table.Column(type: "timestamp with time zone", nullable: true), + BuyerId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_FoodOffers", x => x.Id); + table.ForeignKey( + name: "FK_FoodOffers_FoodServings_ServingId", + column: x => x.ServingId, + principalTable: "FoodServings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FoodOffers_ParticipantFoods_ParticipantId_FoodTypeId_OrderD~", + columns: x => new { x.ParticipantId, x.FoodTypeId, x.OrderDate }, + principalTable: "ParticipantFoods", + principalColumns: new[] { "ParticipantId", "FoodTypeId", "Date" }, + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "FoodServingTypes", + columns: table => new + { + FoodServingId = table.Column(type: "integer", nullable: false), + FoodTypesId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_FoodServingTypes", x => new { x.FoodServingId, x.FoodTypesId }); + table.ForeignKey( + name: "FK_FoodServingTypes_FoodServings_FoodServingId", + column: x => x.FoodServingId, + principalTable: "FoodServings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FoodServingTypes_FoodTypes_FoodTypesId", + column: x => x.FoodTypesId, + principalTable: "FoodTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_FoodHandouts_ParticipantId_FoodTypeId_OrderDate", + table: "FoodHandouts", + columns: new[] { "ParticipantId", "FoodTypeId", "OrderDate" }); + + migrationBuilder.CreateIndex( + name: "IX_FoodHandouts_ServingId", + table: "FoodHandouts", + column: "ServingId"); + + migrationBuilder.CreateIndex( + name: "IX_FoodOffers_ParticipantId_FoodTypeId_OrderDate", + table: "FoodOffers", + columns: new[] { "ParticipantId", "FoodTypeId", "OrderDate" }); + + migrationBuilder.CreateIndex( + name: "IX_FoodOffers_ServingId", + table: "FoodOffers", + column: "ServingId"); + + migrationBuilder.CreateIndex( + name: "IX_FoodServings_Date_MealPeriod", + table: "FoodServings", + columns: new[] { "Date", "MealPeriod" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_FoodServingTypes_FoodTypesId", + table: "FoodServingTypes", + column: "FoodTypesId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "FoodHandouts"); + + migrationBuilder.DropTable( + name: "FoodOffers"); + + migrationBuilder.DropTable( + name: "FoodServingTypes"); + + migrationBuilder.DropTable( + name: "FoodServings"); + + migrationBuilder.DropColumn( + name: "Diet", + table: "FoodTypes"); + + migrationBuilder.DropColumn( + name: "MealPeriod", + table: "FoodTypes"); + } + } +} diff --git a/backend/src/Fastasys.ApiService/Data/Migrations/InfosysDbContextModelSnapshot.cs b/backend/src/Fastasys.ApiService/Data/Migrations/InfosysDbContextModelSnapshot.cs index 2315d83..86c7350 100644 --- a/backend/src/Fastasys.ApiService/Data/Migrations/InfosysDbContextModelSnapshot.cs +++ b/backend/src/Fastasys.ApiService/Data/Migrations/InfosysDbContextModelSnapshot.cs @@ -1756,6 +1756,104 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("EntranceTypes"); }); + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodHandout", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("FoodTypeId") + .HasColumnType("integer"); + + b.Property("HandedOutAt") + .HasColumnType("timestamp with time zone"); + + b.Property("OrderDate") + .HasColumnType("timestamp with time zone"); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("ServingId") + .HasColumnType("integer"); + + b.Property("UndoneAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ServingId"); + + b.HasIndex("ParticipantId", "FoodTypeId", "OrderDate"); + + b.ToTable("FoodHandouts"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodOffer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("BuyerId") + .HasColumnType("integer"); + + b.Property("ClosedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("FoodTypeId") + .HasColumnType("integer"); + + b.Property("OfferedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("OrderDate") + .HasColumnType("timestamp with time zone"); + + b.Property("ParticipantId") + .HasColumnType("integer"); + + b.Property("ServingId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ServingId"); + + b.HasIndex("ParticipantId", "FoodTypeId", "OrderDate"); + + b.ToTable("FoodOffers"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodServing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("EndsAt") + .HasColumnType("time without time zone"); + + b.Property("MealPeriod") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartsAt") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("Date", "MealPeriod") + .IsUnique(); + + b.ToTable("FoodServings"); + }); + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodType", b => { b.Property("Id") @@ -1764,9 +1862,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("Diet") + .HasColumnType("text"); + b.Property("IsActive") .HasColumnType("boolean"); + b.Property("MealPeriod") + .HasColumnType("text"); + b.Property("Name") .IsRequired() .HasColumnType("text"); @@ -3240,6 +3344,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("WearItems"); }); + modelBuilder.Entity("FoodServingTypes", b => + { + b.Property("FoodServingId") + .HasColumnType("integer"); + + b.Property("FoodTypesId") + .HasColumnType("integer"); + + b.HasKey("FoodServingId", "FoodTypesId"); + + b.HasIndex("FoodTypesId"); + + b.ToTable("FoodServingTypes"); + }); + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.BoardgameLoan", b => { b.HasOne("Fastasys.ApiService.Data.Entities.Boardgame", "Boardgame") @@ -3259,6 +3378,44 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Participant"); }); + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodHandout", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.FoodServing", "Serving") + .WithMany() + .HasForeignKey("ServingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.ParticipantFood", "Order") + .WithMany("Handouts") + .HasForeignKey("ParticipantId", "FoodTypeId", "OrderDate") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Serving"); + }); + + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.FoodOffer", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.FoodServing", "Serving") + .WithMany() + .HasForeignKey("ServingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.ParticipantFood", "Order") + .WithMany("Offers") + .HasForeignKey("ParticipantId", "FoodTypeId", "OrderDate") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Serving"); + }); + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.HeroForceShift", b => { b.HasOne("Fastasys.ApiService.Data.Entities.HeroForceCategory", "Category") @@ -3581,6 +3738,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("User"); }); + modelBuilder.Entity("FoodServingTypes", b => + { + b.HasOne("Fastasys.ApiService.Data.Entities.FoodServing", null) + .WithMany() + .HasForeignKey("FoodServingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Fastasys.ApiService.Data.Entities.FoodType", null) + .WithMany() + .HasForeignKey("FoodTypesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Activity", b => { b.Navigation("Schedules"); @@ -3622,6 +3794,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Wears"); }); + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.ParticipantFood", b => + { + b.Navigation("Handouts"); + + b.Navigation("Offers"); + }); + modelBuilder.Entity("Fastasys.ApiService.Data.Entities.Privilege", b => { b.Navigation("RolePrivileges"); diff --git a/backend/src/Fastasys.ApiService/Program.cs b/backend/src/Fastasys.ApiService/Program.cs index 3ad670c..f4075e0 100644 --- a/backend/src/Fastasys.ApiService/Program.cs +++ b/backend/src/Fastasys.ApiService/Program.cs @@ -83,7 +83,14 @@ .AddPolicy("ActivityView", "activity_view", "activity_edit") .AddPolicy("ActivityManagement", "activity_edit") .AddPolicy("HeroForceManagement", "hero_force_management") - .AddPolicy("ShopManagement", "shop_management"); + .AddPolicy("ShopManagement", "shop_management") + .AddPolicy("FoodManagement", "food_edit") + .AddPolicy("FoodOrdering", "food_participant_edit") + .AddPolicy("FoodDistribution", "food_distribute_edit") + .AddPolicy("FoodMarketplace", "food_marketplace_edit") + .AddPolicy("FoodMarketplaceView", "food_marketplace_view", "food_marketplace_edit") + .AddPolicy("FoodServingView", "food_view", "food_edit", "food_participant_edit", "food_distribute_edit", "food_marketplace_view", "food_marketplace_edit") + .AddPolicy("FoodParticipantLookup", "food_participant_edit", "food_distribute_edit", "food_marketplace_edit"); // Add Controllers, EndpointsApiExplorer & SwaggerGen documentation metadata builder.Services.AddControllers() diff --git a/backend/src/Fastasys.ApiService/Services/FoodOrders.cs b/backend/src/Fastasys.ApiService/Services/FoodOrders.cs new file mode 100644 index 0000000..f92c2ce --- /dev/null +++ b/backend/src/Fastasys.ApiService/Services/FoodOrders.cs @@ -0,0 +1,57 @@ +using Fastasys.ApiService.Data; +using Fastasys.ApiService.Data.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage; + +namespace Fastasys.ApiService.Services; + +internal static class FoodOrders +{ + private static readonly TimeZoneInfo Copenhagen = TimeZoneInfo.FindSystemTimeZoneById("Europe/Copenhagen"); + + public static DateTime LocalNow() => TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, Copenhagen); + + public static DateTime OrderDate(DateOnly date) => date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc); + + public static Task GetServing(InfosysDbContext db, int id, CancellationToken ct) => + db.FoodServings.AsNoTracking().Include(serving => serving.FoodTypes).SingleOrDefaultAsync(serving => serving.Id == id, ct); + + public static IQueryable ForServing(InfosysDbContext db, FoodServing serving) + { + var date = OrderDate(serving.Date); + var types = serving.FoodTypes.Select(food => food.Id).ToArray(); + return db.ParticipantFoods.Where(order => order.Date == date && types.Contains(order.FoodTypeId) && !order.Participant.IsAnnulled); + } + + public static async Task AllocatedQuantity(InfosysDbContext db, ParticipantFood order, CancellationToken ct) + { + var handedOut = await db.Entry(order).Collection(item => item.Handouts).Query().CountAsync(item => item.UndoneAt == null, ct); + var offered = await db.Entry(order).Collection(item => item.Offers).Query().CountAsync(item => item.ClosedAt == null, ct); + return handedOut + offered; + } + + // Serializes changes to orders, handouts, and offers for a serving, including creation of a buyer's order. + public static Task LockServing(InfosysDbContext db, int id, CancellationToken ct) => + Lock(db, $"SELECT 1 FROM \"FoodServings\" WHERE \"Id\" = {id} FOR UPDATE", ct); + + // Rescheduling a dish's meal period must not race with assigning it to a serving. + public static Task LockTypes(InfosysDbContext db, int[] ids, CancellationToken ct) => + Lock(db, $"SELECT 1 FROM \"FoodTypes\" WHERE \"Id\" = ANY({ids}) ORDER BY \"Id\" FOR UPDATE", ct); + + private static async Task Lock(InfosysDbContext db, FormattableString query, CancellationToken ct) + { + if (!db.Database.IsNpgsql()) return null; + + var transaction = await db.Database.BeginTransactionAsync(ct); + try + { + await db.Database.ExecuteSqlInterpolatedAsync(query, ct); + return transaction; + } + catch + { + await transaction.DisposeAsync(); + throw; + } + } +} diff --git a/backend/tests/Fastasys.Tests/FoodTests.cs b/backend/tests/Fastasys.Tests/FoodTests.cs new file mode 100644 index 0000000..df79200 --- /dev/null +++ b/backend/tests/Fastasys.Tests/FoodTests.cs @@ -0,0 +1,113 @@ +using System.Net.Http.Json; +using Fastasys.ApiService.Controllers; +using Fastasys.ApiService.Data; +using Fastasys.ApiService.Data.Entities; +using Fastasys.ApiService.Services; +using Fastasys.Tests.testHelpers; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Fastasys.Tests; + +public class FoodTests(TestWebApplicationFactory factory) : IClassFixture +{ + private static CancellationToken Ct => TestContext.Current.CancellationToken; + + [Fact] + public async Task StaffCanCreateServingsAndTransferAnUndeliveredPortion() + { + var seller = new Participant { FirstName = "Food seller" }; + var buyer = new Participant { FirstName = "Food buyer" }; + using (var scope = factory.Services.CreateScope()) + { + var db = scope.ServiceProvider.GetRequiredService(); + db.Participants.AddRange(seller, buyer); + await db.SaveChangesAsync(Ct); + } + + var helper = new TestHelper(factory); + using var unprivileged = await helper.CreateClientWithPrivilegeAsync([]); + using var staff = await helper.CreateClientWithPrivilegeAsync( + ["food_edit", "food_participant_edit", "food_distribute_edit", "food_marketplace_edit"]); + var fields = new FoodTypeRequest("Kyllingesandwich", "Chicken sandwich", 49.50m, MealPeriod.Lunch, FoodDiet.Standard); + using var rejected = await unprivileged.PostAsJsonAsync("/api/food/types", fields, Ct); + Assert.Equal(HttpStatusCode.Forbidden, rejected.StatusCode); + + using var dishResponse = await staff.PostAsJsonAsync("/api/food/types", fields, Ct); + Assert.Equal(HttpStatusCode.Created, dishResponse.StatusCode); + var dish = (await dishResponse.Content.ReadFromJsonAsync(Ct))!; + var date = new DateOnly(2037, 3, 26); + var servingFields = new FoodServingRequest(date, MealPeriod.Lunch, new(12, 0), new(14, 0), [dish.Id]); + var lunch = await CreateServing(staff, servingFields); + var nextDay = await CreateServing(staff, servingFields with { Date = date.AddDays(1) }); + var root = $"/api/food/servings/{lunch.Id}"; + using var order = await staff.PutAsJsonAsync(root + "/order", new SetFoodOrderDto(seller.Id, dish.Id, 2), Ct); + Assert.Equal(HttpStatusCode.NoContent, order.StatusCode); + var lookup = root + $"/participants/{ParticipantRules.Ean8ForParticipant(seller.Id, date.Year)}"; + var sellerOrders = await staff.GetFromJsonAsync(lookup, Ct); + Assert.Equal(2, Assert.Single(sellerOrders!.Orders).Remaining); + var tomorrow = await staff.GetFromJsonAsync($"/api/food/servings/{nextDay.Id}/participants/{seller.Id}", Ct); + Assert.Empty(tomorrow!.Orders); + + var handout = new FoodPortionRequest(Guid.NewGuid(), seller.Id, dish.Id); + using var handedOut = await staff.PostAsJsonAsync(root + "/handouts", handout, Ct); + using var duplicate = await staff.PostAsJsonAsync(root + "/handouts", handout, Ct); + Assert.Equal(HttpStatusCode.OK, handedOut.StatusCode); + Assert.Equal(HttpStatusCode.OK, duplicate.StatusCode); + + var offer = handout with { RequestId = Guid.NewGuid() }; + using var offered = await staff.PostAsJsonAsync(root + "/offers", offer, Ct); + Assert.Equal(HttpStatusCode.NoContent, offered.StatusCode); + using var unavailable = await staff.PostAsJsonAsync(root + "/handouts", handout with { RequestId = Guid.NewGuid() }, Ct); + Assert.Equal(HttpStatusCode.Conflict, unavailable.StatusCode); + using var transferred = await staff.PutAsJsonAsync(root + $"/offers/{offer.RequestId}/transfer", new FoodTransferRequest(buyer.Id), Ct); + Assert.Equal(HttpStatusCode.NoContent, transferred.StatusCode); + using var retried = await staff.PutAsJsonAsync(root + $"/offers/{offer.RequestId}/transfer", new FoodTransferRequest(buyer.Id), Ct); + Assert.Equal(HttpStatusCode.NoContent, retried.StatusCode); + + var buyerOrders = await staff.GetFromJsonAsync(root + $"/participants/{buyer.Id}", Ct); + Assert.Equal(1, Assert.Single(buyerOrders!.Orders).Remaining); + var counts = await staff.GetFromJsonAsync(root + "/counts", Ct); + Assert.Equal(new FoodServingCount(dish.Id, Ordered: 2, HandedOut: 1), Assert.Single(counts!)); + + using var undone = await staff.PutAsync(root + $"/handouts/{handout.RequestId}/undo", null, Ct); + Assert.Equal(HttpStatusCode.NoContent, undone.StatusCode); + sellerOrders = await staff.GetFromJsonAsync(lookup, Ct); + Assert.Equal(1, Assert.Single(sellerOrders!.Orders).Remaining); + } + + [PostgresFact] + public async Task ConcurrentHandoutsCannotExceedTheOrderedQuantity() + { + await using var database = await PostgresTestDatabase.CreateAsync(Ct); + await using var db = new InfosysDbContext(database.Options); + await db.Database.MigrateAsync(Ct); + var person = new Participant { FirstName = "Last breakfast" }; + var dish = new FoodType { Name = "Morgenmad", NameEnglish = "Breakfast", MealPeriod = MealPeriod.Breakfast, Diet = FoodDiet.Standard }; + db.AddRange(person, dish); + await db.SaveChangesAsync(Ct); + var catalog = new FoodController(db); + var fields = new FoodServingRequest(new DateOnly(2037, 3, 26), MealPeriod.Breakfast, new(8, 0), new(10, 0), [dish.Id]); + var created = Assert.IsType((await catalog.CreateServing(fields, Ct)).Result); + var serving = Assert.IsType(created.Value); + Assert.IsType(await catalog.SetOrder(serving.Id, new(person.Id, dish.Id, 1), Ct)); + + async Task HandOut() + { + await using var worker = new InfosysDbContext(database.Options); + return await new FoodOperationsController(worker).HandOut(serving.Id, new(Guid.NewGuid(), person.Id, dish.Id), Ct); + } + + var results = await Task.WhenAll(HandOut(), HandOut()); + Assert.Single(results.OfType()); + Assert.Single(results.OfType()); + Assert.Equal(1, await db.FoodHandouts.CountAsync(Ct)); + } + + private static async Task CreateServing(HttpClient staff, FoodServingRequest request) + { + using var response = await staff.PostAsJsonAsync("/api/food/servings", request, Ct); + Assert.Equal(HttpStatusCode.Created, response.StatusCode); + return (await response.Content.ReadFromJsonAsync(Ct))!; + } +} diff --git a/frontend/public/assets/i18n/da.json b/frontend/public/assets/i18n/da.json index 6941aaf..5ad044f 100644 --- a/frontend/public/assets/i18n/da.json +++ b/frontend/public/assets/i18n/da.json @@ -1,4 +1,90 @@ { + "foodManagement": { + "admin": "Madadministration", + "pickup": "Madudlevering", + "types": "Madtyper", + "servings": "Udleveringstider", + "market": "Madbørs", + "serving": "Udlevering", + "chooseServing": "Vælg en udlevering", + "noServings": "Der er endnu ingen udleveringstider.", + "participantNumber": "Deltagernummer", + "lookUp": "Slå op", + "dish": "Ret", + "ordered": "Bestilt", + "handedOut": "Udleveret", + "remaining": "Til gode", + "chooseDish": "Vælg en ret", + "handOutOne": "Udlever én portion", + "noRemaining": "Deltageren har ingen portioner til gode til denne udlevering.", + "undoHandout": "Fortryd udlevering", + "handoutUndone": "Udleveringen er fortrudt.", + "period": "Måltid", + "diet": "Kosttype", + "price": "Pris", + "priceDkk": "Pris (DKK)", + "unclassified": "Ikke angivet", + "noTypes": "Der er endnu ingen madtyper.", + "addType": "Opret madtype", + "editType": "Rediger madtype", + "nameDanish": "Dansk navn", + "nameEnglish": "Engelsk navn", + "choosePeriod": "Vælg et måltid", + "servingCounts": "Bestilt og udleveret", + "setOrder": "Registrer deltagerbestilling", + "totalPortions": "Samlet antal bestilte portioner", + "addServing": "Opret udleveringstid", + "date": "Dato", + "startsAt": "Starttid", + "endsAt": "Sluttid", + "servingDishes": "Retter til udlevering", + "noServingDishes": "Opret først en madtype til dette måltid.", + "listedPortions": "Tilgængelige portioner", + "transfer": "Overfør", + "withdraw": "Træk tilbage", + "buyerNumber": "Modtagerens deltagernummer", + "confirmTransfer": "Bekræft overførsel", + "noOffers": "Der er ingen portioner på madbørsen til denne udlevering.", + "addOffer": "Sæt en portion på madbørsen", + "sellerNumber": "Sælgerens deltagernummer", + "offerOne": "Sæt én portion på madbørsen", + "typeSaved": "Madtypen er gemt.", + "servingSaved": "Udleveringstiden er oprettet.", + "orderSaved": "Deltagerens bestilling er gemt.", + "offerSaved": "Portionen er sat på madbørsen.", + "transferred": "Portionen er overført.", + "offerCancelled": "Portionen er trukket tilbage.", + "periods": { + "Breakfast": "Morgenmad", + "Lunch": "Frokost", + "Dinner": "Aftensmad" + }, + "diets": { + "Standard": "Standard", + "Vegetarian": "Vegetarisk", + "Vegan": "Vegansk" + }, + "errors": { + "requestFailed": "Der opstod en fejl. Prøv igen.", + "forbidden": "Du har ikke adgang til siden.", + "invalidType": "Indtast begge navne, måltid, kosttype og en gyldig pris.", + "typeNotFound": "Madtypen blev ikke fundet.", + "typeAssigned": "Måltidet kan først ændres, når retten ikke længere er knyttet til en udlevering.", + "invalidServing": "Vælg en dato og angiv en sluttid efter starttiden.", + "invalidServingTypes": "Vælg mindst én ret til dette måltid.", + "servingExists": "Der findes allerede en udlevering til dette måltid på datoen.", + "servingNotFound": "Udleveringen blev ikke fundet.", + "invalidOrder": "Angiv en ret og et gyldigt antal portioner.", + "participantNotFound": "Der blev ikke fundet en aktiv deltager.", + "orderAlreadyAllocated": "Det samlede antal kan ikke sættes lavere end antallet af udleverede portioner og portioner på madbørsen.", + "orderExists": "Deltageren har allerede en bestilling på denne ret og dato.", + "portionUnavailable": "Portionen er ikke længere tilgængelig.", + "handoutNotFound": "Udleveringen blev ikke fundet.", + "offerNotFound": "Tilbuddet blev ikke fundet.", + "offerClosed": "Tilbuddet er allerede lukket.", + "sameParticipant": "Vælg en anden deltager som modtager." + } + }, "nav": { "brand": "Fastasys", "participants": "Deltagere", diff --git a/frontend/public/assets/i18n/en.json b/frontend/public/assets/i18n/en.json index 80a8fa8..37f406c 100644 --- a/frontend/public/assets/i18n/en.json +++ b/frontend/public/assets/i18n/en.json @@ -1,4 +1,90 @@ { + "foodManagement": { + "admin": "Food administration", + "pickup": "Food pickup", + "types": "Food types", + "servings": "Serving times", + "market": "Meal exchange", + "serving": "Serving", + "chooseServing": "Select a serving", + "noServings": "No servings have been created yet.", + "participantNumber": "Participant number", + "lookUp": "Look up", + "dish": "Dish", + "ordered": "Ordered", + "handedOut": "Handed out", + "remaining": "Available", + "chooseDish": "Select a dish", + "handOutOne": "Hand out one portion", + "noRemaining": "This participant has no portions available for this serving.", + "undoHandout": "Undo handout", + "handoutUndone": "Handout undone.", + "period": "Meal period", + "diet": "Diet", + "price": "Price", + "priceDkk": "Price (DKK)", + "unclassified": "Unclassified", + "noTypes": "No food types yet.", + "addType": "Create food type", + "editType": "Edit food type", + "nameDanish": "Danish name", + "nameEnglish": "English name", + "choosePeriod": "Select a meal period", + "servingCounts": "Ordered and handed out", + "setOrder": "Set participant order", + "totalPortions": "Total portions ordered", + "addServing": "Create serving", + "date": "Date", + "startsAt": "Starts at", + "endsAt": "Ends at", + "servingDishes": "Dishes for this serving", + "noServingDishes": "Create a food type for this meal period first.", + "listedPortions": "Available offers", + "transfer": "Transfer", + "withdraw": "Withdraw", + "buyerNumber": "Recipient’s participant number", + "confirmTransfer": "Confirm transfer", + "noOffers": "No portions are listed for this serving.", + "addOffer": "List a portion", + "sellerNumber": "Seller’s participant number", + "offerOne": "List one portion", + "typeSaved": "Food type saved.", + "servingSaved": "Serving created.", + "orderSaved": "Participant order saved.", + "offerSaved": "Portion listed.", + "transferred": "Portion transferred.", + "offerCancelled": "Offer withdrawn.", + "periods": { + "Breakfast": "Breakfast", + "Lunch": "Lunch", + "Dinner": "Dinner" + }, + "diets": { + "Standard": "Standard", + "Vegetarian": "Vegetarian", + "Vegan": "Vegan" + }, + "errors": { + "requestFailed": "Something went wrong. Please try again.", + "forbidden": "You do not have access to this page.", + "invalidType": "Enter both names, a meal period, a diet and a valid price.", + "typeNotFound": "Food type could not be found.", + "typeAssigned": "The meal period cannot be changed while this dish is assigned to a serving.", + "invalidServing": "Select a date and enter an end time after the start time.", + "invalidServingTypes": "Choose at least one dish for this meal period.", + "servingExists": "A serving for this meal period already exists on this date.", + "servingNotFound": "Serving could not be found.", + "invalidOrder": "Enter a dish and a valid number of portions.", + "participantNotFound": "Active participant could not be found.", + "orderAlreadyAllocated": "The order cannot be reduced below the number of portions handed out or listed.", + "orderExists": "This participant already has an order for this dish and date.", + "portionUnavailable": "This portion is no longer available.", + "handoutNotFound": "Handout could not be found.", + "offerNotFound": "Offer could not be found.", + "offerClosed": "This offer is already closed.", + "sameParticipant": "Choose a different participant as recipient." + } + }, "nav": { "brand": "Fastasys", "participants": "Participants", diff --git a/frontend/src/app/app.routes.ts b/frontend/src/app/app.routes.ts index a3f7a50..3a68c06 100644 --- a/frontend/src/app/app.routes.ts +++ b/frontend/src/app/app.routes.ts @@ -20,6 +20,7 @@ import { ParticipantPhotoComponent } from './features/participants/participant-p import { IdCardTemplatesComponent } from './features/id-cards/id-card-templates/id-card-templates'; import { IdCardsPrintComponent } from './features/id-cards/id-cards-print/id-cards-print'; import { FoodComponent } from './features/resources/food/food'; +import { FoodPickupComponent } from './features/resources/food/food-pickup'; import { RoomsComponent } from './features/resources/rooms/rooms'; import { WearComponent } from './features/resources/wear/wear'; import { ShopComponent } from './features/shop/shop'; @@ -55,7 +56,9 @@ export const routes: Routes = [ { path: 'runs/:id/edit', component: RunFormComponent, canActivate: [authGuard] }, { path: 'hero-force', component: HeroForceComponent, canActivate: [authGuard] }, { path: 'shop', component: ShopComponent, canActivate: [authGuard] }, - { path: 'resources/food', component: FoodComponent, canActivate: [authGuard] }, + { path: 'resources/food', redirectTo: 'resources/food/admin', pathMatch: 'full' }, + { path: 'resources/food/admin', component: FoodComponent, canActivate: [authGuard] }, + { path: 'resources/food/pickup', component: FoodPickupComponent, canActivate: [authGuard] }, { path: 'resources/wear', component: WearComponent, canActivate: [authGuard] }, { path: 'resources/rooms', component: RoomsComponent, canActivate: [authGuard] }, { path: 'resources', redirectTo: 'resources/food', pathMatch: 'full' }, diff --git a/frontend/src/app/features/resources/food/food-api.ts b/frontend/src/app/features/resources/food/food-api.ts new file mode 100644 index 0000000..42303bf --- /dev/null +++ b/frontend/src/app/features/resources/food/food-api.ts @@ -0,0 +1,141 @@ +import { HttpClient, HttpErrorResponse } from '@angular/common/http'; +import { Injectable, inject } from '@angular/core'; +import { FoodDiet, FoodType, MealPeriod } from '@shared/types'; +import { firstValueFrom } from 'rxjs'; + +export const mealPeriods: readonly MealPeriod[] = ['Breakfast', 'Lunch', 'Dinner']; +export const foodDiets: readonly FoodDiet[] = ['Standard', 'Vegetarian', 'Vegan']; + +export interface FoodTypeFields { + name: string; + nameEnglish: string; + price: number | null; + mealPeriod: MealPeriod | null; + diet: FoodDiet | null; +} + +export interface ServingFields { + date: string; + mealPeriod: MealPeriod; + startsAt: string; + endsAt: string; + foodTypeIds: number[]; +} + +export interface FoodServing extends ServingFields { + id: number; + isCurrent: boolean; +} + +export interface FoodCount { + foodTypeId: number; + ordered: number; + handedOut: number; +} + +export interface FoodOrder extends FoodCount { + offered: number; + remaining: number; +} + +export interface FoodParticipant { + id: number; + name: string; + orders: FoodOrder[]; +} + +export interface FoodPortion { + requestId: string; + participantId: number; + foodTypeId: number; +} + +export interface FoodOffer { + id: string; + participantId: number; + participantName: string; + foodTypeId: number; +} + +export function foodError(error: unknown): string { + const code = error instanceof HttpErrorResponse ? error.error?.code : undefined; + return 'foodManagement.errors.' + (typeof code === 'string' ? code : 'requestFailed'); +} + +@Injectable({ providedIn: 'root' }) +export class FoodApi { + private readonly http = inject(HttpClient); + private readonly root = '/api/food'; + + public types() { + return firstValueFrom(this.http.get(this.root + '/types')); + } + + public saveType(fields: FoodTypeFields, id: number | null) { + return firstValueFrom( + id === null + ? this.http.post(this.root + '/types', fields) + : this.http.put(this.root + '/types/' + id, fields), + ); + } + + public servings() { + return firstValueFrom(this.http.get(this.root + '/servings')); + } + + public createServing(fields: ServingFields) { + return firstValueFrom( + this.http.post(this.root + '/servings', { + ...fields, + startsAt: fields.startsAt + ':00', + endsAt: fields.endsAt + ':00', + }), + ); + } + + public counts(serving: number) { + return firstValueFrom(this.http.get(this.servingUrl(serving) + '/counts')); + } + + public setOrder(serving: number, participantId: number, foodTypeId: number, quantity: number) { + return firstValueFrom( + this.http.put(this.servingUrl(serving) + '/order', { participantId, foodTypeId, quantity }), + ); + } + + public participant(serving: number, lookup: string) { + return firstValueFrom( + this.http.get(this.servingUrl(serving) + '/participants/' + encodeURIComponent(lookup)), + ); + } + + public handOut(serving: number, portion: FoodPortion) { + return firstValueFrom(this.http.post<{ id: string }>(this.servingUrl(serving) + '/handouts', portion)); + } + + public undo(serving: number, id: string) { + return firstValueFrom(this.http.put(this.servingUrl(serving) + '/handouts/' + id + '/undo', null)); + } + + public offers(serving: number) { + return firstValueFrom(this.http.get(this.servingUrl(serving) + '/offers')); + } + + public offer(serving: number, portion: FoodPortion) { + return firstValueFrom(this.http.post(this.servingUrl(serving) + '/offers', portion)); + } + + public transfer(serving: number, offerId: string, buyerId: number) { + return firstValueFrom( + this.http.put(this.servingUrl(serving) + '/offers/' + offerId + '/transfer', { buyerId }), + ); + } + + public cancelOffer(serving: number, offerId: string) { + return firstValueFrom(this.http.delete(this.servingUrl(serving) + '/offers/' + offerId)); + } + + private servingUrl(id: number): string { + return this.root + '/servings/' + id; + } +} diff --git a/frontend/src/app/features/resources/food/food-pickup.html b/frontend/src/app/features/resources/food/food-pickup.html new file mode 100644 index 0000000..e77afc9 --- /dev/null +++ b/frontend/src/app/features/resources/food/food-pickup.html @@ -0,0 +1,107 @@ +
+ + + @if (!allowed) { +

{{ 'foodManagement.errors.forbidden' | translate }}

+ } @else { @if (actionError(); as error) { + + } + +
+ + @if (servings().length === 0 && !busy()) { +

{{ 'foodManagement.noServings' | translate }}

+ } + + +
+
+ + @if (receipt(); as last) { +
+ {{ 'foodManagement.handedOut' | translate }} {{ dishName(last.foodTypeId) }} · #{{ + last.participant.id }} {{ last.participant.name }} + +
+ } @else if (undone()) { +

{{ 'foodManagement.handoutUndone' | translate }}

+ } @if (participant(); as person) { + +

#{{ person.id }} {{ person.name }}

+ @if (person.orders.length > 0) { + + + + + + + + + + + @for (order of person.orders; track order.foodTypeId) { + + + + + + + } + +
{{ 'foodManagement.dish' | translate }}{{ 'foodManagement.ordered' | translate }}{{ 'foodManagement.handedOut' | translate }}{{ 'foodManagement.remaining' | translate }}
{{ dishName(order.foodTypeId) }}{{ order.ordered }}{{ order.handedOut }}{{ order.remaining }}
+ } @if (available().length > 0) { +
+ @if (available().length > 1) { + + } @else { +

{{ dishName(available()[0].foodTypeId) }}

+ } + +
+ } @else { +

{{ 'foodManagement.noRemaining' | translate }}

+ } +
+ } } +
diff --git a/frontend/src/app/features/resources/food/food-pickup.spec.ts b/frontend/src/app/features/resources/food/food-pickup.spec.ts new file mode 100644 index 0000000..8c9b420 --- /dev/null +++ b/frontend/src/app/features/resources/food/food-pickup.spec.ts @@ -0,0 +1,107 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { signal } from '@angular/core'; +import { AuthService, TranslationService } from '@shared/services'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { FoodApi, FoodParticipant } from './food-api'; +import { FoodPickupComponent } from './food-pickup'; + +describe('Food pickup', () => { + const person: FoodParticipant = { + id: 42, + name: 'Test Participant', + orders: [ + { foodTypeId: 11, ordered: 2, handedOut: 0, offered: 0, remaining: 2 }, + { foodTypeId: 12, ordered: 1, handedOut: 0, offered: 0, remaining: 1 }, + ], + }; + let fixture: ComponentFixture; + let api: { + participant: ReturnType; + handOut: ReturnType; + undo: ReturnType; + }; + + beforeEach(async () => { + api = { + participant: vi.fn().mockResolvedValue(person), + handOut: vi.fn().mockResolvedValue({ id: 'one-portion' }), + undo: vi.fn().mockResolvedValue(undefined), + }; + await TestBed.configureTestingModule({ + imports: [FoodPickupComponent], + providers: [ + { provide: AuthService, useValue: { hasPrivilege: () => true } }, + { + provide: TranslationService, + useValue: { currentLang: signal('en'), translations: signal({}), translate: (key: string) => key }, + }, + { + provide: FoodApi, + useValue: { + ...api, + types: vi.fn().mockResolvedValue([ + { id: 11, name: 'Kylling', nameEnglish: 'Chicken sandwich' }, + { id: 12, name: 'Falafel', nameEnglish: 'Falafel sandwich' }, + ]), + servings: vi.fn().mockResolvedValue([ + { + id: 8, + date: '2037-03-26', + mealPeriod: 'Lunch', + startsAt: '12:00:00', + endsAt: '14:00:00', + isCurrent: true, + foodTypeIds: [11, 12], + }, + ]), + }, + }, + ], + }).compileComponents(); + fixture = TestBed.createComponent(FoodPickupComponent); + fixture.detectChanges(); + await fixture.whenStable(); + }); + + it('requires a choice among ordered dishes and undoes the exact recorded portion', async () => { + const component = fixture.componentInstance; + expect(component.servingId()).toBe(8); + component.changeLookup('42'); + component.search(); + await fixture.whenStable(); + fixture.detectChanges(); + const html = fixture.nativeElement as HTMLElement; + expect(html.textContent).toContain('Chicken sandwich'); + expect(html.textContent).toContain('Falafel sandwich'); + expect(component.dish()).toBeNull(); + component.handOut(); + expect(api.handOut).not.toHaveBeenCalled(); + + api.participant.mockResolvedValueOnce({ + ...person, + orders: [{ ...person.orders[0], handedOut: 1, remaining: 1 }, person.orders[1]], + }); + component.chooseDish(11); + component.handOut(); + await fixture.whenStable(); + expect(api.handOut).toHaveBeenCalledExactlyOnceWith( + 8, + expect.objectContaining({ participantId: 42, foodTypeId: 11, requestId: expect.any(String) }), + ); + expect(component.available()[0].remaining).toBe(1); + + component.undo(); + await fixture.whenStable(); + expect(api.undo).toHaveBeenCalledExactlyOnceWith(8, 'one-portion'); + expect(component.available()[0].remaining).toBe(2); + }); + + it('selects the only available dish for a fast handout', async () => { + api.participant.mockResolvedValueOnce({ ...person, orders: [person.orders[0]] }); + const component = fixture.componentInstance; + component.changeLookup('42'); + component.search(); + await fixture.whenStable(); + expect(component.dish()).toBe(11); + }); +}); diff --git a/frontend/src/app/features/resources/food/food-pickup.ts b/frontend/src/app/features/resources/food/food-pickup.ts new file mode 100644 index 0000000..3085116 --- /dev/null +++ b/frontend/src/app/features/resources/food/food-pickup.ts @@ -0,0 +1,158 @@ +import { DatePipe } from '@angular/common'; +import { HttpErrorResponse } from '@angular/common/http'; +import { Component, OnInit, computed, inject, signal, viewChild, ElementRef } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; +import { Card } from '@shared/components'; +import { TranslatePipe } from '@shared/pipes'; +import { AuthService, TranslationService } from '@shared/services'; +import { FoodType } from '@shared/types'; +import { FoodApi, FoodParticipant, FoodPortion, FoodServing, foodError } from './food-api'; + +interface Receipt { + id: string; + servingId: number; + foodTypeId: number; + participant: FoodParticipant; +} + +@Component({ + selector: 'app-food-pickup', + imports: [Card, DatePipe, FormsModule, MatButtonModule, TranslatePipe], + templateUrl: './food-pickup.html', + styleUrl: './food.scss', +}) +export class FoodPickupComponent implements OnInit { + private readonly api = inject(FoodApi); + private readonly lang = inject(TranslationService).currentLang; + private readonly lookupInput = viewChild>('lookupInput'); + private pendingPortion: FoodPortion | null = null; + + readonly allowed = inject(AuthService).hasPrivilege('food_distribute_edit'); + readonly types = signal([]); + readonly servings = signal([]); + readonly servingId = signal(null); + readonly lookup = signal(''); + readonly participant = signal(null); + readonly available = computed(() => this.participant()?.orders.filter(order => order.remaining > 0) ?? []); + readonly selectedDish = signal(null); + readonly dish = computed(() => { + const orders = this.available(); + return orders.length === 1 ? orders[0].foodTypeId : this.selectedDish(); + }); + readonly busy = signal(false); + readonly actionError = signal(null); + readonly receipt = signal(null); + readonly undone = signal(false); + + ngOnInit(): void { + if (!this.allowed) return; + void this.run(async () => { + const [types, servings] = await Promise.all([this.api.types(), this.api.servings()]); + this.types.set(types); + this.servings.set(servings); + const current = servings.filter(serving => serving.isCurrent); + this.servingId.set(current.length === 1 ? current[0].id : null); + }); + } + + public changeServing(id: number | null): void { + this.servingId.set(id); + this.changeLookup(''); + } + + public changeLookup(value: string): void { + this.lookup.set(value); + this.participant.set(null); + this.chooseDish(null); + this.actionError.set(null); + } + + public chooseDish(id: number | null): void { + this.selectedDish.set(id); + this.pendingPortion = null; + } + + public search(): void { + const servingId = this.servingId(); + const number = this.lookup().trim(); + if (!servingId || !number) return; + this.chooseDish(null); + void this.run(async () => this.participant.set(await this.api.participant(servingId, number))); + } + + public handOut(): void { + const participant = this.participant(); + const servingId = this.servingId(); + const foodTypeId = this.dish(); + if (!participant || !servingId || !foodTypeId || !this.available().some(order => order.foodTypeId === foodTypeId)) + return; + + void this.run(async () => { + const portion = (this.pendingPortion ??= { + requestId: crypto.randomUUID(), + participantId: participant.id, + foodTypeId, + }); + try { + const { id } = await this.api.handOut(servingId, portion); + this.receipt.set({ id, servingId, foodTypeId, participant }); + this.undone.set(false); + this.chooseDish(null); + this.focusLookup(); + } catch (error) { + if (error instanceof HttpErrorResponse && error.status === 409) { + this.chooseDish(null); + await this.refreshParticipant(servingId, participant.id); + } + throw error; + } + await this.refreshParticipant(servingId, participant.id); + }); + } + + public undo(): void { + const receipt = this.receipt(); + if (!receipt) return; + void this.run(async () => { + await this.api.undo(receipt.servingId, receipt.id); + this.receipt.set(null); + this.undone.set(true); + if (this.servingId() === receipt.servingId && this.participant()?.id === receipt.participant.id) { + await this.refreshParticipant(receipt.servingId, receipt.participant.id); + } + }); + } + + public dishName(id: number): string { + const food = this.types().find(type => type.id === id); + if (!food) return String(id); + return this.lang() === 'en' ? food.nameEnglish || food.name : food.name; + } + + private async refreshParticipant(servingId: number, participantId: number): Promise { + this.participant.set(null); + this.participant.set(await this.api.participant(servingId, String(participantId))); + } + + private focusLookup(): void { + const input = this.lookupInput()?.nativeElement; + setTimeout(() => { + input?.focus(); + input?.select(); + }); + } + + private async run(action: () => Promise): Promise { + if (this.busy()) return; + this.actionError.set(null); + this.busy.set(true); + try { + await action(); + } catch (error) { + this.actionError.set(foodError(error)); + } finally { + this.busy.set(false); + } + } +} diff --git a/frontend/src/app/features/resources/food/food.html b/frontend/src/app/features/resources/food/food.html index f53752e..7f232f3 100644 --- a/frontend/src/app/features/resources/food/food.html +++ b/frontend/src/app/features/resources/food/food.html @@ -1,21 +1,333 @@
-
- @for (food of foodTypes(); track food.id) { - - + } }
diff --git a/frontend/src/app/features/resources/food/food.scss b/frontend/src/app/features/resources/food/food.scss index 3a88f4b..70f583b 100644 --- a/frontend/src/app/features/resources/food/food.scss +++ b/frontend/src/app/features/resources/food/food.scss @@ -1,62 +1,127 @@ .page-container { - padding: 2rem; - max-width: 1280px; + max-width: 1200px; margin: 0 auto; + padding: clamp(1rem, 3vw, 2rem); + display: grid; + gap: 1rem; } -.page-header { - margin-bottom: 1rem; - h1 { - margin: 0; - font-size: 1.75rem; - } - p { - margin: 0.25rem 0 0 0; - color: #64748b; - } +.page-header h1 { + margin: 0; + font-size: 1.75rem; } -.sub-nav-tabs { - display: flex; - gap: 0.5rem; - border-bottom: 2px solid #e2e8f0; - margin-bottom: 1.5rem; + +h2 { + margin: 0 0 0.75rem; + font-size: 1.125rem; } -.tab-btn { + +.sections, +.actions, +.receipt { display: flex; align-items: center; - gap: 0.5rem; - padding: 0.75rem 1.25rem; - border: none; - background: transparent; - font-size: 0.95rem; - font-weight: 600; - color: #64748b; - cursor: pointer; - border-bottom: 3px solid transparent; - text-decoration: none; - transition: all 0.2s ease; - - &:hover { - color: #1e293b; - } - &.active { - color: #3b82f6; - border-bottom-color: #3b82f6; - } -} -.cards-grid { + flex-wrap: wrap; + gap: 0.75rem; +} + +.selected, +.receipt { + background: var(--mat-sys-secondary-container); + color: var(--mat-sys-on-secondary-container); +} + +.receipt { + justify-content: space-between; + padding: 0.75rem 1rem; + border-radius: 0.5rem; +} + +.columns, +.stack { + display: grid; + gap: 1rem; + align-items: start; +} + +.columns { + grid-template-columns: repeat(auto-fit, minmax(min(100%, 28rem), 1fr)); +} + +.field-form { + display: grid; + gap: 0.75rem; + max-width: 30rem; + justify-items: start; +} + +fieldset.field-form { + border: 0; + margin: 0; + min-inline-size: 0; + padding: 0; +} + +.field-form label { display: grid; - grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); - gap: 1.5rem; + gap: 0.3rem; + width: 100%; + font-weight: 500; } -.card-footer { + +.field-form input:not([type='checkbox']), +.field-form select { + box-sizing: border-box; + width: 100%; + min-height: 2.5rem; + padding: 0.45rem 0.65rem; + border-radius: 0.35rem; + border: 1px solid var(--mat-sys-outline, #767676); + color: var(--mat-sys-on-surface); + background: var(--mat-sys-surface); + font: inherit; +} + +label.inline { display: flex; - justify-content: space-between; align-items: center; - margin-top: 1.5rem; } -.price { - font-size: 1.25rem; - font-weight: 700; - color: #1e293b; + +.choices { + width: 100%; + padding: 0.5rem; + margin: 0; + box-sizing: border-box; + border: 1px solid var(--mat-sys-outline-variant, #ccc); +} + +table { + border-collapse: collapse; + width: 100%; +} + +td, +th { + padding: 0.5rem 0.35rem; + border-bottom: 1px solid var(--mat-sys-outline-variant, #ccc); + text-align: left; + overflow-wrap: anywhere; +} + +th[scope='row'] { + font-weight: 500; +} + +.offers { + padding: 0; + list-style: none; +} + +.offers li { + padding-block: 0.5rem; + border-bottom: 1px solid var(--mat-sys-outline-variant, #ccc); +} + +.error { + color: var(--mat-sys-error, #a41f16); } diff --git a/frontend/src/app/features/resources/food/food.ts b/frontend/src/app/features/resources/food/food.ts index 735ba0c..886f760 100644 --- a/frontend/src/app/features/resources/food/food.ts +++ b/frontend/src/app/features/resources/food/food.ts @@ -1,33 +1,281 @@ -import { CommonModule } from '@angular/common'; -import { HttpClient } from '@angular/common/http'; -import { Component, inject, OnInit, signal } from '@angular/core'; -import { MatIcon } from '@angular/material/icon'; +import { CurrencyPipe, DatePipe } from '@angular/common'; +import { Component, OnInit, computed, inject, signal } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; import { Card } from '@shared/components'; import { TranslatePipe } from '@shared/pipes'; -import { FoodType } from '@shared/types'; +import { AuthService, TranslationService } from '@shared/services'; +import { FoodType, MealPeriod } from '@shared/types'; +import { + FoodApi, + FoodCount, + FoodOffer, + FoodParticipant, + FoodPortion, + FoodServing, + FoodTypeFields, + ServingFields, + foodDiets, + foodError, + mealPeriods, +} from './food-api'; + +type Section = 'types' | 'servings' | 'market'; + +const blankType = (): FoodTypeFields => ({ + name: '', + nameEnglish: '', + price: null, + mealPeriod: null, + diet: 'Standard', +}); @Component({ selector: 'app-food', - imports: [CommonModule, Card, TranslatePipe, MatIcon], + imports: [Card, CurrencyPipe, DatePipe, FormsModule, MatButtonModule, TranslatePipe], templateUrl: './food.html', styleUrl: './food.scss', }) export class FoodComponent implements OnInit { - private readonly http = inject(HttpClient); + private readonly api = inject(FoodApi); + private readonly auth = inject(AuthService); + private readonly lang = inject(TranslationService).currentLang; + private pendingOffer: FoodPortion | null = null; + + readonly canEdit = this.auth.hasPrivilege('food_edit'); + readonly canOrder = this.auth.hasPrivilege('food_participant_edit'); + readonly canView = this.auth.hasPrivilege('food_view') || this.canEdit || this.canOrder; + readonly canTrade = this.auth.hasPrivilege('food_marketplace_edit'); + readonly canViewMarket = this.canTrade || this.auth.hasPrivilege('food_marketplace_view'); + readonly sections: Section[] = [ + ...(this.canView ? (['types', 'servings'] as const) : []), + ...(this.canViewMarket ? (['market'] as const) : []), + ]; + readonly section = signal
(this.sections[0] ?? 'types'); - public foodTypes = signal([]); + readonly periods = mealPeriods; + readonly diets = foodDiets; + readonly types = signal([]); + readonly servings = signal([]); + readonly counts = signal([]); + readonly offers = signal([]); + readonly servingId = signal(null); + readonly selectedServing = computed(() => this.servings().find(serving => serving.id === this.servingId())); + readonly busy = signal(false); + readonly actionError = signal(null); + readonly saved = signal(null); + + typeFields = blankType(); + editingType: number | null = null; + servingFields: ServingFields = { date: '', mealPeriod: 'Breakfast', startsAt: '', endsAt: '', foodTypeIds: [] }; + orderParticipant: number | null = null; + orderDish: number | null = null; + quantity: number | null = 1; + sellerNumber = ''; + readonly seller = signal(null); + offerDish: number | null = null; + buyerNumber: number | null = null; + selectedOffer: string | null = null; + readonly groups = computed(() => { + const groups = new Map(); + for (const offer of this.offers()) { + const group = groups.get(offer.foodTypeId) ?? []; + group.push(offer); + groups.set(offer.foodTypeId, group); + } + return [...groups.entries()].sort(([a], [b]) => this.dishName(a).localeCompare(this.dishName(b))); + }); ngOnInit(): void { - this.loadData(); + if (this.sections.length === 0) return; + void this.run(async () => { + const [types, servings] = await Promise.all([this.api.types(), this.api.servings()]); + this.types.set(types); + this.setServings(servings); + await this.loadServing(); + }); + } + + public selectSection(section: Section): void { + this.section.set(section); + this.resetInputs(); + void this.run(() => this.loadServing()); + } + + public selectServing(id: number | null): void { + this.servingId.set(id); + this.resetInputs(); + void this.run(() => this.loadServing()); + } + + public editType(type: FoodType): void { + this.editingType = type.id; + this.typeFields = { + name: type.name, + nameEnglish: type.nameEnglish, + mealPeriod: type.mealPeriod, + diet: type.diet, + price: type.price, + }; + this.saved.set(null); + this.actionError.set(null); + } + + public resetType(): void { + this.editingType = null; + this.typeFields = blankType(); + } + + public saveType(): void { + void this.run(async () => { + const type = await this.api.saveType(this.typeFields, this.editingType); + this.types.update(types => + [...types.filter(item => item.id !== type.id), type].sort((a, b) => a.name.localeCompare(b.name)), + ); + this.resetType(); + this.saved.set('typeSaved'); + }); + } + + public changeServingPeriod(period: MealPeriod): void { + this.servingFields.mealPeriod = period; + this.servingFields.foodTypeIds = []; + } + + public get servingDishes(): FoodType[] { + return this.types().filter(type => type.mealPeriod === this.servingFields.mealPeriod); + } + + public toggleServingDish(id: number, checked: boolean): void { + const ids = this.servingFields.foodTypeIds; + this.servingFields.foodTypeIds = checked ? [...ids, id] : ids.filter(value => value !== id); + } + + public createServing(): void { + void this.run(async () => { + const serving = await this.api.createServing(this.servingFields); + this.setServings([...this.servings(), serving]); + this.servingId.set(serving.id); + this.resetInputs(); + this.saved.set('servingSaved'); + await this.loadServing(); + }); + } + + public setOrder(): void { + const serving = this.servingId(); + const { orderParticipant, orderDish, quantity } = this; + if (!serving || !orderParticipant || !orderDish || quantity === null) return; + void this.run(async () => { + await this.api.setOrder(serving, orderParticipant, orderDish, quantity); + this.saved.set('orderSaved'); + await this.loadServing(); + }); + } + + public searchSeller(): void { + const serving = this.servingId(); + if (!serving || !this.sellerNumber.trim()) return; + this.offerDish = null; + this.seller.set(null); + void this.run(async () => this.setSeller(await this.api.participant(serving, this.sellerNumber.trim()))); + } + + public createOffer(): void { + const serving = this.servingId(); + const seller = this.seller(); + const foodTypeId = this.offerDish; + if (!serving || !seller || !foodTypeId) return; + void this.run(async () => { + if (this.pendingOffer?.participantId !== seller.id || this.pendingOffer.foodTypeId !== foodTypeId) { + this.pendingOffer = { requestId: crypto.randomUUID(), participantId: seller.id, foodTypeId }; + } + await this.api.offer(serving, this.pendingOffer); + this.pendingOffer = null; + this.seller.set(null); + this.saved.set('offerSaved'); + await this.loadServing(); + this.setSeller(await this.api.participant(serving, String(seller.id))); + }); + } + + public chooseOffer(id: string): void { + this.selectedOffer = id; + this.buyerNumber = null; + } + + public transfer(): void { + const serving = this.servingId(); + const { selectedOffer, buyerNumber } = this; + if (!serving || !selectedOffer || !buyerNumber) return; + void this.run(async () => { + await this.api.transfer(serving, selectedOffer, buyerNumber); + this.saved.set('transferred'); + this.resetInputs(); + await this.loadServing(); + }); + } + + public cancel(offerId: string): void { + const serving = this.servingId(); + if (!serving) return; + void this.run(async () => { + await this.api.cancelOffer(serving, offerId); + this.saved.set('offerCancelled'); + this.resetInputs(); + await this.loadServing(); + }); + } + + public dishName(id: number): string { + const type = this.types().find(type => type.id === id); + if (!type) return String(id); + return this.lang() === 'en' ? type.nameEnglish || type.name : type.name; + } + + private setServings(servings: FoodServing[]): void { + servings.sort((a, b) => a.date.localeCompare(b.date) || a.startsAt.localeCompare(b.startsAt)); + this.servings.set(servings); + const current = servings.find(serving => serving.isCurrent); + this.servingId.set(current?.id ?? servings[0]?.id ?? null); + } + + private setSeller(seller: FoodParticipant): void { + this.seller.set(seller); + const available = seller.orders.filter(order => order.remaining > 0); + this.offerDish = available.length === 1 ? available[0].foodTypeId : null; + } + + private resetInputs(): void { + this.pendingOffer = null; + this.orderDish = null; + this.seller.set(null); + this.sellerNumber = ''; + this.offerDish = null; + this.selectedOffer = null; + this.buyerNumber = null; } - private loadData(): void { - this.http.get('/api/food/types').subscribe(data => this.foodTypes.set(data)); + private async loadServing(): Promise { + this.counts.set([]); + this.offers.set([]); + const serving = this.servingId(); + if (!serving) return; + if (this.section() === 'servings') this.counts.set(await this.api.counts(serving)); + if (this.section() === 'market') this.offers.set(await this.api.offers(serving)); } - public orderFood(food: FoodType): void { - this.http - .post('/api/food/order', { participantId: 1, foodTypeId: food.id, date: new Date().toISOString() }) - .subscribe(() => this.loadData()); + private async run(action: () => Promise): Promise { + if (this.busy()) return; + this.saved.set(null); + this.actionError.set(null); + this.busy.set(true); + try { + await action(); + } catch (error) { + this.actionError.set(foodError(error)); + } finally { + this.busy.set(false); + } } } diff --git a/frontend/src/app/shared/components/toolbar/toolbar-navigation.ts b/frontend/src/app/shared/components/toolbar/toolbar-navigation.ts index 0b11b80..e81c60a 100644 --- a/frontend/src/app/shared/components/toolbar/toolbar-navigation.ts +++ b/frontend/src/app/shared/components/toolbar/toolbar-navigation.ts @@ -107,13 +107,18 @@ export const toolbarNavigation: readonly NavigationItem[] = [ icon: 'restaurant', activePaths: ['/resources/food'], links: [ - { label: 'infosysNav.overview', path: '/resources/food' }, - { label: 'infosysNav.foodTypes', path: '/resources/food' }, - { label: 'infosysNav.createFoodType' }, - { label: 'infosysNav.statistics' }, - { label: 'infosysNav.foodPickup' }, - { label: 'infosysNav.foodExchange' }, - { label: 'infosysNav.resetMealTimes' }, + { + label: 'foodManagement.admin', + path: '/resources/food/admin', + privileges: [ + 'food_view', + 'food_edit', + 'food_participant_edit', + 'food_marketplace_view', + 'food_marketplace_edit', + ], + }, + { label: 'foodManagement.pickup', path: '/resources/food/pickup', privileges: ['food_distribute_edit'] }, ], }, { diff --git a/frontend/src/app/shared/types/resources.types.ts b/frontend/src/app/shared/types/resources.types.ts index 9dba592..fed204b 100644 --- a/frontend/src/app/shared/types/resources.types.ts +++ b/frontend/src/app/shared/types/resources.types.ts @@ -1,9 +1,14 @@ +export type MealPeriod = 'Breakfast' | 'Lunch' | 'Dinner'; +export type FoodDiet = 'Standard' | 'Vegetarian' | 'Vegan'; + export interface FoodType { id: number; name: string; nameEnglish: string; price: number; isActive: boolean; + mealPeriod: MealPeriod | null; + diet: FoodDiet | null; } export interface WearItem { From 9b04d56456ca450bcf5261ca489b971cadde8582 Mon Sep 17 00:00:00 2001 From: Mads Heimdal Thy Date: Fri, 4 Dec 2026 12:59:40 +0100 Subject: [PATCH 2/5] Show meal handouts on participant pages and the dashboard --- .../Controllers/DashboardController.cs | 6 +++-- .../Controllers/ParticipantsController.cs | 26 +++++++++++++++---- .../ParticipantsControllerTests.cs | 2 +- .../src/app/features/dashboard/dashboard.html | 13 +++++++--- .../src/app/features/dashboard/dashboard.ts | 1 + .../participant-entrance-food.html | 6 ++++- .../participant-entrance-food.ts | 8 +++--- .../app/shared/types/participants.types.ts | 3 +++ 8 files changed, 48 insertions(+), 17 deletions(-) diff --git a/backend/src/Fastasys.ApiService/Controllers/DashboardController.cs b/backend/src/Fastasys.ApiService/Controllers/DashboardController.cs index 410ff19..13968ee 100644 --- a/backend/src/Fastasys.ApiService/Controllers/DashboardController.cs +++ b/backend/src/Fastasys.ApiService/Controllers/DashboardController.cs @@ -11,7 +11,7 @@ public record DashboardCategoryCount(int Id, string Name, int Count); public record DashboardDailyCount(DateOnly Date, int Count); -public record DashboardOrderCount(int Id, string Name, string? NameEnglish, string? Size, int Ordered); +public record DashboardOrderCount(int Id, string Name, string? NameEnglish, string? Size, int Ordered, int? HandedOut = null); public record DashboardRegistrations( int Total, @@ -91,7 +91,9 @@ public async Task Get(CancellationToken cancellationToken) .ToListAsync(cancellationToken); var food = await db.FoodTypes.AsNoTracking().OrderBy(type => type.Name) .Select(type => new DashboardOrderCount(type.Id, type.Name, type.NameEnglish, null, - type.ParticipantFoodOrders.Where(order => !order.Participant.IsAnnulled).Sum(order => order.Quantity))) + type.ParticipantFoodOrders.Where(order => !order.Participant.IsAnnulled).Sum(order => order.Quantity), + type.ParticipantFoodOrders.Where(order => !order.Participant.IsAnnulled) + .SelectMany(order => order.Handouts).Count(handout => handout.UndoneAt == null))) .ToListAsync(cancellationToken); return new DashboardDto(registrations, arrivals, wear, food); diff --git a/backend/src/Fastasys.ApiService/Controllers/ParticipantsController.cs b/backend/src/Fastasys.ApiService/Controllers/ParticipantsController.cs index a873c96..aa41492 100644 --- a/backend/src/Fastasys.ApiService/Controllers/ParticipantsController.cs +++ b/backend/src/Fastasys.ApiService/Controllers/ParticipantsController.cs @@ -180,8 +180,7 @@ public record ParticipantDetailsDto( string? SleepingNote, // The Wear box. null until wear is ported (see ParticipantWearOrderDto); then the participant's orders. IReadOnlyList? WearOrders, - // The Indgang/Mad box: the tickets (null until entrance is ported, see ParticipantTicketDto) and the meals - // (null until food is ported, see ParticipantMealDto) + // The Indgang/Mad box: tickets and ordered portions for each meal. IReadOnlyList? Tickets, IReadOnlyList? Meals, // The Soveplads box. null until sleeping places are ported (see ParticipantSleepingPlaceDto). @@ -280,7 +279,7 @@ public record ParticipantTicketDto(TicketLine Line, bool IsAllConvention, DateTi // - Time is madtider.dato (a UTC instant; the box shows its Copenhagen day). Category is mad.kategori of the meal's // mad_id. // - IsReceived is deltagere_madtider.received = 1. -public record ParticipantMealDto(DateTime Time, string Category, bool IsReceived); +public record ParticipantMealDto(DateTime Time, string Category, bool IsReceived, int Quantity, int HandedOut, string CategoryEnglish); // One row of the Soveplads box (visdeltager.phtml, #sleeping): Tidsrum "{Starts} -> {Ends}" and Sted (Room). // Infosys writes each day with PHP date('l, j/n'), e.g. "Wednesday, 24/3", with English day names on a Danish page. @@ -981,8 +980,7 @@ private async Task ToDtoAsync(Participant p) WearOrders: null, // TODO when entrance is ported: load the participant's tickets here (see ParticipantTicketDto) Tickets: null, - // TODO when food is ported: load the participant's meals here (see ParticipantMealDto) - Meals: null, + Meals: await LoadMealsAsync(p.Id), // TODO when sleeping places are ported: load them here (see ParticipantSleepingPlaceDto) SleepingPlaces: null, IdCard: await LoadIdCardAsync(p)) @@ -1034,6 +1032,24 @@ await LoadActivitiesAsync(p), // The IDkort box (Infosys ParticipantController::visDeltager: fetchCroppedPhoto, getParticipantIdTemplate and // getCategoryIdTemplate). The photo's address carries its upload time, so the page shows a new photo at once. + private async Task> LoadMealsAsync(int participantId) + { + var orders = await _db.ParticipantFoods.AsNoTracking() + .Where(order => order.ParticipantId == participantId && order.Quantity > 0) + .OrderBy(order => order.Date).ThenBy(order => order.FoodType.Name) + .Select(order => new + { + order.Date, + order.FoodType.Name, + order.FoodType.NameEnglish, + order.Quantity, + HandedOut = order.Handouts.Count(handout => handout.UndoneAt == null) + }) + .ToListAsync(); + return orders.Select(order => new ParticipantMealDto(order.Date, order.Name, order.Quantity == order.HandedOut, + order.Quantity, order.HandedOut, order.NameEnglish)).ToArray(); + } + private async Task LoadIdCardAsync(Participant p) { var photoUpdatedAt = await _db.ParticipantPhotos diff --git a/backend/tests/Fastasys.Tests/ParticipantsControllerTests.cs b/backend/tests/Fastasys.Tests/ParticipantsControllerTests.cs index a6b8e88..92b10d1 100644 --- a/backend/tests/Fastasys.Tests/ParticipantsControllerTests.cs +++ b/backend/tests/Fastasys.Tests/ParticipantsControllerTests.cs @@ -351,7 +351,7 @@ public async Task Get_ShowsEverythingToEditors_WithPreviousAndNext() // these are null Assert.Null(participant.Details.WearOrders); Assert.Null(participant.Details.Tickets); - Assert.Null(participant.Details.Meals); + Assert.Empty(participant.Details.Meals!); Assert.Null(participant.Details.SleepingPlaces); Assert.Null(participant.Price); // No photo and no template yet diff --git a/frontend/src/app/features/dashboard/dashboard.html b/frontend/src/app/features/dashboard/dashboard.html index a07735c..a75babf 100644 --- a/frontend/src/app/features/dashboard/dashboard.html +++ b/frontend/src/app/features/dashboard/dashboard.html @@ -105,7 +105,7 @@

{{ 'dashboard.wear' | translate }}

{{ 'dashboard.food' | translate }}

- + @if (stats.food.length) {
{{ 'dashboard.foodChart' | translate }} @@ -121,7 +121,7 @@

{{ 'dashboard.food' | translate }}

}
- + @if (rows.length) { @@ -136,15 +136,20 @@

{{ 'dashboard.food' | translate }}

- + }
{{ orderName(row) }} {{ row.ordered }}— + @if (hasHandouts) { {{ row.handedOut ?? 0 }} } @else { + — + } +
} @else {

{{ 'dashboard.noItems' | translate }}

- } + } @if (!hasHandouts) {

{{ 'dashboard.handoutsUnavailable' | translate }}

+ }
diff --git a/frontend/src/app/features/dashboard/dashboard.ts b/frontend/src/app/features/dashboard/dashboard.ts index f961b95..e3fd408 100644 --- a/frontend/src/app/features/dashboard/dashboard.ts +++ b/frontend/src/app/features/dashboard/dashboard.ts @@ -13,6 +13,7 @@ interface OrderCount { nameEnglish: string | null; size: string | null; ordered: number; + handedOut?: number | null; } export interface DashboardData { diff --git a/frontend/src/app/features/participants/participant-entrance-food/participant-entrance-food.html b/frontend/src/app/features/participants/participant-entrance-food/participant-entrance-food.html index ea02d39..9ee9194 100644 --- a/frontend/src/app/features/participants/participant-entrance-food/participant-entrance-food.html +++ b/frontend/src/app/features/participants/participant-entrance-food/participant-entrance-food.html @@ -22,7 +22,11 @@
    @for (meal of meals; track $index) { -
  • {{ mealText(meal) }} — ({{ receivedKey(meal) | translate }})
  • +
  • + {{ mealText(meal) }} — @if (meal.quantity && meal.quantity > 1) { + {{ meal.handedOut ?? 0 }}/{{ meal.quantity }} {{ 'participants.entranceFood.received' | translate }} + } @else { ({{ receivedKey(meal) | translate }}) } +
  • }
} diff --git a/frontend/src/app/features/participants/participant-entrance-food/participant-entrance-food.ts b/frontend/src/app/features/participants/participant-entrance-food/participant-entrance-food.ts index 85792d4..f8ce754 100644 --- a/frontend/src/app/features/participants/participant-entrance-food/participant-entrance-food.ts +++ b/frontend/src/app/features/participants/participant-entrance-food/participant-entrance-food.ts @@ -38,9 +38,7 @@ export function mealText(meal: ParticipantMeal, shortDay: (weekday: Weekday) => // tickets on the lines Indgang, Overnatning and Andet, and a list of their meals with whether each has been handed // out. Each line is shown even when it is empty, like Infosys does. // -// Entrance and food are not ported yet, so the page passes null and the box says so. They may be ported one at a -// time, so each half has its own message. When they are ported, the API fills details.tickets and details.meals -// (see ParticipantTicketDto and ParticipantMealDto in ParticipantsController) and this box shows them as is. +// The API supplies food orders with their current handout counts. Tickets can be absent while entrance is being ported. // Infosys's "Ret/slet" link goes to its Indgang/Mad/Wear edit page (deltager/updatemadwear); add it when that page // is ported. @Component({ @@ -65,7 +63,9 @@ export class ParticipantEntranceFoodComponent { } public mealText(meal: ParticipantMeal): string { - return mealText(meal, weekday => this.shortDay(weekday)); + const category = + this.translationService.currentLang() === 'en' ? meal.categoryEnglish || meal.category : meal.category; + return mealText({ ...meal, category }, weekday => this.shortDay(weekday)); } public receivedKey(meal: ParticipantMeal): string { diff --git a/frontend/src/app/shared/types/participants.types.ts b/frontend/src/app/shared/types/participants.types.ts index 1f5a336..7c0c4e9 100644 --- a/frontend/src/app/shared/types/participants.types.ts +++ b/frontend/src/app/shared/types/participants.types.ts @@ -293,6 +293,9 @@ export interface ParticipantMeal { // The food's name, e.g. "Aftensmad" category: string; isReceived: boolean; + quantity?: number; + handedOut?: number; + categoryEnglish?: string; } // One row of the Soveplads box From 4b38d7ab1f9ef8b28f50bfe836ec102a7a8dae5c Mon Sep 17 00:00:00 2001 From: Mads Heimdal Thy Date: Fri, 4 Dec 2026 13:02:05 +0100 Subject: [PATCH 3/5] Quiet EF database command logs in development --- backend/src/Fastasys.ApiService/appsettings.Development.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/Fastasys.ApiService/appsettings.Development.json b/backend/src/Fastasys.ApiService/appsettings.Development.json index 0b164b7..79c8017 100644 --- a/backend/src/Fastasys.ApiService/appsettings.Development.json +++ b/backend/src/Fastasys.ApiService/appsettings.Development.json @@ -5,7 +5,8 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "Microsoft.EntityFrameworkCore.Database.Command": "Warning" } } } From e9b8b85539100f0c80a8a05804dc04e1407822ce Mon Sep 17 00:00:00 2001 From: Mads Heimdal Thy Date: Fri, 4 Dec 2026 13:14:06 +0100 Subject: [PATCH 4/5] Create food servings before assigning dishes --- .../Controllers/FoodController.cs | 45 +++++++++---- .../Services/FoodOrders.cs | 7 +- backend/tests/Fastasys.Tests/FoodTests.cs | 24 +++++-- frontend/public/assets/i18n/da.json | 8 +-- frontend/public/assets/i18n/en.json | 8 +-- .../app/features/resources/food/food-api.ts | 3 +- .../src/app/features/resources/food/food.html | 64 +++++++++++-------- .../src/app/features/resources/food/food.ts | 31 ++++++--- 8 files changed, 124 insertions(+), 66 deletions(-) diff --git a/backend/src/Fastasys.ApiService/Controllers/FoodController.cs b/backend/src/Fastasys.ApiService/Controllers/FoodController.cs index dd6b497..9501d21 100644 --- a/backend/src/Fastasys.ApiService/Controllers/FoodController.cs +++ b/backend/src/Fastasys.ApiService/Controllers/FoodController.cs @@ -10,10 +10,10 @@ namespace Fastasys.ApiService.Controllers; public record FoodTypeRequest([Required, MaxLength(256)] string Name, [Required, MaxLength(256)] string NameEnglish, - [Required] decimal? Price, [Required] MealPeriod? MealPeriod, [Required] FoodDiet? Diet); + [Required] decimal? Price, [Required] MealPeriod? MealPeriod, [Required] FoodDiet? Diet, [Required] int[] ServingIds); public record FoodServingRequest([Required] DateOnly? Date, [Required] MealPeriod? MealPeriod, - [Required] TimeOnly? StartsAt, [Required] TimeOnly? EndsAt, [Required] int[] FoodTypeIds); + [Required] TimeOnly? StartsAt, [Required] TimeOnly? EndsAt); public record FoodServingDto(int Id, DateOnly Date, MealPeriod MealPeriod, TimeOnly StartsAt, TimeOnly EndsAt, int[] FoodTypeIds, bool IsCurrent); @@ -39,7 +39,10 @@ public async Task> CreateType(FoodTypeRequest request, Ca { var food = new FoodType(); if (!ApplyType(food, request)) return BadRequest(new { code = "invalidType" }); + var servings = await LoadTypeServings(null, request.ServingIds, ct); + if (!ValidTypeServings(servings, request)) return BadRequest(new { code = "invalidTypeServings" }); db.FoodTypes.Add(food); + foreach (var serving in servings) serving.FoodTypes.Add(food); await db.SaveChangesAsync(ct); return StatusCode(StatusCodes.Status201Created, food); } @@ -51,9 +54,22 @@ public async Task> UpdateType(int id, FoodTypeRequest req await using var transaction = await FoodOrders.LockTypes(db, [id], ct); var food = await db.FoodTypes.FindAsync([id], ct); if (food is null) return NotFound(new { code = "typeNotFound" }); - if (food.MealPeriod != request.MealPeriod && await db.FoodServings.AnyAsync(serving => serving.FoodTypes.Any(type => type.Id == id), ct)) - return Conflict(new { code = "typeAssigned" }); if (!ApplyType(food, request)) return BadRequest(new { code = "invalidType" }); + var servings = await LoadTypeServings(id, request.ServingIds, ct); + if (!ValidTypeServings(servings, request)) return BadRequest(new { code = "invalidTypeServings" }); + var removed = servings.Where(s => !request.ServingIds.Contains(s.Id)).ToArray(); + if (removed.Length > 0) + { + if (transaction is not null) await FoodOrders.LockServingRows(db, removed.Select(s => s.Id).ToArray(), ct); + var dates = removed.Select(s => FoodOrders.OrderDate(s.Date)).ToArray(); + if (await db.ParticipantFoods.AnyAsync(o => o.FoodTypeId == id && dates.Contains(o.Date) && + (o.Quantity > 0 || o.Handouts.Any() || o.Offers.Any()), ct)) + return Conflict(new { code = "servingHasOrders" }); + } + + foreach (var serving in removed) serving.FoodTypes.Remove(food); + foreach (var serving in servings.Where(s => request.ServingIds.Contains(s.Id) && !s.FoodTypes.Contains(food))) + serving.FoodTypes.Add(food); await db.SaveChangesAsync(ct); if (transaction is not null) await transaction.CommitAsync(ct); @@ -78,20 +94,14 @@ public async Task> CreateServing(FoodServingRequest request.StartsAt is not TimeOnly starts || request.EndsAt is not TimeOnly ends || ends <= starts) return BadRequest(new { code = "invalidServing" }); - var ids = request.FoodTypeIds.Distinct().ToArray(); - if (ids.Length == 0) return BadRequest(new { code = "invalidServingTypes" }); - await using var transaction = await FoodOrders.LockTypes(db, ids, ct); - var types = await db.FoodTypes.Where(food => ids.Contains(food.Id) && food.IsActive && food.MealPeriod == period).ToListAsync(ct); - if (ids.Length != types.Count) return BadRequest(new { code = "invalidServingTypes" }); if (await db.FoodServings.AnyAsync(s => s.Date == date && s.MealPeriod == period, ct)) return Conflict(new { code = "servingExists" }); - var serving = new FoodServing { Date = date, MealPeriod = period, StartsAt = starts, EndsAt = ends, FoodTypes = types }; + var serving = new FoodServing { Date = date, MealPeriod = period, StartsAt = starts, EndsAt = ends }; db.FoodServings.Add(serving); try { await db.SaveChangesAsync(ct); - if (transaction is not null) await transaction.CommitAsync(ct); } catch (DbUpdateException e) when (e.InnerException is PostgresException { SqlState: PostgresErrorCodes.UniqueViolation }) { @@ -148,6 +158,7 @@ public async Task SetOrder(int id, SetFoodOrderDto request, Cance public async Task OrderFood(OrderFoodDto request, CancellationToken ct) { if (request.Quantity <= 0) return BadRequest(new { code = "invalidOrder" }); + await using var transaction = await FoodOrders.LockTypes(db, [request.FoodTypeId], ct); if (!await db.FoodTypes.AnyAsync(food => food.Id == request.FoodTypeId && food.IsActive, ct)) return NotFound(new { code = "typeNotFound" }); if (!await db.Participants.AnyAsync(p => p.Id == request.ParticipantId && !p.IsAnnulled, ct)) @@ -160,6 +171,7 @@ public async Task OrderFood(OrderFoodDto request, CancellationTok try { await db.SaveChangesAsync(ct); + if (transaction is not null) await transaction.CommitAsync(ct); } catch (DbUpdateException e) when (e.InnerException is PostgresException { SqlState: PostgresErrorCodes.UniqueViolation }) { @@ -168,6 +180,17 @@ public async Task OrderFood(OrderFoodDto request, CancellationTok return Ok(new { message = "Food ordered successfully" }); } + private Task> LoadTypeServings(int? typeId, int[] servingIds, CancellationToken ct) => + db.FoodServings.Include(s => s.FoodTypes) + .Where(s => servingIds.Contains(s.Id) || s.FoodTypes.Any(type => type.Id == typeId)).ToListAsync(ct); + + private static bool ValidTypeServings(List servings, FoodTypeRequest request) + { + var selected = servings.Where(s => request.ServingIds.Contains(s.Id)).ToArray(); + return selected.Length > 0 && selected.Length == request.ServingIds.Distinct().Count() && + selected.All(s => s.MealPeriod == request.MealPeriod); + } + private static bool ApplyType(FoodType food, FoodTypeRequest request) { if (string.IsNullOrWhiteSpace(request.Name) || string.IsNullOrWhiteSpace(request.NameEnglish) || diff --git a/backend/src/Fastasys.ApiService/Services/FoodOrders.cs b/backend/src/Fastasys.ApiService/Services/FoodOrders.cs index f92c2ce..8a0bf41 100644 --- a/backend/src/Fastasys.ApiService/Services/FoodOrders.cs +++ b/backend/src/Fastasys.ApiService/Services/FoodOrders.cs @@ -34,9 +34,12 @@ public static async Task AllocatedQuantity(InfosysDbContext db, Participant public static Task LockServing(InfosysDbContext db, int id, CancellationToken ct) => Lock(db, $"SELECT 1 FROM \"FoodServings\" WHERE \"Id\" = {id} FOR UPDATE", ct); - // Rescheduling a dish's meal period must not race with assigning it to a serving. + // Serialize edits to a dish and legacy orders for that dish. public static Task LockTypes(InfosysDbContext db, int[] ids, CancellationToken ct) => - Lock(db, $"SELECT 1 FROM \"FoodTypes\" WHERE \"Id\" = ANY({ids}) ORDER BY \"Id\" FOR UPDATE", ct); + Lock(db, $"SELECT 1 FROM \"FoodTypes\" WHERE \"Id\" = ANY({ids}) ORDER BY \"Id\" FOR NO KEY UPDATE", ct); + + public static Task LockServingRows(InfosysDbContext db, int[] ids, CancellationToken ct) => + db.Database.ExecuteSqlInterpolatedAsync($"SELECT 1 FROM \"FoodServings\" WHERE \"Id\" = ANY({ids}) ORDER BY \"Id\" FOR UPDATE", ct); private static async Task Lock(InfosysDbContext db, FormattableString query, CancellationToken ct) { diff --git a/backend/tests/Fastasys.Tests/FoodTests.cs b/backend/tests/Fastasys.Tests/FoodTests.cs index df79200..2023529 100644 --- a/backend/tests/Fastasys.Tests/FoodTests.cs +++ b/backend/tests/Fastasys.Tests/FoodTests.cs @@ -29,20 +29,30 @@ public async Task StaffCanCreateServingsAndTransferAnUndeliveredPortion() using var unprivileged = await helper.CreateClientWithPrivilegeAsync([]); using var staff = await helper.CreateClientWithPrivilegeAsync( ["food_edit", "food_participant_edit", "food_distribute_edit", "food_marketplace_edit"]); - var fields = new FoodTypeRequest("Kyllingesandwich", "Chicken sandwich", 49.50m, MealPeriod.Lunch, FoodDiet.Standard); + var date = new DateOnly(2037, 3, 26); + var servingFields = new FoodServingRequest(date, MealPeriod.Lunch, new(12, 0), new(14, 0)); + var lunch = await CreateServing(staff, servingFields); + Assert.Empty(lunch.FoodTypeIds); + var nextDay = await CreateServing(staff, servingFields with { Date = date.AddDays(1) }); + var dinner = await CreateServing(staff, servingFields with { MealPeriod = MealPeriod.Dinner, StartsAt = new(17, 0), EndsAt = new(19, 0) }); + var fields = new FoodTypeRequest("Kyllingesandwich", "Chicken sandwich", 49.50m, MealPeriod.Dinner, FoodDiet.Standard, [dinner.Id]); using var rejected = await unprivileged.PostAsJsonAsync("/api/food/types", fields, Ct); Assert.Equal(HttpStatusCode.Forbidden, rejected.StatusCode); using var dishResponse = await staff.PostAsJsonAsync("/api/food/types", fields, Ct); Assert.Equal(HttpStatusCode.Created, dishResponse.StatusCode); var dish = (await dishResponse.Content.ReadFromJsonAsync(Ct))!; - var date = new DateOnly(2037, 3, 26); - var servingFields = new FoodServingRequest(date, MealPeriod.Lunch, new(12, 0), new(14, 0), [dish.Id]); - var lunch = await CreateServing(staff, servingFields); - var nextDay = await CreateServing(staff, servingFields with { Date = date.AddDays(1) }); + var lunchDish = fields with { MealPeriod = MealPeriod.Lunch, ServingIds = [lunch.Id] }; + using var updated = await staff.PutAsJsonAsync($"/api/food/types/{dish.Id}", lunchDish, Ct); + Assert.Equal(HttpStatusCode.OK, updated.StatusCode); + var servings = await staff.GetFromJsonAsync("/api/food/servings", Ct); + Assert.Equal(dish.Id, Assert.Single(servings!.Single(s => s.Id == lunch.Id).FoodTypeIds)); + Assert.Empty(servings!.Single(s => s.Id == dinner.Id).FoodTypeIds); var root = $"/api/food/servings/{lunch.Id}"; using var order = await staff.PutAsJsonAsync(root + "/order", new SetFoodOrderDto(seller.Id, dish.Id, 2), Ct); Assert.Equal(HttpStatusCode.NoContent, order.StatusCode); + using var dateChange = await staff.PutAsJsonAsync($"/api/food/types/{dish.Id}", lunchDish with { ServingIds = [nextDay.Id] }, Ct); + Assert.Equal(HttpStatusCode.Conflict, dateChange.StatusCode); var lookup = root + $"/participants/{ParticipantRules.Ean8ForParticipant(seller.Id, date.Year)}"; var sellerOrders = await staff.GetFromJsonAsync(lookup, Ct); Assert.Equal(2, Assert.Single(sellerOrders!.Orders).Remaining); @@ -87,9 +97,11 @@ public async Task ConcurrentHandoutsCannotExceedTheOrderedQuantity() db.AddRange(person, dish); await db.SaveChangesAsync(Ct); var catalog = new FoodController(db); - var fields = new FoodServingRequest(new DateOnly(2037, 3, 26), MealPeriod.Breakfast, new(8, 0), new(10, 0), [dish.Id]); + var fields = new FoodServingRequest(new DateOnly(2037, 3, 26), MealPeriod.Breakfast, new(8, 0), new(10, 0)); var created = Assert.IsType((await catalog.CreateServing(fields, Ct)).Result); var serving = Assert.IsType(created.Value); + var assigned = await catalog.UpdateType(dish.Id, new(dish.Name, dish.NameEnglish, 45, MealPeriod.Breakfast, FoodDiet.Standard, [serving.Id]), Ct); + Assert.NotNull(assigned.Value); Assert.IsType(await catalog.SetOrder(serving.Id, new(person.Id, dish.Id, 1), Ct)); async Task HandOut() diff --git a/frontend/public/assets/i18n/da.json b/frontend/public/assets/i18n/da.json index 5ad044f..0eb3ef1 100644 --- a/frontend/public/assets/i18n/da.json +++ b/frontend/public/assets/i18n/da.json @@ -37,8 +37,8 @@ "date": "Dato", "startsAt": "Starttid", "endsAt": "Sluttid", - "servingDishes": "Retter til udlevering", - "noServingDishes": "Opret først en madtype til dette måltid.", + "noTypeServings": "Opret først en udleveringstid til dette måltid.", + "emptyServing": "Der er endnu ingen retter til denne udlevering.", "listedPortions": "Tilgængelige portioner", "transfer": "Overfør", "withdraw": "Træk tilbage", @@ -69,9 +69,9 @@ "forbidden": "Du har ikke adgang til siden.", "invalidType": "Indtast begge navne, måltid, kosttype og en gyldig pris.", "typeNotFound": "Madtypen blev ikke fundet.", - "typeAssigned": "Måltidet kan først ændres, når retten ikke længere er knyttet til en udlevering.", + "servingHasOrders": "Retten har bestillinger eller udleveringshistorik til en udlevering, du prøver at fjerne.", "invalidServing": "Vælg en dato og angiv en sluttid efter starttiden.", - "invalidServingTypes": "Vælg mindst én ret til dette måltid.", + "invalidTypeServings": "Vælg mindst én dateret udlevering til dette måltid.", "servingExists": "Der findes allerede en udlevering til dette måltid på datoen.", "servingNotFound": "Udleveringen blev ikke fundet.", "invalidOrder": "Angiv en ret og et gyldigt antal portioner.", diff --git a/frontend/public/assets/i18n/en.json b/frontend/public/assets/i18n/en.json index 37f406c..c06bfad 100644 --- a/frontend/public/assets/i18n/en.json +++ b/frontend/public/assets/i18n/en.json @@ -37,8 +37,8 @@ "date": "Date", "startsAt": "Starts at", "endsAt": "Ends at", - "servingDishes": "Dishes for this serving", - "noServingDishes": "Create a food type for this meal period first.", + "noTypeServings": "Create a serving time for this meal period first.", + "emptyServing": "No dishes are assigned to this serving yet.", "listedPortions": "Available offers", "transfer": "Transfer", "withdraw": "Withdraw", @@ -69,9 +69,9 @@ "forbidden": "You do not have access to this page.", "invalidType": "Enter both names, a meal period, a diet and a valid price.", "typeNotFound": "Food type could not be found.", - "typeAssigned": "The meal period cannot be changed while this dish is assigned to a serving.", + "servingHasOrders": "This dish has orders or handout history for a serving you are trying to remove.", "invalidServing": "Select a date and enter an end time after the start time.", - "invalidServingTypes": "Choose at least one dish for this meal period.", + "invalidTypeServings": "Choose at least one dated serving for this meal period.", "servingExists": "A serving for this meal period already exists on this date.", "servingNotFound": "Serving could not be found.", "invalidOrder": "Enter a dish and a valid number of portions.", diff --git a/frontend/src/app/features/resources/food/food-api.ts b/frontend/src/app/features/resources/food/food-api.ts index 42303bf..97ee638 100644 --- a/frontend/src/app/features/resources/food/food-api.ts +++ b/frontend/src/app/features/resources/food/food-api.ts @@ -12,6 +12,7 @@ export interface FoodTypeFields { price: number | null; mealPeriod: MealPeriod | null; diet: FoodDiet | null; + servingIds: number[]; } export interface ServingFields { @@ -19,12 +20,12 @@ export interface ServingFields { mealPeriod: MealPeriod; startsAt: string; endsAt: string; - foodTypeIds: number[]; } export interface FoodServing extends ServingFields { id: number; isCurrent: boolean; + foodTypeIds: number[]; } export interface FoodCount { diff --git a/frontend/src/app/features/resources/food/food.html b/frontend/src/app/features/resources/food/food.html index 7f232f3..4cf3f15 100644 --- a/frontend/src/app/features/resources/food/food.html +++ b/frontend/src/app/features/resources/food/food.html @@ -48,7 +48,12 @@

{{ 'foodManagement.types' | translate }}

{{ dishName(type.id) }} {{ (type.mealPeriod ? 'foodManagement.periods.' + type.mealPeriod : 'foodManagement.unclassified') | - translate }} + translate }} @for (serving of servingsForType(type.id); track serving.id) { +
+ {{ serving.date | date: 'dd/MM/yyyy' }} · {{ serving.startsAt.slice(0, 5) }}–{{ serving.endsAt.slice(0, + 5) }} +
+ } {{ (type.diet ? 'foodManagement.diets.' + type.diet : 'foodManagement.unclassified') | translate }} {{ type.price | currency: 'DKK' }} @@ -92,13 +97,30 @@

{{ (editingType === null ? 'foodManagement.addType' : 'foodManagement.editTy + @if (typeFields.mealPeriod) { +
+ {{ 'foodManagement.servings' | translate }} + @for (serving of matchingServings; track serving.id) { + + } @empty { +

{{ 'foodManagement.noTypeServings' | translate }}

+ } +
+ }
- @if (editingType !== null) { @@ -146,6 +172,9 @@

{{ (editingType === null ? 'foodManagement.addType' : 'foodManagement.editTy

{{ 'foodManagement.servingCounts' | translate }}

+ @if (serving.foodTypeIds.length === 0) { +

{{ 'foodManagement.emptyServing' | translate }}

+ } @else { @@ -164,8 +193,9 @@

{{ 'foodManagement.servingCounts' | translate }}

}
+ }
- @if (canOrder) { + @if (canOrder && serving.foodTypeIds.length > 0) {

{{ 'foodManagement.setOrder' | translate }}

@@ -206,11 +236,7 @@

{{ 'foodManagement.addServing' | translate }}

-
- {{ 'foodManagement.servingDishes' | translate }} - @for (type of servingDishes; track type.id) { - - } @empty { -

{{ 'foodManagement.noServingDishes' | translate }}

- } -
- diff --git a/frontend/src/app/features/resources/food/food.ts b/frontend/src/app/features/resources/food/food.ts index 886f760..591fb84 100644 --- a/frontend/src/app/features/resources/food/food.ts +++ b/frontend/src/app/features/resources/food/food.ts @@ -28,6 +28,7 @@ const blankType = (): FoodTypeFields => ({ price: null, mealPeriod: null, diet: 'Standard', + servingIds: [], }); @Component({ @@ -48,7 +49,7 @@ export class FoodComponent implements OnInit { readonly canTrade = this.auth.hasPrivilege('food_marketplace_edit'); readonly canViewMarket = this.canTrade || this.auth.hasPrivilege('food_marketplace_view'); readonly sections: Section[] = [ - ...(this.canView ? (['types', 'servings'] as const) : []), + ...(this.canView ? (['servings', 'types'] as const) : []), ...(this.canViewMarket ? (['market'] as const) : []), ]; readonly section = signal
(this.sections[0] ?? 'types'); @@ -67,7 +68,7 @@ export class FoodComponent implements OnInit { typeFields = blankType(); editingType: number | null = null; - servingFields: ServingFields = { date: '', mealPeriod: 'Breakfast', startsAt: '', endsAt: '', foodTypeIds: [] }; + servingFields: ServingFields = { date: '', mealPeriod: 'Breakfast', startsAt: '', endsAt: '' }; orderParticipant: number | null = null; orderDish: number | null = null; quantity: number | null = 1; @@ -116,6 +117,7 @@ export class FoodComponent implements OnInit { mealPeriod: type.mealPeriod, diet: type.diet, price: type.price, + servingIds: this.servingsForType(type.id).map(serving => serving.id), }; this.saved.set(null); this.actionError.set(null); @@ -134,21 +136,30 @@ export class FoodComponent implements OnInit { ); this.resetType(); this.saved.set('typeSaved'); + this.setServings(await this.api.servings()); }); } - public changeServingPeriod(period: MealPeriod): void { - this.servingFields.mealPeriod = period; - this.servingFields.foodTypeIds = []; + public changeTypePeriod(period: MealPeriod | null): void { + this.typeFields.mealPeriod = period; + this.typeFields.servingIds = []; } - public get servingDishes(): FoodType[] { - return this.types().filter(type => type.mealPeriod === this.servingFields.mealPeriod); + public get matchingServings(): FoodServing[] { + return this.servings().filter(serving => serving.mealPeriod === this.typeFields.mealPeriod); } - public toggleServingDish(id: number, checked: boolean): void { - const ids = this.servingFields.foodTypeIds; - this.servingFields.foodTypeIds = checked ? [...ids, id] : ids.filter(value => value !== id); + public toggleTypeServing(id: number, checked: boolean): void { + const ids = this.typeFields.servingIds; + this.typeFields.servingIds = checked ? [...ids, id] : ids.filter(value => value !== id); + } + + public servingsForType(id: number): FoodServing[] { + return this.servings().filter(serving => serving.foodTypeIds.includes(id)); + } + + public servingDate(date: string): string { + return new Intl.DateTimeFormat(this.lang(), { dateStyle: 'full', timeZone: 'UTC' }).format(new Date(date)); } public createServing(): void { From 8f9232425d264ae972a72118cd2e7e2611c1c7c7 Mon Sep 17 00:00:00 2001 From: Mads Heimdal Thy Date: Fri, 4 Dec 2026 13:17:50 +0100 Subject: [PATCH 5/5] Group food type serving options by date --- frontend/public/assets/i18n/da.json | 4 +- frontend/public/assets/i18n/en.json | 4 +- .../src/app/features/resources/food/food.html | 56 +++++++++++-------- .../src/app/features/resources/food/food.scss | 13 +---- .../src/app/features/resources/food/food.ts | 39 +++++++++---- 5 files changed, 65 insertions(+), 51 deletions(-) diff --git a/frontend/public/assets/i18n/da.json b/frontend/public/assets/i18n/da.json index 0eb3ef1..65dc045 100644 --- a/frontend/public/assets/i18n/da.json +++ b/frontend/public/assets/i18n/da.json @@ -29,7 +29,6 @@ "editType": "Rediger madtype", "nameDanish": "Dansk navn", "nameEnglish": "Engelsk navn", - "choosePeriod": "Vælg et måltid", "servingCounts": "Bestilt og udleveret", "setOrder": "Registrer deltagerbestilling", "totalPortions": "Samlet antal bestilte portioner", @@ -37,7 +36,8 @@ "date": "Dato", "startsAt": "Starttid", "endsAt": "Sluttid", - "noTypeServings": "Opret først en udleveringstid til dette måltid.", + "noTypeServings": "Opret først en udleveringstid.", + "servingSelectionHint": "Vælg en eller flere udleveringer til samme måltid. Fjern dine valg for at skifte måltid.", "emptyServing": "Der er endnu ingen retter til denne udlevering.", "listedPortions": "Tilgængelige portioner", "transfer": "Overfør", diff --git a/frontend/public/assets/i18n/en.json b/frontend/public/assets/i18n/en.json index c06bfad..844585b 100644 --- a/frontend/public/assets/i18n/en.json +++ b/frontend/public/assets/i18n/en.json @@ -29,7 +29,6 @@ "editType": "Edit food type", "nameDanish": "Danish name", "nameEnglish": "English name", - "choosePeriod": "Select a meal period", "servingCounts": "Ordered and handed out", "setOrder": "Set participant order", "totalPortions": "Total portions ordered", @@ -37,7 +36,8 @@ "date": "Date", "startsAt": "Starts at", "endsAt": "Ends at", - "noTypeServings": "Create a serving time for this meal period first.", + "noTypeServings": "Create a serving time first.", + "servingSelectionHint": "Select one or more servings of the same meal. Clear your selection to switch meals.", "emptyServing": "No dishes are assigned to this serving yet.", "listedPortions": "Available offers", "transfer": "Transfer", diff --git a/frontend/src/app/features/resources/food/food.html b/frontend/src/app/features/resources/food/food.html index 4cf3f15..9ba05ba 100644 --- a/frontend/src/app/features/resources/food/food.html +++ b/frontend/src/app/features/resources/food/food.html @@ -95,31 +95,39 @@

{{ (editingType === null ? 'foodManagement.addType' : 'foodManagement.editTy >{{ 'foodManagement.priceDkk' | translate }} - - @if (typeFields.mealPeriod) { -
- {{ 'foodManagement.servings' | translate }} - @for (serving of matchingServings; track serving.id) { - - } @empty { -

{{ 'foodManagement.noTypeServings' | translate }}

- } -
+ + {{ 'foodManagement.servingSelectionHint' | translate }} + + } @else if (!busy()) { +

{{ 'foodManagement.noTypeServings' | translate }}

}