Skip to content

Commit 6b8c263

Browse files
authored
bug: 봉사 지원 조회 (#260)
* fix(volunteer-apply): 특정 모집글 봉사자 지원 단건 조회 버그 해결 - 지원 내역이 없는 경우 210 반환 * test(volunteer-apply): 특정 모집글 봉사자 지원 단건 조회 테스트 - 지원 내역이 없는 경우 210 반환
1 parent 34a2ede commit 6b8c263

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.somemore.domains.volunteerapply.controller;
22

3-
import static org.springframework.data.domain.Sort.Direction.DESC;
4-
3+
import com.somemore.domains.volunteerapply.domain.ApplyStatus;
54
import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition;
65
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto;
76
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplySummaryResponseDto;
@@ -10,21 +9,19 @@
109
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
1110
import com.somemore.global.auth.annotation.CurrentUser;
1211
import com.somemore.global.common.response.ApiResponse;
13-
import com.somemore.global.exception.BadRequestException;
14-
import com.somemore.domains.volunteerapply.domain.ApplyStatus;
12+
import com.somemore.global.exception.NoSuchElementException;
1513
import io.swagger.v3.oas.annotations.Operation;
1614
import io.swagger.v3.oas.annotations.tags.Tag;
17-
import java.util.UUID;
1815
import lombok.RequiredArgsConstructor;
1916
import org.springframework.data.domain.Page;
2017
import org.springframework.data.domain.Pageable;
2118
import org.springframework.data.web.PageableDefault;
2219
import org.springframework.security.access.annotation.Secured;
23-
import org.springframework.web.bind.annotation.GetMapping;
24-
import org.springframework.web.bind.annotation.PathVariable;
25-
import org.springframework.web.bind.annotation.RequestMapping;
26-
import org.springframework.web.bind.annotation.RequestParam;
27-
import org.springframework.web.bind.annotation.RestController;
20+
import org.springframework.web.bind.annotation.*;
21+
22+
import java.util.UUID;
23+
24+
import static org.springframework.data.domain.Sort.Direction.DESC;
2825

2926
@Tag(name = "Volunteer Apply Query API", description = "봉사 활동 지원 조회 API")
3027
@RequiredArgsConstructor
@@ -48,7 +45,7 @@ public ApiResponse<?> getVolunteerApplyByRecruitIdAndVolunteerId(
4845
recruitBoardId, volunteerId),
4946
"특정 모집글에 대한 봉사자 지원 단건 조회 성공"
5047
);
51-
} catch (BadRequestException e) {
48+
} catch (NoSuchElementException e) {
5249
return ApiResponse.ok(210, "지원 내역이 없습니다.");
5350
}
5451
}

src/test/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiControllerTest.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
package com.somemore.domains.volunteerapply.controller;
22

3-
import static com.somemore.domains.volunteerapply.domain.ApplyStatus.WAITING;
4-
import static org.mockito.ArgumentMatchers.any;
5-
import static org.mockito.BDDMockito.given;
6-
import static org.springframework.http.MediaType.APPLICATION_JSON;
7-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
8-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
9-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
10-
113
import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition;
124
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto;
135
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyResponseDto;
146
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplySummaryResponseDto;
157
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto;
168
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase;
179
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
10+
import com.somemore.global.exception.NoSuchElementException;
1811
import com.somemore.support.ControllerTestSupport;
1912
import com.somemore.support.annotation.WithMockCustomUser;
20-
import java.util.Collections;
21-
import java.util.UUID;
2213
import org.junit.jupiter.api.DisplayName;
2314
import org.junit.jupiter.api.Test;
2415
import org.springframework.boot.test.mock.mockito.MockBean;
2516
import org.springframework.data.domain.Page;
2617
import org.springframework.data.domain.PageImpl;
2718

19+
import java.util.Collections;
20+
import java.util.UUID;
21+
22+
import static com.somemore.domains.volunteerapply.domain.ApplyStatus.WAITING;
23+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY;
24+
import static org.mockito.ArgumentMatchers.any;
25+
import static org.mockito.BDDMockito.given;
26+
import static org.springframework.http.MediaType.APPLICATION_JSON;
27+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
28+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
29+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
30+
2831
class VolunteerApplyQueryApiControllerTest extends ControllerTestSupport {
2932

3033
@MockBean
@@ -68,6 +71,27 @@ void getVolunteerApplyByRecruitIdAndVolunteerId() throws Exception {
6871
.andExpect(jsonPath("$.data.attended").value(false));
6972
}
7073

74+
@DisplayName("특정 모집글 봉사자 지원 단건 조회 성공 테스트 - 지원 내역이 없는 경우")
75+
@Test
76+
void getVolunteerApplyByRecruitIdAndVolunteerIdWhenDoesNotExist() throws Exception {
77+
// given
78+
Long recruitBoardId = 1L;
79+
UUID volunteerId = UUID.randomUUID();
80+
81+
given(volunteerApplyQueryUseCase.getVolunteerApplyByRecruitIdAndVolunteerId(recruitBoardId,
82+
volunteerId))
83+
.willThrow(new NoSuchElementException(NOT_EXISTS_VOLUNTEER_APPLY));
84+
85+
// when & then
86+
mockMvc.perform(
87+
get("/api/volunteer-apply/recruit-board/{recruitBoardId}/volunteer/{volunteerId}",
88+
recruitBoardId, volunteerId)
89+
.accept(APPLICATION_JSON))
90+
.andExpect(status().isOk())
91+
.andExpect(jsonPath("$.code").value(210))
92+
.andExpect(jsonPath("$.message").value("지원 내역이 없습니다."));
93+
}
94+
7195
@DisplayName("모집글 지원자 통계 조회 성공 테스트")
7296
@Test
7397
void getSummaryByRecruitBoardId() throws Exception {

0 commit comments

Comments
 (0)