using System.Collections.Generic;
using AutoMapper;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using skydiveLogs_api.DataContract;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
namespace skydiveLogs_api.Controllers
{
public class GearController : Base
{
#region Public Constructors
public GearController(IGearService gearService,
IMapper mapper)
{
_gearService = gearService;
_mapper = mapper;
}
#endregion Public Constructors
#region Public Methods
///
/// Deletes a gear item by its ID.
///
/// The gear ID to delete.
[HttpDelete("{id}")]
[EnableCors]
public void Delete(int id)
{
_gearService.DeleteGearById(id);
}
///
/// Retrieves a list of all gear items.
///
/// A collection of GearResp objects containing all gear data.
[HttpGet]
[EnableCors]
public IEnumerable Get()
{
var result = _gearService.GetAllGears();
return _mapper.Map>(result);
}
///
/// Retrieves a gear item by its ID.
///
/// The gear ID to retrieve.
/// A GearResp object containing the gear details.
[HttpGet("{id}")]
[EnableCors]
public GearResp Get(int id)
{
var result = _gearService.GetGearById(id);
return _mapper.Map(result);
}
///
/// Adds a new gear item to the system.
///
/// GearReq object containing the new gear data.
[HttpPost]
[EnableCors]
public void Post([FromBody] GearReq value)
{
_gearService.AddNewGear(_mapper.Map(value));
}
///
/// Updates an existing gear item.
///
/// The gear ID to update.
/// GearReq object containing the updated gear data.
[HttpPut("{id}")]
[EnableCors]
public void Put(int id, [FromBody] GearReq value)
{
_gearService.UpdateGear(id, _mapper.Map(value));
}
#endregion Public Methods
#region Private Fields
private readonly IGearService _gearService;
private readonly IMapper _mapper;
#endregion Private Fields
}
}