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;
}
}

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;
}
}

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 JumpController : ControllerBase
{
public JumpController(IJumpService jumpService)
public JumpController(IJumpService jumpService,
IMapper mapper)
{
_jumpService = jumpService;
_mapper = mapper;
}
// GET: api/Jump
[HttpGet]
public IEnumerable<JumpResp> Get()
{
return new JumpResp[] { "value1", "value2" };
return _jumpService.GetAllJumps();
}
// GET: api/Jump/5
[HttpGet("{id}", Name = "Get")]
public JumpResp Get(int id)
{
return "value";
return _jumpService.GetJumpById(id);
}
// POST: api/Jump
[HttpPost]
public void Post([FromBody] JumpReq value)
{
_jumpService.AddNewJump(_mapper.Map<Jump>(value));
}
// PUT: api/Jump/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] JumpReq value)
{
_jumpService.UpdateJump(id, _mapper.Map<Jump>(value));
}
// DELETE: api/ApiWithActions/5
[HttpDelete("{id}")]
public void Delete(int id)
{
_jumpService.DeleteJumpById(id);
}
private readonly IJumpService _jumpService;
private readonly IMapper _mapper;
}
}

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 JumpTypeController : ControllerBase
{
public JumpTypeController(IJumpTypeService jumpTypeService)
public JumpTypeController(IJumpTypeService jumpTypeService,
IMapper mapper)
{
_jumpTypeService = jumpTypeService;
_mapper = mapper;
}
// GET: api/JumpType
[HttpGet]
public IEnumerable<JumpTypeResp> Get()
{
return new JumpTypeResp[] { "value1", "value2" };
return _jumpTypeService.GetAllJumpTypes();
}
// GET: api/JumpType/5
[HttpGet("{id}", Name = "Get")]
public JumpTypeResp Get(int id)
{
return "value";
return _jumpTypeService.GetJumpTypeById(id);
}
// POST: api/JumpType
[HttpPost]
public void Post([FromBody] JumpTypeReq value)
{
_jumpTypeService.AddNewJumpType(_mapper.Map<JumpType>(value));
}
// PUT: api/JumpType/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] JumpTypeReq value)
{
_jumpTypeService.UpdateJumpType(id, _mapper.Map<JumpType>(value));
}
// DELETE: api/ApiWithActions/5
[HttpDelete("{id}")]
public void Delete(int id)
{
_jumpTypeService.DeleteJumpTypeById(id);
}
private readonly IJumpTypeService _jumpTypeService;
private readonly IMapper _mapper;
}
}