Skip to content

Commit

Permalink
Merge pull request #36 from PLADI-ALM/feat/PDS-76-returnResource
Browse files Browse the repository at this point in the history
[PDS-76/feat] 자원 예약 반납 API
  • Loading branch information
psyeon1120 authored Oct 3, 2023
2 parents 13451e3 + 4b61515 commit ae3fa8a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ public ResponseCustom cancelBookingOffice(

//////////////////////////////////////////////////////////////////////////////////////////

/**
* 자원 예약 반납
*/
@Operation(summary = "자원 예약 반납", description = "자원 예약을 반납한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)자원 에약 취소 성공", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "403", description = "(G0002)접근권한이 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(B0006)존재하지 않는 예약입니다. (U0001)사용자를 찾을 수 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "409", description = "(B0007)이미 취소된 예약입니다. (B0008)이미 사용이 완료된 예약입니다. (B0009)사용중인 상태에서만 반납이 가능합니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class)))
})
@PatchMapping("/resources/{resourceBookingId}")
public ResponseCustom returnBookingResource(
@Parameter(description = "(Long) 자원 예약 Id", example = "1") @PathVariable(name = "resourceBookingId") Long resourceBookingId
){
bookingService.returnBookingResource(resourceBookingId);
return ResponseCustom.OK();
}


/**
* 자원 예약 취소
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ public class ResourceBooking {
public void cancelBookingResource() {
status = BookingStatus.CANCELED;
}

public void returnBookingResource() { status = BookingStatus.FINISHED; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,21 @@ public void cancelBookingResource(Long resourceBookingId) {
resourceBooking.cancelBookingResource();
resourceBookingRepository.save(resourceBooking);
}

@Transactional
public void returnBookingResource(Long resourceBookingId) {
User user = userRepository.findById(1L)
.orElseThrow(() -> new BaseException(BaseResponseCode.USER_NOT_FOUND));
ResourceBooking resourceBooking = resourceBookingRepository.findById(resourceBookingId)
.orElseThrow(() -> new BaseException(BaseResponseCode.BOOKING_NOT_FOUND));

// 사용자가 예약한 경우가 아니면
if(!resourceBooking.getUser().equals(user)) throw new BaseException(BaseResponseCode.NO_ATUTHENTIFICATION);
// 사용중 아니라면 -> 사용중 상태에서만 반납이 가능함
if(!resourceBooking.getStatus().equals(BookingStatus.USING)) throw new BaseException(BaseResponseCode.MUST_BE_IN_USE);

// 예약 반납
resourceBooking.returnBookingResource();
resourceBookingRepository.save(resourceBooking);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum BaseResponseCode {
BOOKING_NOT_FOUND("B0006", HttpStatus.NOT_FOUND, "존재하지 않는 예약입니다."),
ALREADY_CANCELED_BOOKING("B0007", HttpStatus.CONFLICT, "이미 취소된 예약입니다."),
ALREADY_FINISHED_BOOKING("B0008", HttpStatus.CONFLICT, "이미 사용이 완료된 예약입니다."),
MUST_BE_IN_USE("B0009", HttpStatus.CONFLICT, "사용중인 상태에서만 반납이 가능합니다."),

// Office
OFFICE_NOT_FOUND("O0001", HttpStatus.NOT_FOUND, "존재하지 않는 회의실입니다."),
Expand Down

0 comments on commit ae3fa8a

Please sign in to comment.