-
Notifications
You must be signed in to change notification settings - Fork 1
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/#215] article_view_his 테이블 추가 및 조회수 응답 추가 #216
Changes from 4 commits
3c02659
977de9a
1334ccf
390b898
2304654
29ca0fb
bfaebe6
362999e
9c17140
abde0c3
89a188f
a8342ba
21c0ad4
4ce6ac9
51671e4
a76ed19
dc76e36
7bac2fc
ba64abd
3348881
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.few.api.repo.dao.article | ||
|
||
import com.few.api.repo.dao.article.command.ArticleViewHisCommand | ||
import com.few.api.repo.dao.article.query.ArticleViewHisCountQuery | ||
import jooq.jooq_dsl.tables.ArticleViewHis | ||
import org.jooq.DSLContext | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 종준님은 DAO에 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
class ArticleViewHisDao( | ||
private val dslContext: DSLContext, | ||
) { | ||
|
||
fun insertArticleViewHis(command: ArticleViewHisCommand) { | ||
dslContext.insertInto( | ||
ArticleViewHis.ARTICLE_VIEW_HIS, | ||
ArticleViewHis.ARTICLE_VIEW_HIS.ARTICLE_MST_ID, | ||
ArticleViewHis.ARTICLE_VIEW_HIS.MEMBER_ID | ||
).values( | ||
command.articleId, | ||
command.memberId | ||
).execute() | ||
} | ||
Comment on lines
+14
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
fun selectArticleViews(query: ArticleViewHisCountQuery): Long { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return dslContext.selectCount() | ||
.from(ArticleViewHis.ARTICLE_VIEW_HIS) | ||
.where(ArticleViewHis.ARTICLE_VIEW_HIS.ARTICLE_MST_ID.eq(query.articleId)) | ||
.fetchOne(0, Long::class.java) ?: 0L | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서는 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로직은 최대한 UC로 뺴는게 좋겠네요 |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아티클 별 view 개수 조회. 이거때문에 article id에 인덱스 해야겠네요 추가커밋 할게요 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.few.api.repo.dao.article.command | ||
|
||
data class ArticleViewHisCommand( | ||
val articleId: Long, | ||
val memberId: Long, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.few.api.repo.dao.article.query | ||
|
||
data class ArticleViewHisCountQuery( | ||
val articleId: Long, | ||
) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.few.api.domain.article.service | ||
|
||
import com.few.api.domain.article.service.dto.AddArticleViewHisInDto | ||
import com.few.api.domain.article.service.dto.ReadArticleViewsInDto | ||
import com.few.api.repo.dao.article.ArticleViewHisDao | ||
import com.few.api.repo.dao.article.command.ArticleViewHisCommand | ||
import com.few.api.repo.dao.article.query.ArticleViewHisCountQuery | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ArticleViewHisService( | ||
private val articleViewHisDao: ArticleViewHisDao, | ||
) { | ||
fun addArticleViewHis(inDto: AddArticleViewHisInDto) { | ||
articleViewHisDao.insertArticleViewHis( | ||
ArticleViewHisCommand(inDto.articleId, inDto.memberId) | ||
) | ||
} | ||
|
||
fun readArticleViews(inDto: ReadArticleViewsInDto): Long { | ||
return articleViewHisDao.selectArticleViews( | ||
ArticleViewHisCountQuery(inDto.articleId) | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.few.api.domain.article.service.dto | ||
|
||
data class AddArticleViewHisInDto( | ||
val articleId: Long, | ||
val memberId: Long, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.few.api.domain.article.service.dto | ||
|
||
data class ReadArticleViewsInDto( | ||
val articleId: Long, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
package com.few.api.domain.article.usecase | ||
|
||
import com.few.api.domain.article.service.ArticleViewHisService | ||
import com.few.api.domain.article.usecase.dto.ReadArticleUseCaseIn | ||
import com.few.api.domain.article.usecase.dto.ReadArticleUseCaseOut | ||
import com.few.api.domain.article.usecase.dto.WriterDetail | ||
import com.few.api.domain.article.service.BrowseArticleProblemsService | ||
import com.few.api.domain.article.service.ReadArticleWriterRecordService | ||
import com.few.api.domain.article.service.dto.AddArticleViewHisInDto | ||
import com.few.api.domain.article.service.dto.BrowseArticleProblemIdsInDto | ||
import com.few.api.domain.article.service.dto.ReadArticleViewsInDto | ||
import com.few.api.domain.article.service.dto.ReadWriterRecordInDto | ||
import com.few.api.exception.common.NotFoundException | ||
import com.few.api.repo.dao.article.ArticleDao | ||
|
@@ -19,6 +22,7 @@ class ReadArticleUseCase( | |
private val articleDao: ArticleDao, | ||
private val readArticleWriterRecordService: ReadArticleWriterRecordService, | ||
private val browseArticleProblemsService: BrowseArticleProblemsService, | ||
private val articleViewHisService: ArticleViewHisService, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. articleView 도 article 도메인에 포함된다고 생각해서 저는 ArticleViewDao를 바로 사용해도 괜찮지 않을까 생각하는데 어떻게 생각하시는지 궁금합니다 |
||
) { | ||
|
||
@Transactional(readOnly = true) | ||
|
@@ -35,6 +39,9 @@ class ReadArticleUseCase( | |
browseArticleProblemsService.execute(query) | ||
} | ||
|
||
articleViewHisService.addArticleViewHis(AddArticleViewHisInDto(useCaseIn.articleId, useCaseIn.memberId)) | ||
val views = articleViewHisService.readArticleViews(ReadArticleViewsInDto(useCaseIn.articleId)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거는 아이디어 차원의 이야기인데 아래 방법은 어떨지 궁금합니다. 기존:
제안:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제안한 방식 나도 생각했던건데.. Insert는 테이블 락 + 인덱스 재구조화 때문에 항상 신중해야하는데, 안그래도 엄청 자주 호출될 SQL이라... 그게 좋은거 같아요 |
||
|
||
return ReadArticleUseCaseOut( | ||
id = articleRecord.articleId, | ||
writer = WriterDetail( | ||
|
@@ -46,7 +53,8 @@ class ReadArticleUseCase( | |
content = articleRecord.content, | ||
problemIds = problemIds.problemIds, | ||
category = CategoryType.convertToDisplayName(articleRecord.category), | ||
createdAt = articleRecord.createdAt | ||
createdAt = articleRecord.createdAt, | ||
views = views | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ class ArticleController( | |
@Min(value = 1, message = "{min.id}") | ||
articleId: Long, | ||
): ApiResponse<ApiResponse.SuccessBody<ReadArticleResponse>> { | ||
val useCaseOut = ReadArticleUseCaseIn(articleId).let { useCaseIn: ReadArticleUseCaseIn -> | ||
val useCaseOut = ReadArticleUseCaseIn(articleId = articleId, memberId = 1L).let { useCaseIn: ReadArticleUseCaseIn -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거는 관련 처리를 하지 않아서 1L로 한것이죠? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네네 유저관련 기능 개발해주시면서 해당 부분 변경 부탁드립니다! 일단 0으로 해둘게요 |
||
readArticleUseCase.execute(useCaseIn) | ||
} | ||
|
||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- 아티클 조회수 저장 테이블 | ||
CREATE TABLE ARTICLE_VIEW_HIS | ||
( | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
article_mst_id BIGINT NOT NULL, | ||
member_id BIGINT NOT NULL, | ||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
deleted_at TIMESTAMP NULL DEFAULT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
Comment on lines
+2
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
각 모듈별로 jooq 필드시 생성되는 .sql 파일이 gitignore되어있었는데, 최상위 위치에 통합관리하도록 변경했습니다