Skip to content

Commit abfeeab

Browse files
committed
feat: 신규 가입자 추이 응답에 기간 전체 합계(totalCount) 추가
1 parent 9eda91e commit abfeeab

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎docs/api-specs/dashboard-api.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,15 @@
110110

111111
`granularity=week`일 때 각 항목의 `date`는 그 주의 시작일(월요일)입니다.
112112

113+
`totalCount`는 `from`~`to` 구간 전체의 정확한 합계입니다. `granularity=week`로 조회하면 주 경계가 `from`/`to`를 벗어나는 날짜까지 포함할 수 있어(예: `to`가 주 중간이면 그 주 전체가 한 항목으로 잡힘) `items`의 `count`를 그냥 더한 값과 `totalCount`가 다를 수 있습니다 — **임의 기간의 정확한 합계가 필요하면 `granularity` 값과 무관하게 `totalCount`를 사용하세요.**
114+
113115
성공 응답 `200 OK` (`granularity=day`):
114116

115117
```json
116118
{
117119
"statusCode": 200,
118120
"data": {
121+
"totalCount": 20,
119122
"items": [
120123
{ "date": "2026-08-01", "count": 12 },
121124
{ "date": "2026-08-02", "count": 8 }
@@ -131,6 +134,7 @@
131134
{
132135
"statusCode": 200,
133136
"data": {
137+
"totalCount": 130,
134138
"items": [
135139
{ "date": "2026-07-27", "count": 65 },
136140
{ "date": "2026-08-03", "count": 71 }

‎src/main/java/com/swyp/picke/domain/admin/dto/dashboard/response/AdminDashboardNewUsersResponse.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
import java.util.List;
44

55
public record AdminDashboardNewUsersResponse(
6+
long totalCount,
67
List<AdminDashboardTrendItemResponse> items
78
) {}

‎src/main/java/com/swyp/picke/domain/admin/service/AdminDashboardService.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public AdminDashboardNewUsersResponse getNewUsersTrend(LocalDate from, LocalDate
6767
.map(row -> new AdminDashboardTrendItemResponse(row.getActivityDate(), row.getCount()))
6868
.toList();
6969

70-
return new AdminDashboardNewUsersResponse(items);
70+
// week 단위 items는 주 경계가 from~to 범위를 벗어날 수 있어(예: to가 주 중간이면 그 주 전체를 포함),
71+
// 요청한 기간 전체의 정확한 합계는 items 합산이 아니라 별도 카운트로 계산한다.
72+
long totalCount = userRepository.countByCreatedAtBetween(from.atStartOfDay(), to.plusDays(1).atStartOfDay());
73+
74+
return new AdminDashboardNewUsersResponse(totalCount, items);
7175
}
7276
}

‎src/test/java/com/swyp/picke/domain/admin/service/AdminDashboardServiceTest.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ void getNewUsersTrend_day_returnsDailyCounts() {
103103
dailyUserCount(LocalDate.of(2026, 8, 2), 5L)
104104
);
105105
when(userRepository.findDailyNewUserCounts(from, to)).thenReturn(rows);
106+
when(userRepository.countByCreatedAtBetween(any(), any())).thenReturn(8L);
106107

107108
var response = adminDashboardService.getNewUsersTrend(from, to, "day");
108109

109110
assertThat(response.items()).hasSize(2);
110111
assertThat(response.items().get(1).count()).isEqualTo(5L);
112+
assertThat(response.totalCount()).isEqualTo(8L);
111113
}
112114

113115
@Test
@@ -117,11 +119,13 @@ void getNewUsersTrend_week_returnsWeeklyCounts() {
117119
LocalDate to = LocalDate.of(2026, 8, 14);
118120
List<DailyUserCount> rows = List.of(dailyUserCount(LocalDate.of(2026, 7, 27), 20L));
119121
when(userRepository.findWeeklyNewUserCounts(from, to)).thenReturn(rows);
122+
when(userRepository.countByCreatedAtBetween(any(), any())).thenReturn(18L);
120123

121124
var response = adminDashboardService.getNewUsersTrend(from, to, "week");
122125

123126
assertThat(response.items()).hasSize(1);
124127
assertThat(response.items().get(0).count()).isEqualTo(20L);
128+
assertThat(response.totalCount()).isEqualTo(18L);
125129
}
126130

127131
@Test

0 commit comments

Comments
 (0)