feat(annotations): add updateAnnotation service method with partial-update DTO

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-14 10:39:50 +02:00
parent 26c7181ba4
commit 1558881c01
3 changed files with 82 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package org.raddatz.familienarchiv.dto;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
/**
* Partial update payload for annotation position and size.
* All fields are optional — only non-null values are applied.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UpdateAnnotationDTO {
@DecimalMin("0.0") @DecimalMax("1.0")
private Double x;
@DecimalMin("0.0") @DecimalMax("1.0")
private Double y;
@DecimalMin("0.01") @DecimalMax("1.0")
private Double width;
@DecimalMin("0.01") @DecimalMax("1.0")
private Double height;
}

View File

@@ -2,6 +2,7 @@ package org.raddatz.familienarchiv.service;
import lombok.RequiredArgsConstructor;
import org.raddatz.familienarchiv.dto.CreateAnnotationDTO;
import org.raddatz.familienarchiv.dto.UpdateAnnotationDTO;
import org.raddatz.familienarchiv.exception.DomainException;
import org.raddatz.familienarchiv.exception.ErrorCode;
import org.raddatz.familienarchiv.model.DocumentAnnotation;
@@ -61,6 +62,21 @@ public class AnnotationService {
return annotationRepository.save(annotation);
}
@Transactional
public DocumentAnnotation updateAnnotation(UUID documentId, UUID annotationId, UpdateAnnotationDTO dto) {
DocumentAnnotation annotation = annotationRepository
.findByIdAndDocumentId(annotationId, documentId)
.orElseThrow(() -> DomainException.notFound(
ErrorCode.ANNOTATION_NOT_FOUND, "Annotation not found: " + annotationId));
if (dto.getX() != null) annotation.setX(dto.getX());
if (dto.getY() != null) annotation.setY(dto.getY());
if (dto.getWidth() != null) annotation.setWidth(dto.getWidth());
if (dto.getHeight() != null) annotation.setHeight(dto.getHeight());
return annotationRepository.save(annotation);
}
@Transactional
public void deleteAnnotation(UUID documentId, UUID annotationId, UUID userId) {
DocumentAnnotation annotation = annotationRepository