Add AutoMapper and update the interface of business services

This commit is contained in:
Sébastien André
2019-09-25 19:38:52 +02:00
parent cb105c13af
commit a2718e4ba7
17 changed files with 102 additions and 20 deletions

View File

@@ -6,6 +6,8 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.DataContract;
using AutoMapper;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Controllers
{
@@ -13,43 +15,49 @@ namespace skydiveLogs_api.Controllers
[ApiController]
public class DropZoneController : ControllerBase
{
public DropZoneController(IDropZoneService dropZoneService)
public DropZoneController(IDropZoneService dropZoneService,
IMapper mapper)
{
_dropZoneService = dropZoneService;
_mapper = mapper;
}
// GET: api/DropZone
[HttpGet]
public IEnumerable<DropZoneResp> Get()
{
return new DropZoneResp[] { "value1", "value2" };
return _dropZoneService.GetAllDzs();
}
// GET: api/DropZone/5
[HttpGet("{id}", Name = "Get")]
public DropZoneResp Get(int id)
{
return "value";
return _dropZoneService.GetDzById(id);
}
// POST: api/DropZone
[HttpPost]
public void Post([FromBody] DropZoneReq value)
{
_dropZoneService.AddNewDz(_mapper.Map<DropZone>(value));
}
// PUT: api/DropZone/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] DropZoneReq value)
{
_dropZoneService.UpdateDz(id, _mapper.Map<DropZone>(value));
}
// DELETE: api/ApiWithActions/5
[HttpDelete("{id}")]
public void Delete(int id)
{
_dropZoneService.DeleteDzById(id);
}
private readonly IDropZoneService _dropZoneService;
private readonly IMapper _mapper;
}
}