diff options
| -rw-r--r-- | src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs | 13 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/UserRepository.cs | 74 | ||||
| -rw-r--r-- | src/DevHive.Services/Interfaces/IUserService.cs | 5 | ||||
| -rw-r--r-- | src/DevHive.Services/Services/UserService.cs | 51 |
4 files changed, 2 insertions, 141 deletions
diff --git a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs index 456eb94..c29669d 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs @@ -8,10 +8,7 @@ namespace DevHive.Data.Interfaces.Repositories { public interface IUserRepository : IRepository<User> { - Task<bool> AddFriendToUserAsync(User user, User friend); - Task<bool> AddLanguageToUserAsync(User user, Language language); - Task<bool> AddTechnologyToUserAsync(User user, Technology technology); - + //Read Task<User> GetByUsernameAsync(string username); Language GetUserLanguage(User user, Language language); HashSet<Language> GetUserLanguages(User user); @@ -19,13 +16,7 @@ namespace DevHive.Data.Interfaces.Repositories Technology GetUserTechnology(User user, Technology technology); IEnumerable<User> QueryAll(); - Task<bool> EditUserLanguageAsync(User user, Language oldLang, Language newLang); - Task<bool> EditUserTechnologyAsync(User user, Technology oldTech, Technology newTech); - - Task<bool> RemoveFriendAsync(User user, User friend); - Task<bool> RemoveLanguageFromUserAsync(User user, Language language); - Task<bool> RemoveTechnologyFromUserAsync(User user, Technology technology); - + //Validations Task<bool> DoesEmailExistAsync(string email); Task<bool> DoesUserExistAsync(Guid id); Task<bool> DoesUserHaveThisFriendAsync(Guid userId, Guid friendId); diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index c769f7e..f0c28f1 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -2,11 +2,9 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using DevHive.Common.Models.Misc; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.ChangeTracking; namespace DevHive.Data.Repositories { @@ -28,32 +26,6 @@ namespace DevHive.Data.Repositories return await this.SaveChangesAsync(this._context); } - - public async Task<bool> AddFriendToUserAsync(User user, User friend) - { - this._context.Update(user); - user.Friends.Add(friend); - - return await this.SaveChangesAsync(this._context); - } - - public async Task<bool> AddLanguageToUserAsync(User user, Language language) - { - this._context.Update(user); - - user.Languages.Add(language); - - return await this.SaveChangesAsync(this._context); - } - - public async Task<bool> AddTechnologyToUserAsync(User user, Technology technology) - { - this._context.Update(user); - - user.Technologies.Add(technology); - - return await this.SaveChangesAsync(this._context); - } #endregion #region Read @@ -120,26 +92,6 @@ namespace DevHive.Data.Repositories return await this.SaveChangesAsync(this._context); } - - public async Task<bool> EditUserLanguageAsync(User user, Language oldLang, Language newLang) - { - this._context.Update(user); - - user.Languages.Remove(oldLang); - user.Languages.Add(newLang); - - return await this.SaveChangesAsync(this._context); - } - - public async Task<bool> EditUserTechnologyAsync(User user, Technology oldTech, Technology newTech) - { - this._context.Update(user); - - user.Technologies.Remove(oldTech); - user.Technologies.Add(newTech); - - return await this.SaveChangesAsync(this._context); - } #endregion #region Delete @@ -151,32 +103,6 @@ namespace DevHive.Data.Repositories return await this.SaveChangesAsync(this._context); } - - public async Task<bool> RemoveFriendAsync(User user, User friend) - { - this._context.Update(user); - user.Friends.Remove(friend); - - return await this.SaveChangesAsync(this._context); - } - - public async Task<bool> RemoveLanguageFromUserAsync(User user, Language language) - { - this._context.Update(user); - - user.Languages.Remove(language); - - return await this.SaveChangesAsync(this._context); - } - - public async Task<bool> RemoveTechnologyFromUserAsync(User user, Technology technology) - { - this._context.Update(user); - - user.Technologies.Remove(technology); - - return await this.SaveChangesAsync(this._context); - } #endregion #region Validations diff --git a/src/DevHive.Services/Interfaces/IUserService.cs b/src/DevHive.Services/Interfaces/IUserService.cs index 923e9bb..51e3cf9 100644 --- a/src/DevHive.Services/Interfaces/IUserService.cs +++ b/src/DevHive.Services/Interfaces/IUserService.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Common.Models.Identity; -using DevHive.Common.Models.Misc; using DevHive.Services.Models.Identity.User; namespace DevHive.Services.Interfaces @@ -12,15 +10,12 @@ namespace DevHive.Services.Interfaces Task<TokenModel> LoginUser(LoginServiceModel loginModel); Task<TokenModel> RegisterUser(RegisterServiceModel registerModel); - Task<bool> AddFriend(Guid userId, Guid friendId); - Task<UserServiceModel> GetUserByUsername(string username); Task<UserServiceModel> GetUserById(Guid id); Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateModel); Task DeleteUser(Guid id); - Task<bool> RemoveFriend(Guid userId, Guid friendId); Task<bool> ValidJWT(Guid id, string rawTokenData); } diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index a57fd23..217154e 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -84,35 +84,7 @@ namespace DevHive.Services.Services } #endregion - #region Create - - public async Task<bool> AddFriend(Guid userId, Guid friendId) - { - Task<bool> userExists = this._userRepository.DoesUserExistAsync(userId); - Task<bool> friendExists = this._userRepository.DoesUserExistAsync(friendId); - - await Task.WhenAll(userExists, friendExists); - - if (!userExists.Result) - throw new ArgumentException("User doesn't exist!"); - - if (!friendExists.Result) - throw new ArgumentException("Friend doesn't exist!"); - - if (await this._userRepository.DoesUserHaveThisFriendAsync(userId, friendId)) - throw new ArgumentException("Friend already exists in your friends list."); - - User user = await this._userRepository.GetByIdAsync(userId); - User friend = await this._userRepository.GetByIdAsync(friendId); - - return user != null && friend != null ? - await this._userRepository.AddFriendToUserAsync(user, friend) : - throw new ArgumentException("Invalid user!"); - } - #endregion - #region Read - public async Task<UserServiceModel> GetUserById(Guid id) { User user = await this._userRepository.GetByIdAsync(id) @@ -133,7 +105,6 @@ namespace DevHive.Services.Services #endregion #region Update - public async Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateUserServiceModel) { await this.ValidateUserOnUpdate(updateUserServiceModel); @@ -191,7 +162,6 @@ namespace DevHive.Services.Services #endregion #region Delete - public async Task DeleteUser(Guid id) { if (!await this._userRepository.DoesUserExistAsync(id)) @@ -203,30 +173,9 @@ namespace DevHive.Services.Services if (!result) throw new InvalidOperationException("Unable to delete user!"); } - - public async Task<bool> RemoveFriend(Guid userId, Guid friendId) - { - bool userExists = await this._userRepository.DoesUserExistAsync(userId); - bool friendExists = await this._userRepository.DoesUserExistAsync(friendId); - - if (!userExists) - throw new ArgumentException("User doesn't exist!"); - - if (!friendExists) - throw new ArgumentException("Friend doesn't exist!"); - - if (!await this._userRepository.DoesUserHaveThisFriendAsync(userId, friendId)) - throw new ArgumentException("This ain't your friend, amigo."); - - User user = await this._userRepository.GetByIdAsync(userId); - User homie = await this._userRepository.GetByIdAsync(friendId); - - return await this._userRepository.RemoveFriendAsync(user, homie); - } #endregion #region Validations - public async Task<bool> ValidJWT(Guid id, string rawTokenData) { // There is authorization name in the beginning, i.e. "Bearer eyJh..." |
