49 lines
No EOL
1.5 KiB
C#
49 lines
No EOL
1.5 KiB
C#
using DrinkRateAPI.ApiModels.UserProfile;
|
|
using DrinkRateAPI.AuthorizationPolicies;
|
|
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 = PolicyConstants.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 = PolicyConstants.AdminOnly)]
|
|
[Produces("application/json")]
|
|
public async Task<UserProfileGet> GetUserProfile(string userId)
|
|
{
|
|
return await _userProfileService.GetUserProfileAsync(User, userId);
|
|
}
|
|
} |