Added endpoints to update verspakketten and add beoordeling. Added some validations and other tweaks

This commit is contained in:
moarten
2026-04-18 20:07:24 +02:00
parent a10bcfa1d6
commit 11bff0de63
23 changed files with 628 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
using Cortex.Mediator;
using Lutra.API.Requests;
using Lutra.Application.Verspakketten;
using Microsoft.AspNetCore.Mvc;
@@ -72,5 +73,48 @@ namespace Lutra.API.Controllers
return BadRequest(ex.Message);
}
}
/// <summary>
/// Updates an existing verspakket with the provided values.
/// </summary>
/// <param name="id">The verspakket identifier.</param>
/// <param name="request">The updated verspakket values.</param>
/// <returns>
/// Returns 204 No Content when the update succeeds.
/// Returns 404 Not Found when the specified verspakket does not exist.
/// </returns>
[HttpPut("{id:guid}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateVerspakketRequest request)
{
var command = new UpdateVerspakket.Command(id, request.Naam, request.PrijsInCenten, request.AantalPersonen, request.SupermarktId);
await mediator.SendCommandAsync<UpdateVerspakket.Command, UpdateVerspakket.Response>(command);
return NoContent();
}
/// <summary>
/// Adds a beoordeling to an existing verspakket.
/// </summary>
/// <param name="id">The verspakket ID.</param>
/// <param name="request">The beoordeling values to add.</param>
/// <returns>Returns 201 Created with the created beoordeling identifier.</returns>
[HttpPost("{id:guid}/beoordelingen")]
[ProducesResponseType(typeof(AddBeoordeling.Response), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ActionResult<AddBeoordeling.Response>> AddBeoordeling(Guid id, [FromBody] AddBeoordelingRequest request)
{
try
{
var command = new AddBeoordeling.Command(id, request.CijferSmaak, request.CijferBereiden, request.Aanbevolen, request.Tekst);
var result = await mediator.SendCommandAsync<AddBeoordeling.Command, AddBeoordeling.Response>(command);
return CreatedAtAction(nameof(GetById), new { id }, result);
}
catch (InvalidOperationException ex)
{
return BadRequest(ex.Message);
}
}
}
}

View File

@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace Lutra.API.Requests;
/// <summary>
/// Represents the data required to add a beoordeling to a verspakket.
/// </summary>
public sealed record AddBeoordelingRequest(
[Range(1, 10)] int CijferSmaak,
[Range(1, 10)] int CijferBereiden,
bool Aanbevolen,
[MaxLength(1024)] string? Tekst);

View File

@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace Lutra.API.Requests;
/// <summary>
/// Represents the data required to update a verspakket.
/// </summary>
public sealed record UpdateVerspakketRequest(
[Required, MaxLength(50)] string Naam,
[Range(0, int.MaxValue)] int PrijsInCenten,
[Range(1, 10)] int AantalPersonen,
[Required] Guid SupermarktId);