diff options
Diffstat (limited to 'src/DevHive.Services')
| -rw-r--r-- | src/DevHive.Services/Interfaces/ILanguageService.cs | 17 | ||||
| -rw-r--r-- | src/DevHive.Services/Interfaces/IPostService.cs | 24 | ||||
| -rw-r--r-- | src/DevHive.Services/Interfaces/IRoleService.cs | 17 | ||||
| -rw-r--r-- | src/DevHive.Services/Interfaces/ITechnologyService.cs | 17 | ||||
| -rw-r--r-- | src/DevHive.Services/Interfaces/IUserService.cs | 31 | ||||
| -rw-r--r-- | src/DevHive.Services/Services/LanguageService.cs | 22 | ||||
| -rw-r--r-- | src/DevHive.Services/Services/PostService.cs | 27 | ||||
| -rw-r--r-- | src/DevHive.Services/Services/RoleService.cs | 11 | ||||
| -rw-r--r-- | src/DevHive.Services/Services/TechnologyService.cs | 11 | ||||
| -rw-r--r-- | src/DevHive.Services/Services/UserService.cs | 22 |
10 files changed, 161 insertions, 38 deletions
diff --git a/src/DevHive.Services/Interfaces/ILanguageService.cs b/src/DevHive.Services/Interfaces/ILanguageService.cs new file mode 100644 index 0000000..f62bce7 --- /dev/null +++ b/src/DevHive.Services/Interfaces/ILanguageService.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; +using DevHive.Services.Models.Language; + +namespace DevHive.Services.Interfaces +{ + public interface ILanguageService + { + Task<bool> CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel); + + Task<LanguageServiceModel> GetLanguageById(Guid id); + + Task<bool> UpdateLanguage(UpdateLanguageServiceModel languageServiceModel); + + Task<bool> DeleteLanguage(Guid id); + } +}
\ No newline at end of file diff --git a/src/DevHive.Services/Interfaces/IPostService.cs b/src/DevHive.Services/Interfaces/IPostService.cs new file mode 100644 index 0000000..9cb21ed --- /dev/null +++ b/src/DevHive.Services/Interfaces/IPostService.cs @@ -0,0 +1,24 @@ +using System; +using System.Threading.Tasks; +using DevHive.Services.Models.Post.Comment; +using DevHive.Services.Models.Post.Post; + +namespace DevHive.Services.Interfaces +{ + public interface IPostService + { + Task<bool> CreatePost(CreatePostServiceModel postServiceModel); + Task<bool> AddComment(CreateCommentServiceModel commentServiceModel); + + Task<CommentServiceModel> GetCommentById(Guid id); + Task<PostServiceModel> GetPostById(Guid id); + + Task<bool> UpdateComment(UpdateCommentServiceModel commentServiceModel); + Task<bool> UpdatePost(UpdatePostServiceModel postServiceModel); + + Task<bool> DeleteComment(Guid id); + Task<bool> DeletePost(Guid id); + + Task<bool> ValidateJwtForComment(Guid commentId, string rawTokenData); + } +}
\ No newline at end of file diff --git a/src/DevHive.Services/Interfaces/IRoleService.cs b/src/DevHive.Services/Interfaces/IRoleService.cs new file mode 100644 index 0000000..3bf236c --- /dev/null +++ b/src/DevHive.Services/Interfaces/IRoleService.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; +using DevHive.Common.Models.Identity; + +namespace DevHive.Services.Interfaces +{ + public interface IRoleService + { + Task<bool> CreateRole(RoleModel roleServiceModel); + + Task<RoleModel> GetRoleById(Guid id); + + Task<bool> UpdateRole(RoleModel roleServiceModel); + + Task<bool> DeleteRole(Guid id); + } +}
\ No newline at end of file diff --git a/src/DevHive.Services/Interfaces/ITechnologyService.cs b/src/DevHive.Services/Interfaces/ITechnologyService.cs new file mode 100644 index 0000000..33032e2 --- /dev/null +++ b/src/DevHive.Services/Interfaces/ITechnologyService.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; +using DevHive.Services.Models.Technology; + +namespace DevHive.Services.Interfaces +{ + public interface ITechnologyService + { + Task<bool> Create(CreateTechnologyServiceModel technologyServiceModel); + + Task<TechnologyServiceModel> GetTechnologyById(Guid id); + + Task<bool> UpdateTechnology(UpdateTechnologyServiceModel updateTechnologyServiceModel); + + Task<bool> DeleteTechnology(Guid id); + } +}
\ No newline at end of file diff --git a/src/DevHive.Services/Interfaces/IUserService.cs b/src/DevHive.Services/Interfaces/IUserService.cs new file mode 100644 index 0000000..ba53563 --- /dev/null +++ b/src/DevHive.Services/Interfaces/IUserService.cs @@ -0,0 +1,31 @@ +using System; +using System.Threading.Tasks; +using DevHive.Common.Models.Identity; +using DevHive.Services.Models.Identity.User; +using DevHive.Services.Models.Language; +using DevHive.Services.Models.Technology; + +namespace DevHive.Services.Interfaces +{ + public interface IUserService + { + Task<TokenModel> LoginUser(LoginServiceModel loginModel); + Task<TokenModel> RegisterUser(RegisterServiceModel registerModel); + + Task<bool> AddFriend(Guid userId, Guid friendId); + Task<bool> AddLanguageToUser(Guid userId, LanguageServiceModel languageServiceModel); + Task<bool> AddTechnologyToUser(Guid userId, TechnologyServiceModel technologyServiceModel); + + Task<UserServiceModel> GetFriendById(Guid friendId); + Task<UserServiceModel> GetUserById(Guid id); + + Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateModel); + + Task DeleteUser(Guid id); + Task<bool> RemoveFriend(Guid userId, Guid friendId); + Task<bool> RemoveLanguageFromUser(Guid userId, LanguageServiceModel languageServiceModel); + Task<bool> RemoveTechnologyFromUser(Guid userId, TechnologyServiceModel technologyServiceModel); + + Task<bool> ValidJWT(Guid id, string rawTokenData); + } +}
\ No newline at end of file diff --git a/src/DevHive.Services/Services/LanguageService.cs b/src/DevHive.Services/Services/LanguageService.cs index ccc64fd..ac7652b 100644 --- a/src/DevHive.Services/Services/LanguageService.cs +++ b/src/DevHive.Services/Services/LanguageService.cs @@ -1,34 +1,39 @@ using System; using System.Threading.Tasks; using AutoMapper; +using DevHive.Data.Interfaces; using DevHive.Data.Models; -using DevHive.Data.Repositories; +using DevHive.Services.Interfaces; using DevHive.Services.Models.Language; namespace DevHive.Services.Services { - public class LanguageService + public class LanguageService : ILanguageService { - private readonly LanguageRepository _languageRepository; + private readonly ILanguageRepository _languageRepository; private readonly IMapper _languageMapper; - public LanguageService(LanguageRepository languageRepository, IMapper mapper) + public LanguageService(ILanguageRepository languageRepository, IMapper mapper) { this._languageRepository = languageRepository; this._languageMapper = mapper; } + #region Create + public async Task<bool> CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel) { if (await this._languageRepository.DoesLanguageNameExistAsync(createLanguageServiceModel.Name)) throw new ArgumentException("Language already exists!"); - //TODO: Fix, cuz it breaks Language language = this._languageMapper.Map<Language>(createLanguageServiceModel); bool result = await this._languageRepository.AddAsync(language); return result; } + #endregion + + #region Read public async Task<LanguageServiceModel> GetLanguageById(Guid id) { @@ -39,6 +44,9 @@ namespace DevHive.Services.Services return this._languageMapper.Map<LanguageServiceModel>(language); } + #endregion + + #region Update public async Task<bool> UpdateLanguage(UpdateLanguageServiceModel languageServiceModel) { @@ -56,6 +64,9 @@ namespace DevHive.Services.Services Language lang = this._languageMapper.Map<Language>(languageServiceModel); return await this._languageRepository.EditAsync(lang); } + #endregion + + #region Delete public async Task<bool> DeleteLanguage(Guid id) { @@ -65,5 +76,6 @@ namespace DevHive.Services.Services Language language = await this._languageRepository.GetByIdAsync(id); return await this._languageRepository.DeleteAsync(language); } + #endregion } }
\ No newline at end of file diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 321c694..da9e76b 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -7,17 +7,18 @@ using DevHive.Services.Models.Post.Comment; using DevHive.Services.Models.Post.Post; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; -using DevHive.Data.Repositories; +using DevHive.Services.Interfaces; +using DevHive.Data.Interfaces; namespace DevHive.Services.Services { - public class PostService + public class PostService : IPostService { - private readonly PostRepository _postRepository; - private readonly UserRepository _userRepository; + private readonly IPostRepository _postRepository; + private readonly IUserRepository _userRepository; private readonly IMapper _postMapper; - public PostService(PostRepository postRepository, UserRepository userRepository , IMapper postMapper) + public PostService(IPostRepository postRepository, IUserRepository userRepository, IMapper postMapper) { this._postRepository = postRepository; this._userRepository = userRepository; @@ -36,16 +37,16 @@ namespace DevHive.Services.Services { commentServiceModel.TimeCreated = DateTime.Now; Comment comment = this._postMapper.Map<Comment>(commentServiceModel); - + bool result = await this._postRepository.AddCommentAsync(comment); return result; } - + //Read public async Task<PostServiceModel> GetPostById(Guid id) { - Post post = await this._postRepository.GetByIdAsync(id) + Post post = await this._postRepository.GetByIdAsync(id) ?? throw new ArgumentException("Post does not exist!"); return this._postMapper.Map<PostServiceModel>(post); @@ -55,7 +56,7 @@ namespace DevHive.Services.Services { Comment comment = await this._postRepository.GetCommentByIdAsync(id); - if(comment == null) + if (comment == null) throw new ArgumentException("The comment does not exist"); return this._postMapper.Map<CommentServiceModel>(comment); @@ -88,7 +89,7 @@ namespace DevHive.Services.Services Post post = await this._postRepository.GetByIdAsync(id); return await this._postRepository.DeleteAsync(post); } - + public async Task<bool> DeleteComment(Guid id) { if (!await this._postRepository.DoesCommentExist(id)) @@ -118,7 +119,7 @@ namespace DevHive.Services.Services string jwtUserName = this.GetClaimTypeValues("unique_name", jwt.Claims)[0]; //List<string> jwtRoleNames = this.GetClaimTypeValues("role", jwt.Claims); - + User user = await this._userRepository.GetByUsername(jwtUserName) ?? throw new ArgumentException("User does not exist!"); @@ -128,8 +129,8 @@ namespace DevHive.Services.Services private List<string> GetClaimTypeValues(string type, IEnumerable<Claim> claims) { List<string> toReturn = new(); - - foreach(var claim in claims) + + foreach (var claim in claims) if (claim.Type == type) toReturn.Add(claim.Value); diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs index 7ba0a98..fd56c2c 100644 --- a/src/DevHive.Services/Services/RoleService.cs +++ b/src/DevHive.Services/Services/RoleService.cs @@ -2,17 +2,18 @@ using System; using System.Threading.Tasks; using AutoMapper; using DevHive.Common.Models.Identity; +using DevHive.Data.Interfaces; using DevHive.Data.Models; -using DevHive.Data.Repositories; +using DevHive.Services.Interfaces; namespace DevHive.Services.Services { - public class RoleService + public class RoleService : IRoleService { - private readonly RoleRepository _roleRepository; + private readonly IRoleRepository _roleRepository; private readonly IMapper _roleMapper; - public RoleService(RoleRepository roleRepository, IMapper mapper) + public RoleService(IRoleRepository roleRepository, IMapper mapper) { this._roleRepository = roleRepository; this._roleMapper = mapper; @@ -30,7 +31,7 @@ namespace DevHive.Services.Services public async Task<RoleModel> GetRoleById(Guid id) { - Role role = await this._roleRepository.GetByIdAsync(id) + Role role = await this._roleRepository.GetByIdAsync(id) ?? throw new ArgumentException("Role does not exist!"); return this._roleMapper.Map<RoleModel>(role); diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs index 883b8c5..cb8fdfc 100644 --- a/src/DevHive.Services/Services/TechnologyService.cs +++ b/src/DevHive.Services/Services/TechnologyService.cs @@ -1,18 +1,19 @@ using System; using System.Threading.Tasks; using AutoMapper; +using DevHive.Data.Interfaces; using DevHive.Data.Models; -using DevHive.Data.Repositories; +using DevHive.Services.Interfaces; using DevHive.Services.Models.Technology; namespace DevHive.Services.Services { - public class TechnologyService + public class TechnologyService : ITechnologyService { - private readonly TechnologyRepository _technologyRepository; + private readonly ITechnologyRepository _technologyRepository; private readonly IMapper _technologyMapper; - public TechnologyService(TechnologyRepository technologyRepository, IMapper technologyMapper) + public TechnologyService(ITechnologyRepository technologyRepository, IMapper technologyMapper) { this._technologyRepository = technologyRepository; this._technologyMapper = technologyMapper; @@ -38,7 +39,7 @@ namespace DevHive.Services.Services { Technology technology = await this._technologyRepository.GetByIdAsync(id); - if(technology == null) + if (technology == null) throw new ArgumentException("The technology does not exist"); return this._technologyMapper.Map<TechnologyServiceModel>(technology); diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index c1de741..6a6662d 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -12,24 +12,26 @@ using System.Text; using System.Collections.Generic; using DevHive.Common.Models.Identity; using DevHive.Services.Models.Language; -using DevHive.Data.Repositories; +using DevHive.Services.Interfaces; using DevHive.Services.Models.Technology; +using DevHive.Data.Repositories; +using DevHive.Data.Interfaces; namespace DevHive.Services.Services { - public class UserService + public class UserService : IUserService { - private readonly UserRepository _userRepository; - private readonly RoleRepository _roleRepository; - private readonly LanguageRepository _languageRepository; - private readonly TechnologyRepository _technologyRepository; + private readonly IUserRepository _userRepository; + private readonly IRoleRepository _roleRepository; + private readonly ILanguageRepository _languageRepository; + private readonly ITechnologyRepository _technologyRepository; private readonly IMapper _userMapper; private readonly JWTOptions _jwtOptions; - public UserService(UserRepository userRepository, - LanguageRepository languageRepository, - RoleRepository roleRepository, - TechnologyRepository technologyRepository, + public UserService(IUserRepository userRepository, + ILanguageRepository languageRepository, + IRoleRepository roleRepository, + ITechnologyRepository technologyRepository, IMapper mapper, JWTOptions jwtOptions) { |
