-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: ARTICLE_VIEW_COUNT 테이블 생성, 아티클 조회수 순 정렬 등에 사용 예정 * fix: ARTICLE_VIEW_COUNT 테이블 deleted_at 추가 * feat: 아티클 조회시 article view his가 아닌 article view count를 보도록 수정(SL수정: count -> select) * test: ReadArticleUseCaseTest 수정 반영 * feat: ArticleViewCountHandler 추가 * fix: view_count 컬럼 기준 내림차순 정렬 인덱스로 변경 * feat: category_cd 컬럼 추가 in ARTICLE_VIEW_COUNT 테이블 and 인덱싱 * test: category_cd 컬럼 추가 테스트 반영 * refactor: article category 유효하지 않을 경우에 대한 검증 추가 * feat: article.invalid.category 에러코드 추가 --------- Co-authored-by: belljun3395 <[email protected]>
- Loading branch information
1 parent
656db6d
commit 28d00e8
Showing
9 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewCountDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.ArticleViewCountCommand | ||
import com.few.api.repo.dao.article.query.ArticleViewCountQuery | ||
import jooq.jooq_dsl.Tables.ARTICLE_VIEW_COUNT | ||
import org.jooq.DSLContext | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class ArticleViewCountDao( | ||
private val dslContext: DSLContext, | ||
) { | ||
|
||
fun upsertArticleViewCount(query: ArticleViewCountQuery) { | ||
dslContext.insertInto(ARTICLE_VIEW_COUNT) | ||
.set(ARTICLE_VIEW_COUNT.ARTICLE_ID, query.articleId) | ||
.set(ARTICLE_VIEW_COUNT.VIEW_COUNT, 1) | ||
.set(ARTICLE_VIEW_COUNT.CATEGORY_CD, query.categoryType.code) | ||
.onDuplicateKeyUpdate() | ||
.set(ARTICLE_VIEW_COUNT.VIEW_COUNT, ARTICLE_VIEW_COUNT.VIEW_COUNT.plus(1)) | ||
} | ||
|
||
fun selectArticleViewCount(command: ArticleViewCountCommand): Long? { | ||
return dslContext.select( | ||
ARTICLE_VIEW_COUNT.VIEW_COUNT | ||
).from(ARTICLE_VIEW_COUNT) | ||
.where(ARTICLE_VIEW_COUNT.ARTICLE_ID.eq(command.articleId)) | ||
.and(ARTICLE_VIEW_COUNT.DELETED_AT.isNull) | ||
.fetchOneInto(Long::class.java) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
api-repo/src/main/kotlin/com/few/api/repo/dao/article/command/ArticleViewCountCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.few.api.repo.dao.article.command | ||
|
||
data class ArticleViewCountCommand( | ||
val articleId: Long, | ||
) |
8 changes: 8 additions & 0 deletions
8
api-repo/src/main/kotlin/com/few/api/repo/dao/article/query/ArticleViewCountQuery.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.few.api.repo.dao.article.query | ||
|
||
import com.few.data.common.code.CategoryType | ||
|
||
data class ArticleViewCountQuery( | ||
val articleId: Long, | ||
val categoryType: CategoryType, | ||
) |
18 changes: 18 additions & 0 deletions
18
api/src/main/kotlin/com/few/api/domain/article/handler/ArticleViewCountHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.few.api.domain.article.handler | ||
|
||
import com.few.api.repo.dao.article.ArticleViewCountDao | ||
import com.few.api.repo.dao.article.command.ArticleViewCountCommand | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Isolation | ||
import org.springframework.transaction.annotation.Propagation | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class ArticleViewCountHandler( | ||
private val articleViewCountDao: ArticleViewCountDao, | ||
) { | ||
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRES_NEW) | ||
fun browseArticleViewCount(articleId: Long): Long { | ||
return (articleViewCountDao.selectArticleViewCount(ArticleViewCountCommand(articleId)) ?: 0L) + 1L | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
article.notfound.id=\u0061\u0072\u0074\u0069\u0063\u006c\u0065\u002e\u006e\u006f\u0074\u0066\u006f\u0075\u006e\u0064\u002e\u0069\u0064 | ||
article.notfound.articleidworkbookid=\u0061\u0072\u0074\u0069\u0063\u006c\u0065\u002e\u006e\u006f\u0074\u0066\u006f\u0075\u006e\u0064\u002e\u0061\u0072\u0074\u0069\u0063\u006c\u0065\u0069\u0064\u0077\u006f\u0072\u006b\u0062\u006f\u006f\u006b\u0069 | ||
article.invalid.category=\uc874\uc7ac\ud558\uc9c0\u0020\uc54a\ub294\u0020\uc544\ud2f0\ud074\u0020\uce74\ud14c\uace0\ub9ac\uc785\ub2c8\ub2e4\u000d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
data/db/migration/entity/V1.00.0.14__manage_article_view_count.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- article 별 조회수 저장 테이블 | ||
CREATE TABLE ARTICLE_VIEW_COUNT | ||
( | ||
article_id BIGINT NOT NULL, | ||
view_count BIGINT NOT NULL, | ||
category_cd TINYINT NOT NULL, | ||
deleted_at TIMESTAMP NULL DEFAULT NULL, | ||
CONSTRAINT article_view_count_pk PRIMARY KEY (article_id) | ||
); | ||
|
||
-- 조회수 순으로 아티클 조회시 사용하기 위한 인덱스 | ||
-- ex. SELECT * FROM ARTICLE_VIEW_COUNT ORDER BY view_count DESC LIMIT 10; | ||
CREATE INDEX article_view_count_idx1 ON ARTICLE_VIEW_COUNT (view_count DESC); | ||
|
||
-- 카테고리 별 필터링을 위한 인덱스 | ||
CREATE INDEX article_view_count_idx2 ON ARTICLE_VIEW_COUNT (category_cd); |