-
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: 밀린문제 ID 조회 API 1차 구현 * feat: 문제 단건 조회시 articleId 필드 응답 추가 * test: 문제 단건 조회 테스트 코드 수정(articleId 필드 추가) * test: 밀린 문제 조회 컨트롤러 테스트 구현 * test: BrowseUndoneProblemsUseCaseTest 구현(fail) * fix: @transactional 어노테이션 추가 * refactor: ArticleService, SubscriptionService 추가 * refactor: rename method to selectArticleIdsByWorkbookIdLimitDay * refactor: rename field numOfReadArticle -> day * feat: 밀린 문제가 articleId를 기준으로 랜덤 정렬 되도록 수정 * test: UC 코드 변경 테스트 코드 반영 * fix: 테스트를 위한 커밋 수정 * feat: 문제 id 조회시 Size 필드 응답 추가 * test: ProblemController 테스트 코드 리펙토링
- Loading branch information
Showing
30 changed files
with
441 additions
and
19 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/SelectAritlceIdByWorkbookIdAndDayQuery.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 SelectAritlceIdByWorkbookIdAndDayQuery( | ||
val workbookId: Long, | ||
val day: Int, | ||
) |
5 changes: 5 additions & 0 deletions
5
api-repo/src/main/kotlin/com/few/api/repo/dao/article/record/ArticleIdRecord.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.record | ||
|
||
data class ArticleIdRecord( | ||
val articleIds: List<Long>, | ||
) |
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
5 changes: 5 additions & 0 deletions
5
...po/src/main/kotlin/com/few/api/repo/dao/problem/query/SelectProblemIdByArticleIdsQuery.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.problem.query | ||
|
||
data class SelectProblemIdByArticleIdsQuery( | ||
val articleIds: Set<Long>, | ||
) |
6 changes: 6 additions & 0 deletions
6
...repo/src/main/kotlin/com/few/api/repo/dao/problem/query/SelectSubmittedProblemIdsQuery.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.problem.query | ||
|
||
data class SelectSubmittedProblemIdsQuery( | ||
val memberId: Long, | ||
val problemIds: List<Long>, | ||
) |
6 changes: 6 additions & 0 deletions
6
api-repo/src/main/kotlin/com/few/api/repo/dao/problem/record/ProblemIdAndArticleIdRecord.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.problem.record | ||
|
||
data class ProblemIdAndArticleIdRecord( | ||
val problemId: Long, | ||
val articleId: Long, | ||
) |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ data class SelectProblemRecord( | |
val id: Long, | ||
val title: String, | ||
val contents: String, | ||
val articleId: Long, | ||
) |
5 changes: 5 additions & 0 deletions
5
api-repo/src/main/kotlin/com/few/api/repo/dao/problem/record/SubmittedProblemIdsRecord.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.problem.record | ||
|
||
data class SubmittedProblemIdsRecord( | ||
val problemIds: List<Long>, | ||
) |
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
...po/src/main/kotlin/com/few/api/repo/dao/subscription/record/SubscriptionProgressRecord.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.subscription.record | ||
|
||
data class SubscriptionProgressRecord( | ||
val workbookId: Long, | ||
val day: Int, | ||
) |
21 changes: 21 additions & 0 deletions
21
api/src/main/kotlin/com/few/api/domain/problem/service/ArticleService.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,21 @@ | ||
package com.few.api.domain.problem.service | ||
|
||
import com.few.api.domain.problem.service.dto.BrowseArticleIdInDto | ||
import com.few.api.repo.dao.article.ArticleDao | ||
import com.few.api.repo.dao.article.query.SelectAritlceIdByWorkbookIdAndDayQuery | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ArticleService( | ||
private val articleDao: ArticleDao, | ||
) { | ||
|
||
fun browseArticleIdByWorkbookIdLimitDay(inDto: BrowseArticleIdInDto): List<Long> { | ||
return articleDao.selectArticleIdsByWorkbookIdLimitDay( | ||
SelectAritlceIdByWorkbookIdAndDayQuery( | ||
inDto.workbookId, | ||
inDto.day | ||
) | ||
).articleIds | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
api/src/main/kotlin/com/few/api/domain/problem/service/SubscriptionService.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,21 @@ | ||
package com.few.api.domain.problem.service | ||
|
||
import com.few.api.domain.problem.service.dto.BrowseWorkbookIdAndProgressInDto | ||
import com.few.api.domain.problem.service.dto.SubscriptionProgressOutDto | ||
import com.few.api.repo.dao.subscription.SubscriptionDao | ||
import com.few.api.repo.dao.subscription.query.SelectSubscriptionSendStatusQuery | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SubscriptionService( | ||
private val subscriptionDao: SubscriptionDao, | ||
) { | ||
|
||
fun browseWorkbookIdAndProgress(inDto: BrowseWorkbookIdAndProgressInDto): List<SubscriptionProgressOutDto> { | ||
val subscriptionProgresses = subscriptionDao.selectWorkbookIdAndProgressByMember( | ||
SelectSubscriptionSendStatusQuery(inDto.memberId) | ||
) | ||
|
||
return subscriptionProgresses.map { SubscriptionProgressOutDto(it.workbookId, it.day) } | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
api/src/main/kotlin/com/few/api/domain/problem/service/dto/BrowseArticleIdInDto.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.problem.service.dto | ||
|
||
data class BrowseArticleIdInDto( | ||
val workbookId: Long, | ||
val day: Int, | ||
) |
5 changes: 5 additions & 0 deletions
5
...rc/main/kotlin/com/few/api/domain/problem/service/dto/BrowseWorkbookIdAndProgressInDto.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.problem.service.dto | ||
|
||
data class BrowseWorkbookIdAndProgressInDto( | ||
val memberId: Long, | ||
) |
6 changes: 6 additions & 0 deletions
6
api/src/main/kotlin/com/few/api/domain/problem/service/dto/SubscriptionProgressOutDto.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.problem.service.dto | ||
|
||
data class SubscriptionProgressOutDto( | ||
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
82 changes: 82 additions & 0 deletions
82
api/src/main/kotlin/com/few/api/domain/problem/usecase/BrowseUndoneProblemsUseCase.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,82 @@ | ||
package com.few.api.domain.problem.usecase | ||
|
||
import com.few.api.domain.problem.service.ArticleService | ||
import com.few.api.domain.problem.service.SubscriptionService | ||
import com.few.api.domain.problem.service.dto.BrowseArticleIdInDto | ||
import com.few.api.domain.problem.service.dto.BrowseWorkbookIdAndProgressInDto | ||
import com.few.api.domain.problem.usecase.dto.BrowseProblemsUseCaseOut | ||
import com.few.api.domain.problem.usecase.dto.BrowseUndoneProblemsUseCaseIn | ||
import com.few.api.exception.common.NotFoundException | ||
import com.few.api.repo.dao.problem.ProblemDao | ||
import com.few.api.repo.dao.problem.SubmitHistoryDao | ||
import com.few.api.repo.dao.problem.query.SelectProblemIdByArticleIdsQuery | ||
import com.few.api.repo.dao.problem.query.SelectSubmittedProblemIdsQuery | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class BrowseUndoneProblemsUseCase( | ||
private val problemDao: ProblemDao, | ||
private val subscriptionService: SubscriptionService, | ||
private val articleService: ArticleService, | ||
private val submitHistoryDao: SubmitHistoryDao, | ||
) { | ||
|
||
@Transactional(readOnly = true) | ||
fun execute(useCaseIn: BrowseUndoneProblemsUseCaseIn): BrowseProblemsUseCaseOut { | ||
/** | ||
* 유저가 구독한 워크북들에 속한 아티클 개수를 조회함 | ||
* 이때 아티클 개수는 현 시점 기준으로 이메일이 전송된 아티클 개수까지만 조회함 | ||
*/ | ||
val subscriptionProgresses = subscriptionService.browseWorkbookIdAndProgress( | ||
BrowseWorkbookIdAndProgressInDto(useCaseIn.memberId) | ||
).takeIf { it.isNotEmpty() } ?: throw NotFoundException("subscribe.workbook.notexist") | ||
|
||
/** | ||
* 위에서 조회한 워크부에 속한 아티클 개수에 대해 article_id 들을 조회함 | ||
*/ | ||
val sentArticleIds = subscriptionProgresses.flatMap { subscriptionProgress -> | ||
articleService.browseArticleIdByWorkbookIdLimitDay( | ||
BrowseArticleIdInDto( | ||
subscriptionProgress.workbookId, | ||
subscriptionProgress.day | ||
) | ||
) | ||
}.toSet() | ||
|
||
/** | ||
* 위에서 구한 아티클에 속한 모든 problem_id, article_id 조합을 조회함 | ||
*/ | ||
val allProblemIdsAndArticleIdsToBeSolved = problemDao.selectProblemIdByArticleIds( | ||
SelectProblemIdByArticleIdsQuery(sentArticleIds) | ||
) | ||
|
||
/** | ||
* 위에서 구한 문제들에 대해 풀이 이력이 존재하는 problem_id만 추출 후 | ||
* 유저가 풀어야 할 전체 problem_id에 대해 여집합 연산 | ||
*/ | ||
val allProblemIdsToBeSolved = allProblemIdsAndArticleIdsToBeSolved.map { it.problemId } | ||
val submittedProblemIds = submitHistoryDao.selectProblemIdByProblemIds( | ||
SelectSubmittedProblemIdsQuery(useCaseIn.memberId, allProblemIdsToBeSolved) | ||
).problemIds | ||
|
||
val unsubmittedProblemIdAndArticleIds: Map<Long, List<Long>> = allProblemIdsAndArticleIdsToBeSolved | ||
.filter { it.problemId !in submittedProblemIds } | ||
.groupBy { it.articleId } | ||
.mapValues { entry -> entry.value.map { it.problemId } } | ||
|
||
/** | ||
* 결과를 article_id를 기준으로 랜덤화한 뒤 problem_id를 순차적으로 리턴함 | ||
*/ | ||
val randomArticleIds = unsubmittedProblemIdAndArticleIds.keys.shuffled() | ||
val problemIdsRandomizedByArticleId = mutableListOf<Long>() | ||
|
||
randomArticleIds.forEach { articleId -> | ||
unsubmittedProblemIdAndArticleIds[articleId]?.let { problemIds -> | ||
problemIdsRandomizedByArticleId.addAll(problemIds) | ||
} | ||
} | ||
|
||
return BrowseProblemsUseCaseOut(problemIdsRandomizedByArticleId) | ||
} | ||
} |
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
api/src/main/kotlin/com/few/api/domain/problem/usecase/dto/BrowseUndoneProblemsUseCaseIn.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.problem.usecase.dto | ||
|
||
data class BrowseUndoneProblemsUseCaseIn( | ||
val memberId: Long, | ||
) |
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
Oops, something went wrong.