aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/DevHive.Data/DevHive.Data.csproj7
-rw-r--r--src/DevHive.Data/Models/Language.cs9
-rw-r--r--src/DevHive.Data/Models/Technology.cs9
-rw-r--r--src/DevHive.Data/Models/User.cs67
-rw-r--r--src/DevHive.Data/Repositories/DevHiveContext.cs26
-rw-r--r--src/DevHive.Data/Repositories/IRepository.cs24
-rw-r--r--src/DevHive.Data/Repositories/UserRepository.cs69
-rw-r--r--src/DevHive.Services/DevHive.Services.csproj9
-rw-r--r--src/DevHive.Services/Models/Identity/LoginServiceModel.cs8
-rw-r--r--src/DevHive.Services/Models/Identity/RegisterServiceModel.cs11
-rw-r--r--src/DevHive.Services/Models/Identity/UpdateUserServiceModel.cs9
-rw-r--r--src/DevHive.Services/Models/Identity/UserServiceModel.cs11
-rw-r--r--src/DevHive.Services/Options/JWTOptions.cs14
-rw-r--r--src/DevHive.Services/Services/RoleService.cs26
-rw-r--r--src/DevHive.Services/Services/UserService.cs103
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs39
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs54
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs23
-rw-r--r--src/DevHive.Web/Configurations/Mapping/UserMappings.cs16
-rw-r--r--src/DevHive.Web/Controllers/ErrorController.cs20
-rw-r--r--src/DevHive.Web/Controllers/RoleController.cs34
-rw-r--r--src/DevHive.Web/Controllers/UserController.cs66
-rw-r--r--src/DevHive.Web/DevHive.Web.csproj33
-rw-r--r--src/DevHive.Web/Program.cs35
-rw-r--r--src/DevHive.Web/Startup.cs99
-rw-r--r--src/DevHive.Web/appsettings.json6
26 files changed, 745 insertions, 82 deletions
diff --git a/src/DevHive.Data/DevHive.Data.csproj b/src/DevHive.Data/DevHive.Data.csproj
index 563e6f9..0becbe2 100644
--- a/src/DevHive.Data/DevHive.Data.csproj
+++ b/src/DevHive.Data/DevHive.Data.csproj
@@ -4,4 +4,11 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
+ <ItemGroup>
+ <PackageReference Include="AutoMapper" Version="10.1.1" />
+ <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
+
+ <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
+ </ItemGroup>
+
</Project>
diff --git a/src/DevHive.Data/Models/Language.cs b/src/DevHive.Data/Models/Language.cs
new file mode 100644
index 0000000..a455796
--- /dev/null
+++ b/src/DevHive.Data/Models/Language.cs
@@ -0,0 +1,9 @@
+using System;
+
+namespace DevHive.Data.Models
+{
+ public class Language
+ {
+ public Guid Id { get; set; }
+ }
+}
diff --git a/src/DevHive.Data/Models/Technology.cs b/src/DevHive.Data/Models/Technology.cs
new file mode 100644
index 0000000..6f2afeb
--- /dev/null
+++ b/src/DevHive.Data/Models/Technology.cs
@@ -0,0 +1,9 @@
+using System;
+
+namespace DevHive.Data.Models
+{
+ public class Technology
+ {
+ public Guid Id { get; set; }
+ }
+}
diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs
new file mode 100644
index 0000000..fb1fb43
--- /dev/null
+++ b/src/DevHive.Data/Models/User.cs
@@ -0,0 +1,67 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using Microsoft.AspNetCore.Identity;
+
+namespace DevHive.Data.Models
+{
+ [Table("Users")]
+ public class User : IdentityUser<Guid>
+ {
+ private string _firstName;
+ private string _lastName;
+
+ [Required]
+ [Range(3, 50)]
+ [Display(Name = "Username")]
+ public override string UserName
+ {
+ get => base.UserName;
+ set
+ {
+ ValidateString("Username", 3, 50, value, true);
+ base.UserName = value;
+ }
+ }
+
+ [Required]
+ [Range(3, 30)]
+ public string FirstName
+ {
+ get => this._firstName;
+ set
+ {
+ ValidateString("FirstName", 3, 30, value, false);
+ this._firstName = value;
+ }
+ }
+
+ [Required]
+ [Range(3, 30)]
+ public string LastName
+ {
+ get => this._lastName;
+ set
+ {
+ ValidateString("LastName", 3, 30, value, false);
+ this._lastName = value;
+ }
+ }
+
+ public string ProfilePicture { get; set; }
+
+ public string Role { get; set; }
+
+ //public List<User> Friends { get; set; }
+
+ private static void ValidateString(string propertyName, int minLength, int maxLength, string value, bool canBeDigit)
+ {
+ if (value.Length < minLength || value.Length > maxLength)
+ throw new ArgumentException($"{propertyName} length cannot be less than {minLength} and more than {maxLength}.");
+
+ foreach (char ch in value)
+ if (!Char.IsLetter(ch) && !(Char.IsDigit(ch) && canBeDigit))
+ throw new ArgumentException($"{propertyName} contains invalid characters.");
+ }
+ }
+}
diff --git a/src/DevHive.Data/Repositories/DevHiveContext.cs b/src/DevHive.Data/Repositories/DevHiveContext.cs
new file mode 100644
index 0000000..be5cc56
--- /dev/null
+++ b/src/DevHive.Data/Repositories/DevHiveContext.cs
@@ -0,0 +1,26 @@
+using System;
+using DevHive.Data.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore;
+
+namespace DevHive.Data.Repositories
+{
+ public class DevHiveContext : IdentityDbContext<User, IdentityRole<Guid>, Guid>
+ {
+ public DevHiveContext(DbContextOptions options)
+ : base(options) { }
+
+ public DbSet<Technology> Technologies { get; set; }
+ public DbSet<Language> Languages { get; set; }
+
+ protected override void OnModelCreating(ModelBuilder builder)
+ {
+ builder.Entity<User>()
+ .HasIndex(x => x.UserName)
+ .IsUnique();
+
+ base.OnModelCreating(builder);
+ }
+ }
+}
diff --git a/src/DevHive.Data/Repositories/IRepository.cs b/src/DevHive.Data/Repositories/IRepository.cs
new file mode 100644
index 0000000..81a1a35
--- /dev/null
+++ b/src/DevHive.Data/Repositories/IRepository.cs
@@ -0,0 +1,24 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace Data.Models.Interfaces.Database
+{
+ public interface IRepository<TEntity>
+ where TEntity : class
+ {
+ //Add Entity to database
+ Task AddAsync(TEntity entity);
+
+ //Return *count* instances of Entity from the database
+ IEnumerable<TEntity> Query(int count);
+
+ //Find entity by id
+ Task<TEntity> FindByIdAsync(object id);
+
+ //Modify Entity from database
+ Task EditAsync(object id, TEntity newEntity);
+
+ //Delete Entity from database
+ Task DeleteAsync(object id);
+ }
+} \ No newline at end of file
diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs
new file mode 100644
index 0000000..5bd9d97
--- /dev/null
+++ b/src/DevHive.Data/Repositories/UserRepository.cs
@@ -0,0 +1,69 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Data.Models.Interfaces.Database;
+using DevHive.Data.Models;
+
+namespace DevHive.Data.Repositories
+{
+ public class UserRepository : IRepository<User>
+ {
+ /* private readonly UserRepository<User> _dbRepository;
+
+ public UserRepository(DbContext context)
+ : base (context)
+ {
+ this._dbRepository = new DbRepository<User>(context);
+ }
+
+ public User FindByUsername(string username)
+ {
+ return this._dbRepository.DbSet
+ .FirstOrDefault(usr => usr.UserName == username);
+ }
+
+ public bool DoesUsernameExist(string username)
+ {
+ return this._dbRepository.DbSet
+ .Any(x => x.UserName == username);
+ }
+
+ public bool DoesUserExist(Guid id)
+ {
+ return this._dbRepository.DbSet
+ .Any(x => x.Id == id);
+ }
+
+ public bool HasThisUsername(Guid id, string username)
+ {
+ return this._dbRepository.DbSet
+ .Any(x => x.Id == id &&
+ x.UserName == username);
+ } */
+
+ public Task AddAsync(User entity)
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public IEnumerable<User> Query(int count)
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public Task<User> FindByIdAsync(object id)
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public Task EditAsync(object id, User newEntity)
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public Task DeleteAsync(object id)
+ {
+ throw new System.NotImplementedException();
+ }
+ }
+}
diff --git a/src/DevHive.Services/DevHive.Services.csproj b/src/DevHive.Services/DevHive.Services.csproj
index 563e6f9..277a342 100644
--- a/src/DevHive.Services/DevHive.Services.csproj
+++ b/src/DevHive.Services/DevHive.Services.csproj
@@ -1,7 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
-
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\DevHive.Data\DevHive.Data.csproj" />
+
+ <PackageReference Include="AutoMapper" Version="10.1.1" />
+ <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
+ </ItemGroup>
+
+
</Project>
diff --git a/src/DevHive.Services/Models/Identity/LoginServiceModel.cs b/src/DevHive.Services/Models/Identity/LoginServiceModel.cs
new file mode 100644
index 0000000..d056f9a
--- /dev/null
+++ b/src/DevHive.Services/Models/Identity/LoginServiceModel.cs
@@ -0,0 +1,8 @@
+namespace DevHive.Services.Models.Identity
+{
+ public class LoginServiceModel
+ {
+ public string UserName { get; set; }
+ public string Password { get; set; }
+ }
+}
diff --git a/src/DevHive.Services/Models/Identity/RegisterServiceModel.cs b/src/DevHive.Services/Models/Identity/RegisterServiceModel.cs
new file mode 100644
index 0000000..45f42d2
--- /dev/null
+++ b/src/DevHive.Services/Models/Identity/RegisterServiceModel.cs
@@ -0,0 +1,11 @@
+namespace DevHive.Services.Models.Identity
+{
+ public class RegisterServiceModel
+ {
+ public string UserName { get; set; }
+ public string Email { get; set; }
+ public string FirstName { get; set; }
+ public string LastName { get; set; }
+ public string Password { get; set; }
+ }
+}
diff --git a/src/DevHive.Services/Models/Identity/UpdateUserServiceModel.cs b/src/DevHive.Services/Models/Identity/UpdateUserServiceModel.cs
new file mode 100644
index 0000000..94600ae
--- /dev/null
+++ b/src/DevHive.Services/Models/Identity/UpdateUserServiceModel.cs
@@ -0,0 +1,9 @@
+using System;
+
+namespace DevHive.Services.Models.Identity
+{
+ public class UpdateUserServiceModel : UserServiceModel
+ {
+ public Guid Id { get; set; }
+ }
+} \ No newline at end of file
diff --git a/src/DevHive.Services/Models/Identity/UserServiceModel.cs b/src/DevHive.Services/Models/Identity/UserServiceModel.cs
new file mode 100644
index 0000000..387afdd
--- /dev/null
+++ b/src/DevHive.Services/Models/Identity/UserServiceModel.cs
@@ -0,0 +1,11 @@
+namespace DevHive.Services.Models.Identity
+{
+ public class UserServiceModel
+ {
+ public string UserName { get; set; }
+ public string Email { get; set; }
+ public string FirstName { get; set; }
+ public string LastName { get; set; }
+ public string Role { get; set;}
+ }
+}
diff --git a/src/DevHive.Services/Options/JWTOptions.cs b/src/DevHive.Services/Options/JWTOptions.cs
new file mode 100644
index 0000000..95458f5
--- /dev/null
+++ b/src/DevHive.Services/Options/JWTOptions.cs
@@ -0,0 +1,14 @@
+using Microsoft.Extensions.Options;
+
+namespace DevHive.Services.Options
+{
+ public class JWTOptions
+ {
+ public JWTOptions(string secret)
+ {
+ this.Secret = secret;
+ }
+
+ public string Secret { get; init; }
+ }
+}
diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs
new file mode 100644
index 0000000..202c611
--- /dev/null
+++ b/src/DevHive.Services/Services/RoleService.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Threading.Tasks;
+using DevHive.Data.Repositories;
+
+namespace DevHive.Services.Services
+{
+ public class RoleService
+ {
+ /* private readonly DevHiveContext _context;
+
+ public RoleService(DevHiveContext context)
+ {
+ this._context = context;
+ }
+
+ public Task<IActionResult> CreatePost(string name)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task<IActionResult> GetPostById(uint postId)
+ {
+ throw new NotImplementedException();
+ }*/
+ }
+}
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
new file mode 100644
index 0000000..f06198c
--- /dev/null
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -0,0 +1,103 @@
+namespace DevHive.Services.Services
+{
+ public class UserService
+ {
+ /* private readonly UserRepository _userDbRepository;
+ private readonly IMapper _userMapper;
+ private readonly JWTOptions _jwtOptions;
+
+ public UserService(DevHiveContext context, IMapper mapper, JWTOptions jwtOptions)
+ {
+ this._userDbRepository = new UserRepository(context);
+ this._userMapper = mapper;
+ this._jwtOptions = jwtOptions;
+ }
+
+ public async Task<IActionResult> LoginUser(LoginDTO loginDTO)
+ {
+ User user = this._userDbRepository.FindByUsername(loginDTO.UserName);
+
+ if (user == null)
+ return new NotFoundObjectResult("User does not exist!");
+
+ byte[] key = Encoding.ASCII.GetBytes(_jwtOptions.Secret);
+
+ if (user.PasswordHash != GeneratePasswordHash(loginDTO.Password))
+ return new BadRequestObjectResult("Incorrect password!");
+
+ // Create Jwt Token configuration
+ var tokenDescriptor = new SecurityTokenDescriptor
+ {
+ Subject = new ClaimsIdentity(new Claim[]
+ {
+ new Claim(ClaimTypes.Role, user.Role) // Authorize user by role
+ }),
+ Expires = DateTime.UtcNow.AddDays(7),
+ SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha512Signature)
+ };
+
+ var tokenHandler = new JwtSecurityTokenHandler();
+ var token = tokenHandler.CreateToken(tokenDescriptor);
+ var tokenString = tokenHandler.WriteToken(token);
+
+ return new OkObjectResult(new { Token = tokenString });
+ }
+
+ public async Task<IActionResult> RegisterUser(RegisterDTO registerDTO)
+ {
+
+ if (this._userDbRepository.DoesUsernameExist(registerDTO.UserName))
+ return new BadRequestObjectResult("Username already exists!");
+
+ User user = this._userMapper.Map<User>(registerDTO);
+
+ user.Role = UserRoles.User;
+ user.PasswordHash = GeneratePasswordHash(registerDTO.Password);
+
+ await this._userDbRepository.AddAsync(user);
+
+ return new CreatedResult("CreateUser", user);
+ }
+
+ private string GeneratePasswordHash(string password)
+ {
+ //TODO: Implement
+ return password;
+ }
+
+ public async Task<IActionResult> GetUserById(Guid id)
+ {
+ User user = await this._userDbRepository.FindByIdAsync(id);
+
+ if (user == null)
+ return new NotFoundObjectResult("User does not exist!");
+
+ return new OkObjectResult(user);
+ }
+
+ public async Task<IActionResult> UpdateUser(Guid id, UserDTO userDTO)
+ {
+ if (!this._userDbRepository.DoesUserExist(id))
+ return new NotFoundObjectResult("User does not exist!");
+
+ if (!this._userDbRepository.HasThisUsername(id, userDTO.UserName)
+ && this._userDbRepository.DoesUsernameExist(userDTO.UserName))
+ return new BadRequestObjectResult("Username already exists!");
+
+ User user = this._userMapper.Map<User>(userDTO);
+ await this._userDbRepository.EditAsync(id, user);
+
+ return new AcceptedResult("UpdateUser", user);
+ }
+
+ public async Task<IActionResult> DeleteUser(Guid id)
+ {
+ if (!this._userDbRepository.DoesUserExist(id))
+ return new NotFoundObjectResult("User does not exist!");
+
+ await this._userDbRepository.DeleteAsync(id);
+
+ return new OkResult();
+ }*/
+ }
+}
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs
new file mode 100644
index 0000000..178d345
--- /dev/null
+++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs
@@ -0,0 +1,39 @@
+using Microsoft.Extensions.DependencyInjection;
+using DevHive.Data.Repositories;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using DevHive.Data.Models;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Builder;
+
+namespace DevHive.Web.Configurations.Extensions
+{
+ public static class DatabaseExtensions
+ {
+ public static void DatabaseConfiguration(this IServiceCollection services, IConfiguration configuration)
+ {
+ services.AddDbContext<DevHiveContext>(options =>
+ options.UseNpgsql(configuration.GetConnectionString("DEV")));
+
+ services.AddIdentity<User, IdentityRole>()
+ .AddEntityFrameworkStores<DevHiveContext>();
+
+ services.Configure<IdentityOptions>(options =>
+ {
+ //TODO: Add more validations
+ options.User.RequireUniqueEmail = true;
+
+ options.Password.RequiredLength = 5;
+ });
+ }
+
+ public static void UseDatabaseConfiguration(this IApplicationBuilder app)
+ {
+ app.UseHttpsRedirection();
+ app.UseRouting();
+
+ app.UseAuthentication();
+ app.UseAuthorization();
+ }
+ }
+}
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs
new file mode 100644
index 0000000..bc5ac15
--- /dev/null
+++ b/src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs
@@ -0,0 +1,54 @@
+using System.Text;
+using System.Threading.Tasks;
+using DevHive.Services.Options;
+using Microsoft.AspNetCore.Authentication.JwtBearer;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.IdentityModel.Tokens;
+
+namespace DevHive.Web.Configurations.Extensions
+{
+ public static class JWTExtensions
+ {
+ public static void JWTConfiguration(this IServiceCollection services, IConfiguration configuration)
+ {
+ services.AddSingleton(new JWTOptions(configuration
+ .GetSection("AppSettings")
+ .GetSection("Secret")
+ .Value));
+
+ // Get key from appsettings.json
+ var key = Encoding.ASCII.GetBytes(configuration
+ .GetSection("AppSettings")
+ .GetSection("Secret")
+ .Value);
+
+ // Setup Jwt Authentication
+ services.AddAuthentication(x =>
+ {
+ x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
+ x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
+ })
+ .AddJwtBearer(x =>
+ {
+ x.Events = new JwtBearerEvents
+ {
+ OnTokenValidated = context =>
+ {
+ // TODO: add more authentication
+ return Task.CompletedTask;
+ }
+ };
+ x.RequireHttpsMetadata = false;
+ x.SaveToken = true;
+ x.TokenValidationParameters = new TokenValidationParameters
+ {
+ ValidateIssuerSigningKey = true,
+ IssuerSigningKey = new SymmetricSecurityKey(key),
+ ValidateIssuer = false,
+ ValidateAudience = false
+ };
+ });
+ }
+ }
+} \ No newline at end of file
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
new file mode 100644
index 0000000..a0641ab
--- /dev/null
+++ b/src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
@@ -0,0 +1,23 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.OpenApi.Models;
+
+namespace DevHive.Web.Configurations.Extensions
+{
+ public static class SwaggerExtensions
+ {
+ public static void SwaggerConfiguration(this IServiceCollection services)
+ {
+ services.AddSwaggerGen(c =>
+ {
+ c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
+ });
+ }
+
+ public static void UseSwaggerConfiguration(this IApplicationBuilder app)
+ {
+ app.UseSwagger();
+ app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
+ }
+ }
+} \ No newline at end of file
diff --git a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs
new file mode 100644
index 0000000..f3daf5a
--- /dev/null
+++ b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs
@@ -0,0 +1,16 @@
+using DevHive.Data.Models;
+using AutoMapper;
+using DevHive.Services.Models.Identity;
+
+namespace DevHive.Web.Configurations.Mapping
+{
+ public class UserMappings : Profile
+ {
+ public UserMappings()
+ {
+ CreateMap<UserServiceModel, User>();
+ CreateMap<RegisterServiceModel, User>();
+ CreateMap<UpdateUserServiceModel, User>();
+ }
+ }
+}
diff --git a/src/DevHive.Web/Controllers/ErrorController.cs b/src/DevHive.Web/Controllers/ErrorController.cs
new file mode 100644
index 0000000..560b0da
--- /dev/null
+++ b/src/DevHive.Web/Controllers/ErrorController.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Net;
+using System.Net.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace DevHive.Web.Controllers
+{
+ [ApiController]
+ [Route("/api/[controller]")]
+ public class ErrorController
+ {
+ [HttpGet]
+ public HttpStatusCode HttpError(HttpRequestException exception)
+ {
+ Console.WriteLine("WE HERE, BOIIIIIII");
+
+ return HttpStatusCode.OK;
+ }
+ }
+}
diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs
new file mode 100644
index 0000000..fda8bb2
--- /dev/null
+++ b/src/DevHive.Web/Controllers/RoleController.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Threading.Tasks;
+using DevHive.Data.Repositories;
+using DevHive.Services.Services;
+using Microsoft.AspNetCore.Mvc;
+
+namespace DevHive.Web.Controllers
+{
+ [ApiController]
+ [Route("/api/[controller]")]
+ public class RoleController
+ {
+ private readonly RoleService _service;
+
+ public RoleController(DevHiveContext context)
+ {
+ //this._service = new RoleService(context);
+ }
+
+ [HttpPost]
+ public Task<IActionResult> Create(string name)
+ {
+ //return this._service.CreatePost(name);
+ throw new NotImplementedException();
+ }
+
+ [HttpGet]
+ public Task<IActionResult> ShowPost(uint postId)
+ {
+ //return this._service.GetPostById(postId);
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs
new file mode 100644
index 0000000..84231d1
--- /dev/null
+++ b/src/DevHive.Web/Controllers/UserController.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Threading.Tasks;
+using AutoMapper;
+using DevHive.Data.Repositories;
+using DevHive.Services.Models.Identity;
+using DevHive.Services.Options;
+using DevHive.Services.Services;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace DevHive.Web.Controllers
+{
+ [ApiController]
+ [Route("/api/[controller]")]
+ public class UserController: ControllerBase
+ {
+ private readonly UserService _service;
+
+ public UserController(DevHiveContext context, IMapper mapper, JWTOptions jwtOptions)
+ {
+ //this._service = new UserService(context, mapper, jwtOptions);
+ }
+
+ [HttpPost]
+ [Route("Login")]
+ public async Task<IActionResult> Login([FromBody] LoginServiceModel loginServiceModel)
+ {
+ //return await this._service.LoginUser(loginDTO);
+ throw new NotImplementedException();
+ }
+
+ [HttpPost]
+ [Route("Register")]
+ public async Task<IActionResult> Register([FromBody] RegisterServiceModel registerServiceModel)
+ {
+ //return await this._service.RegisterUser(registerDto);
+ throw new NotImplementedException();
+ }
+
+ //Read
+ [HttpGet]
+ public async Task<IActionResult> GetById(Guid id)
+ {
+ //return await this._service.GetUserById(id);
+ throw new NotImplementedException();
+ }
+
+ //Update
+ [HttpPut]
+ [Authorize]
+ public async Task<IActionResult> Update(Guid id, [FromBody] UpdateUserServiceModel updateUserServiceModel)
+ {
+ //return await this._service.UpdateUser(id, userDTO);
+ throw new NotImplementedException();
+ }
+
+ //Delete
+ [HttpDelete]
+ [Authorize]
+ public async Task<IActionResult> Delete(Guid id)
+ {
+ //return await this._service.DeleteUser(id);
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj
index 218b809..5b5478d 100644
--- a/src/DevHive.Web/DevHive.Web.csproj
+++ b/src/DevHive.Web/DevHive.Web.csproj
@@ -1,13 +1,20 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
-
- <PropertyGroup>
- <TargetFramework>net5.0</TargetFramework>
- </PropertyGroup>
-
- <ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.1" NoWarn="NU1605" />
- <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.1" NoWarn="NU1605" />
- <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
- </ItemGroup>
-
-</Project>
+<Project Sdk="Microsoft.NET.Sdk.Web">
+ <PropertyGroup>
+ <TargetFramework>net5.0</TargetFramework>
+ </PropertyGroup>
+ <ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.1" NoWarn="NU1605" />
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.1" NoWarn="NU1605" />
+
+ <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0" />
+
+ <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
+
+ <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
+ <PackageReference Include="AutoMapper" Version="10.1.1" />
+
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\DevHive.Services\DevHive.Services.csproj" />
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/src/DevHive.Web/Program.cs b/src/DevHive.Web/Program.cs
index 3967a71..9cbe12a 100644
--- a/src/DevHive.Web/Program.cs
+++ b/src/DevHive.Web/Program.cs
@@ -1,26 +1,23 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Logging;
namespace DevHive.Web
{
- public class Program
- {
- public static void Main(string[] args)
- {
- CreateHostBuilder(args).Build().Run();
- }
+ public class Program
+ {
+ private const int HTTPS_PORT = 5000;
- public static IHostBuilder CreateHostBuilder(string[] args) =>
- Host.CreateDefaultBuilder(args)
- .ConfigureWebHostDefaults(webBuilder =>
- {
- webBuilder.UseStartup<Startup>();
- });
- }
+ public static void Main(string[] args)
+ {
+ CreateHostBuilder(args).Build().Run();
+ }
+
+ public static IHostBuilder CreateHostBuilder(string[] args) =>
+ Host.CreateDefaultBuilder(args)
+ .ConfigureWebHostDefaults(webBuilder =>
+ {
+ webBuilder.ConfigureKestrel(opt => opt.ListenLocalhost(HTTPS_PORT));
+ webBuilder.UseStartup<Startup>();
+ });
+ }
}
diff --git a/src/DevHive.Web/Startup.cs b/src/DevHive.Web/Startup.cs
index 303c080..62d9d2c 100644
--- a/src/DevHive.Web/Startup.cs
+++ b/src/DevHive.Web/Startup.cs
@@ -1,59 +1,60 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.HttpsPolicy;
-using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Logging;
-using Microsoft.OpenApi.Models;
+using DevHive.Web.Configurations.Extensions;
+using AutoMapper;
namespace DevHive.Web
{
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
-
- public IConfiguration Configuration { get; }
-
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
-
- services.AddControllers();
- services.AddSwaggerGen(c =>
- {
- c.SwaggerDoc("v1", new OpenApiInfo { Title = "DevHive.Web", Version = "v1" });
- });
- }
-
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- app.UseSwagger();
- app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "DevHive.Web v1"));
- }
-
- app.UseHttpsRedirection();
-
- app.UseRouting();
-
- app.UseAuthorization();
-
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllers();
- });
- }
- }
+ public class Startup
+ {
+ public Startup(IConfiguration configuration)
+ {
+ Configuration = configuration;
+ }
+
+ public IConfiguration Configuration { get; }
+
+ // This method gets called by the runtime. Use this method to add services to the container.
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services.AddControllers();
+
+ services.DatabaseConfiguration(Configuration);
+ services.SwaggerConfiguration();
+ services.JWTConfiguration(Configuration);
+ //services.AutoMapperConfiguration();
+
+ services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
+ }
+
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+ if (env.IsDevelopment())
+ {
+ app.UseDeveloperExceptionPage();
+ //app.UseExceptionHandler("/api/HttpError");
+ app.UseSwaggerConfiguration();
+ }
+ else
+ {
+ app.UseExceptionHandler("/api/HttpError");
+ app.UseHsts();
+ }
+
+ app.UseDatabaseConfiguration();
+
+ app.UseEndpoints(endpoints =>
+ {
+ endpoints.MapControllerRoute(
+ name: "default",
+ pattern: "api/{controller}/{action}"
+ );
+ });
+ }
+ }
}
diff --git a/src/DevHive.Web/appsettings.json b/src/DevHive.Web/appsettings.json
index 81ff877..1784183 100644
--- a/src/DevHive.Web/appsettings.json
+++ b/src/DevHive.Web/appsettings.json
@@ -1,4 +1,10 @@
{
+ "AppSettings": {
+ "Secret": "ADD_ANY_STRING_WITH_32_OR_MORE_CHARACTERS"
+ },
+ "ConnectionStrings" : {
+ "DEV": "Server=localhost;Port=5432;Database=API;User Id=postgres;Password=;"
+ },
"Logging": {
"LogLevel": {
"Default": "Information",