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

#55 feat: GET /api/v1/workbooks/{workbookId} 구현 #101

Merged
merged 16 commits into from
Jun 24, 2024

Conversation

belljun3395
Copy link
Collaborator

🎫 연관 이슈

resolved: #55

💁‍♂️ PR 내용

  • GET /api/v1/workbooks/{workbookId} 구현

🙏 작업

  • WorkbookArticleService#browseWorkbookArticles : 학습지의 아티클 조회
  • WorkbookMemberService#browseWriterRecords : 아티클 작가 조회
  • 254c86e 에서 leftJoin을 3번이나 하여 쿼리를 작성하였습니다.. 해당 쿼리를 집중적으로 같이 분석해보면 좋을 것 같아요

🙈 PR 참고 사항

📸 스크린샷

🤖 테스트 체크리스트

  • 체크 미완료
  • 체크 완료

@belljun3395 belljun3395 requested a review from hun-ca as a code owner June 23, 2024 15:31
@github-actions github-actions bot added the feature 새로운 기능을 만들 때 사용됩니다 label Jun 23, 2024
Copy link
Member

@hun-ca hun-ca left a comment

Choose a reason for hiding this comment

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

고생하셨습니다~!

Comment on lines 71 to 88
return dslContext.select(
ArticleMst.ARTICLE_MST.ID.`as`(SelectWorkBookArticleRecord::articleId.name),
ArticleMst.ARTICLE_MST.MEMBER_ID.`as`(SelectWorkBookArticleRecord::writerId.name),
ArticleMst.ARTICLE_MST.MAIN_IMAGE_URL.`as`(SelectWorkBookArticleRecord::mainImageURL.name),
ArticleMst.ARTICLE_MST.TITLE.`as`(SelectWorkBookArticleRecord::title.name),
ArticleMst.ARTICLE_MST.CATEGORY_CD.`as`(SelectWorkBookArticleRecord::category.name),
ArticleIfo.ARTICLE_IFO.CONTENT.`as`(SelectWorkBookArticleRecord::content.name),
ArticleMst.ARTICLE_MST.CREATED_AT.`as`(SelectWorkBookArticleRecord::createdAt.name),
MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.DAY_COL.`as`(SelectWorkBookArticleRecord::day.name)
)
.from(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE)
.leftJoin(ArticleMst.ARTICLE_MST)
.on(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.ARTICLE_ID.eq(ArticleMst.ARTICLE_MST.ID))
.leftJoin(ArticleIfo.ARTICLE_IFO)
.on(ArticleMst.ARTICLE_MST.ID.eq(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID))
.where(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.WORKBOOK_ID.eq(workbookId))
.fetchInto(SelectWorkBookMappedArticleRecord::class.java)
}
Copy link
Member

Choose a reason for hiding this comment

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

SQL로 변환해서 보면,,,

SELECT 
    article_mst.id AS articleId,
    article_mst.member_id AS writerId,
    article_mst.main_image_url AS mainImageURL,
    article_mst.title AS title,
    article_mst.category_cd AS category,
    article_ifo.content AS content,
    article_mst.created_at AS createdAt,
    mapping_workbook_article.day_col AS day
FROM 
    mapping_workbook_article
LEFT JOIN 
    article_mst 
    ON mapping_workbook_article.article_id = article_mst.id
LEFT JOIN 
    article_ifo 
    ON article_mst.id = article_ifo.article_mst_id
WHERE 
    mapping_workbook_article.workbook_id = :workbookId;

아티클mst에 row가 있다는건 아티클info에서도 row가 있다는건데 Left join을 꼭 해야할까요? 그냥 조인으로 가도 결과 똑같을듯

Copy link
Member

Choose a reason for hiding this comment

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

아 그리고 deleted_at 체크 빠졌네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

join으로 해도 결과가 동일하네요! 감사함다!!

)
.from(Member.MEMBER)
.where(Member.MEMBER.ID.`in`(query.writerIds))
.and(Member.MEMBER.TYPE_CD.eq(1)) // todo fix after considering the type_cd
Copy link
Member

Choose a reason for hiding this comment

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

MemberType 제가 만들어둔걸로 ㄱ ㄱ (직접숫자 넣기X)

Workbook.WORKBOOK.CREATED_AT.`as`(SelectWorkBookRecord::createdAt.name)
)
.from(Workbook.WORKBOOK)
.where(Workbook.WORKBOOK.ID.eq(query.id))
Copy link
Member

Choose a reason for hiding this comment

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

delete_at 필드 체크 필요할듯

Comment on lines 8 to 21
val mainImageUrl: String,
val title: String,
val description: String,
val category: String,
val createdAt: LocalDateTime,
val writers: List<WriterDetail>,
val articles: List<ArticleDetail>
)

data class WriterDetail(
val id: Long,
val name: String,
val url: URL
)
Copy link
Member

Choose a reason for hiding this comment

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

WriterDetail의 url 타입은 URL이고 ReadWorkbookUseCaseOut의 mainImageUrl 타입은 String인데 이렇게 된 이유가 뭔가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

제가 url을 dao에서 부터 String으로 가져오고 있더라고요..!
다른 url: String까지 한번에 고치겠습니다~! 감사합니다!

@belljun3395 belljun3395 changed the title feat: GET /api/v1/workbooks/{workbookId} 구현 #55 feat: GET /api/v1/workbooks/{workbookId} 구현 Jun 24, 2024
@belljun3395 belljun3395 merged commit 16fcaac into main Jun 24, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 새로운 기능을 만들 때 사용됩니다
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GET /api/v1/workbooks/{workbookId} 구현
2 participants