feat(channel-donation-calculate): 채널 후원 정산 응답에 기간 합계를 추가한다
This commit is contained in:
26
docs/20260226_채널후원정산합계추가.md
Normal file
26
docs/20260226_채널후원정산합계추가.md
Normal file
@@ -0,0 +1,26 @@
|
||||
- [x] Admin 채널 후원 정산 조회 흐름(Controller/Service/Repository/DTO) 확인
|
||||
- [x] Creator 정산 조회 흐름(Controller/Service/Repository/DTO) 확인
|
||||
- [x] 날짜 기준 비페이징 합계 조회 방식 결정 및 반영
|
||||
- [x] `GetAdminChannelDonationSettlementResponse`에 합계 필드 추가
|
||||
- [x] `GetCreatorChannelDonationSettlementResponse`에 합계 필드 추가
|
||||
- [x] 관련 테스트/빌드/진단 실행 및 결과 기록
|
||||
|
||||
## 검증 기록
|
||||
|
||||
### 1차 구현
|
||||
- 무엇을: 관리자/크리에이터 관리자 채널 후원 정산 응답에 날짜 범위 전체(비페이징) 합계(`total`)를 추가하고, QueryRepository에 합계 전용 집계 쿼리를 추가했다.
|
||||
- 왜: 기존 응답이 페이지 내 `items`와 `totalCount`만 제공해 날짜 범위 전체 정산 합계를 확인할 수 없었기 때문이다.
|
||||
- 어떻게:
|
||||
- 응답 DTO 확장
|
||||
- `GetAdminChannelDonationSettlementResponse`에 `total` 필드 추가
|
||||
- `GetCreatorChannelDonationSettlementResponse`에 `total` 필드 추가
|
||||
- 합계 DTO/QueryData 추가: `GetAdminChannelDonationSettlementTotal`, `GetCreatorChannelDonationSettlementTotal`, 각 `*TotalQueryData`
|
||||
- 서비스/리포지토리 반영
|
||||
- 관리자: `AdminChannelDonationCalculateQueryRepository.getChannelDonationByCreatorTotal(...)` 추가 후 서비스에서 `total` 매핑
|
||||
- 크리에이터 관리자: `CreatorAdminChannelDonationCalculateQueryRepository.getChannelDonationSettlementTotal(...)` 추가 후 서비스에서 `total` 매핑
|
||||
- 테스트 반영
|
||||
- 컨트롤러/서비스/리포지토리 테스트에서 `total` 필드와 합계 집계 검증 추가
|
||||
- 검증 명령 및 결과
|
||||
- `lsp_diagnostics`(Kotlin 대상): `.kt` LSP 서버 미설정으로 진단 불가(환경 제약)
|
||||
- `./gradlew test --tests "*channelDonation*"` → 성공
|
||||
- `./gradlew build` → 1차 실패(ktlint max line length), 코드 포맷 수정 후 재실행 성공
|
||||
@@ -16,6 +16,29 @@ import java.time.LocalDateTime
|
||||
class AdminChannelDonationCalculateQueryRepository(
|
||||
private val queryFactory: JPAQueryFactory
|
||||
) {
|
||||
fun getChannelDonationByCreatorTotal(
|
||||
startDate: LocalDateTime,
|
||||
endDate: LocalDateTime
|
||||
): GetAdminChannelDonationSettlementTotalQueryData {
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetAdminChannelDonationSettlementTotalQueryData(
|
||||
useCan.id.countDistinct(),
|
||||
useCanCalculate.can.sum()
|
||||
)
|
||||
)
|
||||
.from(useCanCalculate)
|
||||
.innerJoin(useCanCalculate.useCan, useCan)
|
||||
.innerJoin(member)
|
||||
.on(member.id.eq(useCanCalculate.recipientCreatorId))
|
||||
.where(baseWhereCondition(startDate, endDate))
|
||||
.fetchOne()
|
||||
?: GetAdminChannelDonationSettlementTotalQueryData(
|
||||
count = 0L,
|
||||
totalCan = 0
|
||||
)
|
||||
}
|
||||
|
||||
fun getChannelDonationByCreatorTotalCount(startDate: LocalDateTime, endDate: LocalDateTime): Int {
|
||||
val formattedDate = getFormattedDate(useCan.createdAt)
|
||||
val distinctGroupKey = Expressions.stringTemplate(
|
||||
|
||||
@@ -18,11 +18,12 @@ class AdminChannelDonationCalculateService(
|
||||
val startDate = startDateStr.convertLocalDateTime()
|
||||
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
|
||||
val total = repository.getChannelDonationByCreatorTotal(startDate, endDate).toResponseTotal()
|
||||
val totalCount = repository.getChannelDonationByCreatorTotalCount(startDate, endDate)
|
||||
val items = repository
|
||||
.getChannelDonationByCreator(startDate, endDate, offset, limit)
|
||||
.map { it.toResponseItem() }
|
||||
|
||||
return GetAdminChannelDonationSettlementResponse(totalCount, items)
|
||||
return GetAdminChannelDonationSettlementResponse(totalCount, total, items)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,6 @@ package kr.co.vividnext.sodalive.admin.calculate.channelDonation
|
||||
|
||||
data class GetAdminChannelDonationSettlementResponse(
|
||||
val totalCount: Int,
|
||||
val total: GetAdminChannelDonationSettlementTotal,
|
||||
val items: List<GetAdminChannelDonationSettlementItem>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package kr.co.vividnext.sodalive.admin.calculate.channelDonation
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
|
||||
data class GetAdminChannelDonationSettlementTotal(
|
||||
@JsonProperty("count") val count: Int,
|
||||
@JsonProperty("totalCan") val totalCan: Int,
|
||||
@JsonProperty("krw") val krw: Int,
|
||||
@JsonProperty("fee") val fee: Int,
|
||||
@JsonProperty("settlementAmount") val settlementAmount: Int,
|
||||
@JsonProperty("withholdingTax") val withholdingTax: Int,
|
||||
@JsonProperty("depositAmount") val depositAmount: Int
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
package kr.co.vividnext.sodalive.admin.calculate.channelDonation
|
||||
|
||||
import com.querydsl.core.annotations.QueryProjection
|
||||
import kr.co.vividnext.sodalive.calculate.channelDonation.ChannelDonationSettlementCalculator
|
||||
|
||||
data class GetAdminChannelDonationSettlementTotalQueryData @QueryProjection constructor(
|
||||
val count: Long?,
|
||||
val totalCan: Int?
|
||||
) {
|
||||
fun toResponseTotal(): GetAdminChannelDonationSettlementTotal {
|
||||
val totalCan = totalCan ?: 0
|
||||
val settlement = ChannelDonationSettlementCalculator.calculate(totalCan)
|
||||
|
||||
return GetAdminChannelDonationSettlementTotal(
|
||||
count = (count ?: 0L).toInt(),
|
||||
totalCan = totalCan,
|
||||
krw = settlement.krw,
|
||||
fee = settlement.fee,
|
||||
settlementAmount = settlement.settlementAmount,
|
||||
withholdingTax = settlement.withholdingTax,
|
||||
depositAmount = settlement.depositAmount
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,28 @@ import java.time.LocalDateTime
|
||||
class CreatorAdminChannelDonationCalculateQueryRepository(
|
||||
private val queryFactory: JPAQueryFactory
|
||||
) {
|
||||
fun getChannelDonationSettlementTotal(
|
||||
startDate: LocalDateTime,
|
||||
endDate: LocalDateTime,
|
||||
memberId: Long
|
||||
): GetCreatorChannelDonationSettlementTotalQueryData {
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetCreatorChannelDonationSettlementTotalQueryData(
|
||||
useCan.id.countDistinct(),
|
||||
useCanCalculate.can.sum()
|
||||
)
|
||||
)
|
||||
.from(useCanCalculate)
|
||||
.innerJoin(useCanCalculate.useCan, useCan)
|
||||
.where(baseWhereCondition(startDate, endDate, memberId))
|
||||
.fetchOne()
|
||||
?: GetCreatorChannelDonationSettlementTotalQueryData(
|
||||
count = 0L,
|
||||
totalCan = 0
|
||||
)
|
||||
}
|
||||
|
||||
fun getChannelDonationTotalCount(startDate: LocalDateTime, endDate: LocalDateTime, memberId: Long): Int {
|
||||
val formattedDate = getFormattedDate(useCan.createdAt)
|
||||
|
||||
|
||||
@@ -20,11 +20,12 @@ class CreatorAdminChannelDonationCalculateService(
|
||||
val startDate = startDateStr.convertLocalDateTime()
|
||||
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
|
||||
val total = repository.getChannelDonationSettlementTotal(startDate, endDate, memberId).toResponseTotal()
|
||||
val totalCount = repository.getChannelDonationTotalCount(startDate, endDate, memberId)
|
||||
val items = repository
|
||||
.getChannelDonation(startDate, endDate, memberId, offset, limit)
|
||||
.map { it.toResponseItem(creatorNickname) }
|
||||
|
||||
return GetCreatorChannelDonationSettlementResponse(totalCount, items)
|
||||
return GetCreatorChannelDonationSettlementResponse(totalCount, total, items)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,6 @@ package kr.co.vividnext.sodalive.creator.admin.calculate.channelDonation
|
||||
|
||||
data class GetCreatorChannelDonationSettlementResponse(
|
||||
val totalCount: Int,
|
||||
val total: GetCreatorChannelDonationSettlementTotal,
|
||||
val items: List<GetCreatorChannelDonationSettlementItem>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package kr.co.vividnext.sodalive.creator.admin.calculate.channelDonation
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
|
||||
data class GetCreatorChannelDonationSettlementTotal(
|
||||
@JsonProperty("count") val count: Int,
|
||||
@JsonProperty("totalCan") val totalCan: Int,
|
||||
@JsonProperty("krw") val krw: Int,
|
||||
@JsonProperty("fee") val fee: Int,
|
||||
@JsonProperty("settlementAmount") val settlementAmount: Int,
|
||||
@JsonProperty("withholdingTax") val withholdingTax: Int,
|
||||
@JsonProperty("depositAmount") val depositAmount: Int
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
package kr.co.vividnext.sodalive.creator.admin.calculate.channelDonation
|
||||
|
||||
import com.querydsl.core.annotations.QueryProjection
|
||||
import kr.co.vividnext.sodalive.calculate.channelDonation.ChannelDonationSettlementCalculator
|
||||
|
||||
data class GetCreatorChannelDonationSettlementTotalQueryData @QueryProjection constructor(
|
||||
val count: Long?,
|
||||
val totalCan: Int?
|
||||
) {
|
||||
fun toResponseTotal(): GetCreatorChannelDonationSettlementTotal {
|
||||
val totalCan = totalCan ?: 0
|
||||
val settlement = ChannelDonationSettlementCalculator.calculate(totalCan)
|
||||
|
||||
return GetCreatorChannelDonationSettlementTotal(
|
||||
count = (count ?: 0L).toInt(),
|
||||
totalCan = totalCan,
|
||||
krw = settlement.krw,
|
||||
fee = settlement.fee,
|
||||
settlementAmount = settlement.settlementAmount,
|
||||
withholdingTax = settlement.withholdingTax,
|
||||
depositAmount = settlement.depositAmount
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,15 @@ class AdminChannelDonationCalculateControllerTest {
|
||||
fun shouldForwardDateRangeAndPageableToService() {
|
||||
val response = GetAdminChannelDonationSettlementResponse(
|
||||
totalCount = 1,
|
||||
total = GetAdminChannelDonationSettlementTotal(
|
||||
count = 5,
|
||||
totalCan = 35,
|
||||
krw = 3500,
|
||||
fee = 231,
|
||||
settlementAmount = 2770,
|
||||
withholdingTax = 91,
|
||||
depositAmount = 2679
|
||||
),
|
||||
items = listOf(
|
||||
GetAdminChannelDonationSettlementItem(
|
||||
date = "2026-02-26",
|
||||
@@ -54,6 +63,7 @@ class AdminChannelDonationCalculateControllerTest {
|
||||
|
||||
assertEquals(true, apiResponse.success)
|
||||
assertEquals(1, apiResponse.data!!.totalCount)
|
||||
assertEquals(35, apiResponse.data!!.total.totalCan)
|
||||
assertEquals("creator-a", apiResponse.data!!.items[0].creator)
|
||||
assertEquals(2, apiResponse.data!!.items[0].count)
|
||||
assertEquals(20, apiResponse.data!!.items[0].totalCan)
|
||||
|
||||
@@ -65,9 +65,12 @@ class AdminChannelDonationCalculateQueryRepositoryTest @Autowired constructor(
|
||||
val startDate = LocalDateTime.of(2026, 2, 20, 0, 0, 0)
|
||||
val endDate = LocalDateTime.of(2026, 2, 20, 23, 59, 59)
|
||||
|
||||
val total = repository.getChannelDonationByCreatorTotal(startDate, endDate)
|
||||
val totalCount = repository.getChannelDonationByCreatorTotalCount(startDate, endDate)
|
||||
val items = repository.getChannelDonationByCreator(startDate, endDate, offset = 0, limit = 20)
|
||||
|
||||
assertEquals(1L, total.count)
|
||||
assertEquals(50, total.totalCan)
|
||||
assertEquals(1, totalCount)
|
||||
assertEquals(1, items.size)
|
||||
assertEquals("2026-02-20", items[0].date)
|
||||
|
||||
@@ -26,7 +26,17 @@ class AdminChannelDonationCalculateServiceTest {
|
||||
count = 3L,
|
||||
totalCan = 100
|
||||
)
|
||||
val totalQueryData = GetAdminChannelDonationSettlementTotalQueryData(
|
||||
count = 8L,
|
||||
totalCan = 250
|
||||
)
|
||||
|
||||
Mockito.`when`(
|
||||
repository.getChannelDonationByCreatorTotal(
|
||||
"2026-02-20".convertLocalDateTime(),
|
||||
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
)
|
||||
).thenReturn(totalQueryData)
|
||||
Mockito.`when`(
|
||||
repository.getChannelDonationByCreatorTotalCount(
|
||||
"2026-02-20".convertLocalDateTime(),
|
||||
@@ -50,6 +60,9 @@ class AdminChannelDonationCalculateServiceTest {
|
||||
)
|
||||
|
||||
assertEquals(1, result.totalCount)
|
||||
assertEquals(8, result.total.count)
|
||||
assertEquals(250, result.total.totalCan)
|
||||
assertEquals(25_000, result.total.krw)
|
||||
assertEquals(1, result.items.size)
|
||||
assertEquals("2026-02-26", result.items[0].date)
|
||||
assertEquals("creator-a", result.items[0].creator)
|
||||
@@ -58,6 +71,10 @@ class AdminChannelDonationCalculateServiceTest {
|
||||
assertEquals(10_000, result.items[0].krw)
|
||||
assertEquals(660, result.items[0].fee)
|
||||
|
||||
Mockito.verify(repository).getChannelDonationByCreatorTotal(
|
||||
"2026-02-20".convertLocalDateTime(),
|
||||
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
)
|
||||
Mockito.verify(repository).getChannelDonationByCreatorTotalCount(
|
||||
"2026-02-20".convertLocalDateTime(),
|
||||
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
|
||||
@@ -42,6 +42,15 @@ class CreatorAdminChannelDonationCalculateControllerTest {
|
||||
val member = createMember(7L)
|
||||
val response = GetCreatorChannelDonationSettlementResponse(
|
||||
totalCount = 1,
|
||||
total = GetCreatorChannelDonationSettlementTotal(
|
||||
count = 7,
|
||||
totalCan = 40,
|
||||
krw = 4000,
|
||||
fee = 264,
|
||||
settlementAmount = 3176,
|
||||
withholdingTax = 105,
|
||||
depositAmount = 3071
|
||||
),
|
||||
items = listOf(
|
||||
GetCreatorChannelDonationSettlementItem(
|
||||
date = "2026-02-26",
|
||||
@@ -77,6 +86,7 @@ class CreatorAdminChannelDonationCalculateControllerTest {
|
||||
|
||||
assertEquals(true, apiResponse.success)
|
||||
assertEquals(1, apiResponse.data!!.totalCount)
|
||||
assertEquals(40, apiResponse.data!!.total.totalCan)
|
||||
assertEquals("creator-self", apiResponse.data!!.items[0].creator)
|
||||
assertEquals(4, apiResponse.data!!.items[0].count)
|
||||
assertEquals(10, apiResponse.data!!.items[0].totalCan)
|
||||
|
||||
@@ -65,9 +65,12 @@ class CreatorAdminChannelDonationCalculateQueryRepositoryTest @Autowired constru
|
||||
val startDate = LocalDateTime.of(2026, 2, 20, 0, 0, 0)
|
||||
val endDate = LocalDateTime.of(2026, 2, 20, 23, 59, 59)
|
||||
|
||||
val total = repository.getChannelDonationSettlementTotal(startDate, endDate, creator.id!!)
|
||||
val totalCount = repository.getChannelDonationTotalCount(startDate, endDate, creator.id!!)
|
||||
val items = repository.getChannelDonation(startDate, endDate, creator.id!!, offset = 0, limit = 20)
|
||||
|
||||
assertEquals(1L, total.count)
|
||||
assertEquals(50, total.totalCan)
|
||||
assertEquals(1, totalCount)
|
||||
assertEquals(1, items.size)
|
||||
assertEquals("2026-02-20", items[0].date)
|
||||
|
||||
@@ -25,7 +25,18 @@ class CreatorAdminChannelDonationCalculateServiceTest {
|
||||
count = 2L,
|
||||
totalCan = 50
|
||||
)
|
||||
val totalQueryData = GetCreatorChannelDonationSettlementTotalQueryData(
|
||||
count = 4L,
|
||||
totalCan = 120
|
||||
)
|
||||
|
||||
Mockito.`when`(
|
||||
repository.getChannelDonationSettlementTotal(
|
||||
"2026-02-20".convertLocalDateTime(),
|
||||
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59),
|
||||
7L
|
||||
)
|
||||
).thenReturn(totalQueryData)
|
||||
Mockito.`when`(
|
||||
repository.getChannelDonationTotalCount(
|
||||
"2026-02-20".convertLocalDateTime(),
|
||||
@@ -53,12 +64,20 @@ class CreatorAdminChannelDonationCalculateServiceTest {
|
||||
)
|
||||
|
||||
assertEquals(1, result.totalCount)
|
||||
assertEquals(4, result.total.count)
|
||||
assertEquals(120, result.total.totalCan)
|
||||
assertEquals(12_000, result.total.krw)
|
||||
assertEquals(1, result.items.size)
|
||||
assertEquals("creator-self", result.items[0].creator)
|
||||
assertEquals(2, result.items[0].count)
|
||||
assertEquals(50, result.items[0].totalCan)
|
||||
assertEquals(5_000, result.items[0].krw)
|
||||
|
||||
Mockito.verify(repository).getChannelDonationSettlementTotal(
|
||||
"2026-02-20".convertLocalDateTime(),
|
||||
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59),
|
||||
7L
|
||||
)
|
||||
Mockito.verify(repository).getChannelDonationTotalCount(
|
||||
"2026-02-20".convertLocalDateTime(),
|
||||
"2026-02-21".convertLocalDateTime(hour = 23, minute = 59, second = 59),
|
||||
|
||||
Reference in New Issue
Block a user