-
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: selectAllWorkbookSubscriptionStatus, countAllWorkbookSubscription 구현 * feat: BrowseSubscribeWorkbooksUseCase 구현 * feat: browseSubscribeWorkbooks 구현 * refactor: articleInfo에 aritcleId가 포함 되도록 수정 * refactor: 코드 변경 사항 BrowseSubscribeWorkbooksUseCaseTest에 반영 * fix: memberId가 테스트 요청과 일치하지 않아 생긴 문제 해결
- Loading branch information
1 parent
7c1ec42
commit 75ffe72
Showing
17 changed files
with
388 additions
and
29 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
.../main/kotlin/com/few/api/repo/dao/article/query/SelectArticleIdByWorkbookIdAndDayQuery.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,6 @@ | ||
package com.few.api.repo.dao.article.query | ||
|
||
data class SelectArticleIdByWorkbookIdAndDayQuery( | ||
val workbookId: Long, | ||
val day: Int, | ||
) |
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
5 changes: 5 additions & 0 deletions
5
.../src/main/kotlin/com/few/api/repo/dao/subscription/query/CountAllWorkbooksSubscription.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.subscription.query | ||
|
||
data class CountAllWorkbooksSubscription( | ||
val workbookIds: List<Long>, | ||
) |
8 changes: 8 additions & 0 deletions
8
.../subscription/query/SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery.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.subscription.query | ||
|
||
/** | ||
* DeleteAt을 고려하지 않고 멤버의 모든 워크북 구독 상태를 조회하는 쿼리 | ||
*/ | ||
data class SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery( | ||
val memberId: Long, | ||
) |
8 changes: 8 additions & 0 deletions
8
...kotlin/com/few/api/repo/dao/subscription/record/MemberWorkbookSubscriptionStatusRecord.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.subscription.record | ||
|
||
data class MemberWorkbookSubscriptionStatusRecord( | ||
val workbookId: Long, | ||
val isActiveSub: Boolean, | ||
val currentDay: Int, | ||
val totalDay: Int, | ||
) |
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
17 changes: 17 additions & 0 deletions
17
api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionArticleService.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,17 @@ | ||
package com.few.api.domain.subscription.service | ||
|
||
import com.few.api.domain.subscription.service.dto.ReadArticleIdByWorkbookIdAndDayDto | ||
import com.few.api.repo.dao.article.ArticleDao | ||
import com.few.api.repo.dao.article.query.SelectArticleIdByWorkbookIdAndDayQuery | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SubscriptionArticleService( | ||
private val articleDao: ArticleDao, | ||
) { | ||
fun readArticleIdByWorkbookIdAndDay(dto: ReadArticleIdByWorkbookIdAndDayDto): Long? { | ||
SelectArticleIdByWorkbookIdAndDayQuery(dto.workbookId, dto.day).let { query -> | ||
return articleDao.selectArticleIdByWorkbookIdAndDay(query) | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
.../kotlin/com/few/api/domain/subscription/service/dto/ReadArticleIdByWorkbookIdAndDayDto.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,6 @@ | ||
package com.few.api.domain.subscription.service.dto | ||
|
||
data class ReadArticleIdByWorkbookIdAndDayDto( | ||
val workbookId: Long, | ||
val day: Int, | ||
) |
73 changes: 73 additions & 0 deletions
73
...rc/main/kotlin/com/few/api/domain/subscription/usecase/BrowseSubscribeWorkbooksUseCase.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,73 @@ | ||
package com.few.api.domain.subscription.usecase | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.few.api.domain.subscription.service.SubscriptionArticleService | ||
import com.few.api.domain.subscription.service.dto.ReadArticleIdByWorkbookIdAndDayDto | ||
import com.few.api.domain.subscription.usecase.dto.BrowseSubscribeWorkbooksUseCaseIn | ||
import com.few.api.domain.subscription.usecase.dto.BrowseSubscribeWorkbooksUseCaseOut | ||
import com.few.api.domain.subscription.usecase.dto.SubscribeWorkbookDetail | ||
import com.few.api.repo.dao.subscription.SubscriptionDao | ||
import com.few.api.repo.dao.subscription.query.CountAllWorkbooksSubscription | ||
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery | ||
import com.few.api.web.support.WorkBookStatus | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class BrowseSubscribeWorkbooksUseCase( | ||
private val subscriptionDao: SubscriptionDao, | ||
private val subscriptionArticleService: SubscriptionArticleService, | ||
private val objectMapper: ObjectMapper, | ||
) { | ||
@Transactional | ||
fun execute(useCaseIn: BrowseSubscribeWorkbooksUseCaseIn): BrowseSubscribeWorkbooksUseCaseOut { | ||
val subscriptionRecords = | ||
SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery(useCaseIn.memberId).let { | ||
subscriptionDao.selectAllWorkbookSubscriptionStatus(it) | ||
} | ||
|
||
/** | ||
* key: workbookId | ||
* value: workbook의 currentDay에 해당하는 articleId | ||
*/ | ||
val workbookSubscriptionCurrentArticleIdRecords = subscriptionRecords.associate { it -> | ||
val articleId = ReadArticleIdByWorkbookIdAndDayDto(it.workbookId, it.currentDay).let { | ||
subscriptionArticleService.readArticleIdByWorkbookIdAndDay(it) | ||
} ?: throw IllegalArgumentException("articleId is null") | ||
it.workbookId to articleId | ||
} | ||
|
||
val subscriptionWorkbookIds = subscriptionRecords.map { it.workbookId } | ||
val workbookSubscriptionCountRecords = | ||
CountAllWorkbooksSubscription(subscriptionWorkbookIds).let { | ||
subscriptionDao.countAllWorkbookSubscription(it) | ||
} | ||
|
||
subscriptionRecords.map { | ||
/** | ||
* 임시 코드 | ||
* Batch 코드에서 currentDay가 totalDay보다 큰 경우가 발생하여 | ||
* currentDay가 totalDay보다 크면 totalDay로 변경 | ||
* */ | ||
var currentDay = it.currentDay | ||
if (it.currentDay > it.totalDay) { | ||
currentDay = it.totalDay | ||
} | ||
|
||
SubscribeWorkbookDetail( | ||
workbookId = it.workbookId, | ||
isActiveSub = WorkBookStatus.fromStatus(it.isActiveSub), | ||
currentDay = currentDay, | ||
totalDay = it.totalDay, | ||
totalSubscriber = workbookSubscriptionCountRecords[it.workbookId]?.toLong() ?: 0, | ||
articleInfo = objectMapper.writeValueAsString( | ||
mapOf( | ||
"articleId" to workbookSubscriptionCurrentArticleIdRecords[it.workbookId] | ||
) | ||
) | ||
) | ||
}.let { | ||
return BrowseSubscribeWorkbooksUseCaseOut(it) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...n/kotlin/com/few/api/domain/subscription/usecase/dto/BrowseSubscribeWorkbooksUseCaseIn.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.domain.subscription.usecase.dto | ||
|
||
data class BrowseSubscribeWorkbooksUseCaseIn( | ||
val memberId: Long, | ||
) |
17 changes: 17 additions & 0 deletions
17
.../kotlin/com/few/api/domain/subscription/usecase/dto/BrowseSubscribeWorkbooksUseCaseOut.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,17 @@ | ||
package com.few.api.domain.subscription.usecase.dto | ||
|
||
import com.few.api.web.support.WorkBookStatus | ||
|
||
data class BrowseSubscribeWorkbooksUseCaseOut( | ||
val workbooks: List<SubscribeWorkbookDetail>, | ||
) | ||
|
||
data class SubscribeWorkbookDetail( | ||
val workbookId: Long, | ||
val isActiveSub: WorkBookStatus, | ||
val currentDay: Int, | ||
val totalDay: Int, | ||
val rank: Long = 0, | ||
val totalSubscriber: Long, | ||
val articleInfo: String = "{}", | ||
) |
Oops, something went wrong.