using System.ComponentModel.DataAnnotations; using ErsatzTV.Application.MediaCollections; using ErsatzTV.Core; using ErsatzTV.Core.Api.SmartCollections; using MediatR; using Microsoft.AspNetCore.Mvc; namespace ErsatzTV.Controllers.Api; [ApiController] [EndpointGroupName("general")] public class SmartCollectionController(IMediator mediator) : ControllerBase { [HttpGet("/api/collections/smart", Name="GetSmartCollections")] public async Task> GetAll() => await mediator.Send(new GetAllSmartCollectionsForApi()); [HttpPost("/api/collections/smart/new", Name = "CreateSmartCollection")] public async Task AddOne( [Required] [FromBody] CreateSmartCollection request) { Either result = await mediator.Send(request).MapT(r => new CreateSmartCollectionResult(r.Id)); return result.Match(Ok, error => Problem(error.ToString())); } [HttpPut("/api/collections/smart/update", Name="UpdateSmartCollection")] public async Task UpdateOne( [Required] [FromBody] UpdateSmartCollection request) { Either result = await mediator.Send(request); return result.Match(Ok, error => Problem(error.ToString())); } [HttpDelete("/api/collections/smart/delete/{id:int}", Name="DeleteSmartCollection")] public async Task DeleteSmartCollection(int id) { Either result = await mediator.Send(new DeleteSmartCollection(id)); return result.Match(_ => Ok(), error => Problem(error.ToString())); } }