Skip to content

Commit

Permalink
Refactor. BookingOverviewResposne 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Miensoap committed Jun 24, 2024
1 parent 31337ee commit 3aaca32
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
import team07.airbnb.common.auth.aop.Authenticated;
import team07.airbnb.data.booking.dto.response.BookingConfirmedResponse;
import team07.airbnb.data.booking.dto.response.BookingDetailResponse;
import team07.airbnb.data.booking.dto.response.BookingOverviewResponse;
import team07.airbnb.data.booking.enums.CheckAuthType;
import team07.airbnb.entity.UserEntity;
import team07.airbnb.service.booking.BookingAuthService;
import team07.airbnb.service.booking.BookingInquiryService;
import team07.airbnb.service.booking.BookingManageService;
import team07.airbnb.service.user.UserService;

import java.util.List;

import static org.springframework.http.HttpStatus.OK;
import static team07.airbnb.data.user.enums.Role.HOST;

Expand Down Expand Up @@ -64,9 +63,9 @@ public void completeBooking(@PathVariable Long bookingId,
@Authenticated(HOST)
@GetMapping("/management")
@ResponseStatus(OK)
public List<BookingDetailResponse> getBookingInfosOfHosting(
public BookingOverviewResponse getBookingInfosOfHosting(
@Parameter(hidden = true) UserEntity host) {
return bookingInquiryService.getBookingInfoListByHost(host);
return BookingOverviewResponse.of(bookingInquiryService.getBookingInfoListByHost(host));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public static BookingDetailResponse of(BookingEntity booking) {
booking.getPayment()
);
}

public Integer price(){
return payment.getTotalPrice();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team07.airbnb.data.booking.dto.response;

import java.util.List;

public record BookingOverviewResponse(
List<BookingDetailResponse> bookings,
Integer totalIncome
) {

public static BookingOverviewResponse of(List<BookingDetailResponse> bookings) {
return new BookingOverviewResponse(
bookings,
bookings.stream()
.mapToInt(BookingDetailResponse::price)
.sum()
);
}
}

0 comments on commit 3aaca32

Please sign in to comment.