using e_suite.API.Common; using e_suite.API.Common.models; using eSuite.API.security; using eSuite.API.Utilities; using eSuite.Core.Security; using Microsoft.AspNetCore.Mvc; namespace eSuite.API.Controllers; /// /// This part of the API is responsible for allowing a user to edit their own profile /// [Route("api/[controller]")] [ApiController] public class ProfileController : ESuiteControllerBase { private readonly IUserManager _userManager; /// /// /// /// public ProfileController(IUserManager userManager) { _userManager = userManager; } /// /// Returns the general details of your profile /// /// This returns all the general information for your profile, e-mail, twofactor authentication key (used for setting up TFA), when your name and when the account was created. /// [Route("myProfile")] [HttpGet] [AccessKey(SecurityAccess.Everyone)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetMyProfile(CancellationToken cancellationToken = default!) { var profile = await _userManager.GetProfile(User.Email(), cancellationToken); return Ok(profile); } /// /// Use this method to update your own profile. /// /// /// [Route("myProfile")] [HttpPut] [AccessKey(SecurityAccess.Everyone)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ProblemDetails))] [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))] public async Task EditMyProfile( [FromBody] UpdatedUserProfile userProfile, CancellationToken cancellationToken = default! ) { await _userManager.UpdateProfile(AuditUserDetails, User.Email(), userProfile, cancellationToken); return Ok(); } }