From 98e17766b203734a1817eed94338e2d25f4395f7 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 13 Feb 2021 16:20:18 +0200 Subject: Project Restructure P.1 --- src/DevHive.Web/Controllers/UserController.cs | 140 -------------------------- 1 file changed, 140 deletions(-) delete mode 100644 src/DevHive.Web/Controllers/UserController.cs (limited to 'src/DevHive.Web/Controllers/UserController.cs') diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs deleted file mode 100644 index 109bbaa..0000000 --- a/src/DevHive.Web/Controllers/UserController.cs +++ /dev/null @@ -1,140 +0,0 @@ -using System; -using System.Threading.Tasks; -using AutoMapper; -using DevHive.Services.Models.Identity.User; -using DevHive.Web.Models.Identity.User; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using DevHive.Common.Models.Identity; -using DevHive.Services.Interfaces; -using Microsoft.Extensions.Hosting; - -namespace DevHive.Web.Controllers -{ - [ApiController] - [Route("/api/[controller]")] - public class UserController : ControllerBase - { - private readonly IUserService _userService; - private readonly IMapper _userMapper; - - public UserController(IUserService userService, IMapper mapper) - { - this._userService = userService; - this._userMapper = mapper; - } - - #region Authentication - [HttpPost] - [Route("Login")] - [AllowAnonymous] - public async Task Login([FromBody] LoginWebModel loginModel) - { - LoginServiceModel loginServiceModel = this._userMapper.Map(loginModel); - - TokenModel TokenModel = await this._userService.LoginUser(loginServiceModel); - TokenWebModel tokenWebModel = this._userMapper.Map(TokenModel); - - return new OkObjectResult(tokenWebModel); - } - - [HttpPost] - [Route("Register")] - [AllowAnonymous] - public async Task Register([FromBody] RegisterWebModel registerModel) - { - RegisterServiceModel registerServiceModel = this._userMapper.Map(registerModel); - - TokenModel TokenModel = await this._userService.RegisterUser(registerServiceModel); - TokenWebModel tokenWebModel = this._userMapper.Map(TokenModel); - - return new CreatedResult("Register", tokenWebModel); - } - #endregion - - #region Read - [HttpGet] - [Authorize(Roles = "User,Admin")] - public async Task GetById(Guid id, [FromHeader] string authorization) - { - if (!await this._userService.ValidJWT(id, authorization)) - return new UnauthorizedResult(); - - UserServiceModel userServiceModel = await this._userService.GetUserById(id); - UserWebModel userWebModel = this._userMapper.Map(userServiceModel); - - return new OkObjectResult(userWebModel); - } - - [HttpGet] - [Route("GetUser")] - [AllowAnonymous] - public async Task GetUser(string username) - { - UserServiceModel friendServiceModel = await this._userService.GetUserByUsername(username); - UserWebModel friend = this._userMapper.Map(friendServiceModel); - - return new OkObjectResult(friend); - } - #endregion - - #region Update - [HttpPut] - [Authorize(Roles = "User,Admin")] - public async Task Update(Guid id, [FromBody] UpdateUserWebModel updateUserWebModel, [FromHeader] string authorization) - { - if (!await this._userService.ValidJWT(id, authorization)) - return new UnauthorizedResult(); - - UpdateUserServiceModel updateUserServiceModel = this._userMapper.Map(updateUserWebModel); - updateUserServiceModel.Id = id; - - UserServiceModel userServiceModel = await this._userService.UpdateUser(updateUserServiceModel); - UserWebModel userWebModel = this._userMapper.Map(userServiceModel); - - return new AcceptedResult("UpdateUser", userWebModel); - } - - [HttpPut] - [Route("ProfilePicture")] - [Authorize(Roles = "User,Admin")] - public async Task UpdateProfilePicture(Guid userId, [FromForm] UpdateProfilePictureWebModel updateProfilePictureWebModel, [FromHeader] string authorization) - { - if (!await this._userService.ValidJWT(userId, authorization)) - return new UnauthorizedResult(); - - UpdateProfilePictureServiceModel updateProfilePictureServiceModel = this._userMapper.Map(updateProfilePictureWebModel); - updateProfilePictureServiceModel.UserId = userId; - - ProfilePictureServiceModel profilePictureServiceModel = await this._userService.UpdateProfilePicture(updateProfilePictureServiceModel); - ProfilePictureWebModel profilePictureWebModel = this._userMapper.Map(profilePictureServiceModel); - - return new AcceptedResult("UpdateProfilePicture", profilePictureWebModel); - } - #endregion - - #region Delete - [HttpDelete] - [Authorize(Roles = "User,Admin")] - public async Task Delete(Guid id, [FromHeader] string authorization) - { - if (!await this._userService.ValidJWT(id, authorization)) - return new UnauthorizedResult(); - - bool result = await this._userService.DeleteUser(id); - if (!result) - return new BadRequestObjectResult("Could not delete User"); - - return new OkResult(); - } - #endregion - - [HttpPost] - [Authorize(Roles = "User,Admin")] - [Route("SuperSecretPromotionToAdmin")] - public async Task SuperSecretPromotionToAdmin(Guid userId) - { - return new OkObjectResult(await this._userService.SuperSecretPromotionToAdmin(userId)); - } - } -} -- cgit v1.2.3