Fix implementation of infrastructure layer of publication creation.
This commit is contained in:
@@ -8,6 +8,7 @@ import java.util.UUID;
|
|||||||
import org.codiki.application.security.AuthenticationFacade;
|
import org.codiki.application.security.AuthenticationFacade;
|
||||||
import org.codiki.application.security.JwtService;
|
import org.codiki.application.security.JwtService;
|
||||||
import org.codiki.application.security.annotation.AllowedToAdmins;
|
import org.codiki.application.security.annotation.AllowedToAdmins;
|
||||||
|
import org.codiki.application.security.model.CustomUserDetails;
|
||||||
import org.codiki.domain.exception.LoginFailureException;
|
import org.codiki.domain.exception.LoginFailureException;
|
||||||
import org.codiki.domain.exception.RefreshTokenDoesNotExistException;
|
import org.codiki.domain.exception.RefreshTokenDoesNotExistException;
|
||||||
import org.codiki.domain.exception.UserDoesNotExistException;
|
import org.codiki.domain.exception.UserDoesNotExistException;
|
||||||
@@ -79,8 +80,9 @@ public class UserUseCases {
|
|||||||
public Optional<User> getAuthenticatedUser() {
|
public Optional<User> getAuthenticatedUser() {
|
||||||
return Optional.of(authenticationFacade.getAuthentication())
|
return Optional.of(authenticationFacade.getAuthentication())
|
||||||
.map(Authentication::getPrincipal)
|
.map(Authentication::getPrincipal)
|
||||||
.filter(String.class::isInstance)
|
.filter(CustomUserDetails.class::isInstance)
|
||||||
.map(String.class::cast)
|
.map(CustomUserDetails.class::cast)
|
||||||
|
.map(CustomUserDetails::getUsername)
|
||||||
.map(UUID::fromString)
|
.map(UUID::fromString)
|
||||||
.flatMap(userPort::findById);
|
.flatMap(userPort::findById);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.codiki.infrastructure.category;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.codiki.domain.category.model.Category;
|
||||||
|
import org.codiki.domain.category.port.CategoryPort;
|
||||||
|
import org.codiki.infrastructure.category.model.CategoryEntity;
|
||||||
|
import org.codiki.infrastructure.category.repository.CategoryRepository;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CategoryJpaAdapter implements CategoryPort {
|
||||||
|
private final CategoryRepository categoryRepository;
|
||||||
|
|
||||||
|
public CategoryJpaAdapter(CategoryRepository categoryRepository) {
|
||||||
|
this.categoryRepository = categoryRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Category> findById(UUID categoryId) {
|
||||||
|
return categoryRepository.findById(categoryId)
|
||||||
|
.map(CategoryEntity::toDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.codiki.infrastructure.category.model;
|
package org.codiki.infrastructure.category.model;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.codiki.domain.category.model.Category;
|
import org.codiki.domain.category.model.Category;
|
||||||
@@ -8,20 +10,36 @@ import jakarta.persistence.Column;
|
|||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "category")
|
@Table(name = "category")
|
||||||
public record CategoryEntity(
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CategoryEntity {
|
||||||
@Id
|
@Id
|
||||||
UUID id,
|
private UUID id;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
String name
|
private String name;
|
||||||
// List<Category> subCategories
|
// List<Category> subCategories
|
||||||
) {
|
|
||||||
public CategoryEntity(Category category) {
|
public CategoryEntity(Category category) {
|
||||||
this(
|
this(
|
||||||
category.id(),
|
category.id(),
|
||||||
category.name()
|
category.name()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Category toDomain() {
|
||||||
|
return new Category(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
emptyList()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.codiki.infrastructure.category.repository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.codiki.infrastructure.category.model.CategoryEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface CategoryRepository extends JpaRepository<CategoryEntity, UUID> {
|
||||||
|
}
|
||||||
@@ -8,16 +8,24 @@ import jakarta.persistence.Column;
|
|||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "`user`")
|
@Table(name = "`user`")
|
||||||
public record AuthorEntity(
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AuthorEntity {
|
||||||
@Id
|
@Id
|
||||||
UUID id,
|
private UUID id;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
String name,
|
private String name;
|
||||||
String image
|
private String image;
|
||||||
) {
|
|
||||||
public AuthorEntity(Author author) {
|
public AuthorEntity(Author author) {
|
||||||
this(
|
this(
|
||||||
author.id(),
|
author.id(),
|
||||||
|
|||||||
@@ -13,31 +13,39 @@ import jakarta.persistence.Id;
|
|||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "publication")
|
@Table(name = "publication")
|
||||||
public record PublicationEntity(
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PublicationEntity {
|
||||||
@Id
|
@Id
|
||||||
UUID id,
|
private UUID id;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
String key,
|
private String key;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
String title,
|
private String title;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
String text,
|
private String text;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
String description,
|
private String description;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
String image,
|
private String image;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
ZonedDateTime creationDate,
|
private ZonedDateTime creationDate;
|
||||||
@ManyToOne(fetch = LAZY)
|
@ManyToOne(fetch = LAZY)
|
||||||
@JoinColumn(name = "author_id")
|
@JoinColumn(name = "author_id")
|
||||||
AuthorEntity author,
|
private AuthorEntity author;
|
||||||
@ManyToOne(fetch = LAZY)
|
@ManyToOne(fetch = LAZY)
|
||||||
@JoinColumn(name = "category_id")
|
@JoinColumn(name = "category_id")
|
||||||
CategoryEntity categoryId
|
private CategoryEntity categoryId;
|
||||||
) {
|
|
||||||
public PublicationEntity(Publication publication) {
|
public PublicationEntity(Publication publication) {
|
||||||
this(
|
this(
|
||||||
publication.id(),
|
publication.id(),
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ CREATE TABLE IF NOT EXISTS publication (
|
|||||||
text VARCHAR NOT NULL,
|
text VARCHAR NOT NULL,
|
||||||
description VARCHAR NOT NULL,
|
description VARCHAR NOT NULL,
|
||||||
image VARCHAR NOT NULL,
|
image VARCHAR NOT NULL,
|
||||||
creationDate TIMESTAMP NOT NULL,
|
creation_date TIMESTAMP NOT NULL,
|
||||||
author_id UUID NOT NULL,
|
author_id UUID NOT NULL,
|
||||||
category_id UUID NOT NULL,
|
category_id UUID NOT NULL,
|
||||||
CONSTRAINT publication_pk PRIMARY KEY (id),
|
CONSTRAINT publication_pk PRIMARY KEY (id),
|
||||||
|
|||||||
@@ -4,8 +4,15 @@ meta {
|
|||||||
seq: 1
|
seq: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
post {
|
||||||
url:
|
url: {{url}}/api/users/login
|
||||||
body: none
|
body: json
|
||||||
auth: none
|
auth: none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"id": "5ad462b8-8f9e-4a26-bb86-c74fef5d11b6",
|
||||||
|
"password": "password"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user