Add implementation of publication creation use case.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package org.codiki.domain.publication.model;
|
||||
package org.codiki.domain.category.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.codiki.domain.category.port;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.category.model.Category;
|
||||
|
||||
public interface CategoryPort {
|
||||
Optional<Category> findById(final UUID uuid);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.codiki.domain.exception;
|
||||
|
||||
public class AuthenticationRequiredException extends FunctionnalException {
|
||||
public AuthenticationRequiredException() {
|
||||
super("Authentication is required to perform this action.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.codiki.domain.publication.exception;
|
||||
|
||||
import org.codiki.domain.exception.FunctionnalException;
|
||||
|
||||
public class PublicationCreationException extends FunctionnalException {
|
||||
public PublicationCreationException(String reason) {
|
||||
super(String.format("Impossible to create a publication because : %s", reason));
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,12 @@ package org.codiki.domain.publication.model;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.user.model.User;
|
||||
|
||||
public record Author(
|
||||
UUID id,
|
||||
String name,
|
||||
String image
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.codiki.domain.publication.model;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.category.model.Category;
|
||||
|
||||
public record Publication(
|
||||
UUID id,
|
||||
String key,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.codiki.domain.publication.model;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record PublicationCreationRequest(
|
||||
String title,
|
||||
String text,
|
||||
String description,
|
||||
String image,
|
||||
UUID categoryId
|
||||
) {}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.codiki.domain.publication.model.builder;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.publication.model.Author;
|
||||
import org.codiki.domain.user.model.User;
|
||||
|
||||
public class AuthorBuilder {
|
||||
private UUID id;
|
||||
private String name;
|
||||
private String image;
|
||||
|
||||
private AuthorBuilder() {}
|
||||
|
||||
public static AuthorBuilder anAuthor() {
|
||||
return new AuthorBuilder();
|
||||
}
|
||||
|
||||
public AuthorBuilder basedOn(User user) {
|
||||
return new AuthorBuilder()
|
||||
.withId(user.id())
|
||||
// .withName(user.name())
|
||||
// .withImage(user.image())
|
||||
;
|
||||
}
|
||||
|
||||
public AuthorBuilder withId(UUID id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
public AuthorBuilder withName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
public AuthorBuilder withImage(String image) {
|
||||
this.image = image;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Author build() {
|
||||
return new Author(id, name, image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.codiki.domain.publication.model.builder;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.publication.model.Author;
|
||||
import org.codiki.domain.category.model.Category;
|
||||
import org.codiki.domain.publication.model.Publication;
|
||||
|
||||
public class PublicationBuilder {
|
||||
private UUID id;
|
||||
private String key;
|
||||
private String title;
|
||||
private String text;
|
||||
private String description;
|
||||
private String image;
|
||||
private ZonedDateTime creationDate;
|
||||
private Author author;
|
||||
private Category category;
|
||||
|
||||
private PublicationBuilder() {}
|
||||
|
||||
public static PublicationBuilder aPublication() {
|
||||
return new PublicationBuilder();
|
||||
}
|
||||
|
||||
public PublicationBuilder withId(UUID id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicationBuilder withKey(String key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicationBuilder withTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicationBuilder withText(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicationBuilder withDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicationBuilder withImage(String image) {
|
||||
this.image = image;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicationBuilder withCreationDate(ZonedDateTime creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicationBuilder withAuthor(Author author) {
|
||||
this.author = author;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicationBuilder withCategory(Category category) {
|
||||
this.category = category;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Publication build() {
|
||||
return new Publication(
|
||||
id,
|
||||
key,
|
||||
title,
|
||||
text,
|
||||
description,
|
||||
image,
|
||||
creationDate,
|
||||
author,
|
||||
category
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.codiki.domain.publication.port;
|
||||
|
||||
import org.codiki.domain.publication.model.Publication;
|
||||
|
||||
public interface PublicationPort {
|
||||
void save(Publication publication);
|
||||
}
|
||||
Reference in New Issue
Block a user