Phase 2: Backend API Implementation - DTOs, Services, and Controllers

This commit is contained in:
steinhelge
2025-11-23 15:55:03 +01:00
parent 0661bebd87
commit 9ed5adbfb5
22 changed files with 1066 additions and 33 deletions
@@ -0,0 +1,61 @@
using Hospitality.Backend.DTOs;
using Hospitality.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Hospitality.Backend.Services;
public class QrCodeService : IQrCodeService
{
private readonly HospitalityDbContext _context;
public QrCodeService(HospitalityDbContext context)
{
_context = context;
}
public async Task<PersonDetailResponse?> GetPersonByQrCodeAsync(Guid qrCode)
{
var person = await _context.People
.Include(p => p.Quotas)
.ThenInclude(q => q.Product)
.FirstOrDefaultAsync(p => p.QrCode == qrCode);
if (person == null) return null;
return new PersonDetailResponse(
person.Id,
person.GroupId,
person.QrCode,
person.Name,
person.Email,
person.PhoneNumber,
person.Quotas.Select(q => new QuotaResponse(
q.ProductId,
q.Product.Name,
q.Product.Type.ToString(),
q.InitialAmount,
q.UsedAmount,
q.RemainingAmount
)).ToList()
);
}
public async Task<IEnumerable<QuotaResponse>> GetQuotasByQrCodeAsync(Guid qrCode)
{
var quotas = await _context.PersonQuotas
.Include(q => q.Product)
.Include(q => q.Person)
.Where(q => q.Person.QrCode == qrCode)
.Select(q => new QuotaResponse(
q.ProductId,
q.Product.Name,
q.Product.Type.ToString(),
q.InitialAmount,
q.UsedAmount,
q.RemainingAmount
))
.ToListAsync();
return quotas;
}
}