Files
SkydiveLogs/Back/skydiveLogs-api/Controllers/ImageController.cs
T
sandre ceed44f997 Little test with AI + Add the equipment (#8)
Tests using local LLM AI to add comments in the C# files
For the flights tunnel, show the total to day/hours
For the jump, add the equipment (now just with the wingsuit)

Reviewed-on: #8
Co-authored-by: sandre <perso@sebastienandre.com>
Co-committed-by: sandre <perso@sebastienandre.com>
2026-05-16 09:24:13 +00:00

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