Files
SkydiveLogs/Back/skydiveLogs-api/Controllers/JumpController.cs
Sébastien André 143127cd01 Add a cache system on the referential info
+ Add an identity service
2021-04-17 22:17:45 +02:00

82 lines
2.1 KiB
C#

using AutoMapper;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using skydiveLogs_api.DataContract;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
using System.Collections.Generic;
namespace skydiveLogs_api.Controllers
{
public class JumpController : Base
{
#region Public Constructors
public JumpController(IJumpService jumpService,
IMapper mapper)
{
_jumpService = jumpService;
_mapper = mapper;
}
#endregion Public Constructors
#region Public Methods
// DELETE: api/Jump/5
[HttpDelete("{id}")]
[EnableCors]
public void Delete(int id)
{
_jumpService.DeleteJumpById(id);
}
// GET: api/Jump
[HttpGet]
[EnableCors]
public IEnumerable<JumpResp> Get()
{
var result = _jumpService.GetAllJumps();
return _mapper.Map<IEnumerable<JumpResp>>(result);
}
// GET: api/Jump/5
[HttpGet("{id}")]
[EnableCors]
public JumpResp Get(int id)
{
var result = _jumpService.GetJumpById(id);
return _mapper.Map<JumpResp>(result);
}
// POST: api/Jump
[HttpPost]
[EnableCors]
public void Post([FromBody] JumpReq value)
{
_jumpService.AddNewJump(value.AircraftId,
value.DropZoneId,
value.JumpTypeId,
value.GearId,
_mapper.Map<Jump>(value));
}
// PUT: api/Jump/5
[HttpPut("{id}")]
[EnableCors]
public void Put(int id, [FromBody] JumpReq value)
{
_jumpService.UpdateJump(id, _mapper.Map<Jump>(value));
}
#endregion Public Methods
#region Private Fields
private readonly IJumpService _jumpService;
private readonly IMapper _mapper;
#endregion Private Fields
}
}