Files
SkydiveLogs/Back/skydiveLogs-api/Controllers/DropZoneController.cs
T
2026-03-25 21:00:48 +01:00

135 lines
4.2 KiB
C#

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 DropZoneController : Base
{
#region Public Constructors
public DropZoneController(IDropZoneService dropZoneService,
IMapper mapper)
{
_dropZoneService = dropZoneService;
_mapper = mapper;
}
#endregion Public Constructors
#region Public Methods
/// <summary>
/// Adds a drop zone to the user's favorites.
/// </summary>
/// <param name="id">The drop zone ID to add to favorites.</param>
/// <returns>True if successful, false otherwise.</returns>
[HttpPut("AddToFavorite/{id}")]
[EnableCors]
public bool AddToFavorite(int id)
{
return _dropZoneService.AddToFavorite(id);
}
/// <summary>
/// Deletes a drop zone by its ID.
/// </summary>
/// <param name="id">The drop zone ID to delete.</param>
[HttpDelete("{id}")]
[EnableCors]
public void Delete(int id)
{
_dropZoneService.DeleteDzById(id);
}
/// <summary>
/// Retrieves a list of all drop zones.
/// </summary>
/// <returns>A collection of DropZoneResp objects containing all drop zones.</returns>
[HttpGet]
[EnableCors]
public IEnumerable<DropZoneResp> Get()
{
var result = _dropZoneService.GetAllDzs();
return _mapper.Map<IEnumerable<DropZoneResp>>(result);
}
/// <summary>
/// Retrieves a drop zone by its ID.
/// </summary>
/// <param name="id">The drop zone ID to retrieve.</param>
/// <returns>A DropZoneResp object containing the drop zone details.</returns>
[HttpGet("{id}")]
[EnableCors]
public DropZoneResp Get(int id)
{
var result = _dropZoneService.GetDzById(id);
return _mapper.Map<DropZoneResp>(result);
}
/// <summary>
/// Retrieves a simplified list of all drop zones.
/// </summary>
/// <returns>A collection of DropZoneSimpleResp objects containing simplified drop zone data.</returns>
[HttpGet("GetSimple")]
[EnableCors]
public IEnumerable<DropZoneSimpleResp> GetSimple()
{
var result = _dropZoneService.GetAllDzs();
return _mapper.Map<IEnumerable<DropZoneSimpleResp>>(result);
}
/// <summary>
/// Adds a new drop zone to the system.
/// </summary>
/// <param name="value">DropZoneReq object containing the new drop zone data.</param>
[HttpPost]
[EnableCors]
public void Post([FromBody] DropZoneReq value)
{
_dropZoneService.AddNewDz(_mapper.Map<DropZone>(value));
}
/// <summary>
/// Updates an existing drop zone.
/// </summary>
/// <param name="id">The drop zone ID to update.</param>
/// <param name="value">DropZoneReq object containing the updated drop zone data.</param>
/// <returns>True if successful, false otherwise.</returns>
[HttpPut("{id}")]
[EnableCors]
public bool Put(int id, [FromBody] DropZoneReq value)
{
return _dropZoneService.UpdateDz(id, _mapper.Map<DropZone>(value));
}
/// <summary>
/// Removes a drop zone from the user's favorites.
/// </summary>
/// <param name="id">The drop zone ID to remove from favorites.</param>
/// <returns>True if successful, false otherwise.</returns>
[HttpPut("RemoveToFavorite/{id}")]
[EnableCors]
public bool RemoveToFavorite(int id)
{
return _dropZoneService.RemoveToFavorite(id);
}
#endregion Public Methods
#region Private Fields
private readonly IDropZoneService _dropZoneService;
private readonly IMapper _mapper;
#endregion Private Fields
}
}