Change category field of publication entity to its id.
This commit is contained in:
@@ -27,6 +27,10 @@ public class CategoryUseCases {
|
||||
return categoryPort.findById(categoryId);
|
||||
}
|
||||
|
||||
public boolean existsById(UUID categoryId) {
|
||||
return categoryPort.existsById(categoryId);
|
||||
}
|
||||
|
||||
public Category createCategory(String name, List<UUID> subCategoryIds) {
|
||||
if (isNull(name)) {
|
||||
throw new CategoryEditionException("name can not be empty");
|
||||
|
||||
@@ -62,10 +62,11 @@ public class PublicationUseCases {
|
||||
User authenticatedUser = userUseCases.getAuthenticatedUser()
|
||||
.orElseThrow(AuthenticationRequiredException::new);
|
||||
|
||||
Category category = categoryUseCases.findById(request.categoryId())
|
||||
.orElseThrow(() -> new PublicationEditionException(
|
||||
if (!categoryUseCases.existsById(request.categoryId())) {
|
||||
throw new PublicationEditionException(
|
||||
new CategoryNotFoundException(request.categoryId())
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
if (!pictureUseCases.existsById(request.illustrationId())) {
|
||||
throw new PublicationEditionException(
|
||||
@@ -79,10 +80,10 @@ public class PublicationUseCases {
|
||||
.withTitle(request.title())
|
||||
.withText(request.text())
|
||||
.withDescription(request.description())
|
||||
.withIllustrationId(request.illustrationId())
|
||||
.withCreationDate(ZonedDateTime.now(clock))
|
||||
.withIllustrationId(request.illustrationId())
|
||||
.withCategoryId(request.categoryId())
|
||||
.withAuthor(anAuthor().basedOn(authenticatedUser).build())
|
||||
.withCategory(category)
|
||||
.build();
|
||||
|
||||
publicationPort.save(newPublication);
|
||||
@@ -127,12 +128,13 @@ public class PublicationUseCases {
|
||||
}
|
||||
|
||||
if (!isNull(request.categoryId())) {
|
||||
Category newCategory = categoryUseCases.findById(request.categoryId())
|
||||
.orElseThrow(() -> new PublicationEditionException(
|
||||
if (!categoryUseCases.existsById(request.categoryId())) {
|
||||
throw new PublicationEditionException(
|
||||
new CategoryNotFoundException(request.categoryId())
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
publicationBuilder.withCategory(newCategory);
|
||||
publicationBuilder.withCategoryId(request.categoryId());
|
||||
}
|
||||
|
||||
Publication updatedPublication = publicationBuilder.build();
|
||||
|
||||
Reference in New Issue
Block a user