-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from PLADI-ALM/feat/PDS-73-getBookings
[PDS-73/feat] 예약 목록 조회(자원) API
- Loading branch information
Showing
6 changed files
with
91 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 21 additions & 9 deletions
30
src/main/java/com/example/pladialmserver/booking/dto/response/BookingRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,49 @@ | ||
package com.example.pladialmserver.booking.dto.response; | ||
|
||
import com.example.pladialmserver.booking.entity.OfficeBooking; | ||
import com.example.pladialmserver.booking.entity.ResourceBooking; | ||
import com.example.pladialmserver.global.utils.DateTimeUtil; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import static com.example.pladialmserver.global.Constants.DATE_TIME_PATTERN; | ||
|
||
@Getter | ||
@Builder | ||
public class BookingRes { | ||
|
||
@Schema(type = "Long", description = "회의실 Id / 자원 Id", example = "1") | ||
private Long id; | ||
@Schema(type = "String", description = "회의실명 / 자원명", example = "'회의실1' / '카메라1'") | ||
private String name; | ||
private String location; | ||
@Schema(type = "String", description = "회의실 위치 / 카테고리", example = "'401호' / '촬영장비'") | ||
private String detailInfo; | ||
@Schema(type = "String", description = "예약일자(시작일)", example = "'2023-10-01 12:00' / '2023-10-01'") | ||
private String startDateTime; | ||
@Schema(type = "String", description = "예약일자(종료일)", example = "'2023-10-01 13:00' / '2023-10-03'") | ||
private String endDateTime; | ||
@Schema(type = "String", description = "상태", example = "'예약대기' / '예약중' / '사용중' / '사용완료' / '예약취소'") | ||
private String status; | ||
|
||
public static BookingRes toDto(OfficeBooking officeBooking) { | ||
return BookingRes.builder() | ||
.id(officeBooking.getOfficeBookingId()) | ||
.name(officeBooking.getOffice().getName()) | ||
.location(officeBooking.getOffice().getLocation()) | ||
.detailInfo(officeBooking.getOffice().getLocation()) | ||
.startDateTime(DateTimeUtil.dateAndTimeToString(officeBooking.getDate(), officeBooking.getStartTime())) | ||
.endDateTime(DateTimeUtil.dateAndTimeToString(officeBooking.getDate(), officeBooking.getEndTime())) | ||
.status(officeBooking.getStatus().getValue()) | ||
.build(); | ||
} | ||
|
||
public static BookingRes toDto(ResourceBooking resourceBooking) { | ||
return BookingRes.builder() | ||
.id(resourceBooking.getResourceBookingId()) | ||
.name(resourceBooking.getResource().getName()) | ||
.detailInfo(resourceBooking.getResource().getCategory().getValue()) | ||
.startDateTime(DateTimeUtil.dateToString(resourceBooking.getStartDate())) | ||
.endDateTime(DateTimeUtil.dateToString(resourceBooking.getEndDate())) | ||
.status(resourceBooking.getStatus().getValue()) | ||
.build(); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
.../com/example/pladialmserver/booking/repository/resourceBooking/ResourceBookingCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.example.pladialmserver.booking.repository.resourceBooking; | ||
|
||
import com.example.pladialmserver.booking.dto.response.BookingRes; | ||
import com.example.pladialmserver.user.entity.User; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface ResourceBookingCustom { | ||
Page<BookingRes> getBookingsByUser(User user, Pageable pageable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...mple/pladialmserver/booking/repository/resourceBooking/ResourceBookingRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.pladialmserver.booking.repository.resourceBooking; | ||
|
||
import com.example.pladialmserver.booking.dto.response.BookingRes; | ||
import com.example.pladialmserver.booking.entity.ResourceBooking; | ||
import com.example.pladialmserver.user.entity.User; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.example.pladialmserver.booking.entity.QResourceBooking.resourceBooking; | ||
|
||
|
||
@RequiredArgsConstructor | ||
public class ResourceBookingRepositoryImpl implements ResourceBookingCustom{ | ||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public Page<BookingRes> getBookingsByUser(User user, Pageable pageable) { | ||
List<ResourceBooking> bookings = jpaQueryFactory.selectFrom(resourceBooking) | ||
.where(resourceBooking.user.eq(user) | ||
.and(resourceBooking.isEnable.eq(true))) | ||
.orderBy(resourceBooking.createdAt.desc()) | ||
.fetch(); | ||
|
||
List<BookingRes> res = bookings.stream() | ||
.map(BookingRes::toDto) | ||
.collect(Collectors.toList()); | ||
|
||
int start = (int) pageable.getOffset(); | ||
int end = Math.min((start + pageable.getPageSize()), res.size()); | ||
return new PageImpl<>(res.subList(start, end), pageable, res.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters