Add AutoMapper and update the interface of business services
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
18
Back/skydiveLogs-api/Mapper/ModelProfile.cs
Normal file
18
Back/skydiveLogs-api/Mapper/ModelProfile.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace skydiveLogs_api.Mapper
|
||||
{
|
||||
public class ModelProfile : Profile
|
||||
{
|
||||
public ModelProfile()
|
||||
{
|
||||
CreateMap<DataContract.JumpReq, Model.Jump>();
|
||||
CreateMap<DataContract.JumpTypeReq, Model.JumpType>();
|
||||
CreateMap<DataContract.AircraftReq, Model.Aircraft>();
|
||||
CreateMap<DataContract.DropZoneReq, Model.DropZone>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ namespace skydiveLogs_api
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using skydiveLogs_api.Ioc;
|
||||
|
||||
|
||||
namespace skydiveLogs_api
|
||||
{
|
||||
public class Startup
|
||||
@@ -24,6 +26,8 @@ namespace skydiveLogs_api
|
||||
// IoC
|
||||
var iocService = new IocService(services);
|
||||
iocService.Configure();
|
||||
|
||||
services.AddAutoMapper(typeof(Mapper.ModelProfile));
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
|
||||
|
||||
Reference in New Issue
Block a user