Skip to content

Commit

Permalink
refactor: WishlistListReponse 생성 #11
Browse files Browse the repository at this point in the history
  • Loading branch information
tmdgus717 committed Jun 13, 2024
1 parent a20cf99 commit e406a54
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Wishlist {
@JoinColumn(name = "user_id")
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "accommodation_id")
private Accommodation accommodation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void createWishList(WishlistCreateRequest wishlistCreateRequest) {
userRepository.findById(wishlistCreateRequest.userId())
.orElseThrow(NoSuchElementException::new);


wishlistRepository.save(Wishlist.createWishlist(user, accommodation));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import com.team01.airdnb.accommadation.Accommodation;
import com.team01.airdnb.amenity.Amenity;
import com.team01.airdnb.user.User;
import com.team01.airdnb.amenity.AmenityStatus;
import com.team01.airdnb.wishlist.Wishlist;
import lombok.Getter;
import lombok.Setter;

@Getter
public class WishlistListResponse {
Expand All @@ -21,9 +20,45 @@ public WishlistListResponse(Wishlist wishlist) {
static class WishlistAccommodation{
Long id;
String title;
WishlistAmenity wishlistAmenity;


public WishlistAccommodation(Accommodation accommodation) {
this.id = accommodation.getId();
this.title = accommodation.getTitle();
if(accommodation.getAmenity() == null){
this.wishlistAmenity = null;
}
if (accommodation.getAmenity() != null){
this.wishlistAmenity = new WishlistAmenity(accommodation.getAmenity());
}
}
}

@Getter
static class WishlistAmenity {
Integer beds;
Integer bathrooms;
AmenityStatus kitchen;
AmenityStatus dedicated_workspace;
AmenityStatus tv;
AmenityStatus washing_machine;
AmenityStatus air_conditioning;
AmenityStatus wireless_internet;
AmenityStatus free_parking;
AmenityStatus paid_parking;
public WishlistAmenity(Amenity amenity){
this.beds = amenity.getBeds();
this.bathrooms = amenity.getBathrooms();
this.kitchen = amenity.getKitchen();
this.dedicated_workspace = amenity.getDedicatedWorkspace();
this.tv = amenity.getTv();
this.washing_machine = amenity.getWashingMachine();
this.air_conditioning = amenity.getAirConditioner();
this.wireless_internet = amenity.getWirelessInternet();
this.free_parking = amenity.getFreeParking();
this.paid_parking = amenity.getPaidParking();
}
}

}

0 comments on commit e406a54

Please sign in to comment.