70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Cors;
|
|
|
|
using AutoMapper;
|
|
|
|
using skydiveLogs_api.Domain;
|
|
using skydiveLogs_api.DomainBusiness.Interfaces;
|
|
using skydiveLogs_api.DataContract;
|
|
|
|
|
|
namespace skydiveLogs_api.Controllers
|
|
{
|
|
public class GearController : Base
|
|
{
|
|
public GearController(IGearService gearService,
|
|
IMapper mapper)
|
|
{
|
|
_gearService = gearService;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
// GET: api/Gear
|
|
[HttpGet]
|
|
[EnableCors]
|
|
public IEnumerable<GearResp> Get()
|
|
{
|
|
var result = _gearService.GetAllGears(ConnectedUser);
|
|
return _mapper.Map<IEnumerable<GearResp>>(result);
|
|
}
|
|
|
|
// GET: api/Gear/5
|
|
[HttpGet("{id}")]
|
|
[EnableCors]
|
|
public GearResp Get(int id)
|
|
{
|
|
var result = _gearService.GetGearById(id);
|
|
return _mapper.Map<GearResp>(result);
|
|
}
|
|
|
|
// POST: api/Gear
|
|
[HttpPost]
|
|
[EnableCors]
|
|
public void Post([FromBody] GearReq value)
|
|
{
|
|
_gearService.AddNewGear(_mapper.Map<Gear>(value), ConnectedUser);
|
|
}
|
|
|
|
// PUT: api/Gear/5
|
|
[HttpPut("{id}")]
|
|
[EnableCors]
|
|
public void Put(int id, [FromBody] GearReq value)
|
|
{
|
|
_gearService.UpdateGear(id, _mapper.Map<Gear>(value));
|
|
}
|
|
|
|
// DELETE: api/ApiWithActions/5
|
|
[HttpDelete("{id}")]
|
|
[EnableCors]
|
|
public void Delete(int id)
|
|
{
|
|
_gearService.DeleteGearById(id);
|
|
}
|
|
|
|
private readonly IGearService _gearService;
|
|
|
|
private readonly IMapper _mapper;
|
|
}
|
|
}
|