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