Files
SkydiveLogs/Back/skydiveLogs-api/Controllers/AircraftController.cs
2019-09-30 15:16:34 +02:00

66 lines
1.8 KiB
C#

using System;
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
{
[Route("api/[controller]")]
[ApiController]
public class AircraftController : ControllerBase
{
public AircraftController(IAircraftService aircraftService,
IMapper mapper)
{
_aircraftService = aircraftService;
_mapper = mapper;
}
// GET: api/Aircraft
[HttpGet]
public IEnumerable<AircraftResp> Get()
{
var result = _aircraftService.GetAllAircrafts();
return _mapper.Map<IEnumerable<AircraftResp>>(result);
}
// GET: api/Aircraft/5
[HttpGet("{id}")]
public AircraftResp Get(int id)
{
var result = _aircraftService.GetAircraftById(id);
return _mapper.Map<AircraftResp>(result);
}
// 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;
}
}