Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add(.footprint) : 발자취 도메인 엔티티 분리 및 매핑 #178

Merged
merged 27 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fb62831
Add: 발자취 JPA 엔티티 추가
JuwoongKim Feb 14, 2024
053958b
Add: 발자취 도메인 JPA 엔티티 매퍼 추가
JuwoongKim Feb 14, 2024
04e6e00
Add: 발자취 생성을 위한 Port, Adaptor 구현
JuwoongKim Feb 14, 2024
ea89d41
Test: 발자취 생성을 위한 Port, Adaptor 구현 테스트
JuwoongKim Feb 14, 2024
e9b0727
Add: 발자취 도메인 객체 식별자 멤벼 변수 추가
JuwoongKim Feb 14, 2024
31155bf
Add: 발자취 매퍼 JPA -> 도메인 매핑 기능 추가
JuwoongKim Feb 14, 2024
06c4737
Add: 발자취 도메인 NOT_FOUND 에러 코드 추가
JuwoongKim Feb 14, 2024
f8d79c8
Add: 발자취 단건 조회를 위한 Port, Adaptor 구현
JuwoongKim Feb 14, 2024
5cf27d0
Test: 발자취 단건 조회를 위한 Port, Adaptor 구현 테스트
JuwoongKim Feb 14, 2024
caae242
Docs: flyway 회고 도메인 DDL 작성
JuwoongKim Feb 14, 2024
af8fb52
Update: 데이터 동기화 문제 방지를 위한 발자취 JPA 엔티티 수정
JuwoongKim Feb 16, 2024
86601d0
Update: 발자취 엔티티 연관 관계 제외, 벨류 객체 엔티티 생성, 불필요한 파일 제거
JuwoongKim Feb 16, 2024
9b95c9a
Update: 유형별 분리된 발자취 매퍼를 하나로 통일
JuwoongKim Feb 16, 2024
e6b0649
Update: 발자취 생성 어뎁터 하나로 통일 및 테스트 코드 수정
JuwoongKim Feb 16, 2024
46bf824
Update: 발자취 조회 어뎁터 하나로 통일 및 테스트 코드 수정
JuwoongKim Feb 16, 2024
213b7d1
Delete: 발자취 도메인에서 아좌좌 제거
JuwoongKim Feb 17, 2024
881a536
Update: 발자취 팩토리 클래스 상속 차단 및 네이밍 변경
JuwoongKim Feb 17, 2024
5286551
Delete: 발자취 도메인 태그 도메인 분리에 따른 불필요한 파일 제거 및 수정
JuwoongKim Feb 17, 2024
5863b20
Update: 발자취 도메인 DDL sql 스크립트 수정
JuwoongKim Feb 17, 2024
51c64aa
Delete: 발자취 도메인 불필요한 주석 제거
JuwoongKim Feb 17, 2024
a1d6d61
Test: 발자취 GetFootprintAdaptor 임시 데이터 객체 생성
JuwoongKim Feb 17, 2024
c884136
Test: 발자취 GetFootprintAdaptor 임시 데이터 객체 생성
JuwoongKim Feb 17, 2024
01f8482
Refactor: 발자취 도메인 객체 생성 심플 팩토리 패턴 적용
JuwoongKim Feb 19, 2024
e1d1d78
Refactor: 발자취 도메인 객체 생성 시 객체 완전성을 보장 하도록 수정
JuwoongKim Feb 20, 2024
89b9381
Chore: 발자취 DDL 불필요한 조건 삭제, ajaja 발자취 관련 메서드 네이밍 수정
JuwoongKim Feb 20, 2024
a3d8bfb
Update: 발자취 도메인 벨류 매핑을 위한 dto 생성, 조회 방식 변경
JuwoongKim Feb 20, 2024
75482a0
Update: 발자취 생성 및 조회 adaptor 변경 사항 반영
JuwoongKim Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/me/ajaja/global/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum ErrorCode {
NEVER_LOGIN(NOT_FOUND, "로그인한 이력을 찾을 수 없습니다. 다시 로그인 해주세요."),
NOT_FOUND_PLAN(NOT_FOUND, "계획 정보가 존재하지 않습니다."),
NOT_FOUND_FEEDBACK(NOT_FOUND, "피드백 정보가 존재하지 않습니다."),
NOT_FOUND_FOOTPRINT(NOT_FOUND, "작성한 발자취가 존재하지 않습니다."),

// 409
ALREADY_FEEDBACK(CONFLICT, "이미 평가된 피드백 정보가 있습니다."),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/ajaja/module/ajaja/domain/Ajaja.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Ajaja {

public enum Type {
PLAN,
RETROSPECT, // 회고
FOOTPRINT, // 회고
DEFAULT
}

Expand All @@ -42,7 +42,7 @@ public static Ajaja plan(Long targetId, Long userId) {
}

public static Ajaja retrospect(Long targetId, Long userId) {
Hejow marked this conversation as resolved.
Show resolved Hide resolved
return new Ajaja(targetId, userId, Type.RETROSPECT);
return new Ajaja(targetId, userId, Type.FOOTPRINT);
}

public static Ajaja defaultValue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.ajaja.module.footprint.adapter.out.persistence;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;
import me.ajaja.module.footprint.adapter.out.persistence.model.FootprintEntity;
import me.ajaja.module.footprint.application.port.out.CreateFootprintPort;
import me.ajaja.module.footprint.domain.Footprint;
import me.ajaja.module.footprint.mapper.FootprintMapper;

@Repository
@Transactional
@RequiredArgsConstructor
public class CreateFootprintAdaptor implements CreateFootprintPort {
private final FootprintJpaRepository footprintJpaRepository;
private final FootprintMapper footprintMapper;

@Override
public Long create(Footprint footprint) {
FootprintEntity footprintEntity = footprintMapper.toEntity(footprint);
return footprintJpaRepository.save(footprintEntity).getId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.ajaja.module.footprint.adapter.out.persistence;

import org.springframework.data.jpa.repository.JpaRepository;

import me.ajaja.module.footprint.adapter.out.persistence.model.FootprintEntity;

interface FootprintJpaRepository extends JpaRepository<FootprintEntity, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package me.ajaja.module.footprint.adapter.out.persistence;

import static me.ajaja.global.exception.ErrorCode.*;
import static me.ajaja.module.plan.adapter.out.persistence.model.QPlanEntity.*;
import static me.ajaja.module.user.adapter.out.persistence.model.QUserEntity.*;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;
import me.ajaja.global.exception.AjajaException;
import me.ajaja.module.footprint.adapter.out.persistence.model.FootprintEntity;
import me.ajaja.module.footprint.adapter.out.persistence.model.TargetEntity;
import me.ajaja.module.footprint.adapter.out.persistence.model.WriterEntity;
import me.ajaja.module.footprint.application.port.out.GetFootprintPort;
import me.ajaja.module.footprint.domain.Footprint;
import me.ajaja.module.footprint.mapper.FootprintMapper;

@Repository
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class GetFootprintAdaptor implements GetFootprintPort {
private final FootprintJpaRepository footprintJpaRepository;
private final JPAQueryFactory queryFactory;
private final FootprintMapper footprintMapper;

@Override
public Footprint getFootprint(Long id) {
FootprintEntity footprintEntity = footprintJpaRepository.findById(id)
.orElseThrow(() -> AjajaException.withId(id, NOT_FOUND_FOOTPRINT));

TargetEntity targetEntity = queryFactory.select(
Projections.constructor(TargetEntity.class, planEntity.id, planEntity.title))
.from(planEntity)
.where(planEntity.id.eq(footprintEntity.getTargetId()))
.fetchOne();

WriterEntity writerEntity = queryFactory.select(
Projections.constructor(WriterEntity.class, userEntity.id, userEntity.nickname))
.from(userEntity)
.where(userEntity.id.eq(footprintEntity.getWriterId()))
.fetchOne();

Footprint footprint = footprintMapper.toDomain(footprintEntity, targetEntity, writerEntity);

return footprint;
}
Hejow marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package me.ajaja.module.footprint.adapter.out.persistence.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import me.ajaja.global.common.BaseEntity;

@Getter
@Entity
@Table(name = "footprints")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class FootprintEntity extends BaseEntity<FootprintEntity> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "footprint_id")
private Long id;

@Column(nullable = false)
private Long targetId;

@Column(nullable = false)
private Long writerId;

@Column(name = "footprint_type", nullable = false, length = 10)
private String type;

@Column(nullable = false, length = 50)
private String title;

@Column(nullable = false)
private boolean visible;

@Column(nullable = false)
private boolean deleted;

@Column(columnDefinition = "TEXT")
private String content;

@Column(columnDefinition = "TEXT")
private String keepContent;

@Column(columnDefinition = "TEXT")
private String problemContent;

@Column(columnDefinition = "TEXT")
private String tryContent;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.ajaja.module.footprint.adapter.out.persistence.model;

public record TargetEntity(
Hejow marked this conversation as resolved.
Show resolved Hide resolved
Long id,
String title
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.ajaja.module.footprint.adapter.out.persistence.model;

public record WriterEntity(
Long id,
String nickname
) {
}
Hejow marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.ajaja.module.footprint.application.port.out;

import me.ajaja.module.footprint.domain.Footprint;

public interface CreateFootprintPort {
Long create(Footprint footprint);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.ajaja.module.footprint.application.port.out;

import me.ajaja.module.footprint.domain.Footprint;

public interface GetFootprintPort {
Footprint getFootprint(Long id);

}
19 changes: 0 additions & 19 deletions src/main/java/me/ajaja/module/footprint/domain/Ajaja.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package me.ajaja.module.footprint.domain;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import lombok.AllArgsConstructor;
import lombok.Getter;
import me.ajaja.global.common.SelfValidating;

@Getter
@AllArgsConstructor
public abstract class Footprint extends SelfValidating<Footprint> {
private final Long id;
private final Target target;
private final Writer writer;

private Title title;
private boolean visible;
private boolean deleted;

private Set<Tag> tags = new HashSet<>();
private List<Ajaja> ajajas = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
package me.ajaja.module.footprint.domain;

import java.util.ArrayList;

import me.ajaja.module.footprint.dto.FootprintParam;

public class FootprintFactory {
public static FreeFootprint createFreeFootprint(FootprintParam.Create create, String content) {
public final class FootprintFactory {
public static FreeFootprint freeTemplate(FootprintParam.Create create, String content) {
return new FreeFootprint(
null,
Hejow marked this conversation as resolved.
Show resolved Hide resolved
create.getTarget(),
create.getWriter(),
create.getTitle(),
create.isVisible(),
false,
create.getTags(),
new ArrayList<>(),
content
);
}

public static KptFootprint createkptFootprint(
public static KptFootprint kptTemplate(
FootprintParam.Create create, String keepContent, String problemContent, String tryContent
) {
return new KptFootprint(
null,
create.getTarget(),
create.getWriter(),
create.getTitle(),
create.isVisible(),
false,
create.getTags(),
new ArrayList<>(),
keepContent,
problemContent,
tryContent
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package me.ajaja.module.footprint.domain;

import java.util.List;
import java.util.Set;

import jakarta.validation.constraints.NotBlank;
import lombok.Getter;

Expand All @@ -11,9 +8,9 @@ public class FreeFootprint extends Footprint {
@NotBlank
private String content;

FreeFootprint(Target target, Writer writer, Title title, boolean visible, boolean deleted,
Set<Tag> tags, List<Ajaja> ajajas, String content) {
super(target, writer, title, visible, deleted, tags, ajajas);
public FreeFootprint(Long id, Target target, Writer writer, Title title, boolean visible, boolean deleted,
String content) {
super(id, target, writer, title, visible, deleted);
this.content = content;
this.validateSelf();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package me.ajaja.module.footprint.domain;

import java.util.List;
import java.util.Set;

import jakarta.validation.constraints.NotBlank;
import lombok.Getter;

Expand All @@ -15,9 +12,9 @@ public class KptFootprint extends Footprint {
@NotBlank
private String tryContent;

KptFootprint(Target target, Writer writer, Title title, boolean visible, boolean deleted, Set<Tag> tags,
List<Ajaja> ajajas, String keepContent, String problemContent, String tryContent) {
super(target, writer, title, visible, deleted, tags, ajajas);
public KptFootprint(Long id, Target target, Writer writer, Title title, boolean visible, boolean deleted,
String keepContent, String problemContent, String tryContent) {
super(id, target, writer, title, visible, deleted);
this.keepContent = keepContent;
this.problemContent = problemContent;
this.tryContent = tryContent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package me.ajaja.module.footprint.dto;

import java.beans.ConstructorProperties;
import java.util.Set;

import lombok.Data;
import me.ajaja.module.footprint.domain.Tag;
import me.ajaja.module.footprint.domain.Target;
import me.ajaja.module.footprint.domain.Title;
import me.ajaja.module.footprint.domain.Writer;
Expand All @@ -16,15 +14,13 @@ public static class Create {
private final Writer writer;
private final Title title;
private final boolean visible;
private final Set<Tag> tags;

@ConstructorProperties({"target", "writer", "title", "visible", "tags"})
public Create(Target target, Writer writer, Title title, boolean visible, Set<Tag> tags) {
@ConstructorProperties({"target", "writer", "title", "visible"})
Hejow marked this conversation as resolved.
Show resolved Hide resolved
public Create(Target target, Writer writer, Title title, boolean visible) {
this.target = target;
this.writer = writer;
this.title = title;
this.visible = visible;
this.tags = tags;
}
}
}
Loading
Loading