Skip to content

Commit

Permalink
Merge pull request #93 from PLADI-ALM/feat/PDS-11-facility-add
Browse files Browse the repository at this point in the history
[PDS-11/feat] 회의실 목록 조회 시설 검색 기능 추가
  • Loading branch information
chaerlo127 authored Oct 14, 2023
2 parents 6b7ef3d + 6d577b5 commit ebe62e6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ public interface OfficeBookingRepository extends JpaRepository<OfficeBooking, Lo
@Query("SELECT ob.office.officeId FROM OfficeBooking ob WHERE ob.date = :date AND ((ob.startTime <= :startTime AND ob.endTime > :startTime) OR (ob.startTime < :endTime AND ob.endTime >= :endTime))")
List<Long> findBookedOfficeIdsByDateAndTime(@Param("date") LocalDate date, @Param("startTime") LocalTime startTime, @Param("endTime") LocalTime endTime);
Page<OfficeBooking> findByStatusIn(List<BookingStatus> list, Pageable pageable);
Page<OfficeBooking> findByStatus(BookingStatus status, Pageable pageable);
List<OfficeBooking> findByOfficeAndDateAndStatusNot(Office office, LocalDate date, BookingStatus bookingStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ public ResponseCustom<Page<OfficeRes>> searchOffice(
@Parameter(description = "예약 날짜",example = "2023-09-20") @RequestParam(required = false) @DateTimeFormat(pattern = DATE_PATTERN) LocalDate date,
@Parameter(description = "시작 예약 시간",example = "12:00") @RequestParam(required = false) @DateTimeFormat(pattern = TIME_PATTERN) LocalTime startTime,
@Parameter(description = "종료 예약 시간",example = "13:00") @RequestParam(required = false) @DateTimeFormat(pattern = TIME_PATTERN) LocalTime endTime,
@Parameter(description = "시설",example = "빔 프로젝터")@RequestParam(required = false) String facilityName,
Pageable pageable
) {
// 날짜와 시작 시간 또는 종료 시간 중 하나라도 입력되지 않았다면 에러 반환
if ((date != null && (startTime == null || endTime == null)) ||
(date == null && (startTime != null || endTime != null))) {
throw new BaseException(BaseResponseCode.DATE_OR_TIME_IS_NULL);
}
return ResponseCustom.OK(officeService.findAvailableOffices(date, startTime, endTime,pageable));
return ResponseCustom.OK(officeService.findAvailableOffices(date, startTime, endTime,facilityName,pageable));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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.util.List;
import java.util.Optional;
Expand All @@ -12,5 +14,17 @@ public interface OfficeRepository extends JpaRepository<Office, Long> {
Optional<Office> findByOfficeId(Long officeId);
Page<Office> findAllByOfficeIdNotIn(List<Long> ids, Pageable pageable);
Page<Office> findAll(Pageable pageable);
@Query("SELECT ofc.office " +
"FROM OfficeFacility ofc " +
"WHERE ofc.facility.name = :facilityName")
Page<Office> findByFacilityName(@Param("facilityName") String facilityName, Pageable pageable);

@Query("SELECT ofc.office " +
"FROM OfficeFacility ofc " +
"WHERE ofc.facility.name = :facilityName" +
" AND ofc.office.officeId " +
"NOT IN :bookedOfficeIds")
Page<Office> findByFacilityNameAndOfficeIdNotIn(@Param("facilityName") String facilityName, @Param("bookedOfficeIds") List<Long> bookedOfficeIds, Pageable pageable);


}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class OfficeService {
/**
* 전체 회의실 목록 조회 and 예약 가능한 회의실 목록 조회
*/
public Page<OfficeRes> findAvailableOffices(LocalDate date, LocalTime startTime, LocalTime endTime, Pageable pageable) {
public Page<OfficeRes> findAvailableOffices(LocalDate date, LocalTime startTime, LocalTime endTime, String facilityName,Pageable pageable) {

Page<Office> allOffices;

Expand All @@ -46,12 +46,27 @@ public Page<OfficeRes> findAvailableOffices(LocalDate date, LocalTime startTime,

// 예약된 회의실을 제외한 회의실 목록을 페이징 처리하여 조회
if (!bookedOfficeIds.isEmpty()) {
allOffices = officeRepository.findAllByOfficeIdNotIn(bookedOfficeIds, pageable);
if (facilityName != null && !facilityName.isEmpty()) {
// 시설 이름이 입력되었다면 해당 시설을 포함하는 회의실만 조회
allOffices = officeRepository.findByFacilityNameAndOfficeIdNotIn(facilityName, bookedOfficeIds, pageable);
}else {
allOffices = officeRepository.findAllByOfficeIdNotIn(bookedOfficeIds, pageable);
}
} else {
allOffices = officeRepository.findAll(pageable);
if (facilityName != null && !facilityName.isEmpty()) {
// 시설 이름이 입력되었다면 해당 시설을 포함하는 회의실만 조회
allOffices = officeRepository.findByFacilityName(facilityName, pageable);
}else {
allOffices = officeRepository.findAll(pageable);
}
}
}else{
allOffices = officeRepository.findAll(pageable);
if (facilityName != null && !facilityName.isEmpty()) {
// 시설 이름이 입력되었다면 해당 시설을 포함하는 회의실만 조회
allOffices = officeRepository.findByFacilityName(facilityName, pageable);
}else {
allOffices = officeRepository.findAll(pageable);
}
}

return allOffices.map(office -> {
Expand Down

0 comments on commit ebe62e6

Please sign in to comment.