aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers
diff options
context:
space:
mode:
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