aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-01-17 15:30:09 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-01-17 15:30:09 +0200
commit8f6a50566a069c782482a167f601e6eca9588e73 (patch)
treef3732aab96e3e9be3180acbe5d0b07216629170c
parent8d1d0b40d56f90248f948e474330258bf57cf0b6 (diff)
downloadDevHive-8f6a50566a069c782482a167f601e6eca9588e73.tar
DevHive-8f6a50566a069c782482a167f601e6eca9588e73.tar.gz
DevHive-8f6a50566a069c782482a167f601e6eca9588e73.zip
User update now updates languages, roles and friends
-rw-r--r--src/DevHive.Services/Configurations/Mapping/UserMappings.cs3
-rw-r--r--src/DevHive.Services/Models/Identity/User/UpdateUserCollectionServiceModel.cs7
-rw-r--r--src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs12
-rw-r--r--src/DevHive.Services/Services/UserService.cs33
-rw-r--r--src/DevHive.Web/Configurations/Mapping/UserMappings.cs7
5 files changed, 60 insertions, 2 deletions
diff --git a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs
index d57c6ba..97355d6 100644
--- a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs
+++ b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs
@@ -11,6 +11,9 @@ namespace DevHive.Services.Configurations.Mapping
CreateMap<UserServiceModel, User>();
CreateMap<RegisterServiceModel, User>();
CreateMap<UpdateUserServiceModel, User>();
+ CreateMap<UpdateUserCollectionServiceModel, User>()
+ .ForMember(up => up.UserName, u => u.MapFrom(src => src.Name));
+
CreateMap<User, UserServiceModel>();
}
diff --git a/src/DevHive.Services/Models/Identity/User/UpdateUserCollectionServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UpdateUserCollectionServiceModel.cs
new file mode 100644
index 0000000..c40a980
--- /dev/null
+++ b/src/DevHive.Services/Models/Identity/User/UpdateUserCollectionServiceModel.cs
@@ -0,0 +1,7 @@
+namespace DevHive.Services.Models.Identity.User
+{
+ public class UpdateUserCollectionServiceModel
+ {
+ public string Name { get; set; }
+ }
+}
diff --git a/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs
index 96d1ff0..5b5a178 100644
--- a/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs
+++ b/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs
@@ -1,9 +1,19 @@
using System;
+using System.Collections.Generic;
namespace DevHive.Services.Models.Identity.User
{
- public class UpdateUserServiceModel : UserServiceModel
+ public class UpdateUserServiceModel : BaseUserServiceModel
{
public Guid Id { get; set; }
+
+ public IList<UpdateUserCollectionServiceModel> Roles { get; set; } = new List<UpdateUserCollectionServiceModel>();
+
+ public IList<UpdateUserCollectionServiceModel> Friends { get; set; } = new List<UpdateUserCollectionServiceModel>();
+
+ public IList<UpdateUserCollectionServiceModel> Languages { get; set; } = new List<UpdateUserCollectionServiceModel>();
+
+ public IList<UpdateUserCollectionServiceModel> Technologies { get; set; } = new List<UpdateUserCollectionServiceModel>();
+
}
}
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index 1dc1bd5..3dd030a 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -13,6 +13,7 @@ using System.Collections.Generic;
using DevHive.Common.Models.Identity;
using DevHive.Services.Interfaces;
using DevHive.Data.Interfaces.Repositories;
+using DevHive.Services.Models.Language;
namespace DevHive.Services.Services
{
@@ -139,7 +140,7 @@ namespace DevHive.Services.Services
&& await this._userRepository.DoesUsernameExistAsync(updateModel.UserName))
throw new ArgumentException("Username already exists!");
- //Add validations for everything else
+ await this.ValidateUserCollections(updateModel);
User user = this._userMapper.Map<User>(updateModel);
bool result = await this._userRepository.EditAsync(user);
@@ -149,6 +150,36 @@ namespace DevHive.Services.Services
return this._userMapper.Map<UserServiceModel>(user); ;
}
+
+ private async Task ValidateUserCollections(UpdateUserServiceModel updateUserServiceModel)
+ {
+ // Friends
+ foreach (UpdateUserCollectionServiceModel friend in updateUserServiceModel.Friends)
+ {
+ User returnedFriend = await this._userRepository.GetByUsernameAsync(friend.Name);
+
+ if (default(User) == returnedFriend)
+ throw new ArgumentException($"User {friend.Name} does not exist!");
+ }
+
+ // Languages
+ foreach (UpdateUserCollectionServiceModel language in updateUserServiceModel.Languages)
+ {
+ Language returnedLanguage = await this._languageRepository.GetByNameAsync(language.Name);
+
+ if (default(Language) == returnedLanguage)
+ throw new ArgumentException($"Language {language.Name} does not exist!");
+ }
+
+ // Technology
+ foreach (UpdateUserCollectionServiceModel technology in updateUserServiceModel.Technologies)
+ {
+ Technology returnedTechnology = await this._technologyRepository.GetByNameAsync(technology.Name);
+
+ if (default(Technology) == returnedTechnology)
+ throw new ArgumentException($"Technology {technology.Name} does not exist!");
+ }
+ }
#endregion
#region Delete
diff --git a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs
index 59003ea..aa22ce2 100644
--- a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs
+++ b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs
@@ -2,6 +2,8 @@ using AutoMapper;
using DevHive.Services.Models.Identity.User;
using DevHive.Web.Models.Identity.User;
using DevHive.Common.Models.Identity;
+using DevHive.Web.Models.Language;
+using DevHive.Web.Models.Technology;
namespace DevHive.Web.Configurations.Mapping
{
@@ -17,6 +19,11 @@ namespace DevHive.Web.Configurations.Mapping
CreateMap<UserServiceModel, UserWebModel>();
CreateMap<TokenModel, TokenWebModel>();
+
+ CreateMap<FriendWebModel, UpdateUserCollectionServiceModel>()
+ .ForMember(f => f.Name, u => u.MapFrom(src => src.Username));
+ CreateMap<UpdateLanguageWebModel, UpdateUserCollectionServiceModel>();
+ CreateMap<UpdateTechnologyWebModel, UpdateUserCollectionServiceModel>();
}
}
}