15def7ff1c
CI/CD / CI · API (dotnet build + test) (push) Successful in 1m10s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 52s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m5s
CI/CD / CI · Admin Web (tsc) (push) Successful in 35s
CI/CD / CI · Website (tsc) (push) Successful in 45s
CI/CD / CI · Koja (tsc) (push) Successful in 55s
CI/CD / Deploy · all services (push) Successful in 3m29s
Delete (every manageable entity that only had "add" now has delete):
- Ingredients (warehouse): new DELETE /inventory/ingredients/{id} (soft-delete via
the global DeletedAt filter — no FK trouble with recipes/movements) + NoOp stub +
trash button in the materials cards.
- Reservations: new DELETE /reservations/{id} (soft-delete) + per-card delete button.
- Coupons & Customers: backend DELETE already existed; wired delete buttons in the UI.
- Shared ConfirmDialog component used by all delete flows (RTL-aware).
- Audit result: tables/branches/taxes/kitchen-stations/expenses/menu/terminals already
had delete; HR has no "add" so no delete needed; shifts intentionally excluded
(financial open/close records, not add-style entities).
Koja visibility:
- New Cafe.ShowOnKoja flag, default TRUE (DB default true so existing cafés stay
listed). Discover query now filters IsVerified && !Deleted && ShowOnKoja.
- public-profile GET/PUT expose showOnKoja; dashboard public-profile panel has an
on-by-default toggle that persists immediately. Platform IsVerified gate unchanged.
- EF migration AddCafeShowOnKoja (defaultValue: true).
Also: added the missing errors.generic i18n key (fa/en/ar) so useApiError's fallback
resolves instead of rendering the literal "errors.generic". 81 API tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
158 lines
4.8 KiB
C#
158 lines
4.8 KiB
C#
using Meezi.API.Models.Public;
|
|
using Meezi.Core.Entities;
|
|
using Meezi.Core.Enums;
|
|
using Meezi.Infrastructure.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Meezi.API.Services;
|
|
|
|
public interface IReservationService
|
|
{
|
|
Task<IReadOnlyList<ReservationDto>> GetReservationsAsync(
|
|
string cafeId,
|
|
DateOnly? date,
|
|
ReservationStatus? status,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
Task<ReservationDto?> CreateAsync(
|
|
string cafeId,
|
|
CreateReservationRequest request,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
Task<ReservationDto?> UpdateStatusAsync(
|
|
string cafeId,
|
|
string reservationId,
|
|
ReservationStatus status,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
Task<bool> DeleteAsync(
|
|
string cafeId,
|
|
string reservationId,
|
|
CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
public class ReservationService : IReservationService
|
|
{
|
|
private readonly AppDbContext _db;
|
|
private readonly IKdsNotifier _kdsNotifier;
|
|
|
|
public ReservationService(AppDbContext db, IKdsNotifier kdsNotifier)
|
|
{
|
|
_db = db;
|
|
_kdsNotifier = kdsNotifier;
|
|
}
|
|
|
|
public async Task<IReadOnlyList<ReservationDto>> GetReservationsAsync(
|
|
string cafeId,
|
|
DateOnly? date,
|
|
ReservationStatus? status,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var query = _db.TableReservations
|
|
.Include(r => r.Table)
|
|
.Where(r => r.CafeId == cafeId);
|
|
if (date.HasValue)
|
|
query = query.Where(r => r.Date == date.Value);
|
|
if (status.HasValue)
|
|
query = query.Where(r => r.Status == status.Value);
|
|
|
|
var list = await query
|
|
.OrderBy(r => r.Date)
|
|
.ThenBy(r => r.Time)
|
|
.ToListAsync(cancellationToken);
|
|
|
|
return list.Select(Map).ToList();
|
|
}
|
|
|
|
public async Task<ReservationDto?> CreateAsync(
|
|
string cafeId,
|
|
CreateReservationRequest request,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
if (!string.IsNullOrEmpty(request.TableId))
|
|
{
|
|
var tableOk = await _db.Tables.AnyAsync(
|
|
t => t.Id == request.TableId && t.CafeId == cafeId,
|
|
cancellationToken);
|
|
if (!tableOk) return null;
|
|
}
|
|
|
|
var entity = new TableReservation
|
|
{
|
|
CafeId = cafeId,
|
|
TableId = request.TableId,
|
|
GuestName = request.GuestName.Trim(),
|
|
GuestPhone = request.GuestPhone.Trim(),
|
|
Date = request.Date,
|
|
Time = request.Time,
|
|
PartySize = request.PartySize,
|
|
Notes = request.Notes,
|
|
Status = ReservationStatus.Confirmed
|
|
};
|
|
|
|
_db.TableReservations.Add(entity);
|
|
await _db.SaveChangesAsync(cancellationToken);
|
|
|
|
if (!string.IsNullOrEmpty(entity.TableId))
|
|
await _kdsNotifier.NotifyTableStatusChangedAsync(cafeId, cancellationToken);
|
|
|
|
var loaded = await _db.TableReservations
|
|
.Include(r => r.Table)
|
|
.FirstAsync(r => r.Id == entity.Id, cancellationToken);
|
|
|
|
return Map(loaded);
|
|
}
|
|
|
|
public async Task<ReservationDto?> UpdateStatusAsync(
|
|
string cafeId,
|
|
string reservationId,
|
|
ReservationStatus status,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var entity = await _db.TableReservations
|
|
.Include(r => r.Table)
|
|
.FirstOrDefaultAsync(r => r.Id == reservationId && r.CafeId == cafeId, cancellationToken);
|
|
if (entity is null) return null;
|
|
|
|
entity.Status = status;
|
|
await _db.SaveChangesAsync(cancellationToken);
|
|
|
|
if (!string.IsNullOrEmpty(entity.TableId))
|
|
await _kdsNotifier.NotifyTableStatusChangedAsync(cafeId, cancellationToken);
|
|
|
|
return Map(entity);
|
|
}
|
|
|
|
public async Task<bool> DeleteAsync(
|
|
string cafeId,
|
|
string reservationId,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var entity = await _db.TableReservations
|
|
.FirstOrDefaultAsync(r => r.Id == reservationId && r.CafeId == cafeId, cancellationToken);
|
|
if (entity is null) return false;
|
|
|
|
// Soft delete: TableReservation has a global DeletedAt query filter.
|
|
entity.DeletedAt = DateTime.UtcNow;
|
|
await _db.SaveChangesAsync(cancellationToken);
|
|
|
|
if (!string.IsNullOrEmpty(entity.TableId))
|
|
await _kdsNotifier.NotifyTableStatusChangedAsync(cafeId, cancellationToken);
|
|
|
|
return true;
|
|
}
|
|
|
|
internal static ReservationDto Map(TableReservation r) => new(
|
|
r.Id,
|
|
r.CafeId,
|
|
r.TableId,
|
|
r.Table?.Number,
|
|
r.GuestName,
|
|
r.GuestPhone,
|
|
r.Date,
|
|
r.Time,
|
|
r.PartySize,
|
|
r.Status,
|
|
r.Notes);
|
|
}
|