Skip to content

Commit

Permalink
Merge pull request #35 from PLADI-ALM/feat/PDS-51-cancelBookingResource
Browse files Browse the repository at this point in the history
[PDS-51/feat] 자원 예약 취소 API
  • Loading branch information
chaerlo127 authored Oct 2, 2023
2 parents c9f2d0a + 90c9467 commit 4a38ddb
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,24 @@ public ResponseCustom cancelBookingOffice(
return ResponseCustom.OK();
}

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


/**
* 자원 예약 취소
*/
@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)이미 사용이 완료된 예약입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class)))
})
@PatchMapping("/resources/{resourceBookingId}/cancel")
public ResponseCustom cancelBookingResource(
@Parameter(description = "(Long) 자원 예약 Id", example = "1") @PathVariable(name = "resourceBookingId") Long resourceBookingId
){
bookingService.cancelBookingResource(resourceBookingId);
return ResponseCustom.OK();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ public class ResourceBooking {
@NotNull
private LocalDate endDate;

@NotNull
private LocalDateTime returnDate;

@NotNull
@Size(max = 100)
private String memo;

@Enumerated(EnumType.STRING)
private BookingStatus status = BookingStatus.WAITING;

public void cancelBookingResource() {
status = BookingStatus.CANCELED;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.pladialmserver.booking.repository;
package com.example.pladialmserver.booking.repository.officeBooking;

import com.example.pladialmserver.booking.dto.response.BookingRes;
import com.example.pladialmserver.booking.entity.OfficeBooking;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.pladialmserver.booking.repository;
package com.example.pladialmserver.booking.repository.officeBooking;

import com.example.pladialmserver.booking.entity.OfficeBooking;
import com.example.pladialmserver.office.entity.Office;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.pladialmserver.booking.repository;
package com.example.pladialmserver.booking.repository.officeBooking;

import com.example.pladialmserver.booking.dto.response.BookingRes;
import com.example.pladialmserver.booking.entity.OfficeBooking;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.example.pladialmserver.booking.repository;
package com.example.pladialmserver.booking.repository.resourceBooking;

import com.example.pladialmserver.booking.entity.ResourceBooking;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ResourceBookingRepository extends JpaRepository<ResourceBooking,Long> {
public interface ResourceBookingRepository extends JpaRepository<ResourceBooking, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.example.pladialmserver.booking.dto.response.BookingRes;
import com.example.pladialmserver.booking.dto.response.OfficeBookingDetailRes;
import com.example.pladialmserver.booking.entity.OfficeBooking;
import com.example.pladialmserver.booking.repository.OfficeBookingRepository;
import com.example.pladialmserver.booking.entity.ResourceBooking;
import com.example.pladialmserver.booking.repository.officeBooking.OfficeBookingRepository;
import com.example.pladialmserver.booking.repository.resourceBooking.ResourceBookingRepository;
import com.example.pladialmserver.global.entity.BookingStatus;
import com.example.pladialmserver.global.exception.BaseException;
import com.example.pladialmserver.global.exception.BaseResponseCode;
Expand All @@ -24,6 +26,7 @@
public class BookingService {
private final UserRepository userRepository;
private final OfficeBookingRepository officeBookingRepository;
private final ResourceBookingRepository resourceBookingRepository;

/**
* 예약 목록 조회
Expand Down Expand Up @@ -93,4 +96,26 @@ public void checkBookingTime(){
officeBookingRepository.saveAll(checkSTList);
}

/**
* 자원 예약 취소
*/
@Transactional
public void cancelBookingResource(Long resourceBookingId) {
// todo: 로그인 기능 생성 후 변경 예정
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.CANCELED)) throw new BaseException(BaseResponseCode.ALREADY_CANCELED_BOOKING);
// 취소하려는 예약이 이미 사용이 완료된 경우
if(resourceBooking.getStatus().equals(BookingStatus.FINISHED)) throw new BaseException(BaseResponseCode.ALREADY_FINISHED_BOOKING);

// 예약 취소
resourceBooking.cancelBookingResource();
resourceBookingRepository.save(resourceBooking);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.example.pladialmserver.office.dto.response.BookedTimeRes;
import com.example.pladialmserver.office.dto.response.OfficeRes;
import com.example.pladialmserver.office.entity.*;
import com.example.pladialmserver.booking.repository.OfficeBookingRepository;
import com.example.pladialmserver.booking.repository.officeBooking.OfficeBookingRepository;
import com.example.pladialmserver.office.repository.OfficeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

Expand All @@ -28,6 +25,7 @@ public class Resource {
private String name;

@NotNull
@Enumerated(EnumType.STRING)
private Category category;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.example.pladialmserver.resouce.repository;

import com.example.pladialmserver.resouce.entity.Resource;
import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.pladialmserver.resouce.service;

import com.example.pladialmserver.booking.repository.ResourceBookingRepository;
import com.example.pladialmserver.booking.repository.resourceBooking.ResourceBookingRepository;
import com.example.pladialmserver.resouce.repository.ResourceRepository;
import com.example.pladialmserver.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
Expand Down

0 comments on commit 4a38ddb

Please sign in to comment.