
Relocates the endpoint for updating user admin status from the dedicated AdminController to the UserProfileController. This consolidates user profile management under a single controller and leverages existing authorization policies.
39 lines
No EOL
1.3 KiB
C#
39 lines
No EOL
1.3 KiB
C#
using System.Security.Claims;
|
|
using DrinkRateAPI.ApiModels.UserProfile;
|
|
using DrinkRateAPI.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DrinkRateAPI.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("userProfile")]
|
|
public class UserProfileController : ControllerBase
|
|
{
|
|
private readonly ILogger<UserProfileController> _logger;
|
|
private readonly UserProfileService _userProfileService;
|
|
|
|
public UserProfileController(ILogger<UserProfileController> logger, UserProfileService userProfileService)
|
|
{
|
|
_logger = logger;
|
|
_userProfileService = userProfileService;
|
|
}
|
|
|
|
[HttpPut(Name = "user_profile")]
|
|
public UserProfileGet PutUserProfile(UserProfilePut userProfile)
|
|
{
|
|
throw new ApplicationException();
|
|
var x = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; //HttpContext.User.Identities.First();
|
|
return new();
|
|
}
|
|
|
|
[HttpPut("{userId}/adminStatus")]
|
|
[Authorize(Policy = "AdminOnly")]
|
|
[Produces("application/json")]
|
|
public async Task<IActionResult> PutUserAdminStatus(string userId, [FromBody] ChangeAdminStatusBody body)
|
|
{
|
|
var changedProfile = await _userProfileService.PutUserProfileAdminStatusAsync(userId, body.ChangeStatusTo);
|
|
|
|
return Ok(changedProfile);
|
|
}
|
|
} |