Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: erd 변경과 코드 수정 #227

Merged
merged 21 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
42f3e51
refactor: address 테이블 삭제 후 accommodation에 병합 - 비즈니스, 테스트 모두 빌드 테스트 통과
decten Feb 1, 2024
c33045c
refactor: roomStock 양방향 관계 삭제
decten Feb 1, 2024
19816fb
refactor: accommodation과 accommodationOption의 일대일 유지 & 외래키 관계 변경
decten Feb 1, 2024
563eb66
test: accommodation과 accommodationOption의 관계 변경에 따른 테스트 코드 수정 및 빌드 확인 완료
decten Feb 2, 2024
c68250b
refactor: room과 roomOption의 일대일 유지 & 외래키 관계 변경
decten Feb 2, 2024
8d67345
refactor: room 처럼 accommodation도 option을 dto가 아닌 entity로 받도록 수정
decten Feb 2, 2024
0bcc313
refactor: 다른 도메인에서는 RoomQueryService 아닌 RoomQueryUseCase 사용 하도록 변경
decten Feb 2, 2024
583767c
test: room과 roomOption 관계 변경에 따른 테스트 코드 수정 및 빌드 확인 완료
decten Feb 2, 2024
fc099a6
refactor: room과 roomPrice의 일대일 유지 & 외래키 관계 변경
decten Feb 2, 2024
7b6fa40
fix: CouponService와 RoomQueryService(RoomQueryUseCase)의 순환 참조 해결 하기 위…
decten Feb 2, 2024
6d1e0cc
test: room과 roomPrice 관계 변경에 따른 테스트 코드 수정 및 빌드 확인 완료
decten Feb 3, 2024
86de510
refactor: Accommodation과 이미지 양방향 연관 관계 삭제
decten Feb 3, 2024
06c16fb
test: Accommodation과 Image 양방향 삭제에 따른 테스트 코드 수정 및 빌드 확인 완료
decten Feb 3, 2024
ae58020
refactor: Room과 Image 양방향 연관 관계 삭제
decten Feb 3, 2024
b59f91a
feat: room에 해당 하는 모든 이미지 DB에서 삭제 하는 메서드 추가
decten Feb 3, 2024
934d742
test: Room과 Image 양방향 삭제에 따른 테스트 코드 수정 및 빌드 확인 완료
decten Feb 3, 2024
40d79aa
other: 주석 처리한 redis 다시 복원
decten Feb 4, 2024
a935a31
fix: 숙소 식별자는 받지 않도록 DTO 수정
JeongUijeong Feb 5, 2024
9d1d12d
refactor: 추가 에러코드는 순차적으로 작성하도록 수정
JeongUijeong Feb 5, 2024
7f3a949
test: 테스트에서도 숙소 옵션 DTO에서 숙소 식별자를 받지 않도록 수정
JeongUijeong Feb 5, 2024
9b62002
refactor: roomPrice 쿼리 중복 제거
chaewon12 Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.backoffice.upjuyanolja.domain.accommodation.dto.request;

import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation;
import com.backoffice.upjuyanolja.domain.accommodation.entity.AccommodationOption;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

