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

@@ -2,10 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.DataContract;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Controllers
{
@@ -13,43 +15,49 @@ namespace skydiveLogs_api.Controllers
[ApiController]
public class AircraftController : ControllerBase
{
public AircraftController(IAircraftService aircraftService)
public AircraftController(IAircraftService aircraftService,
IMapper mapper)
{
_aircraftService = aircraftService;
_mapper = mapper;
}
// GET: api/Aircraft
[HttpGet]
public IEnumerable<AircraftResp> Get()
{
return new AircraftResp[] { "value1", "value2" };
return _aircraftService.GetAllAircrafts();
}
// GET: api/Aircraft/5
[HttpGet("{id}", Name = "Get")]
public AircraftResp Get(int id)
{
return "value";
return _aircraftService.GetAircraftById(id);
}
// POST: api/Aircraft
[HttpPost]
public void Post([FromBody] AircraftReq value)
{
_aircraftService.AddNewAircraft(_mapper.Map<Aircraft>(value));
}
// PUT: api/Aircraft/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] AircraftReq value)
{
_aircraftService.UpdateAircraft(id, _mapper.Map<Aircraft>(value));
}
// DELETE: api/ApiWithActions/5
[HttpDelete("{id}")]
public void Delete(int id)
{
_aircraftService.DeleteAircraftById(id);
}
private readonly IAircraftService _aircraftService;
private readonly IMapper _mapper;
}
}