aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Services/Services')
-rw-r--r--src/DevHive.Services/Services/LanguageService.cs1
-rw-r--r--src/DevHive.Services/Services/TechnologyService.cs67
-rw-r--r--src/DevHive.Services/Services/UserService.cs7
3 files changed, 70 insertions, 5 deletions
diff --git a/src/DevHive.Services/Services/LanguageService.cs b/src/DevHive.Services/Services/LanguageService.cs
index 79d77fd..0454aaf 100644
--- a/src/DevHive.Services/Services/LanguageService.cs
+++ b/src/DevHive.Services/Services/LanguageService.cs
@@ -4,7 +4,6 @@ using AutoMapper;
using DevHive.Data.Models;
using DevHive.Data.Repositories;
using DevHive.Services.Models.Language;
-using Microsoft.AspNetCore.Mvc;
namespace DevHive.Services.Services
{
diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs
new file mode 100644
index 0000000..246ad2c
--- /dev/null
+++ b/src/DevHive.Services/Services/TechnologyService.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Threading.Tasks;
+using AutoMapper;
+using DevHive.Data.Models;
+using DevHive.Data.Repositories;
+using DevHive.Services.Models.Technology;
+
+namespace DevHive.Services.Services
+{
+ public class TechnologyService
+ {
+ private readonly TechnologyRepository _technologyRepository;
+ private readonly IMapper _technologyMapper;
+
+ public TechnologyService(DevHiveContext context, IMapper technologyMapper)
+ {
+ this._technologyRepository = new TechnologyRepository(context);
+ this._technologyMapper = technologyMapper;
+ }
+
+ public async Task<bool> Create(TechnologyServiceModel technologyServiceModel)
+ {
+ if (!await this._technologyRepository.DoesTechnologyNameExist(technologyServiceModel.Name))
+ throw new ArgumentException("Technology already exists!");
+
+ Technology technology = this._technologyMapper.Map<Technology>(technologyServiceModel);
+ bool result = await this._technologyRepository.AddAsync(technology);
+
+ return result;
+ }
+
+ public async Task<TechnologyServiceModel> GetTechnologyById(Guid id)
+ {
+ Technology technology = await this._technologyRepository.GetByIdAsync(id);
+
+ if(technology == null)
+ throw new ArgumentException("The technology does not exist");
+
+ return this._technologyMapper.Map<TechnologyServiceModel>(technology);
+ }
+
+ public async Task<bool> UpdateTechnology(UpdateTechnologyServiceModel updateTechnologyServiceModel)
+ {
+ if (!await this._technologyRepository.DoesTechnologyExist(updateTechnologyServiceModel.Id))
+ throw new ArgumentException("Technology does not exist!");
+
+ if (!await this._technologyRepository.DoesTechnologyNameExist(updateTechnologyServiceModel.Name))
+ throw new ArgumentException("Technology name already exists!");
+
+ Technology technology = this._technologyMapper.Map<Technology>(updateTechnologyServiceModel);
+ bool result = await this._technologyRepository.EditAsync(technology);
+
+ return result;
+ }
+
+ public async Task<bool> DeleteTechnology(Guid id)
+ {
+ if (!await this._technologyRepository.DoesTechnologyExist(id))
+ throw new ArgumentException("Technology does not exist!");
+
+ Technology technology = await this._technologyRepository.GetByIdAsync(id);
+ bool result = await this._technologyRepository.DeleteAsync(technology);
+
+ return result;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index 134a142..d3c0d0d 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -40,7 +40,7 @@ namespace DevHive.Services.Services
if (user.PasswordHash != GeneratePasswordHash(loginModel.Password))
throw new ArgumentException("Incorrect password!");
- return new TokenModel(WriteJWTSecurityToken(user.UserName, user.PasswordHash, user.Roles));
+ return new TokenModel(WriteJWTSecurityToken(user.UserName, user.Roles));
}
public async Task<TokenModel> RegisterUser(RegisterServiceModel registerModel)
@@ -64,7 +64,7 @@ namespace DevHive.Services.Services
await this._userRepository.AddAsync(user);
- return new TokenModel(WriteJWTSecurityToken(user.UserName, user.PasswordHash, user.Roles));
+ return new TokenModel(WriteJWTSecurityToken(user.UserName, user.Roles));
}
public async Task<UserServiceModel> GetUserById(Guid id)
@@ -110,14 +110,13 @@ namespace DevHive.Services.Services
return string.Join(string.Empty, SHA512.HashData(Encoding.ASCII.GetBytes(password)));
}
- private string WriteJWTSecurityToken(string userName, string passwordHash, IList<Role> roles)
+ private string WriteJWTSecurityToken(string userName, IList<Role> roles)
{
byte[] signingKey = Encoding.ASCII.GetBytes(_jwtOptions.Secret);
List<Claim> claims = new()
{
new Claim(ClaimTypes.Name, userName),
- new Claim(ClaimTypes.Hash, passwordHash)
};
foreach(var role in roles)