@Builder
public record AccommodationOptionRequest(

@NotNull(message = "숙소 ID를 입력하세요.")
Long AccommodationId,
JeongUijeong marked this conversation as resolved.
Show resolved Hide resolved

@NotNull(message = "객실 내 취사 여부를 입력하세요.")
boolean cooking,

Expand Down Expand Up @@ -34,8 +39,12 @@ public record AccommodationOptionRequest(
boolean seminar
) {

public static AccommodationOption toEntity(AccommodationOptionRequest request) {
public static AccommodationOption toEntity(
AccommodationOptionRequest request,
Accommodation accommodation
) {
return AccommodationOption.builder()
.accommodation(accommodation)
.cooking(request.cooking)
.parking(request.parking)
.pickup(request.pickup)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.backoffice.upjuyanolja.domain.accommodation.dto.request;

import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation;
import com.backoffice.upjuyanolja.domain.accommodation.entity.Address;
import com.backoffice.upjuyanolja.domain.accommodation.entity.Category;
import com.backoffice.upjuyanolja.domain.room.dto.request.RoomRegisterRequest;
import jakarta.validation.constraints.NotBlank;
Expand Down Expand Up @@ -51,16 +50,12 @@ public static Accommodation toEntity(
) {
return Accommodation.builder()
.name(request.name())
.address(Address.builder()
.address(request.address())
.detailAddress(request.detailAddress())
.zipCode(request.zipCode())
.build())
.address(request.address())
.detailAddress(request.detailAddress())
.zipCode(request.zipCode())
.category(category)
.description(request.description())
.thumbnail(request.thumbnail())
.images(new ArrayList<>())
.option(AccommodationOptionRequest.toEntity(request.option()))
.rooms(new ArrayList<>())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.backoffice.upjuyanolja.domain.accommodation.dto.response;

import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation;
import com.backoffice.upjuyanolja.domain.accommodation.entity.AccommodationOption;
import com.backoffice.upjuyanolja.domain.room.dto.response.RoomResponse;
import java.util.List;
import lombok.Builder;
Expand All @@ -19,26 +20,21 @@ public record AccommodationDetailResponse(
) {

public static AccommodationDetailResponse of(
Accommodation accommodation, String mainCoupon, List<RoomResponse> rooms
Accommodation accommodation, String mainCoupon, AccommodationOption option,
List<String> images, List<RoomResponse> rooms
) {
return AccommodationDetailResponse.builder()
.id(accommodation.getId())
.name(accommodation.getName())
.address(
accommodation.getAddress().getAddress() + "\n"
+ accommodation.getAddress().getDetailAddress()
accommodation.getAddress() + "\n"
+ accommodation.getDetailAddress()
)
.description(accommodation.getDescription())
.category(accommodation.getCategory().getName())
.mainCoupon(mainCoupon)
.images(
accommodation.getImages().stream()
.map(image -> image.getUrl())
.toList()
)
.option(
AccommodationOptionResponse.of(accommodation.getOption())
)
.option(AccommodationOptionResponse.of(option))
.images(images)
.rooms(rooms)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.backoffice.upjuyanolja.domain.accommodation.dto.response;

import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation;
import com.backoffice.upjuyanolja.domain.accommodation.entity.AccommodationImage;
import com.backoffice.upjuyanolja.domain.accommodation.entity.AccommodationOption;
import com.backoffice.upjuyanolja.domain.room.dto.response.RoomInfoResponse;
import java.util.ArrayList;
import java.util.List;
import lombok.Builder;

Expand All @@ -18,19 +19,20 @@ public record AccommodationInfoResponse(
List<RoomInfoResponse> rooms
) {

public static AccommodationInfoResponse of(Accommodation accommodation) {
List<RoomInfoResponse> rooms = new ArrayList<>();
accommodation.getRooms().forEach(room -> rooms.add(RoomInfoResponse.of(room)));
public static AccommodationInfoResponse of(
Accommodation accommodation, AccommodationOption option, List<AccommodationImage> images,
List<RoomInfoResponse> rooms
) {
return AccommodationInfoResponse.builder()
.accommodationId(accommodation.getId())
.name(accommodation.getName())
.category(accommodation.getCategory().getName())
.description(accommodation.getDescription())
.address(accommodation.getAddress().getAddress()
.address(accommodation.getAddress()
+ " "
+ accommodation.getAddress().getDetailAddress())
.images(AccommodationImageResponse.of(accommodation.getImages()))
.option(AccommodationOptionResponse.of(accommodation.getOption()))
+ accommodation.getDetailAddress())
.option(AccommodationOptionResponse.of(option))
.images(AccommodationImageResponse.of(images))
.rooms(rooms)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static AccommodationSummaryResponse of(
return AccommodationSummaryResponse.builder()
.id(accommodation.getId())
.name(accommodation.getName())
.address(accommodation.getAddress().getAddress())
.address(accommodation.getAddress())
.category(accommodation.getCategory().getName())
.lowestPrice(lowestPrice)
.discountPrice(discountPrice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -36,15 +35,6 @@ public class Accommodation extends BaseTime {
@Comment("숙소 이름")
private String name;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@Comment("숙소 위치")
private Address address;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
@Comment("숙소 카테고리")
private Category category;

@Column(columnDefinition = "TEXT", nullable = false)
@Comment("숙소 설명")
private String description;
Expand All @@ -53,12 +43,22 @@ public class Accommodation extends BaseTime {
@Comment("숙소 대표 이미지 URL")
private String thumbnail;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@Comment("숙소 옵션 식별자")
private AccommodationOption option;
@Column(nullable = false)
@Comment("주소")
private String address;

@OneToMany(mappedBy = "accommodation", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<AccommodationImage> images = new ArrayList<>();
@Column(nullable = false)
@Comment("상세 주소")
private String detailAddress;

@Column(nullable = false)
@Comment("우편번호")
private String zipCode;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
@Comment("숙소 카테고리")
private Category category;

@OneToMany(mappedBy = "accommodation", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<Room> rooms = new ArrayList<>();
Expand All @@ -67,26 +67,25 @@ public class Accommodation extends BaseTime {
public Accommodation(
Long id,
String name,
Address address,
String address,
String detailAddress,
String zipCode,
Category category,
String description,
String thumbnail,
AccommodationOption option,
List<AccommodationImage> images,
List<Room> rooms
) {
this.id = id;
this.name = name;
this.address = address;
this.detailAddress = detailAddress;
this.zipCode = zipCode;
this.category = category;
this.description = description;
this.thumbnail = thumbnail;
this.option = option;
this.images = images;
this.rooms = rooms;
}

// 숙소의 ID로 동등 비교를 하기 위해 추가함.
@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.backoffice.upjuyanolja.domain.accommodation.entity;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -21,6 +24,10 @@ public class AccommodationOption {
@Comment("숙소 옵션 식별자")
private Long id;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@Comment("숙소 식별자")
private Accommodation accommodation;

@Column(nullable = false)
@Comment("객실 내 취사 여부")
private boolean cooking;
Expand Down Expand Up @@ -60,6 +67,7 @@ public class AccommodationOption {
@Builder
public AccommodationOption(
Long id,
Accommodation accommodation,
boolean cooking,
boolean parking,
boolean pickup,
Expand All @@ -71,6 +79,7 @@ public AccommodationOption(
boolean seminar
) {
this.id = id;
this.accommodation = accommodation;
this.cooking = cooking;
this.parking = parking;
this.pickup = pickup;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.backoffice.upjuyanolja.domain.accommodation.exception;

import com.backoffice.upjuyanolja.global.exception.ApplicationException;
import com.backoffice.upjuyanolja.global.exception.ErrorCode;

public class AccommodationOptionNotFoundException extends ApplicationException {

public AccommodationOptionNotFoundException() {
super(ErrorCode.ACCOMMODATION_OPTION_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.backoffice.upjuyanolja.domain.accommodation.repository;

import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation;
import com.backoffice.upjuyanolja.domain.accommodation.entity.AccommodationImage;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AccommodationImageRepository extends JpaRepository<AccommodationImage, Long> {

List<AccommodationImage> findByAccommodation(Accommodation accommodation);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.backoffice.upjuyanolja.domain.accommodation.repository;

import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation;
import com.backoffice.upjuyanolja.domain.accommodation.entity.AccommodationOption;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AccommodationOptionRepository extends JpaRepository<AccommodationOption, Long> {

Optional<AccommodationOption> findByAccommodation(Accommodation accommodation);

}
Loading
Loading