Skip to content

Commit 246537b

Browse files
authored
[FEAT] 제출 완료된 지원서 수 조회 (#307)
* feat: 제출된 지원서 수 조회 DTO 구 * feat: 제출된 지원서 수 조회 쿼리 메서드 구 * feat: 제출된 지원서 수 조회 비즈니스 로직 구 * test: 제출된 지원서 수 조회 비즈니스 로직 테스트 * feat: 제출된 지원서 수 조회 API 스펙 추가 * feat: 제출된 지원서 수 조회 API 엔드포인 추가
1 parent 451d030 commit 246537b

7 files changed

Lines changed: 108 additions & 2 deletions

File tree

src/main/java/org/ject/support/domain/admin/controller/SubmittedApplyApiSpec.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
import io.swagger.v3.oas.annotations.tags.Tag;
55
import jakarta.validation.Valid;
66
import org.ject.support.domain.admin.dto.SubmittedApplyBulkDeleteRequest;
7+
import org.ject.support.domain.admin.dto.SubmittedApplyCountResponse;
78
import org.springframework.web.bind.annotation.PathVariable;
89
import org.springframework.web.bind.annotation.RequestBody;
910

1011
@Tag(name = "Submitted Apply", description = "제출된 지원서 관리 API")
1112
public interface SubmittedApplyApiSpec {
1213

14+
@Operation(
15+
summary = "제출된 지원서 수 조회",
16+
description = "제출된 상태의 지원서 총 개수를 조회합니다.")
17+
SubmittedApplyCountResponse getSubmittedApplyCount();
18+
1319
@Operation(
1420
summary = "제출된 지원서 삭제",
1521
description = "선택한 제출된 지원서를 삭제합니다.")

src/main/java/org/ject/support/domain/admin/controller/SubmittedApplyController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import jakarta.validation.Valid;
44
import lombok.RequiredArgsConstructor;
55
import org.ject.support.domain.admin.dto.SubmittedApplyBulkDeleteRequest;
6+
import org.ject.support.domain.admin.dto.SubmittedApplyCountResponse;
67
import org.ject.support.domain.admin.service.SubmittedApplyService;
78
import org.springframework.security.access.prepost.PreAuthorize;
89
import org.springframework.web.bind.annotation.DeleteMapping;
10+
import org.springframework.web.bind.annotation.GetMapping;
911
import org.springframework.web.bind.annotation.PathVariable;
1012
import org.springframework.web.bind.annotation.RequestBody;
1113
import org.springframework.web.bind.annotation.RequestMapping;
@@ -18,6 +20,13 @@ public class SubmittedApplyController implements SubmittedApplyApiSpec {
1820

1921
private final SubmittedApplyService submittedApplyService;
2022

23+
@Override
24+
@GetMapping("/count")
25+
@PreAuthorize("hasRole('ROLE_ADMIN')")
26+
public SubmittedApplyCountResponse getSubmittedApplyCount() {
27+
return submittedApplyService.countSubmittedApply();
28+
}
29+
2130
@Override
2231
@DeleteMapping("/{applyId}")
2332
@PreAuthorize("hasRole('ROLE_ADMIN')")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.ject.support.domain.admin.dto;
2+
3+
public record SubmittedApplyCountResponse(
4+
Long count
5+
) {
6+
public SubmittedApplyCountResponse {
7+
if (count == null) {
8+
count = 0L;
9+
}
10+
}
11+
}

src/main/java/org/ject/support/domain/admin/service/SubmittedApplyService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.List;
44
import lombok.RequiredArgsConstructor;
5+
import org.ject.support.domain.admin.dto.SubmittedApplyCountResponse;
56
import org.ject.support.domain.apply.domain.Apply;
67
import org.ject.support.domain.apply.domain.Apply.Status;
78
import org.ject.support.domain.apply.exception.ApplyErrorCode;
@@ -17,6 +18,11 @@ public class SubmittedApplyService {
1718

1819
private final ApplyRepository applyRepository;
1920

21+
public SubmittedApplyCountResponse countSubmittedApply() {
22+
Long count = applyRepository.countByStatus(Status.SUBMITTED);
23+
return new SubmittedApplyCountResponse(count);
24+
}
25+
2026
@Transactional
2127
public void deleteSubmittedApply(final Long applyId) {
2228
Apply apply = applyRepository.findByIdAndStatusWithMember(applyId, Status.SUBMITTED)

src/main/java/org/ject/support/domain/apply/repository/ApplyRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ public interface ApplyRepository extends JpaRepository<Apply, Long> {
2121

2222
@Query("select a from Apply a join fetch a.member m where a.id in :applyIds and a.status = :status")
2323
List<Apply> findAllByIdAndStatusWithMember(@Param("applyIds") List<Long> applyIds, @Param("status") Apply.Status status);
24+
25+
@Query("select COUNT(a) FROM Apply a WHERE a.status = :status")
26+
Long countByStatus(@Param("status") Apply.Status status);
2427
}

src/test/java/org/ject/support/domain/admin/service/SubmittedApplyServiceTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatThrownBy;
55
import static org.mockito.BDDMockito.given;
6+
import static org.mockito.BDDMockito.then;
7+
import static org.mockito.Mockito.times;
68
import static org.mockito.Mockito.verify;
79

810
import java.util.List;
911
import java.util.Optional;
1012
import org.ject.support.base.UnitTestSupport;
13+
import org.ject.support.domain.admin.dto.SubmittedApplyCountResponse;
1114
import org.ject.support.domain.apply.domain.ApplicationForm;
1215
import org.ject.support.domain.apply.domain.Apply;
1316
import org.ject.support.domain.apply.domain.Apply.Status;
@@ -149,4 +152,34 @@ void setUp() {
149152
.isInstanceOf(ApplyException.class)
150153
.hasFieldOrPropertyWithValue("errorCode", ApplyErrorCode.NOT_FOUND_APPLY);
151154
}
155+
156+
@Test
157+
void 제출된_지원서_수_조회_성공() {
158+
// given
159+
Long expectedCount = 10L;
160+
given(applyRepository.countByStatus(Status.SUBMITTED))
161+
.willReturn(expectedCount);
162+
163+
// when
164+
SubmittedApplyCountResponse response = submittedApplyService.countSubmittedApply();
165+
166+
// then
167+
assertThat(response.count()).isEqualTo(expectedCount);
168+
then(applyRepository).should(times(1)).countByStatus(Status.SUBMITTED);
169+
}
170+
171+
@Test
172+
void 제출된_지원서가_없을_때_0_반환() {
173+
// given
174+
Long expectedCount = 0L;
175+
given(applyRepository.countByStatus(Status.SUBMITTED))
176+
.willReturn(expectedCount);
177+
178+
// when
179+
SubmittedApplyCountResponse response = submittedApplyService.countSubmittedApply();
180+
181+
// then
182+
assertThat(response.count()).isZero();
183+
then(applyRepository).should(times(1)).countByStatus(Status.SUBMITTED);
184+
}
152185
}

src/test/java/org/ject/support/domain/apply/repository/ApplyRepositoryTest.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,48 @@ void setUp() {
8282
List<Apply> result = applyRepository.findByRecruitAndStatus(beRecruit, TEMP_SAVED);
8383

8484
// then
85-
assertThat(result).hasSize(2);
86-
assertThat(result).containsExactlyInAnyOrder(be2TempApply, be3TempApply);
85+
assertThat(result)
86+
.hasSize(2)
87+
.containsExactlyInAnyOrder(be2TempApply, be3TempApply);
8788
}
8889

90+
@Test
91+
void 상태별_지원서_수_조회_성공() {
92+
// given
93+
Member feApplicant = createMember("emailFE@test.com", Role.APPLY);
94+
Member beApplicant = createMember("emailBE@test.com", Role.APPLY);
95+
memberRepository.saveAll(List.of(feApplicant, beApplicant));
96+
97+
Apply feTempApply = getApply(feApplicant, feRecruit, TEMP_SAVED);
98+
Apply beSubmitApply = getApply(beApplicant, beRecruit, SUBMITTED);
99+
applyRepository.saveAll(List.of(feTempApply, beSubmitApply));
100+
101+
// when
102+
Long count = applyRepository.countByStatus(SUBMITTED);
103+
104+
// then
105+
assertThat(count).isEqualTo(1L);
106+
}
107+
108+
@Test
109+
void 해당_상태의_지원서가_없을_때_0_반환() {
110+
// given
111+
Member feApplicant = createMember("emailFE@test.com", Role.APPLY);
112+
Member beApplicant = createMember("emailBE@test.com", Role.APPLY);
113+
memberRepository.saveAll(List.of(feApplicant, beApplicant));
114+
115+
Apply feTempApply = getApply(feApplicant, feRecruit, TEMP_SAVED);
116+
Apply beSubmitApply = getApply(beApplicant, beRecruit, TEMP_SAVED);
117+
applyRepository.saveAll(List.of(feTempApply, beSubmitApply));
118+
119+
// when
120+
Long count = applyRepository.countByStatus(SUBMITTED);
121+
122+
// then
123+
assertThat(count).isZero();
124+
}
125+
126+
89127
private Recruit getRecruit(JobFamily jobFamily) {
90128
return Recruit.builder()
91129
.semester(semester)

0 commit comments

Comments
 (0)