Skip to content

Commit

Permalink
Merge pull request #113 from PawWithU/feat/112-intermediary-completed…
Browse files Browse the repository at this point in the history
…-application-api

[Feature] 이동봉사 중개 봉사 완료 API 구현
  • Loading branch information
kyeong-hyeok authored Nov 19, 2023
2 parents 8df667a + fa69920 commit 12384cc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,17 @@ public ResponseEntity<ApplicationVolunteerInfoResponse> getMyInfo(@Authenticatio
ApplicationVolunteerInfoResponse response = applicationService.getMyInfo(loginUser.getUsername());
return ResponseEntity.ok(response);
}

@Operation(summary = "봉사 관리 - 진행중 - 봉사 완료하기", description = "진행중인 봉사를 완료합니다.",
responses = {@ApiResponse(responseCode = "204", description = "봉사 신청 확정 성공")
, @ApiResponse(responseCode = "400"
, description = "M2, 해당 이동봉사 중개를 찾을 수 없습니다. \t\n AP2, 해당 신청 내역을 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping( "/intermediaries/applications/{applicationId}/completed")
public ResponseEntity<Void> completeApplication(@AuthenticationPrincipal UserDetails loginUser,
@PathVariable Long applicationId) {
applicationService.completeApplication(loginUser.getUsername(), applicationId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.pawwithu.connectdog.domain.application.dto.response.*;
import com.pawwithu.connectdog.domain.application.entity.Application;
import com.pawwithu.connectdog.domain.application.entity.ApplicationStatus;
import org.springframework.data.domain.Pageable;

import java.util.List;
Expand All @@ -12,7 +13,7 @@ public interface CustomApplicationRepository {
List<ApplicationVolunteerWaitingResponse> getVolunteerWaitingApplications(Long volunteerId, Pageable pageable);
List<ApplicationVolunteerProgressingResponse> getVolunteerProgressingApplications(Long volunteerId, Pageable pageable);
Optional<Application> findByIdAndVolunteerIdWithPost(Long applicationId, Long volunteerId);
Optional<Application> findByIdAndIntermediaryIdWithPost(Long applicationId, Long intermediaryId);
Optional<Application> findByIdAndIntermediaryIdAndStatusWithPost(Long applicationId, Long intermediaryId, ApplicationStatus status);
List<ApplicationIntermediaryWaitingResponse> getIntermediaryWaitingApplications(Long intermediaryId, Pageable pageable);
List<ApplicationIntermediaryProgressingResponse> getIntermediaryProgressingApplications(Long intermediaryId, Pageable pageable);
List<ApplicationVolunteerCompletedResponse> getVolunteerCompletedApplications(Long volunteerId, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ public Optional<Application> findByIdAndVolunteerIdWithPost(Long applicationId,
}

@Override
public Optional<Application> findByIdAndIntermediaryIdWithPost(Long applicationId, Long intermediaryId) {
public Optional<Application> findByIdAndIntermediaryIdAndStatusWithPost(Long applicationId, Long intermediaryId, ApplicationStatus status) {
return Optional.ofNullable(queryFactory
.select(application)
.from(application)
.join(application.post, post).fetchJoin()
.where(application.id.eq(applicationId)
.and(application.intermediary.id.eq(intermediaryId))
.and(application.status.eq(ApplicationStatus.WAITING)))
.and(application.status.eq(status)))
.fetchOne());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void confirmApplication(String email, Long applicationId) {
// 이동봉사 중개
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
// 신청 내역 + post
Application application = customApplicationRepository.findByIdAndIntermediaryIdWithPost(applicationId, intermediary.getId()).orElseThrow(() -> new BadRequestException(APPLICATION_NOT_FOUND));
Application application = customApplicationRepository.findByIdAndIntermediaryIdAndStatusWithPost(applicationId, intermediary.getId(), ApplicationStatus.WAITING).orElseThrow(() -> new BadRequestException(APPLICATION_NOT_FOUND));
Post post = application.getPost();
// 상태 업데이트 (승인 대기중 -> 진행중)
application.updateStatus(ApplicationStatus.PROGRESSING);
Expand All @@ -113,7 +113,7 @@ public void cancelApplication(String email, Long applicationId) {
// 이동봉사 중개
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
// 신청 내역 + post
Application application = customApplicationRepository.findByIdAndIntermediaryIdWithPost(applicationId, intermediary.getId()).orElseThrow(() -> new BadRequestException(APPLICATION_NOT_FOUND));
Application application = customApplicationRepository.findByIdAndIntermediaryIdAndStatusWithPost(applicationId, intermediary.getId(), ApplicationStatus.WAITING).orElseThrow(() -> new BadRequestException(APPLICATION_NOT_FOUND));
applicationRepository.delete(application);
// 상태 업데이트 (승인 대기중 -> 모집중)
Post post = application.getPost();
Expand Down Expand Up @@ -162,10 +162,22 @@ public ApplicationIntermediaryGetOneResponse getIntermediaryOneApplication(Strin
return oneApplication;
}

@Transactional(readOnly = true)
public ApplicationVolunteerInfoResponse getMyInfo(String email) {
// 이동봉사자
Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND));
ApplicationVolunteerInfoResponse volunteerInfo = ApplicationVolunteerInfoResponse.of(volunteer.getName(), volunteer.getPhone());
return volunteerInfo;
}

public void completeApplication(String email, Long applicationId) {
// 이동봉사 중개
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
// 신청 내역 + post
Application application = customApplicationRepository.findByIdAndIntermediaryIdAndStatusWithPost(applicationId, intermediary.getId(), ApplicationStatus.PROGRESSING).orElseThrow(() -> new BadRequestException(APPLICATION_NOT_FOUND));
Post post = application.getPost();
// 상태 업데이트 (진행중 -> 봉사 완료)
application.updateStatus(ApplicationStatus.COMPLETED);
post.updateStatus(PostStatus.COMPLETED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,19 @@ void setUp() {
verify(applicationService, times(1)).getMyInfo(anyString());
}

@Test
void 이동봉사_완료() throws Exception {
//given
Long applicationId = 1L;

//when
ResultActions result = mockMvc.perform(
patch("/intermediaries/applications/{applicationId}/completed", applicationId)
);

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

}

0 comments on commit 12384cc

Please sign in to comment.