Add AutoMapper and update the interface of business services
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user