using DXPBLL.Auth; using DXPDAL.Common; using DXPSL.Parameters.Auth; using FastEndpoints; using GB5Shared.DTO.Framework.Enum; using GB5Shared.DTO.Framework.ResponseStandard; namespace DXPSL.Endpoints.Auth; // Anonymous — no account exists yet, so there is nothing to authenticate against. public class Register : Endpoint> { private readonly IAuthBLL _bll; private readonly IDXPSystemContext _systemContext; public Register(IAuthBLL bll, IDXPSystemContext systemContext) { _bll = bll; _systemContext = systemContext; } public override void Configure() { Post("/DXP/Auth/Register"); AllowAnonymous(); } public override async Task HandleAsync(RegisterParameters req, CancellationToken ct) { try { var message = await _bll.RegisterAsync( req.FullName, req.Email, req.Mobile, req.Password, _systemContext.GetSystemLogin(), ct); await Send.ResponseAsync(new ResponseStandardDTO { Status = FrameworkEnumDTO.ResponseStatus.Ok, Body = message }, cancellation: ct); } catch (Exception ex) when (ex is ArgumentException or InvalidOperationException) { await Send.ResponseAsync(new ResponseStandardDTO { Status = FrameworkEnumDTO.ResponseStatus.Failed, ErrorBody = ex.Message }, statusCode: 400, cancellation: ct); } } }