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

[Feat]: Category, Article 도메인 및 JPA 모델 설계 및 초기 UseCase, API 구현 #5

Merged
merged 58 commits into from
Jan 8, 2024

Conversation

jihwan2da
Copy link
Member

@jihwan2da jihwan2da commented Jan 5, 2024

resolved #4

작업한 일 🥹

  • Category 도메인, DB, ReadModel 설계 (상세한 설계 내용은 notion에 작성)
  • Article, ArticleLike 도메인, DB, ReadModel 설계 (상세한 설계 내용은 notion에 작성)
  • kotlin Jpa 환경 구축
  • 테스트 환경 구축
    • domain 모듈에 java-test-fixtures 플러그인 추가(fixture을 모든 모듈에서 공통으로 편하게 사용하기 위함)
    • persist 테스트 환경 구축
  • Command UseCase 및 Controller 작성 (article 생성, article 삭제, article 좋아요)
  • Query UseCase 및 Controller 작성(article preview 조회, article 상세 조회)
  • Swagger 환경 구축

논의 정리

카테고리를 Enum이 아닌 Table로 설계한 이유
카테고리는 현재 기획 상 정해져 있는 형식(Admin 페이지에서 직접 관리자가 등록안하는)이기 때문에 Enum으로 관리할 수 있지만, 이후 카테고리에 대한 변경 사항이 많이 발생할 것이라고 발생하고, Admin페이지에서 직접 카테고리를 관리자가 관리하게 확장하게 된다면 Table로 관리되어져야되기 때문에 유지보수 및 확장성을 생각하여 Table로 설계하였습니다.

DDL

create table category
(
    id   bigint auto_increment,
    name varchar(255) not null,
    primary key (id)
);
create table article
(
    id            bigint auto_increment,
    user_id       bigint      not null,
    category_id   bigint      not null,
    title         varchar(70) not null,
    content       longtext    not null,
    images        longtext,
    comment_count int         not null,
    like_count    int         not null,
    deleted       bit(1)      not null,
    created_at    datetime(6) not null,
    updated_at    datetime(6) not null,
    primary key (id),
    foreign key (category_id) references category (id)
);
create table article_like
(
    id         bigint auto_increment,
    article_id bigint not null,
    user_id    bigint not null,
    created_at    datetime(6) not null,
    updated_at    datetime(6) not null,
    primary key (id),
    foreign key (article_id) references article (id)
);

@jihwan2da jihwan2da self-assigned this Jan 5, 2024
Copy link
Member Author

@jihwan2da jihwan2da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 Read API 설계는 하지 않았지만, ReadModel에는 기존서버의 user 정보가 필요합니다.
Read작업을 할 때마다 기존서버와 HTTP 통신을 통해서 가져올 수는 있지만 시스템간 결합 문제가 발생해 MSA의 장점이 사라진다고 생각합니다. 따라서 아래의 방법 중 하나로 해결해야 할 것 같습니다!!

  1. HTTP 통신으로 들고 오지만 들고온 데이터는 커뮤니티 서버에서 캐싱(만약 update되면 데이터 정합성 맞추기 힘들듯?)
  2. 기존 서버에 Batch를 돌려 user 정보를 메시지 큐에 발행하고 해당 서버에서 컨슘해 자체적으로 저장

Comment on lines +5 to +18
data class ArticleImage(
val images: List<String>?
) {

init {
verifySize(images)
}

private fun verifySize(images: List<String>?) {
if (!images.isNullOrEmpty() && images.size > 3) {
throw ArticleImageSizeOverException()
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

회의 내용!! 기록
도메인의 대한 유효성 검사는 init + require()을 활용하기로 하였습니다.
require 함수를 사용하도록 수정하겠습니당

Comment on lines +5 to +19
data class ArticleLike(
val userId: UserId,
val article: Article,
val id: Long? = null,
) {
init {
verifyArticle(article)
}

private fun verifyArticle(article: Article) {
if (article.id == null) {
throw RuntimeException("ArticleLike 생성 오류 : 영속화 되지 않은 Article을 입력으로 받았습니다.")
}
}
}
Copy link
Member Author

@jihwan2da jihwan2da Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArticleLike 도메인을 생성할 때는 무조건 영속화된(Id를 가진) Aritcle을 받아야 합니다.
테스트 코드 작성중 발견한 도메인 유효성인데 해당 유효성 검증이 올바른지는 모르겠네요 ㅎ.ㅎ

Comment on lines +9 to +11
plugins {
id("java-test-fixtures")
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domain에서 정의한 test Fixture을 다른 모듈에서도 활용할 수 있도록하기 위해 java-test-fixtures을 활용하였습니다.
참고 블로그

@jihwan2da jihwan2da merged commit 6abd505 into dev Jan 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"카테고리, 게시글" 도메인, 데이터 모델을 설계하고, 관련 API를 구현한다.
1 participant