feat(api): .NET 10 multi-tenant REST API
Full backend implementation: - Multi-tenant cafe/restaurant management (menus, orders, tables, staff) - POS order flow with ZarinPal and Snappfood payment integration - OTP authentication via Kavenegar SMS - QR digital menu with public discover/finder endpoints - Customer loyalty, coupons, CRM - PostgreSQL via EF Core, Redis for caching/sessions - Background jobs, webhook handlers - Full migration history Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Meezi.Core.Discover;
|
||||
|
||||
namespace Meezi.Infrastructure.Discover;
|
||||
|
||||
public static class CafeDiscoverProfileSerializer
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public static CafeDiscoverProfile Deserialize(string? json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
return new CafeDiscoverProfile();
|
||||
|
||||
try
|
||||
{
|
||||
var profile = JsonSerializer.Deserialize<CafeDiscoverProfile>(json, JsonOptions);
|
||||
return Sanitize(profile ?? new CafeDiscoverProfile());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new CafeDiscoverProfile();
|
||||
}
|
||||
}
|
||||
|
||||
public static string Serialize(CafeDiscoverProfile profile) =>
|
||||
JsonSerializer.Serialize(Sanitize(profile), JsonOptions);
|
||||
|
||||
public static CafeDiscoverProfile Sanitize(CafeDiscoverProfile input)
|
||||
{
|
||||
var p = new CafeDiscoverProfile
|
||||
{
|
||||
Size = NormalizeSingle(input.Size, CafeDiscoverProfileKeys.Sizes),
|
||||
Floors = NormalizeSingle(input.Floors, CafeDiscoverProfileKeys.Floors),
|
||||
NoiseLevel = NormalizeSingle(input.NoiseLevel, CafeDiscoverProfileKeys.NoiseLevels),
|
||||
PriceTier = NormalizeSingle(input.PriceTier, CafeDiscoverProfileKeys.PriceTiers),
|
||||
Themes = NormalizeList(input.Themes, CafeDiscoverProfileKeys.Themes),
|
||||
Vibes = NormalizeList(input.Vibes, CafeDiscoverProfileKeys.Vibes),
|
||||
Occasions = NormalizeList(input.Occasions, CafeDiscoverProfileKeys.Occasions),
|
||||
SpaceFeatures = NormalizeList(input.SpaceFeatures, CafeDiscoverProfileKeys.SpaceFeatures)
|
||||
};
|
||||
return p;
|
||||
}
|
||||
|
||||
private static string? NormalizeSingle(string? value, HashSet<string> allowed)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value)) return null;
|
||||
var id = value.Trim().ToLowerInvariant();
|
||||
return allowed.Contains(id) ? id : null;
|
||||
}
|
||||
|
||||
private static List<string> NormalizeList(IEnumerable<string>? values, HashSet<string> allowed)
|
||||
{
|
||||
if (values is null) return [];
|
||||
return values
|
||||
.Select(v => v.Trim().ToLowerInvariant())
|
||||
.Where(v => !string.IsNullOrEmpty(v) && allowed.Contains(v))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Meezi.Core.Discover;
|
||||
using Meezi.Core.Entities;
|
||||
using Meezi.Core.Enums;
|
||||
|
||||
namespace Meezi.Infrastructure.Discover;
|
||||
|
||||
public record CafeBadgeDto(string Key, string Label, string Icon);
|
||||
|
||||
public static class DiscoverBadgeMapping
|
||||
{
|
||||
public static IReadOnlyList<CafeBadgeDto> ToDtos(Cafe cafe, string lang = "fa")
|
||||
{
|
||||
if (cafe.PlanTier != PlanTier.Enterprise)
|
||||
return [];
|
||||
|
||||
var keys = DiscoverBadgesSerializer.Deserialize(cafe.DiscoverBadgesJson);
|
||||
var list = new List<CafeBadgeDto>();
|
||||
foreach (var key in keys)
|
||||
{
|
||||
var def = CafeBadgeCatalog.Resolve(key);
|
||||
if (def is null) continue;
|
||||
var label = lang switch
|
||||
{
|
||||
"en" => def.LabelEn,
|
||||
"ar" => def.LabelAr,
|
||||
_ => def.LabelFa
|
||||
};
|
||||
list.Add(new CafeBadgeDto(def.Key, label, def.Icon));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Text.Json;
|
||||
using Meezi.Core.Discover;
|
||||
|
||||
namespace Meezi.Infrastructure.Discover;
|
||||
|
||||
public static class DiscoverBadgesSerializer
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
};
|
||||
|
||||
public static IReadOnlyList<string> Deserialize(string? json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json)) return [];
|
||||
try
|
||||
{
|
||||
var list = JsonSerializer.Deserialize<List<string>>(json, JsonOptions);
|
||||
return CafeBadgeCatalog.NormalizeKeys(list);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public static string? Serialize(IEnumerable<string>? keys)
|
||||
{
|
||||
var normalized = CafeBadgeCatalog.NormalizeKeys(keys);
|
||||
return normalized.Count == 0 ? null : JsonSerializer.Serialize(normalized, JsonOptions);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user