From 8d1d0b40d56f90248f948e474330258bf57cf0b6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 17 Jan 2021 14:45:48 +0200 Subject: Fixed role implementation by bringing back and improving all role models --- src/DevHive.Web/Controllers/RoleController.cs | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/DevHive.Web/Controllers/RoleController.cs') diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs index 8ea2711..5b3dca5 100644 --- a/src/DevHive.Web/Controllers/RoleController.cs +++ b/src/DevHive.Web/Controllers/RoleController.cs @@ -3,12 +3,12 @@ using Microsoft.AspNetCore.Mvc; using DevHive.Web.Models.Identity.Role; using AutoMapper; using System; -using DevHive.Common.Models.Identity; using DevHive.Services.Interfaces; +using DevHive.Services.Models.Identity.Role; namespace DevHive.Web.Controllers { - [ApiController] + [ApiController] [Route("/api/[controller]")] //[Authorize(Roles = "Admin")] public class RoleController @@ -23,33 +23,33 @@ namespace DevHive.Web.Controllers } [HttpPost] - public async Task Create([FromBody] CreateRoleModel createRoleModel) + public async Task Create([FromBody] CreateRoleWebModel createRoleWebModel) { - RoleModel roleServiceModel = - this._roleMapper.Map(createRoleModel); + RoleServiceModel roleServiceModel = + this._roleMapper.Map(createRoleWebModel); - bool result = await this._roleService.CreateRole(roleServiceModel); + Guid id = await this._roleService.CreateRole(roleServiceModel); - if (!result) - return new BadRequestObjectResult("Could not create role!"); + return id == Guid.Empty ? + new BadRequestObjectResult($"Could not create role {createRoleWebModel.Name}") : + new OkObjectResult(new { Id = id }); - return new OkResult(); } [HttpGet] public async Task GetById(Guid id) { - RoleModel roleServiceModel = await this._roleService.GetRoleById(id); - RoleModel roleWebModel = this._roleMapper.Map(roleServiceModel); + RoleServiceModel roleServiceModel = await this._roleService.GetRoleById(id); + RoleWebModel roleWebModel = this._roleMapper.Map(roleServiceModel); return new OkObjectResult(roleWebModel); } [HttpPut] - public async Task Update(Guid id, [FromBody] UpdateRoleModel updateRoleModel) + public async Task Update(Guid id, [FromBody] UpdateRoleWebModel updateRoleWebModel) { - RoleModel roleServiceModel = - this._roleMapper.Map(updateRoleModel); + RoleServiceModel roleServiceModel = + this._roleMapper.Map(updateRoleWebModel); roleServiceModel.Id = id; bool result = await this._roleService.UpdateRole(roleServiceModel); -- cgit v1.2.3 From 4836e2f4cc3e1eb53f415d26771c76c84d29c280 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 19 Jan 2021 13:13:03 +0200 Subject: Configured launch.json to be workspace wide; Fixed GetFriend to GetUser --- src/DevHive.Services/Interfaces/IUserService.cs | 4 +- src/DevHive.Services/Services/UserService.cs | 2 +- src/DevHive.Web/Controllers/RoleController.cs | 2 +- src/DevHive.Web/Controllers/UserController.cs | 6 +-- src/DevHive.Web/Properties/launchSettings.json | 59 ++++++++++++------------- src/DevHive.Web/appsettings.json | 30 ++++++------- src/DevHive.code-workspace | 20 +++++---- 7 files changed, 61 insertions(+), 62 deletions(-) (limited to 'src/DevHive.Web/Controllers/RoleController.cs') diff --git a/src/DevHive.Services/Interfaces/IUserService.cs b/src/DevHive.Services/Interfaces/IUserService.cs index 19bb939..ef22000 100644 --- a/src/DevHive.Services/Interfaces/IUserService.cs +++ b/src/DevHive.Services/Interfaces/IUserService.cs @@ -2,8 +2,6 @@ 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 { @@ -14,7 +12,7 @@ namespace DevHive.Services.Interfaces Task AddFriend(Guid userId, Guid friendId); - Task GetFriend(string username); + Task GetUserByUsername(string username); Task GetUserById(Guid id); Task UpdateUser(UpdateUserServiceModel updateModel); diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index d4c6f81..bf18007 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -118,7 +118,7 @@ namespace DevHive.Services.Services return this._userMapper.Map(user); } - public async Task GetFriend(string username) + public async Task GetUserByUsername(string username) { User friend = await this._userRepository.GetByUsernameAsync(username); diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs index 5b3dca5..f173ea4 100644 --- a/src/DevHive.Web/Controllers/RoleController.cs +++ b/src/DevHive.Web/Controllers/RoleController.cs @@ -8,7 +8,7 @@ using DevHive.Services.Models.Identity.Role; namespace DevHive.Web.Controllers { - [ApiController] + [ApiController] [Route("/api/[controller]")] //[Authorize(Roles = "Admin")] public class RoleController diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index a306007..dc27cbf 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -72,11 +72,11 @@ namespace DevHive.Web.Controllers } [HttpGet] - [Route("GetFriend")] + [Route("GetUser")] [AllowAnonymous] - public async Task GetAFriend(string username) + public async Task GetUser(string username) { - UserServiceModel friendServiceModel = await this._userService.GetFriend(username); + UserServiceModel friendServiceModel = await this._userService.GetUserByUsername(username); UserWebModel friend = this._userMapper.Map(friendServiceModel); return new OkObjectResult(friend); diff --git a/src/DevHive.Web/Properties/launchSettings.json b/src/DevHive.Web/Properties/launchSettings.json index 44d86fc..5deaadb 100644 --- a/src/DevHive.Web/Properties/launchSettings.json +++ b/src/DevHive.Web/Properties/launchSettings.json @@ -1,31 +1,28 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:1955", - "sslPort": 44326 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "DevHive.Web": { - "commandName": "Project", - "dotnetRunMessages": "true", - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:1955", + "sslPort": 44326 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": false, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "DevHive.Web": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": false, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/DevHive.Web/appsettings.json b/src/DevHive.Web/appsettings.json index a460532..83932a7 100644 --- a/src/DevHive.Web/appsettings.json +++ b/src/DevHive.Web/appsettings.json @@ -1,15 +1,15 @@ -{ - "AppSettings": { - "Secret": "gXfQlU6qpDleFWyimscjYcT3tgFsQg3yoFjcvSLxG56n1Vu2yptdIUq254wlJWjm" - }, - "ConnectionStrings": { - "DEV": "Server=localhost;Port=5432;Database=API;User Id=postgres;Password=;" - }, - "Logging" : { - "LogLevel" : { - "Default" : "Information", - "Microsoft" : "Warning", - "Microsoft.Hosting.Lifetime" : "Information" - } - } -} +{ + "AppSettings": { + "Secret": "gXfQlU6qpDleFWyimscjYcT3tgFsQg3yoFjcvSLxG56n1Vu2yptdIUq254wlJWjm" + }, + "ConnectionStrings": { + "DEV": "Server=localhost;Port=5432;Database=API;User Id=postgres;Password=;" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/DevHive.code-workspace b/src/DevHive.code-workspace index 28b1e3c..10c4276 100644 --- a/src/DevHive.code-workspace +++ b/src/DevHive.code-workspace @@ -46,7 +46,7 @@ "launch": { "configurations": [ { - "name": ".NET Core Launch (web)", + "name": "Launch API", "type": "coreclr", "request": "launch", "preLaunchTask": "workspace-build", @@ -54,16 +54,20 @@ "args": [], "cwd": "${workspaceFolder:DevHive.Web}", "stopAtEntry": false, - "serverReadyAction": { - "action": "openExternally", - "pattern": "\\bNow listening on:\\s+(https?://\\S+)" - }, "env": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "launchBrowser": { - "enabled": false - } + }, + { + "name": "Launch Data Tests", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "workspace-build", + "program": "${workspaceFolder:DevHive.Tests}/DevHive.Data.Tests/bin/Debug/net5.0/DevHive.Data.Tests.dll", + "args": [], + "cwd": "${workspaceFolder:DevHive.Tests}/DevHive.Data.Tests", + "console": "internalConsole", + "stopAtEntry": false }, ], "compounds": [] -- cgit v1.2.3 From 3203ba85dd1948096547608791d82ce83ce123be Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 19 Jan 2021 19:05:25 +0200 Subject: Fixed more issues --- src/DevHive.Web/Controllers/RoleController.cs | 8 ++++---- src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/DevHive.Web/Controllers/RoleController.cs') diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs index f173ea4..227b877 100644 --- a/src/DevHive.Web/Controllers/RoleController.cs +++ b/src/DevHive.Web/Controllers/RoleController.cs @@ -48,11 +48,11 @@ namespace DevHive.Web.Controllers [HttpPut] public async Task Update(Guid id, [FromBody] UpdateRoleWebModel updateRoleWebModel) { - RoleServiceModel roleServiceModel = - this._roleMapper.Map(updateRoleWebModel); - roleServiceModel.Id = id; + UpdateRoleServiceModel updateRoleServiceModel = + this._roleMapper.Map(updateRoleWebModel); + updateRoleServiceModel.Id = id; - bool result = await this._roleService.UpdateRole(roleServiceModel); + bool result = await this._roleService.UpdateRole(updateRoleServiceModel); if (!result) return new BadRequestObjectResult("Could not update role!"); diff --git a/src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs b/src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs index 213ec55..aaf0270 100644 --- a/src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs +++ b/src/DevHive.Web/Models/Identity/Role/UpdateRoleWebModel.cs @@ -1,6 +1,9 @@ +using System; + namespace DevHive.Web.Models.Identity.Role { - public class UpdateRoleWebModel : CreateRoleWebModel + public class UpdateRoleWebModel : RoleWebModel { + public Guid Id { get; set; } } } -- cgit v1.2.3