Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.somemore.domains.volunteerapply.controller;

import static org.springframework.data.domain.Sort.Direction.DESC;

import com.somemore.domains.volunteerapply.domain.ApplyStatus;
import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition;
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto;
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplySummaryResponseDto;
Expand All @@ -10,21 +9,19 @@
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
import com.somemore.global.auth.annotation.CurrentUser;
import com.somemore.global.common.response.ApiResponse;
import com.somemore.global.exception.BadRequestException;
import com.somemore.domains.volunteerapply.domain.ApplyStatus;
import com.somemore.global.exception.NoSuchElementException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

import static org.springframework.data.domain.Sort.Direction.DESC;

@Tag(name = "Volunteer Apply Query API", description = "봉사 활동 지원 조회 API")
@RequiredArgsConstructor
Expand All @@ -48,7 +45,7 @@ public ApiResponse<?> getVolunteerApplyByRecruitIdAndVolunteerId(
recruitBoardId, volunteerId),
"특정 모집글에 대한 봉사자 지원 단건 조회 성공"
);
} catch (BadRequestException e) {
} catch (NoSuchElementException e) {
return ApiResponse.ok(210, "지원 내역이 없습니다.");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
package com.somemore.domains.volunteerapply.controller;

import static com.somemore.domains.volunteerapply.domain.ApplyStatus.WAITING;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition;
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto;
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyResponseDto;
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplySummaryResponseDto;
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto;
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase;
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
import com.somemore.global.exception.NoSuchElementException;
import com.somemore.support.ControllerTestSupport;
import com.somemore.support.annotation.WithMockCustomUser;
import java.util.Collections;
import java.util.UUID;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;

import java.util.Collections;
import java.util.UUID;

import static com.somemore.domains.volunteerapply.domain.ApplyStatus.WAITING;
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class VolunteerApplyQueryApiControllerTest extends ControllerTestSupport {

@MockBean
Expand Down Expand Up @@ -68,6 +71,27 @@ void getVolunteerApplyByRecruitIdAndVolunteerId() throws Exception {
.andExpect(jsonPath("$.data.attended").value(false));
}

@DisplayName("특정 모집글 봉사자 지원 단건 조회 성공 테스트 - 지원 내역이 없는 경우")
@Test
void getVolunteerApplyByRecruitIdAndVolunteerIdWhenDoesNotExist() throws Exception {
// given
Long recruitBoardId = 1L;
UUID volunteerId = UUID.randomUUID();

given(volunteerApplyQueryUseCase.getVolunteerApplyByRecruitIdAndVolunteerId(recruitBoardId,
volunteerId))
.willThrow(new NoSuchElementException(NOT_EXISTS_VOLUNTEER_APPLY));

// when & then
mockMvc.perform(
get("/api/volunteer-apply/recruit-board/{recruitBoardId}/volunteer/{volunteerId}",
recruitBoardId, volunteerId)
.accept(APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(210))
.andExpect(jsonPath("$.message").value("지원 내역이 없습니다."));
}

@DisplayName("모집글 지원자 통계 조회 성공 테스트")
@Test
void getSummaryByRecruitBoardId() throws Exception {
Expand Down
Loading