Skip to content

Commit

Permalink
Merge pull request #142 from PawWithU/feat/141-application-response-add
Browse files Browse the repository at this point in the history
[Feature] 이동봉사 신청 취소, 승인, 반려, 봉사 완료 API 응답 추가
  • Loading branch information
kyeong-hyeok authored Nov 22, 2023
2 parents d8ee939 + cdfd110 commit 484a967
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public ResponseEntity<ApplicationVolunteerGetOneResponse> getVolunteerOneApplica
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@DeleteMapping( "/volunteers/applications/{applicationId}")
public ResponseEntity<Void> deleteApplication(@AuthenticationPrincipal UserDetails loginUser,
@PathVariable Long applicationId) {
applicationService.deleteApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.noContent().build();
public ResponseEntity<ApplicationSuccessResponse> deleteApplication(@AuthenticationPrincipal UserDetails loginUser,
@PathVariable Long applicationId) {
ApplicationSuccessResponse response = applicationService.deleteApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.ok(response);
}

@Operation(summary = "봉사 관리 - 승인 대기중 - 이동봉사자 확인 - 봉사 신청 확정", description = "이동봉사자의 봉사 신청을 확정합니다.",
Expand All @@ -103,10 +103,10 @@ public ResponseEntity<Void> deleteApplication(@AuthenticationPrincipal UserDetai
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping( "/intermediaries/applications/{applicationId}")
public ResponseEntity<Void> confirmApplication(@AuthenticationPrincipal UserDetails loginUser,
public ResponseEntity<ApplicationSuccessResponse> confirmApplication(@AuthenticationPrincipal UserDetails loginUser,
@PathVariable Long applicationId) {
applicationService.confirmApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.noContent().build();
ApplicationSuccessResponse response = applicationService.confirmApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.ok(response);
}

@Operation(summary = "봉사 관리 - 승인 대기중 - 이동봉사자 확인 - 봉사 신청 반려", description = "이동봉사자의 봉사 신청을 반려합니다.",
Expand All @@ -116,10 +116,10 @@ public ResponseEntity<Void> confirmApplication(@AuthenticationPrincipal UserDeta
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@DeleteMapping( "/intermediaries/applications/{applicationId}")
public ResponseEntity<Void> cancelApplication(@AuthenticationPrincipal UserDetails loginUser,
public ResponseEntity<ApplicationSuccessResponse> cancelApplication(@AuthenticationPrincipal UserDetails loginUser,
@PathVariable Long applicationId) {
applicationService.cancelApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.noContent().build();
ApplicationSuccessResponse response = applicationService.cancelApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.ok(response);
}

@Operation(summary = "봉사 관리 - 승인 대기중 목록 조회", description = "이동봉사 승인 대기중 목록을 조회합니다.",
Expand Down Expand Up @@ -206,9 +206,9 @@ public ResponseEntity<ApplicationVolunteerInfoResponse> getMyInfo(@Authenticatio
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping( "/intermediaries/applications/{applicationId}/completed")
public ResponseEntity<Void> completeApplication(@AuthenticationPrincipal UserDetails loginUser,
public ResponseEntity<ApplicationSuccessResponse> completeApplication(@AuthenticationPrincipal UserDetails loginUser,
@PathVariable Long applicationId) {
applicationService.completeApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.noContent().build();
ApplicationSuccessResponse response = applicationService.completeApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pawwithu.connectdog.domain.application.dto.response;

public record ApplicationSuccessResponse(Boolean isSuccess) {
public static ApplicationSuccessResponse of(Boolean isSuccess) {
return new ApplicationSuccessResponse(isSuccess);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public class ApplicationService {
private final ApplicationRepository applicationRepository;
private final CustomApplicationRepository customApplicationRepository;
private final IntermediaryRepository intermediaryRepository;
private final ReviewRepository reviewRepository;
private final DogStatusRepository dogStatusRepository;

public void volunteerApply(String email, Long postId, VolunteerApplyRequest request) {
// 이동봉사자
Expand Down Expand Up @@ -87,7 +85,7 @@ public ApplicationVolunteerGetOneResponse getVolunteerOneApplication(String emai
return oneApplication;
}

public void deleteApplication(String email, Long applicationId) {
public ApplicationSuccessResponse deleteApplication(String email, Long applicationId) {
// 이동봉사자
Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND));
// 신청 내역 + post
Expand All @@ -96,9 +94,11 @@ public void deleteApplication(String email, Long applicationId) {
// 상태 업데이트 (승인 대기중 -> 모집중)
Post post = application.getPost();
post.updateStatus(PostStatus.RECRUITING);
ApplicationSuccessResponse isSuccess = ApplicationSuccessResponse.of(true);
return isSuccess;
}

public void confirmApplication(String email, Long applicationId) {
public ApplicationSuccessResponse confirmApplication(String email, Long applicationId) {
// 이동봉사 중개
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
// 신청 내역 + post
Expand All @@ -107,9 +107,11 @@ public void confirmApplication(String email, Long applicationId) {
// 상태 업데이트 (승인 대기중 -> 진행중)
application.updateStatus(ApplicationStatus.PROGRESSING);
post.updateStatus(PostStatus.PROGRESSING);
ApplicationSuccessResponse isSuccess = ApplicationSuccessResponse.of(true);
return isSuccess;
}

public void cancelApplication(String email, Long applicationId) {
public ApplicationSuccessResponse cancelApplication(String email, Long applicationId) {
// 이동봉사 중개
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
// 신청 내역 + post
Expand All @@ -118,6 +120,8 @@ public void cancelApplication(String email, Long applicationId) {
// 상태 업데이트 (승인 대기중 -> 모집중)
Post post = application.getPost();
post.updateStatus(PostStatus.RECRUITING);
ApplicationSuccessResponse isSuccess = ApplicationSuccessResponse.of(true);
return isSuccess;
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -170,7 +174,7 @@ public ApplicationVolunteerInfoResponse getMyInfo(String email) {
return volunteerInfo;
}

public void completeApplication(String email, Long applicationId) {
public ApplicationSuccessResponse completeApplication(String email, Long applicationId) {
// 이동봉사 중개
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
// 신청 내역 + post
Expand All @@ -179,5 +183,7 @@ public void completeApplication(String email, Long applicationId) {
// 상태 업데이트 (진행중 -> 봉사 완료)
application.updateStatus(ApplicationStatus.COMPLETED);
post.updateStatus(PostStatus.COMPLETED);
ApplicationSuccessResponse isSuccess = ApplicationSuccessResponse.of(true);
return isSuccess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public List<IntermediaryGetDogStatusesResponse> getIntermediaryDogStatuses(Long
return intermediaryDogStatuses;
}

@Transactional(readOnly = true)
public IntermediaryGetHomeResponse getIntermediaryHome(String email) {
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
Map<PostStatus, Long> countOfPostStatus = customPostRepository.getCountOfPostStatus(intermediary.getId(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,44 +135,50 @@ void setUp() {
void 이동봉사_신청_취소() throws Exception {
//given
Long applicationId = 1L;
ApplicationSuccessResponse response = new ApplicationSuccessResponse(true);

//when
given(applicationService.deleteApplication(anyString(), anyLong())).willReturn(response);
ResultActions result = mockMvc.perform(
delete("/volunteers/applications/{applicationId}", applicationId)
);

//then
result.andExpect(status().isNoContent());
result.andExpect(status().isOk());
verify(applicationService, times(1)).deleteApplication(anyString(), anyLong());
}

@Test
void 이동봉사_신청_승인() throws Exception {
//given
Long applicationId = 1L;
ApplicationSuccessResponse response = new ApplicationSuccessResponse(true);

//when
given(applicationService.confirmApplication(anyString(), anyLong())).willReturn(response);
ResultActions result = mockMvc.perform(
patch("/intermediaries/applications/{applicationId}", applicationId)
);

//then
result.andExpect(status().isNoContent());
result.andExpect(status().isOk());
verify(applicationService, times(1)).confirmApplication(anyString(), anyLong());
}

@Test
void 이동봉사_신청_반려() throws Exception {
//given
Long applicationId = 1L;
ApplicationSuccessResponse response = new ApplicationSuccessResponse(true);

//when
given(applicationService.cancelApplication(anyString(), anyLong())).willReturn(response);
ResultActions result = mockMvc.perform(
delete("/intermediaries/applications/{applicationId}", applicationId)
);

//then
result.andExpect(status().isNoContent());
result.andExpect(status().isOk());
verify(applicationService, times(1)).cancelApplication(anyString(), anyLong());
}

Expand Down Expand Up @@ -306,17 +312,19 @@ void setUp() {
}

@Test
void 이동봉사_완료() throws Exception {
void 이동봉사_완료하기() throws Exception {
//given
Long applicationId = 1L;
ApplicationSuccessResponse response = new ApplicationSuccessResponse(true);

//when
given(applicationService.completeApplication(anyString(), anyLong())).willReturn(response);
ResultActions result = mockMvc.perform(
patch("/intermediaries/applications/{applicationId}/completed", applicationId)
);

//then
result.andExpect(status().isNoContent());
result.andExpect(status().isOk());
verify(applicationService, times(1)).completeApplication(anyString(), anyLong());
}

Expand Down

0 comments on commit 484a967

Please sign in to comment.