Add illustration id to publication entity.
This commit is contained in:
@@ -44,4 +44,8 @@ public class PictureUseCases {
|
||||
public Optional<Picture> findById(UUID pictureId) {
|
||||
return picturePort.findById(pictureId);
|
||||
}
|
||||
|
||||
public boolean existsById(UUID pictureId) {
|
||||
return picturePort.existsById(pictureId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ public class PublicationCreationRequestValidator {
|
||||
throw new PublicationEditionException("description cannot be null");
|
||||
}
|
||||
|
||||
if (request.pictureId() == null) {
|
||||
throw new PublicationEditionException("pictureId cannot be null");
|
||||
if (request.illustrationId() == null) {
|
||||
throw new PublicationEditionException("illustrationId cannot be null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class PublicationUpdateRequestValidator {
|
||||
isNull(request.title()) &&
|
||||
isNull(request.text()) &&
|
||||
isNull(request.description()) &&
|
||||
isNull(request.pictureId()) &&
|
||||
isNull(request.illustrationId()) &&
|
||||
isNull(request.categoryId())
|
||||
) {
|
||||
throw new PublicationEditionException("no any field is filled");
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.codiki.domain.category.exception.CategoryNotFoundException;
|
||||
import org.codiki.domain.category.model.Category;
|
||||
import org.codiki.domain.exception.AuthenticationRequiredException;
|
||||
import org.codiki.domain.picture.exception.PictureNotFoundException;
|
||||
import org.codiki.domain.picture.model.Picture;
|
||||
import org.codiki.domain.publication.exception.PublicationEditionException;
|
||||
import org.codiki.domain.publication.exception.PublicationNotFoundException;
|
||||
import org.codiki.domain.publication.exception.PublicationUpdateForbiddenException;
|
||||
@@ -68,10 +67,11 @@ public class PublicationUseCases {
|
||||
new CategoryNotFoundException(request.categoryId())
|
||||
));
|
||||
|
||||
Picture picture = pictureUseCases.findById(request.pictureId())
|
||||
.orElseThrow(() -> new PublicationEditionException(
|
||||
new PictureNotFoundException(request.pictureId())
|
||||
));
|
||||
if (!pictureUseCases.existsById(request.illustrationId())) {
|
||||
throw new PublicationEditionException(
|
||||
new PictureNotFoundException(request.illustrationId())
|
||||
);
|
||||
}
|
||||
|
||||
Publication newPublication = aPublication()
|
||||
.withId(UUID.randomUUID())
|
||||
@@ -79,7 +79,7 @@ public class PublicationUseCases {
|
||||
.withTitle(request.title())
|
||||
.withText(request.text())
|
||||
.withDescription(request.description())
|
||||
.withPicture(picture)
|
||||
.withIllustrationId(request.illustrationId())
|
||||
.withCreationDate(ZonedDateTime.now(clock))
|
||||
.withAuthor(anAuthor().basedOn(authenticatedUser).build())
|
||||
.withCategory(category)
|
||||
@@ -117,12 +117,13 @@ public class PublicationUseCases {
|
||||
publicationBuilder.withDescription(request.description());
|
||||
}
|
||||
|
||||
if (!isNull(request.pictureId())) {
|
||||
Picture picture = pictureUseCases.findById(request.pictureId())
|
||||
.orElseThrow(() -> new PublicationEditionException(
|
||||
new PictureNotFoundException(request.pictureId())
|
||||
));
|
||||
publicationBuilder.withPicture(picture);
|
||||
if (!isNull(request.illustrationId())) {
|
||||
if (!pictureUseCases.existsById(request.illustrationId())) {
|
||||
throw new PublicationEditionException(
|
||||
new PictureNotFoundException(request.illustrationId())
|
||||
);
|
||||
}
|
||||
publicationBuilder.withIllustrationId(request.illustrationId());
|
||||
}
|
||||
|
||||
if (!isNull(request.categoryId())) {
|
||||
|
||||
@@ -13,7 +13,7 @@ public record Publication(
|
||||
String text,
|
||||
String description,
|
||||
ZonedDateTime creationDate,
|
||||
Picture picture,
|
||||
UUID illustrationId,
|
||||
Author author,
|
||||
Category category
|
||||
) {
|
||||
|
||||
@@ -6,6 +6,6 @@ public record PublicationEditionRequest(
|
||||
String title,
|
||||
String text,
|
||||
String description,
|
||||
UUID pictureId,
|
||||
UUID illustrationId,
|
||||
UUID categoryId
|
||||
) {}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class AuthorBuilder {
|
||||
return new AuthorBuilder()
|
||||
.withId(user.id())
|
||||
// .withName(user.name())
|
||||
// .withImage(user.pictureId())
|
||||
// .withImage(user.illustrationId())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@ package org.codiki.domain.publication.model.builder;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.picture.model.Picture;
|
||||
import org.codiki.domain.publication.model.Author;
|
||||
import org.codiki.domain.category.model.Category;
|
||||
import org.codiki.domain.publication.model.Author;
|
||||
import org.codiki.domain.publication.model.Publication;
|
||||
|
||||
public class PublicationBuilder {
|
||||
@@ -14,7 +13,7 @@ public class PublicationBuilder {
|
||||
private String title;
|
||||
private String text;
|
||||
private String description;
|
||||
private Picture picture;
|
||||
private UUID illustrationId;
|
||||
private ZonedDateTime creationDate;
|
||||
private Author author;
|
||||
private Category category;
|
||||
@@ -25,6 +24,19 @@ public class PublicationBuilder {
|
||||
return new PublicationBuilder();
|
||||
}
|
||||
|
||||
public PublicationBuilder basedOn(Publication publication) {
|
||||
return new PublicationBuilder()
|
||||
.withId(publication.id())
|
||||
.withKey(publication.key())
|
||||
.withTitle(publication.title())
|
||||
.withText(publication.text())
|
||||
.withDescription(publication.description())
|
||||
.withIllustrationId(publication.illustrationId())
|
||||
.withCreationDate(publication.creationDate())
|
||||
.withAuthor(publication.author())
|
||||
.withCategory(publication.category());
|
||||
}
|
||||
|
||||
public PublicationBuilder withId(UUID id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
@@ -50,8 +62,8 @@ public class PublicationBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicationBuilder withPicture(Picture picture) {
|
||||
this.picture = picture;
|
||||
public PublicationBuilder withIllustrationId(UUID illustrationId) {
|
||||
this.illustrationId = illustrationId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -77,22 +89,10 @@ public class PublicationBuilder {
|
||||
title,
|
||||
text,
|
||||
description,
|
||||
creationDate, picture,
|
||||
creationDate,
|
||||
illustrationId,
|
||||
author,
|
||||
category
|
||||
);
|
||||
}
|
||||
|
||||
public PublicationBuilder basedOn(Publication publication) {
|
||||
return new PublicationBuilder()
|
||||
.withId(publication.id())
|
||||
.withKey(publication.key())
|
||||
.withTitle(publication.title())
|
||||
.withText(publication.text())
|
||||
.withDescription(publication.description())
|
||||
.withPicture(publication.picture())
|
||||
.withCreationDate(publication.creationDate())
|
||||
.withAuthor(publication.author())
|
||||
.withCategory(publication.category());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public record PublicationDto(
|
||||
String text,
|
||||
String description,
|
||||
ZonedDateTime creationDate,
|
||||
UUID picture,
|
||||
UUID illustrationId,
|
||||
AuthorDto author,
|
||||
CategoryDto category
|
||||
) {
|
||||
@@ -25,7 +25,7 @@ public record PublicationDto(
|
||||
publication.text(),
|
||||
publication.description(),
|
||||
publication.creationDate(),
|
||||
publication.picture().id(),
|
||||
publication.illustrationId(),
|
||||
new AuthorDto(publication.author()),
|
||||
new CategoryDto(publication.category())
|
||||
);
|
||||
|
||||
@@ -8,10 +8,10 @@ public record PublicationEditionRequestDto(
|
||||
String title,
|
||||
String text,
|
||||
String description,
|
||||
UUID pictureId,
|
||||
UUID illustrationId,
|
||||
UUID categoryId
|
||||
) {
|
||||
public PublicationEditionRequest toDomain() {
|
||||
return new PublicationEditionRequest(title, text, description, pictureId, categoryId);
|
||||
return new PublicationEditionRequest(title, text, description, illustrationId, categoryId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ public class AuthorEntity {
|
||||
private UUID id;
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
// private String pictureId;
|
||||
// private String illustrationId;
|
||||
|
||||
public AuthorEntity(Author author) {
|
||||
this(
|
||||
author.id(),
|
||||
author.name()
|
||||
// author.pictureId()
|
||||
// author.illustrationId()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.publication.model.Publication;
|
||||
import org.codiki.infrastructure.category.model.CategoryEntity;
|
||||
import org.codiki.infrastructure.picture.model.PictureEntity;
|
||||
|
||||
import static jakarta.persistence.FetchType.LAZY;
|
||||
import jakarta.persistence.Column;
|
||||
@@ -38,9 +37,8 @@ public class PublicationEntity {
|
||||
private String description;
|
||||
@Column(nullable = false)
|
||||
private ZonedDateTime creationDate;
|
||||
@ManyToOne(fetch = LAZY)
|
||||
@JoinColumn(name = "picture_id")
|
||||
private PictureEntity picture;
|
||||
@Column(nullable = false)
|
||||
private UUID illustrationId;
|
||||
@ManyToOne(fetch = LAZY)
|
||||
@JoinColumn(name = "author_id")
|
||||
private AuthorEntity author;
|
||||
@@ -56,7 +54,7 @@ public class PublicationEntity {
|
||||
publication.text(),
|
||||
publication.description(),
|
||||
publication.creationDate(),
|
||||
new PictureEntity(publication.picture()),
|
||||
publication.illustrationId(),
|
||||
new AuthorEntity(publication.author()),
|
||||
new CategoryEntity(publication.category())
|
||||
);
|
||||
@@ -69,7 +67,8 @@ public class PublicationEntity {
|
||||
title,
|
||||
text,
|
||||
description,
|
||||
creationDate, picture.toDomain(),
|
||||
creationDate,
|
||||
illustrationId,
|
||||
author.toDomain(),
|
||||
category.toDomain()
|
||||
);
|
||||
|
||||
@@ -12,7 +12,6 @@ public interface PublicationRepository extends JpaRepository<PublicationEntity,
|
||||
@Query("""
|
||||
SELECT p
|
||||
FROM PublicationEntity p
|
||||
JOIN FETCH p.picture pi
|
||||
JOIN FETCH p.author a
|
||||
JOIN FETCH p.category c
|
||||
WHERE p.id = :publicationId
|
||||
|
||||
@@ -46,15 +46,15 @@ CREATE TABLE IF NOT EXISTS publication (
|
||||
text VARCHAR NOT NULL,
|
||||
description VARCHAR NOT NULL,
|
||||
creation_date TIMESTAMP NOT NULL,
|
||||
picture_id UUID NOT NULL,
|
||||
illustration_id UUID NOT NULL,
|
||||
author_id UUID NOT NULL,
|
||||
category_id UUID NOT NULL,
|
||||
CONSTRAINT publication_pk PRIMARY KEY (id),
|
||||
CONSTRAINT publication_picture_id_fk FOREIGN KEY (picture_id) REFERENCES picture (id),
|
||||
CONSTRAINT publication_picture_id_fk FOREIGN KEY (illustration_id) REFERENCES picture (id),
|
||||
CONSTRAINT publication_author_id_fk FOREIGN KEY (author_id) REFERENCES "user" (id),
|
||||
CONSTRAINT publication_category_id_fk FOREIGN KEY (category_id) REFERENCES category (id)
|
||||
);
|
||||
CREATE INDEX publication_picture_id_idx ON publication (picture_id);
|
||||
CREATE INDEX publication_picture_id_idx ON publication (illustration_id);
|
||||
CREATE INDEX publication_author_id_idx ON publication (author_id);
|
||||
CREATE INDEX publication_category_id_idx ON publication (category_id);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
vars {
|
||||
url: http://localhost:8080
|
||||
publicationId: e23831a6-9cc0-4f3d-9efa-7a1cae191cb1
|
||||
bearerToken: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1YWQ0NjJiOC04ZjllLTRhMjYtYmI4Ni1jNzRmZWY1ZDExYjYiLCJleHAiOjE3MTA0MjE2Nzd9.Ln2C9_3ZmX0nxZukW7N18j3AfJ_NGCiPfhir24C33T-BuvwsQ2iI_09gcxwGtclPWP5DYyM3gFwcH0jdWtPjkA
|
||||
bearerToken: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1YWQ0NjJiOC04ZjllLTRhMjYtYmI4Ni1jNzRmZWY1ZDExYjYiLCJleHAiOjE3MTA0MjI2NTl9.yHT26uwON5Kk5CWgNvzq2a9OrdJACG4Rk034GPKoZlaxXwK0k8meSHVlrX4ZqTyR3zoL3fm_ujootZRISqOPZw
|
||||
categoryId: 172fa901-3f4b-4540-92f3-1c15820e8ec9
|
||||
pictureId: 65b660b7-66bb-4e4a-a62c-fd0ca101f972
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user