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
Expand Up @@ -161,4 +161,16 @@ public ResponseEntity<Void> extendPost(@AuthenticationPrincipal UserDetails logi
postService.extendPost(loginUser.getUsername(), postId, request);
return ResponseEntity.noContent().build();
}

@Operation(summary = "봉사 관리 - 모집중 - 봉사 완료하기", description = "모집중인 봉사를 완료합니다.",
responses = {@ApiResponse(responseCode = "204", description = "봉사 완료 처리 성공")
, @ApiResponse(responseCode = "400"
, description = "M2, 해당 이동봉사 중개를 찾을 수 없습니다. \t\n P2, 해당 공고를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping( "/intermediaries/posts/{postId}/completed")
public ResponseEntity<PostCompleteResponse> completePost(@AuthenticationPrincipal UserDetails loginUser, @PathVariable Long postId) {
PostCompleteResponse response = postService.completePost(loginUser.getUsername(), postId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pawwithu.connectdog.domain.post.dto.response;

public record PostCompleteResponse(Boolean isSuccess) {
public static PostCompleteResponse of(Boolean isSuccess) {
return new PostCompleteResponse(isSuccess);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,15 @@ public void extendPost(String email, Long postId, PostExtendRequest request) {
// startDate, endDate, pickUpTime 업데이트 및 공고 상태 모집 마감 -> 모집중 변경
post.extendDate(request.startDate(), request.endDate(), request.isAdjust(), request.pickUpTime());
}

public PostCompleteResponse completePost(String email, Long postId) {
// 이동봉사 중개
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
// 공고
Post post = postRepository.findByIdAndIntermediaryIdAndStatus(postId, intermediary.getId(), PostStatus.RECRUITING).orElseThrow(() -> new BadRequestException(POST_NOT_FOUND));
// 상태 업데이트 (모집중 -> 봉사 완료)
post.updateStatus(PostStatus.COMPLETED);
PostCompleteResponse isSuccess = PostCompleteResponse.of(true);
return isSuccess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ void setUp() {
LocalDate startDate = LocalDate.of(2023, 10, 2);
LocalDate endDate = LocalDate.of(2023, 11, 7);
response.add(new IntermediaryGetPostsResponse(1L, "image1", "잔디1", "서울시 성북구", "서울시 중랑구",
startDate, endDate, "13:00", true, DogSize.MEDIUM.getKey(), true));
startDate, endDate, true, "13:00", DogSize.MEDIUM.getKey(), true));
response.add(new IntermediaryGetPostsResponse(2L, "image1", "잔디2", "서울시 성북구", "서울시 중랑구",
startDate, endDate, "13:00", true, DogSize.MEDIUM.getKey(), true));
startDate, endDate, true, "13:00", DogSize.MEDIUM.getKey(), true));


//when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,22 @@ void setUp() {
result.andExpect(status().isNoContent());
verify(postService, times(1)).extendPost(anyString(), anyLong(), any());
}

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

//when
given(postService.completePost(anyString(), anyLong())).willReturn(response);
ResultActions result = mockMvc.perform(
patch("/intermediaries/posts/{postId}/completed", postId)
);

//then
result.andExpect(status().isOk());
verify(postService, times(1)).completePost(anyString(), anyLong());
}

}
Loading