aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-13 11:05:26 +0200
committertranstrike <transtrike@gmail.com>2021-01-13 11:05:26 +0200
commit6deaa6edcd8e347d5ed28ee3389cb8712cc64ea3 (patch)
tree620b8867f3b5f96aa76c0e5e38e985db91498696 /src/DevHive.Services/Services
parent8a18cdf741bed465b4b24626e15370c33365cf11 (diff)
downloadDevHive-6deaa6edcd8e347d5ed28ee3389cb8712cc64ea3.tar
DevHive-6deaa6edcd8e347d5ed28ee3389cb8712cc64ea3.tar.gz
DevHive-6deaa6edcd8e347d5ed28ee3389cb8712cc64ea3.zip
The return of the interfaces
Diffstat (limited to 'src/DevHive.Services/Services')
-rw-r--r--src/DevHive.Services/Services/LanguageService.cs22
-rw-r--r--src/DevHive.Services/Services/PostService.cs27
-rw-r--r--src/DevHive.Services/Services/RoleService.cs11
-rw-r--r--src/DevHive.Services/Services/TechnologyService.cs11
-rw-r--r--src/DevHive.Services/Services/UserService.cs22
5 files changed, 55 insertions, 38 deletions
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)
{