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.JwtService;
|
||||
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.RefreshTokenDoesNotExistException;
|
||||
import org.codiki.domain.exception.UserDoesNotExistException;
|
||||
@@ -79,8 +80,9 @@ public class UserUseCases {
|
||||
public Optional<User> getAuthenticatedUser() {
|
||||
return Optional.of(authenticationFacade.getAuthentication())
|
||||
.map(Authentication::getPrincipal)
|
||||
.filter(String.class::isInstance)
|
||||
.map(String.class::cast)
|
||||
.filter(CustomUserDetails.class::isInstance)
|
||||
.map(CustomUserDetails.class::cast)
|
||||
.map(CustomUserDetails::getUsername)
|
||||
.map(UUID::fromString)
|
||||
.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;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.category.model.Category;
|
||||
@@ -8,20 +10,36 @@ import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "category")
|
||||
public record CategoryEntity(
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CategoryEntity {
|
||||
@Id
|
||||
UUID id,
|
||||
private UUID id;
|
||||
@Column(nullable = false)
|
||||
String name
|
||||
private String name;
|
||||
// List<Category> subCategories
|
||||
) {
|
||||
|
||||
public CategoryEntity(Category category) {
|
||||
this(
|
||||
category.id(),
|
||||
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.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "`user`")
|
||||
public record AuthorEntity(
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AuthorEntity {
|
||||
@Id
|
||||
UUID id,
|
||||
private UUID id;
|
||||
@Column(nullable = false)
|
||||
String name,
|
||||
String image
|
||||
) {
|
||||
private String name;
|
||||
private String image;
|
||||
|
||||
public AuthorEntity(Author author) {
|
||||
this(
|
||||
author.id(),
|
||||
|
||||
@@ -13,31 +13,39 @@ import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "publication")
|
||||
public record PublicationEntity(
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PublicationEntity {
|
||||
@Id
|
||||
UUID id,
|
||||
private UUID id;
|
||||
@Column(nullable = false)
|
||||
String key,
|
||||
private String key;
|
||||
@Column(nullable = false)
|
||||
String title,
|
||||
private String title;
|
||||
@Column(nullable = false)
|
||||
String text,
|
||||
private String text;
|
||||
@Column(nullable = false)
|
||||
String description,
|
||||
private String description;
|
||||
@Column(nullable = false)
|
||||
String image,
|
||||
private String image;
|
||||
@Column(nullable = false)
|
||||
ZonedDateTime creationDate,
|
||||
private ZonedDateTime creationDate;
|
||||
@ManyToOne(fetch = LAZY)
|
||||
@JoinColumn(name = "author_id")
|
||||
AuthorEntity author,
|
||||
private AuthorEntity author;
|
||||
@ManyToOne(fetch = LAZY)
|
||||
@JoinColumn(name = "category_id")
|
||||
CategoryEntity categoryId
|
||||
) {
|
||||
private CategoryEntity categoryId;
|
||||
|
||||
public PublicationEntity(Publication publication) {
|
||||
this(
|
||||
publication.id(),
|
||||
|
||||
@@ -35,7 +35,7 @@ CREATE TABLE IF NOT EXISTS publication (
|
||||
text VARCHAR NOT NULL,
|
||||
description VARCHAR NOT NULL,
|
||||
image VARCHAR NOT NULL,
|
||||
creationDate TIMESTAMP NOT NULL,
|
||||
creation_date TIMESTAMP NOT NULL,
|
||||
author_id UUID NOT NULL,
|
||||
category_id UUID NOT NULL,
|
||||
CONSTRAINT publication_pk PRIMARY KEY (id),
|
||||
|
||||
@@ -4,8 +4,15 @@ meta {
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url:
|
||||
body: none
|
||||
post {
|
||||
url: {{url}}/api/users/login
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"id": "5ad462b8-8f9e-4a26-bb86-c74fef5d11b6",
|
||||
"password": "password"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user