63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
/// This part of the API is responsible for allowing a user to edit their own profile
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class ProfileController : ESuiteControllerBase
|
|
{
|
|
private readonly IUserManager _userManager;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="userManager"></param>
|
|
public ProfileController(IUserManager userManager)
|
|
{
|
|
_userManager = userManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the general details of your profile
|
|
/// </summary>
|
|
/// <remarks>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.</remarks>
|
|
/// <returns></returns>
|
|
[Route("myProfile")]
|
|
[HttpGet]
|
|
[AccessKey(SecurityAccess.Everyone)]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> GetMyProfile(CancellationToken cancellationToken = default!)
|
|
{
|
|
var profile = await _userManager.GetProfile(User.Email(), cancellationToken);
|
|
return Ok(profile);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use this method to update your own profile.
|
|
/// </summary>
|
|
/// <param name="userProfile"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
[Route("myProfile")]
|
|
[HttpPut]
|
|
[AccessKey(SecurityAccess.Everyone)]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ProblemDetails))]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
|
|
public async Task<IActionResult> EditMyProfile(
|
|
[FromBody] UpdatedUserProfile userProfile,
|
|
CancellationToken cancellationToken = default!
|
|
)
|
|
{
|
|
await _userManager.UpdateProfile(AuditUserDetails, User.Email(), userProfile, cancellationToken);
|
|
return Ok();
|
|
}
|
|
} |