aboutsummaryrefslogtreecommitdiff
path: root/src/Web/DevHive.Web
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-03-25 12:22:54 +0200
committertranstrike <transtrike@gmail.com>2021-03-25 12:22:54 +0200
commitd53caaea6094136bac3d01ce9dd2782bb1819fe2 (patch)
tree0c15e12d9a694600a51070295b0358cee1463545 /src/Web/DevHive.Web
parent9b04b4f2b031a3c631dba65908f277996015ae05 (diff)
downloadDevHive-d53caaea6094136bac3d01ce9dd2782bb1819fe2.tar
DevHive-d53caaea6094136bac3d01ce9dd2782bb1819fe2.tar.gz
DevHive-d53caaea6094136bac3d01ce9dd2782bb1819fe2.zip
Profile Picture implemented; Tests and Front end work await
Diffstat (limited to 'src/Web/DevHive.Web')
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs7
-rw-r--r--src/Web/DevHive.Web/Configurations/Mapping/ProfilePictureMappings.cs16
-rw-r--r--src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs3
-rw-r--r--src/Web/DevHive.Web/Controllers/ProfilePictureController.cs42
4 files changed, 43 insertions, 25 deletions
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
index a0d0979..20b66e1 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
@@ -17,20 +17,22 @@ namespace DevHive.Web.Configurations.Extensions
services.AddTransient<ILanguageRepository, LanguageRepository>();
services.AddTransient<IRoleRepository, RoleRepository>();
services.AddTransient<ITechnologyRepository, TechnologyRepository>();
- services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<IPostRepository, PostRepository>();
services.AddTransient<ICommentRepository, CommentRepository>();
services.AddTransient<IFeedRepository, FeedRepository>();
services.AddTransient<IRatingRepository, RatingRepository>();
+ services.AddTransient<IProfilePictureRepository, ProfilePictureRepository>();
+ services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<ILanguageService, LanguageService>();
services.AddTransient<IRoleService, RoleService>();
services.AddTransient<ITechnologyService, TechnologyService>();
- services.AddTransient<IUserService, UserService>();
services.AddTransient<IPostService, PostService>();
services.AddTransient<ICommentService, CommentService>();
services.AddTransient<IFeedService, FeedService>();
services.AddTransient<IRatingService, RatingService>();
+ services.AddTransient<IProfilePictureService, ProfilePictureService>();
+ services.AddTransient<IUserService, UserService>();
services.AddTransient<ICloudService, CloudinaryService>(options =>
new CloudinaryService(
@@ -43,7 +45,6 @@ namespace DevHive.Web.Configurations.Extensions
signingKey: Encoding.ASCII.GetBytes(configuration.GetSection("Jwt").GetSection("signingKey").Value),
validationIssuer: configuration.GetSection("Jwt").GetSection("validationIssuer").Value,
audience: configuration.GetSection("Jwt").GetSection("audience").Value));
- services.AddTransient<IRatingService, RatingService>();
}
}
}
diff --git a/src/Web/DevHive.Web/Configurations/Mapping/ProfilePictureMappings.cs b/src/Web/DevHive.Web/Configurations/Mapping/ProfilePictureMappings.cs
new file mode 100644
index 0000000..8c12a20
--- /dev/null
+++ b/src/Web/DevHive.Web/Configurations/Mapping/ProfilePictureMappings.cs
@@ -0,0 +1,16 @@
+using System;
+using AutoMapper;
+using DevHive.Web.Models.ProfilePicture;
+using DevHive.Services.Models.ProfilePicture;
+
+namespace DevHive.Web.Configurations.Mapping
+{
+ public class ProfilePictureMappings : Profile
+ {
+ public ProfilePictureMappings()
+ {
+ CreateMap<ProfilePictureWebModel, ProfilePictureServiceModel>()
+ .ForMember(dest => dest.ProfilePictureFormFile, src => src.MapFrom(p => p.Picture));
+ }
+ }
+}
diff --git a/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs b/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs
index 14aaa3a..dabec93 100644
--- a/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs
+++ b/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs
@@ -23,9 +23,6 @@ namespace DevHive.Web.Configurations.Mapping
CreateMap<UsernameWebModel, FriendServiceModel>();
CreateMap<UsernameWebModel, UpdateFriendServiceModel>();
- CreateMap<UpdateProfilePictureWebModel, UpdateProfilePictureServiceModel>();
- CreateMap<ProfilePictureServiceModel, ProfilePictureWebModel>();
-
CreateMap<UpdateUserServiceModel, UpdateUserWebModel>();
CreateMap<FriendServiceModel, UsernameWebModel>();
}
diff --git a/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs b/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs
index 2eec99e..1c736f6 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,36 @@ 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>
/// 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 });
}
}
}