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 ImageController : Base
{
#region Public Constructors
public ImageController(IUserImageService imageService,
IMapper mapper)
{
_imageService = imageService;
_mapper = mapper;
}
#endregion Public Constructors
#region Public Methods
///
/// Deletes an image by its ID.
///
/// The image ID to delete.
[HttpDelete("{id}")]
[EnableCors]
public void Delete(int id)
{
_imageService.DeleteImageById(id);
}
///
/// Retrieves a list of all images.
///
/// A collection of ImageResp objects containing all images.
[HttpGet]
[EnableCors]
public IEnumerable Get()
{
var result = _imageService.GetAllImages();
return _mapper.Map>(result);
}
///
/// Retrieves an image by its ID.
///
/// The image ID to retrieve.
/// An ImageResp object containing the image details.
[HttpGet("{id}")]
[EnableCors]
public ImageResp Get(int id)
{
var result = _imageService.GetImageById(id);
return _mapper.Map(result);
}
///
/// Adds a new image to the system.
///
/// ImageReq object containing the new image data.
[HttpPost]
[EnableCors]
public void Post([FromBody] ImageReq value)
{
_imageService.AddNewImage(_mapper.Map(value));
}
///
/// Updates an existing image.
///
/// The image ID to update.
/// ImageReq object containing the updated image data.
[HttpPut("{id}")]
[EnableCors]
public void Put(int id, [FromBody] ImageReq value)
{
_imageService.UpdateImage(id, _mapper.Map(value));
}
#endregion Public Methods
#region Private Fields
private readonly IUserImageService _imageService;
private readonly IMapper _mapper;
#endregion Private Fields
}
}