diff options
| author | Kamen Mladenov <kamen.d.mladenov@protonmail.com> | 2021-04-09 19:51:35 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-09 19:51:35 +0300 |
| commit | 233f38915ba0079079233eff55434ef349c05c45 (patch) | |
| tree | 6c5f69017865bcab87355e910c87339453da1406 /src/DevHive.Web/Controllers/TechnologyController.cs | |
| parent | f4a70c6430db923af9fa9958a11c2d6612cb52cc (diff) | |
| parent | a992357efcf1bc1ece81b95ecee5e05a0b73bfdc (diff) | |
| download | DevHive-0.2.tar DevHive-0.2.tar.gz DevHive-0.2.zip | |
Merge pull request #28 from Team-Kaleidoscope/devHEADv0.2mainheroku/main
Second stage: Complete
Diffstat (limited to 'src/DevHive.Web/Controllers/TechnologyController.cs')
| -rw-r--r-- | src/DevHive.Web/Controllers/TechnologyController.cs | 87 |
1 files changed, 0 insertions, 87 deletions
diff --git a/src/DevHive.Web/Controllers/TechnologyController.cs b/src/DevHive.Web/Controllers/TechnologyController.cs deleted file mode 100644 index e507899..0000000 --- a/src/DevHive.Web/Controllers/TechnologyController.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using AutoMapper; -using DevHive.Services.Interfaces; -using DevHive.Services.Models.Technology; -using DevHive.Web.Models.Technology; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace DevHive.Web.Controllers -{ - [ApiController] - [Route("/api/[controller]")] - public class TechnologyController - { - private readonly ITechnologyService _technologyService; - private readonly IMapper _technologyMapper; - - public TechnologyController(ITechnologyService technologyService, IMapper technologyMapper) - { - this._technologyService = technologyService; - this._technologyMapper = technologyMapper; - } - - [HttpPost] - [Authorize(Roles = "Admin")] - public async Task<IActionResult> Create([FromBody] CreateTechnologyWebModel createTechnologyWebModel) - { - CreateTechnologyServiceModel technologyServiceModel = this._technologyMapper.Map<CreateTechnologyServiceModel>(createTechnologyWebModel); - - Guid id = await this._technologyService.CreateTechnology(technologyServiceModel); - - return id == Guid.Empty ? - new BadRequestObjectResult($"Could not create technology {createTechnologyWebModel.Name}") : - new OkObjectResult(new { Id = id }); - } - - [HttpGet] - [AllowAnonymous] - public async Task<IActionResult> GetById(Guid id) - { - ReadTechnologyServiceModel readTechnologyServiceModel = await this._technologyService.GetTechnologyById(id); - ReadTechnologyWebModel readTechnologyWebModel = this._technologyMapper.Map<ReadTechnologyWebModel>(readTechnologyServiceModel); - - return new OkObjectResult(readTechnologyWebModel); - } - - [HttpGet] - [Route("GetTechnologies")] - [Authorize(Roles = "User,Admin")] - public IActionResult GetAllExistingTechnologies() - { - HashSet<ReadTechnologyServiceModel> technologyServiceModels = this._technologyService.GetTechnologies(); - HashSet<ReadTechnologyWebModel> languageWebModels = this._technologyMapper.Map<HashSet<ReadTechnologyWebModel>>(technologyServiceModels); - - return new OkObjectResult(languageWebModels); - } - - [HttpPut] - [Authorize(Roles = "Admin")] - public async Task<IActionResult> Update(Guid id, [FromBody] UpdateTechnologyWebModel updateModel) - { - UpdateTechnologyServiceModel updateTechnologyServiceModel = this._technologyMapper.Map<UpdateTechnologyServiceModel>(updateModel); - updateTechnologyServiceModel.Id = id; - - bool result = await this._technologyService.UpdateTechnology(updateTechnologyServiceModel); - - if (!result) - return new BadRequestObjectResult("Could not update Technology"); - - return new OkResult(); - } - - [HttpDelete] - [Authorize(Roles = "Admin")] - public async Task<IActionResult> Delete(Guid id) - { - bool result = await this._technologyService.DeleteTechnology(id); - - if (!result) - return new BadRequestObjectResult("Could not delete Technology"); - - return new OkResult(); - } - } -} |
