aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-17 16:26:32 +0200
committertranstrike <transtrike@gmail.com>2021-01-17 16:26:32 +0200
commitf0398cf1b7e6477bbd184e7509a1030054fc1926 (patch)
tree90a5ff56f96972e55f31e4339818aa0af0323b73
parent8f6a50566a069c782482a167f601e6eca9588e73 (diff)
downloadDevHive-f0398cf1b7e6477bbd184e7509a1030054fc1926.tar
DevHive-f0398cf1b7e6477bbd184e7509a1030054fc1926.tar.gz
DevHive-f0398cf1b7e6477bbd184e7509a1030054fc1926.zip
Fix lang naming
-rw-r--r--src/DevHive.Data/Interfaces/Models/IUser.cs2
-rw-r--r--src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.Designer.cs4
-rw-r--r--src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs4
-rw-r--r--src/DevHive.Data/Models/User.cs4
-rw-r--r--src/DevHive.Data/Repositories/UserRepository.cs16
-rw-r--r--src/DevHive.Services/Configurations/Mapping/UserCollectionMappings.cs21
-rw-r--r--src/DevHive.Services/Configurations/Mapping/UserMappings.cs3
-rw-r--r--src/DevHive.Services/Services/UserService.cs23
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs8
-rw-r--r--src/DevHive.Web/Configurations/Mapping/RoleMappings.cs2
10 files changed, 56 insertions, 31 deletions
diff --git a/src/DevHive.Data/Interfaces/Models/IUser.cs b/src/DevHive.Data/Interfaces/Models/IUser.cs
index 0a770f0..ef8c927 100644
--- a/src/DevHive.Data/Interfaces/Models/IUser.cs
+++ b/src/DevHive.Data/Interfaces/Models/IUser.cs
@@ -8,7 +8,7 @@ namespace DevHive.Data.Interfaces.Models
string FirstName { get; set; }
string LastName { get; set; }
string ProfilePictureUrl { get; set; }
- IList<Language> Langauges { get; set; }
+ IList<Language> Languages { get; set; }
IList<Technology> Technologies { get; set; }
IList<Role> Roles { get; set; }
IList<User> Friends { get; set; }
diff --git a/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.Designer.cs b/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.Designer.cs
index 0f1aa80..1605b5b 100644
--- a/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.Designer.cs
+++ b/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.Designer.cs
@@ -307,7 +307,7 @@ namespace DevHive.Data.Migrations
modelBuilder.Entity("DevHive.Data.Models.Language", b =>
{
b.HasOne("DevHive.Data.Models.User", null)
- .WithMany("Langauges")
+ .WithMany("Languages")
.HasForeignKey("UserId");
});
@@ -395,7 +395,7 @@ namespace DevHive.Data.Migrations
{
b.Navigation("Friends");
- b.Navigation("Langauges");
+ b.Navigation("Languages");
b.Navigation("Technologies");
});
diff --git a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs
index cc6d24d..7197c81 100644
--- a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs
+++ b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs
@@ -305,7 +305,7 @@ namespace DevHive.Data.Migrations
modelBuilder.Entity("DevHive.Data.Models.Language", b =>
{
b.HasOne("DevHive.Data.Models.User", null)
- .WithMany("Langauges")
+ .WithMany("Languages")
.HasForeignKey("UserId");
});
@@ -393,7 +393,7 @@ namespace DevHive.Data.Migrations
{
b.Navigation("Friends");
- b.Navigation("Langauges");
+ b.Navigation("Languages");
b.Navigation("Technologies");
});
diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs
index 944bf6a..31e36ac 100644
--- a/src/DevHive.Data/Models/User.cs
+++ b/src/DevHive.Data/Models/User.cs
@@ -18,12 +18,12 @@ namespace DevHive.Data.Models
/// <summary>
/// Languages that the user uses or is familiar with
/// </summary>
- public IList<Language> Langauges { get; set; }
+ public IList<Language> Languages { get; set; }
/// <summary>
/// Technologies that the user uses or is familiar with
/// </summary>
- public IList<Technology> Technologies { get; set; }
+ public IList<Technology> Technologies { get; set; } = new List<Technology>();
public IList<Role> Roles { get; set; } = new List<Role>();
diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs
index 17ca93b..6d4a0bf 100644
--- a/src/DevHive.Data/Repositories/UserRepository.cs
+++ b/src/DevHive.Data/Repositories/UserRepository.cs
@@ -40,7 +40,7 @@ namespace DevHive.Data.Repositories
{
this._context.Update(user);
- user.Langauges.Add(language);
+ user.Languages.Add(language);
return await RepositoryMethods.SaveChangesAsync(this._context);
}
@@ -70,7 +70,7 @@ namespace DevHive.Data.Repositories
return await this._context.Users
.Include(x => x.Friends)
.Include(x => x.Roles)
- .Include(x => x.Langauges)
+ .Include(x => x.Languages)
.Include(x => x.Technologies)
.FirstOrDefaultAsync(x => x.Id == id);
}
@@ -84,12 +84,12 @@ namespace DevHive.Data.Repositories
public IList<Language> GetUserLanguages(User user)
{
- return user.Langauges;
+ return user.Languages;
}
public Language GetUserLanguage(User user, Language language)
{
- return user.Langauges
+ return user.Languages
.FirstOrDefault(x => x.Id == language.Id);
}
@@ -123,8 +123,8 @@ namespace DevHive.Data.Repositories
{
this._context.Update(user);
- user.Langauges.Remove(oldLang);
- user.Langauges.Add(newLang);
+ user.Languages.Remove(oldLang);
+ user.Languages.Add(newLang);
return await RepositoryMethods.SaveChangesAsync(this._context);
}
@@ -162,7 +162,7 @@ namespace DevHive.Data.Repositories
{
this._context.Update(user);
- user.Langauges.Remove(language);
+ user.Languages.Remove(language);
return await RepositoryMethods.SaveChangesAsync(this._context);
}
@@ -224,7 +224,7 @@ namespace DevHive.Data.Repositories
public bool DoesUserHaveThisLanguage(User user, Language language)
{
- return user.Langauges.Contains(language);
+ return user.Languages.Contains(language);
}
public bool DoesUserHaveThisTechnology(User user, Technology technology)
diff --git a/src/DevHive.Services/Configurations/Mapping/UserCollectionMappings.cs b/src/DevHive.Services/Configurations/Mapping/UserCollectionMappings.cs
new file mode 100644
index 0000000..ee505a2
--- /dev/null
+++ b/src/DevHive.Services/Configurations/Mapping/UserCollectionMappings.cs
@@ -0,0 +1,21 @@
+using AutoMapper;
+using DevHive.Data.Models;
+using DevHive.Services.Models.Identity.User;
+
+namespace DevHive.Services.Configurations.Mapping
+{
+ public class UserCollectionMappings : Profile
+ {
+ public UserCollectionMappings()
+ {
+ CreateMap<UpdateUserCollectionServiceModel, User>()
+ .ForMember(up => up.UserName, u => u.MapFrom(src => src.Name));
+ CreateMap<UpdateUserCollectionServiceModel, Role>()
+ .ForMember(r => r.Name, u => u.MapFrom(src => src.Name));
+ CreateMap<UpdateUserCollectionServiceModel, Language>()
+ .ForMember(r => r.Name, u => u.MapFrom(src => src.Name));
+ CreateMap<UpdateUserCollectionServiceModel, Technology>()
+ .ForMember(r => r.Name, u => u.MapFrom(src => src.Name));
+ }
+ }
+}
diff --git a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs
index 97355d6..d57c6ba 100644
--- a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs
+++ b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs
@@ -11,9 +11,6 @@ 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/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index 3dd030a..b549b1c 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -131,21 +131,28 @@ namespace DevHive.Services.Services
#region Update
- public async Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateModel)
+ public async Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateUserServiceModel)
{
- if (!await this._userRepository.DoesUserExistAsync(updateModel.Id))
+ if (!await this._userRepository.DoesUserExistAsync(updateUserServiceModel.Id))
throw new ArgumentException("User does not exist!");
- if (!this._userRepository.DoesUserHaveThisUsername(updateModel.Id, updateModel.UserName)
- && await this._userRepository.DoesUsernameExistAsync(updateModel.UserName))
+ if (!this._userRepository.DoesUserHaveThisUsername(updateUserServiceModel.Id, updateUserServiceModel.UserName)
+ && await this._userRepository.DoesUsernameExistAsync(updateUserServiceModel.UserName))
throw new ArgumentException("Username already exists!");
- await this.ValidateUserCollections(updateModel);
+ await this.ValidateUserCollections(updateUserServiceModel);
- User user = this._userMapper.Map<User>(updateModel);
- bool result = await this._userRepository.EditAsync(user);
+ //Query proper lang, tech and role and insert the full class in updateUserServiceModel
+ List<Language> properLanguages = new();
+ foreach (UpdateUserCollectionServiceModel lang in updateUserServiceModel.Languages)
+ properLanguages.Add(await this._languageRepository.GetByNameAsync(lang.Name));
- if (!result)
+ User user = this._userMapper.Map<User>(updateUserServiceModel);
+ user.Languages = properLanguages;
+
+ bool success = await this._userRepository.EditAsync(user);
+
+ if (!success)
throw new InvalidOperationException("Unable to edit user!");
return this._userMapper.Map<UserServiceModel>(user); ;
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs
index 46f8aaf..b0a5b93 100644
--- a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs
+++ b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs
@@ -86,7 +86,7 @@ namespace DevHive.Data.Tests
//Assert
Assert.True(result, "The language isn't inserted properly to the database");
- Assert.True(dummyUser.Langauges.Contains(language), "The language doesn't get added properly to the user");
+ Assert.True(dummyUser.Languages.Contains(language), "The language doesn't get added properly to the user");
}
[Test]
@@ -165,7 +165,7 @@ namespace DevHive.Data.Tests
//Arrange
User dummyUser = CreateDummyUser();
await this._userRepository.AddAsync(dummyUser);
- IList<Language> dummyUserLanguages = dummyUser.Langauges;
+ IList<Language> dummyUserLanguages = dummyUser.Languages;
//Act
IList<Language> languages = this._userRepository.GetUserLanguages(dummyUser);
@@ -229,7 +229,7 @@ namespace DevHive.Data.Tests
FirstName = "Spas",
LastName = "Spasov",
Email = "abv@abv.bg",
- Langauges = languages,
+ Languages = languages,
Technologies = technologies,
Roles = roles
};
@@ -271,7 +271,7 @@ namespace DevHive.Data.Tests
FirstName = "Alex",
LastName = "Spiridonov",
Email = "a_spiridonov@abv.bg",
- Langauges = languages,
+ Languages = languages,
Technologies = technologies,
Roles = roles
};
diff --git a/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs b/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs
index bce7c07..66ae8e3 100644
--- a/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs
+++ b/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs
@@ -4,7 +4,7 @@ using DevHive.Services.Models.Identity.Role;
namespace DevHive.Web.Configurations.Mapping
{
- public class RoleMappings : Profile
+ public class RoleMappings : Profile
{
public RoleMappings()
{