diff options
| author | transtrike <transtrike@gmail.com> | 2021-04-07 18:41:30 +0300 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-04-07 18:41:30 +0300 |
| commit | b8d1edfc582bee2ef648757bcad1bbadd075bb08 (patch) | |
| tree | 0042a44c3091af36994cdc9b91a835ed1d803eaa /src/Web/DevHive.Web/Controllers/ProfilePictureController.cs | |
| parent | f4eac9c89bef0c21d7ccb29cb0841fa621c79f46 (diff) | |
| parent | da7d6223c261aac8e8f18458c11fb48cf9ca4cfe (diff) | |
| download | DevHive-b8d1edfc582bee2ef648757bcad1bbadd075bb08.tar DevHive-b8d1edfc582bee2ef648757bcad1bbadd075bb08.tar.gz DevHive-b8d1edfc582bee2ef648757bcad1bbadd075bb08.zip | |
Merged from dev
Diffstat (limited to 'src/Web/DevHive.Web/Controllers/ProfilePictureController.cs')
| -rw-r--r-- | src/Web/DevHive.Web/Controllers/ProfilePictureController.cs | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs b/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs index 2eec99e..9a76e2c 100644 --- a/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs +++ b/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs @@ -1,8 +1,12 @@ using System; using System.Threading.Tasks; -using DevHive.Web.Models.User; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using DevHive.Services.Interfaces; +using DevHive.Services.Models.ProfilePicture; +using DevHive.Common.Jwt.Interfaces; +using AutoMapper; +using DevHive.Web.Models.ProfilePicture; namespace DevHive.Web.Controllers { @@ -13,36 +17,50 @@ namespace DevHive.Web.Controllers [Route("api/[controller]")] public class ProfilePictureController { - // private readonly ProfilePictureService _profilePictureService; + private readonly IProfilePictureService _profilePictureService; + private readonly IJwtService _jwtService; + private readonly IMapper _profilePictureMapper; - // public ProfilePictureController(ProfilePictureService profilePictureService) - // { - // this._profilePictureService = profilePictureService; - // } + public ProfilePictureController(IProfilePictureService profilePictureService, IJwtService jwtService, IMapper profilePictureMapper) + { + this._profilePictureService = profilePictureService; + this._jwtService = jwtService; + this._profilePictureMapper = profilePictureMapper; + } + + /// <summary> + /// Get the URL of user's profile picture + /// </summary> + /// <param name="profilePictureId">The profile picture's Id</param> + /// <param name="authorization">JWT Bearer Token</param> + /// <returns>The URL of the profile picture</returns> + [HttpGet] + [AllowAnonymous] + public async Task<IActionResult> ReadProfilePicture(Guid profilePictureId, [FromHeader] string authorization) + { + string profilePicURL = await this._profilePictureService.GetProfilePictureById(profilePictureId); + return new OkObjectResult(new { ProfilePictureURL = profilePicURL} ); + } /// <summary> /// Alter the profile picture of a user /// </summary> /// <param name="userId">The user's Id</param> - /// <param name="updateProfilePictureWebModel">The new profile picture</param> + /// <param name="profilePictureWebModel">The new profile picture</param> /// <param name="authorization">JWT Bearer Token</param> - /// <returns>???</returns> + /// <returns>The URL of the new profile picture</returns> [HttpPut] - [Route("ProfilePicture")] [Authorize(Roles = "User,Admin")] - public async Task<IActionResult> UpdateProfilePicture(Guid userId, [FromForm] UpdateProfilePictureWebModel updateProfilePictureWebModel, [FromHeader] string authorization) + public async Task<IActionResult> UpdateProfilePicture(Guid userId, [FromForm] ProfilePictureWebModel profilePictureWebModel, [FromHeader] string authorization) { - throw new NotImplementedException(); - // if (!await this._userService.ValidJWT(userId, authorization)) - // return new UnauthorizedResult(); - - // UpdateProfilePictureServiceModel updateProfilePictureServiceModel = this._userMapper.Map<UpdateProfilePictureServiceModel>(updateProfilePictureWebModel); - // updateProfilePictureServiceModel.UserId = userId; + if (!this._jwtService.ValidateToken(userId, authorization)) + return new UnauthorizedResult(); - // ProfilePictureServiceModel profilePictureServiceModel = await this._userService.UpdateProfilePicture(updateProfilePictureServiceModel); - // ProfilePictureWebModel profilePictureWebModel = this._userMapper.Map<ProfilePictureWebModel>(profilePictureServiceModel); + ProfilePictureServiceModel profilePictureServiceModel = this._profilePictureMapper.Map<ProfilePictureServiceModel>(profilePictureWebModel); + profilePictureServiceModel.UserId = userId; - // return new AcceptedResult("UpdateProfilePicture", profilePictureWebModel); + string url = await this._profilePictureService.UpdateProfilePicture(profilePictureServiceModel); + return new OkObjectResult(new { URL = url }); } } } |
