Add AutoMapper config to convert the return data API

This commit is contained in:
Sébastien André
2019-09-26 13:36:09 +02:00
parent a2718e4ba7
commit 4d6787af20
8 changed files with 41 additions and 14 deletions

View File

@@ -26,14 +26,16 @@ namespace skydiveLogs_api.Controllers
[HttpGet]
public IEnumerable<AircraftResp> Get()
{
return _aircraftService.GetAllAircrafts();
var result = _aircraftService.GetAllAircrafts();
return _mapper.Map<IEnumerable<AircraftResp>>(result);
}
// GET: api/Aircraft/5
[HttpGet("{id}", Name = "Get")]
public AircraftResp Get(int id)
{
return _aircraftService.GetAircraftById(id);
var result = _aircraftService.GetAircraftById(id);
return _mapper.Map<AircraftResp>(result);
}
// POST: api/Aircraft

View File

@@ -26,14 +26,18 @@ namespace skydiveLogs_api.Controllers
[HttpGet]
public IEnumerable<DropZoneResp> Get()
{
return _dropZoneService.GetAllDzs();
var result = _dropZoneService.GetAllDzs();
return _mapper.Map<IEnumerable<DropZoneResp>>(result);
}
// GET: api/DropZone/5
[HttpGet("{id}", Name = "Get")]
public DropZoneResp Get(int id)
{
return _dropZoneService.GetDzById(id);
var result = _dropZoneService.GetDzById(id);
return _mapper.Map<DropZoneResp>(result);
}
// POST: api/DropZone

View File

@@ -26,14 +26,16 @@ namespace skydiveLogs_api.Controllers
[HttpGet]
public IEnumerable<JumpResp> Get()
{
return _jumpService.GetAllJumps();
var result = _jumpService.GetAllJumps();
return _mapper.Map<IEnumerable<JumpResp>>(result);
}
// GET: api/Jump/5
[HttpGet("{id}", Name = "Get")]
public JumpResp Get(int id)
{
return _jumpService.GetJumpById(id);
var result = _jumpService.GetJumpById(id);
return _mapper.Map<JumpResp>(result);
}
// POST: api/Jump

View File

@@ -26,14 +26,16 @@ namespace skydiveLogs_api.Controllers
[HttpGet]
public IEnumerable<JumpTypeResp> Get()
{
return _jumpTypeService.GetAllJumpTypes();
var result = _jumpTypeService.GetAllJumpTypes();
return _mapper.Map<IEnumerable<JumpTypeResp>>(result);
}
// GET: api/JumpType/5
[HttpGet("{id}", Name = "Get")]
public JumpTypeResp Get(int id)
{
return _jumpTypeService.GetJumpTypeById(id);
var result = _jumpTypeService.GetJumpTypeById(id);
return _mapper.Map<JumpTypeResp>(result);
}
// POST: api/JumpType