drinkrate/DrinkRateAPI/Controllers/UserProfileController.cs
2025-08-11 07:46:14 +02:00

38 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;
}
public UserProfileGet PutUserProfile([FromBody] 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] UserProfileAdminStatusPut body)
{
var changedProfile = await _userProfileService.PutUserProfileAdminStatusAsync(userId, body.ChangeStatusTo);
return Ok(changedProfile);
}
}