Files
SkydiveLogs/Back/skydiveLogs-api/Controllers/JumpController.cs
2022-05-08 16:42:04 +02:00

104 lines
2.7 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;
using System.Linq;
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 JumpListResp Get()
{
var tmp = _jumpService.GetAllJumps();
var result = new JumpListResp
{
Rows = _mapper.Map<IEnumerable<JumpResp>>(tmp),
Count = tmp.Count()
};
return result;
}
// GET: api/Jump/5/10
[HttpGet("{beginJumpIndex}/{endJumpIndex}")]
[EnableCors]
public JumpListResp Get(int beginJumpIndex, int endJumpIndex)
{
var totalJumps = _jumpService.GetJumpCount();
var tmp = _jumpService.GetJumpsByIndexes(beginJumpIndex, endJumpIndex);
var result = new JumpListResp
{
Rows = _mapper.Map<IEnumerable<JumpResp>>(tmp),
Count = totalJumps
};
return 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
}
}