aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-18 10:12:07 +0200
committertranstrike <transtrike@gmail.com>2020-12-18 10:12:07 +0200
commitc50dd1608bff971cd052b375a3c2e618bc98f1c2 (patch)
tree0b9903a1ae284048569c9aa97c5e994e85ead894 /src/DevHive.Web/Controllers
parent12408f43a7a954042358196ee080439aa7aed700 (diff)
parent7acec816fe021db4a3922b70ce9b3f50e7600c79 (diff)
downloadDevHive-c50dd1608bff971cd052b375a3c2e618bc98f1c2.tar
DevHive-c50dd1608bff971cd052b375a3c2e618bc98f1c2.tar.gz
DevHive-c50dd1608bff971cd052b375a3c2e618bc98f1c2.zip
Merge branch 'dev' of github.com:Team-Kaleidoscope/DevHive into dev
Diffstat (limited to 'src/DevHive.Web/Controllers')
-rw-r--r--src/DevHive.Web/Controllers/TechnologyController.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/DevHive.Web/Controllers/TechnologyController.cs b/src/DevHive.Web/Controllers/TechnologyController.cs
new file mode 100644
index 0000000..9e3cf3c
--- /dev/null
+++ b/src/DevHive.Web/Controllers/TechnologyController.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Threading.Tasks;
+using AutoMapper;
+using DevHive.Data.Repositories;
+using DevHive.Services.Models.Technology;
+using DevHive.Services.Services;
+using DevHive.Web.Models.Technology;
+using Microsoft.AspNetCore.Mvc;
+
+namespace DevHive.Web.Controllers
+{
+ [ApiController]
+ [Route("/api/[controller]")]
+ public class TechnologyController
+ {
+ private readonly TechnologyService _technologyService;
+ private readonly IMapper _technologyMapper;
+
+ public TechnologyController(DevHiveContext context, IMapper mapper)
+ {
+ this._technologyService = new TechnologyService(context, mapper);
+ this._technologyMapper = mapper;
+ }
+
+ [HttpPost]
+ public async Task<IActionResult> Create([FromBody] TechnologyWebModel technologyWebModel)
+ {
+ TechnologyServiceModel technologyServiceModel = this._technologyMapper.Map<TechnologyServiceModel>(technologyWebModel);
+
+ bool result = await this._technologyService.Create(technologyServiceModel);
+
+ if(!result)
+ return new BadRequestObjectResult("Could not create the Technology");
+
+ return new OkResult();
+ }
+
+ [HttpGet]
+ public async Task<IActionResult> GetById(Guid id)
+ {
+ TechnologyServiceModel technologyServiceModel = await this._technologyService.GetTechnologyById(id);
+ TechnologyWebModel technologyWebModel = this._technologyMapper.Map<TechnologyWebModel>(technologyServiceModel);
+
+ return new OkObjectResult(technologyWebModel);
+ }
+
+ [HttpPut]
+ public async Task<IActionResult> Update(Guid id, [FromBody] UpdateTechnologyWebModel updateModel)
+ {
+ UpdateTechnologyServiceModel updateTechnologyWebModel = this._technologyMapper.Map<UpdateTechnologyServiceModel>(updateModel);
+ updateTechnologyWebModel.Id = id;
+
+ bool result = await this._technologyService.UpdateTechnology(updateTechnologyWebModel);
+
+ if(!result)
+ return new BadRequestObjectResult("Could not update Technology");
+
+ return new OkResult();
+ }
+
+ [HttpDelete]
+ 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();
+ }
+ }
+} \ No newline at end of file