From 4d6787af2023b1f65da63a73932a9ce3496555d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Thu, 26 Sep 2019 13:36:09 +0200 Subject: [PATCH] Add AutoMapper config to convert the return data API --- .../Interface/IAircraftService.cs | 8 ++++++-- .../Interface/IDropZoneService.cs | 8 ++++++-- Back/skydiveLogs-api.Business/Interface/IJumpService.cs | 8 ++++++-- Back/skydiveLogs-api/Controllers/AircraftController.cs | 6 ++++-- Back/skydiveLogs-api/Controllers/DropZoneController.cs | 8 ++++++-- Back/skydiveLogs-api/Controllers/JumpController.cs | 6 ++++-- Back/skydiveLogs-api/Controllers/JumpTypeController.cs | 6 ++++-- Back/skydiveLogs-api/Mapper/ModelProfile.cs | 5 +++++ 8 files changed, 41 insertions(+), 14 deletions(-) diff --git a/Back/skydiveLogs-api.Business/Interface/IAircraftService.cs b/Back/skydiveLogs-api.Business/Interface/IAircraftService.cs index 8078347..3cba1c9 100644 --- a/Back/skydiveLogs-api.Business/Interface/IAircraftService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IAircraftService.cs @@ -7,10 +7,14 @@ namespace skydiveLogs_api.Business.Interface { public interface IAircraftService { - IEnumerable GetAllAircrafts(); - skydiveLogs_api.DataContract.AircraftResp GetAircraftById(int id); + IEnumerable GetAllAircrafts(); + + Aircraft GetAircraftById(int id); + void AddNewAircraft(Aircraft aircraft); + void UpdateAircraft(int id, Aircraft aircraft); + void DeleteAircraftById(int id); } } diff --git a/Back/skydiveLogs-api.Business/Interface/IDropZoneService.cs b/Back/skydiveLogs-api.Business/Interface/IDropZoneService.cs index 0abf0ef..3e337be 100644 --- a/Back/skydiveLogs-api.Business/Interface/IDropZoneService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IDropZoneService.cs @@ -7,10 +7,14 @@ namespace skydiveLogs_api.Business.Interface { public interface IDropZoneService { - IEnumerable GetAllDzs(); - skydiveLogs_api.DataContract.DropZoneResp GetDzById(int id); + IEnumerable GetAllDzs(); + + DropZone GetDzById(int id); + void DeleteDzById(int id); + void UpdateDz(int id, DropZone dropZone); + void AddNewDz(DropZone dropZone); } } diff --git a/Back/skydiveLogs-api.Business/Interface/IJumpService.cs b/Back/skydiveLogs-api.Business/Interface/IJumpService.cs index a987f9c..eeb9ac3 100644 --- a/Back/skydiveLogs-api.Business/Interface/IJumpService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IJumpService.cs @@ -7,10 +7,14 @@ namespace skydiveLogs_api.Business.Interface { public interface IJumpService { - IEnumerable GetAllJumps(); - skydiveLogs_api.DataContract.JumpResp GetJumpById(int id); + IEnumerable GetAllJumps(); + + Jump GetJumpById(int id); + void AddNewJump(Jump jump); + void UpdateJump(int id, Jump jump); + void DeleteJumpById(int id); } } diff --git a/Back/skydiveLogs-api/Controllers/AircraftController.cs b/Back/skydiveLogs-api/Controllers/AircraftController.cs index 4ac2ae4..9edb60a 100644 --- a/Back/skydiveLogs-api/Controllers/AircraftController.cs +++ b/Back/skydiveLogs-api/Controllers/AircraftController.cs @@ -26,14 +26,16 @@ namespace skydiveLogs_api.Controllers [HttpGet] public IEnumerable Get() { - return _aircraftService.GetAllAircrafts(); + var result = _aircraftService.GetAllAircrafts(); + return _mapper.Map>(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(result); } // POST: api/Aircraft diff --git a/Back/skydiveLogs-api/Controllers/DropZoneController.cs b/Back/skydiveLogs-api/Controllers/DropZoneController.cs index 14617e7..9f1ecb6 100644 --- a/Back/skydiveLogs-api/Controllers/DropZoneController.cs +++ b/Back/skydiveLogs-api/Controllers/DropZoneController.cs @@ -26,14 +26,18 @@ namespace skydiveLogs_api.Controllers [HttpGet] public IEnumerable Get() { - return _dropZoneService.GetAllDzs(); + var result = _dropZoneService.GetAllDzs(); + + return _mapper.Map>(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(result); } // POST: api/DropZone diff --git a/Back/skydiveLogs-api/Controllers/JumpController.cs b/Back/skydiveLogs-api/Controllers/JumpController.cs index bd5dc89..860979d 100644 --- a/Back/skydiveLogs-api/Controllers/JumpController.cs +++ b/Back/skydiveLogs-api/Controllers/JumpController.cs @@ -26,14 +26,16 @@ namespace skydiveLogs_api.Controllers [HttpGet] public IEnumerable Get() { - return _jumpService.GetAllJumps(); + var result = _jumpService.GetAllJumps(); + return _mapper.Map>(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(result); } // POST: api/Jump diff --git a/Back/skydiveLogs-api/Controllers/JumpTypeController.cs b/Back/skydiveLogs-api/Controllers/JumpTypeController.cs index 39d60ff..1758eda 100644 --- a/Back/skydiveLogs-api/Controllers/JumpTypeController.cs +++ b/Back/skydiveLogs-api/Controllers/JumpTypeController.cs @@ -26,14 +26,16 @@ namespace skydiveLogs_api.Controllers [HttpGet] public IEnumerable Get() { - return _jumpTypeService.GetAllJumpTypes(); + var result = _jumpTypeService.GetAllJumpTypes(); + return _mapper.Map>(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(result); } // POST: api/JumpType diff --git a/Back/skydiveLogs-api/Mapper/ModelProfile.cs b/Back/skydiveLogs-api/Mapper/ModelProfile.cs index 54d7bea..281e81f 100644 --- a/Back/skydiveLogs-api/Mapper/ModelProfile.cs +++ b/Back/skydiveLogs-api/Mapper/ModelProfile.cs @@ -13,6 +13,11 @@ namespace skydiveLogs_api.Mapper CreateMap(); CreateMap(); CreateMap(); + + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); } } }