using FastEndpoints; using FrameworkBLL.GCM; using FrameworkDAL.DTO.Gcm; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.GCM { public class SaveGCM : BaseEndpoint> { private readonly IGCMBLL _GCMBLL; public SaveGCM(IGCMBLL GCMBLL) { _GCMBLL = GCMBLL; } public override void Configure() { Post("/GCM/SaveGCM"); AllowAnonymous(); } public record SaveGCMParameters( [property: FromHeader] string Login, [property: FromBody] GcmDTO GcmDTO ); protected override string? GetCacheKey(SaveGCMParameters req, LoginDTO LoginDTO) { return KeyGenerator.KeyGeneration(req.GcmDTO.GcmId, EntityConstant.OBJECTGCM, CacheKeyLevel.USER_LEVEL, LoginDTO); } protected override bool ShouldInvalidateCache(SaveGCMParameters req, LoginDTO LoginDTO) => true; protected override async Task> ExecuteAsync(SaveGCMParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _GCMBLL.SaveGCM(req.GcmDTO, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(Result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }