Files
SkydiveLogs/Back/skydiveLogs-api/Controllers/TunnelFlightController.cs
2023-08-17 11:29:13 +02:00

97 lines
3.0 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 TunnelFlightController : Base
{
#region Public Constructors
public TunnelFlightController(ITunnelFlightService tunnelFlightService,
IMapper mapper)
{
_tunnelFlightService = tunnelFlightService;
_mapper = mapper;
}
#endregion Public Constructors
#region Public Methods
// GET: api/TunnelFlight
[HttpGet]
[EnableCors]
public IEnumerable<TunnelFlightResp> Get()
{
var result = _tunnelFlightService.GetAllTunnelFlights();
return _mapper.Map<IEnumerable<TunnelFlightResp>>(result);
}
// GET: api/TunnelFlight/5
[HttpGet("{id}")]
[EnableCors]
public TunnelFlightResp Get(int id)
{
var result = _tunnelFlightService.GetTunnelFlightById(id);
return _mapper.Map<TunnelFlightResp>(result);
}
// GET: api/TunnelFlight/20230101/20230701
[HttpGet("{beginDate}/{endDate}")]
[EnableCors]
public IEnumerable<TunnelFlightResp> Get(string beginDate, string endDate)
{
var result = _tunnelFlightService.GetTunnelFlightByDates(beginDate, endDate);
return _mapper.Map<IEnumerable<TunnelFlightResp>>(result);
}
// GET: api/TunnelFlight/month/20230101/20230701
[HttpGet("month/{beginDate}/{endDate}")]
[EnableCors]
public IEnumerable<StatisticResp> GetGroupByMonth(string beginDate, string endDate)
{
var result = _tunnelFlightService.GetTunnelFlightGroupByMonth(beginDate, endDate);
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
// POST: api/Tunnel
[HttpPost]
[EnableCors]
public void Post([FromBody] TunnelFlightReq value)
{
_tunnelFlightService.AddNewFlight(value.TunnelId,
value.JumpTypeId,
_mapper.Map<TunnelFlight>(value));
}
// PUT: api/TunnelFlight/5
[HttpPut("{id}")]
[EnableCors]
public void Put(int id, [FromBody] TunnelFlightReq value)
{
_tunnelFlightService.UpdateTunnelFlight(id, _mapper.Map<TunnelFlight>(value));
}
// DELETE: api/TunnelFlight/5
[HttpDelete("{id}")]
[EnableCors]
public void Delete(int id)
{
_tunnelFlightService.DeleteTunnelFlightById(id);
}
#endregion Public Methods
#region Private Fields
private readonly ITunnelFlightService _tunnelFlightService;
private readonly IMapper _mapper;
#endregion Private Fields
}
}