feat(geschichte): add repository and update DTO
GeschichteRepository.search filters by status / personId / documentId in a single JPQL query so the controller can serve the index page, the person discovery card, and the document drawer column from one method. The DTO is shared between create and update like DocumentUpdateDTO. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package org.raddatz.familienarchiv.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.raddatz.familienarchiv.model.GeschichteStatus;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Used for both create and update of a Geschichte. All fields are optional;
|
||||
* the service applies whatever is non-null. {@code body} is rich-text HTML and
|
||||
* is sanitised against an allow-list before persistence.
|
||||
*/
|
||||
@Data
|
||||
public class GeschichteUpdateDTO {
|
||||
private String title;
|
||||
private String body;
|
||||
private GeschichteStatus status;
|
||||
private List<UUID> personIds;
|
||||
private List<UUID> documentIds;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.raddatz.familienarchiv.repository;
|
||||
|
||||
import org.raddatz.familienarchiv.model.Geschichte;
|
||||
import org.raddatz.familienarchiv.model.GeschichteStatus;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
public interface GeschichteRepository extends JpaRepository<Geschichte, UUID>, JpaSpecificationExecutor<Geschichte> {
|
||||
|
||||
@Query("""
|
||||
SELECT g FROM Geschichte g
|
||||
WHERE (:status IS NULL OR g.status = :status)
|
||||
AND (:personId IS NULL OR :personId IN (SELECT p.id FROM g.persons p))
|
||||
AND (:documentId IS NULL OR :documentId IN (SELECT d.id FROM g.documents d))
|
||||
ORDER BY COALESCE(g.publishedAt, g.updatedAt) DESC
|
||||
""")
|
||||
List<Geschichte> search(
|
||||
@Param("status") GeschichteStatus status,
|
||||
@Param("personId") UUID personId,
|
||||
@Param("documentId") UUID documentId,
|
||||
Pageable pageable);
|
||||
}
|
||||
Reference in New Issue
Block a user