drinkrate/DrinkRateAPI/Controllers/UserProfileController.cs
2025-08-11 22:08:13 +02:00

48 lines
No EOL
1.4 KiB
C#

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 UserProfileService _userProfileService;
public UserProfileController(UserProfileService userProfileService)
{
_userProfileService = userProfileService;
}
[HttpPut]
[Produces("application/json")]
public async Task<UserProfileGet> PutUserProfileSelf([FromBody] UserProfileSelfPut userProfile)
{
return await _userProfileService.PutUserProfileSelfAsync(User, userProfile);
}
[HttpGet]
[Produces("application/json")]
public async Task<UserProfileGet> GetUserProfileSelf()
{
return await _userProfileService.GetUserProfileSelfAsync(User);
}
[HttpPut("{userId}")]
[Authorize(Policy = "AdminOnly")]
[Produces("application/json")]
public async Task<UserProfileGet> PutUserProfile(string userId, [FromBody] UserProfilePut userProfile)
{
return await _userProfileService.PutUserProfileAsync(User, userProfile, userId);
}
[HttpGet("{userId}")]
[Authorize(Policy = "AdminOnly")]
[Produces("application/json")]
public async Task<UserProfileGet> GetUserProfile(string userId)
{
return await _userProfileService.GetUserProfileAsync(User, userId);
}
}