using Application.Endpoints; using Application.Endpoints.Authorization.RefreshToken; using Application.Endpoints.Authorization.UserLogin; using Application.Endpoints.Authorization.UserRegister; using Application.Endpoints.Authorization.UserResetPassword; using Application.Services.Database.PostgreSQL; using Application.Services.Email; using Application.Services.Encryption; using Application.Services.Jwt; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace API.Controllers; [Route("api/[controller]")] public class AuthorizationController( IEmailService emailService, IJwtService jwtService, IPatientRepository patientRepository, IDoctorRepository doctorRepository, IAdminRepository adminRepository, IEncryptionService encryptionService) : BaseApiController { [Authorize(Policy = Policies.AnonymousPolicy)] [HttpPost("login")] public async Task> Login(UserLoginCommand request, CancellationToken token) { var handler = new UserLoginHandler(jwtService, encryptionService, doctorRepository, patientRepository, adminRepository); var result = await handler.Handle(request, token); return StatusCode(result.StatusCode, result); } [Authorize(Policy = Policies.AnonymousPolicy)] [HttpPost("register")] public async Task> Register(UserRegisterCommand request, CancellationToken token) { var handler = new UserRegisterHandler(emailService, encryptionService, doctorRepository, patientRepository, adminRepository); var result = await handler.Handle(request, token); return StatusCode(result.StatusCode, result); } [Authorize(Policy = Policies.AnonymousPolicy)] [HttpPost("reset_password")] public async Task> ResetPassword(UserResetPasswordCommand request, CancellationToken token) { var handler = new UserResetPasswordHandler(emailService, encryptionService, doctorRepository, patientRepository, adminRepository); var result = await handler.Handle(request, token); return StatusCode(result.StatusCode, result); } [Authorize(Policy = Policies.AnonymousPolicy)] [HttpPost("refresh_token")] public async Task> RefreshToken([FromBody] RefreshJwtCommand request, CancellationToken cancellationToken) { var handler = new RefreshJwtHandler(jwtService); var result = await handler.Handle(request, cancellationToken); return StatusCode(result.StatusCode, result); } }