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

SAPHY-181 feat: 기기 상세 정보 이미지 에러 해결 #99

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion src/main/java/saphy/saphy/item/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
Expand Down Expand Up @@ -62,7 +64,8 @@ public class Item extends BaseEntity {
@OneToMany(mappedBy = "item", cascade = CascadeType.ALL)
private List<ItemImage> images = new ArrayList<>();

@OneToOne(mappedBy = "item", cascade = CascadeType.ALL)
@OneToOne(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name = "item_description_image_id")
private ItemDescriptionImage itemDescriptionImage;

public boolean canOrder() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package saphy.saphy.item.domain.repository;

import java.util.Optional;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import saphy.saphy.item.domain.Item;
import saphy.saphy.item.domain.enumeration.DeviceType;
import saphy.saphy.item.domain.repository.custom.ItemQueryDslRepository;

public interface ItemRepository<T extends Item> extends JpaRepository<T, Long>, ItemQueryDslRepository {
Slice<T> findByDeviceType(DeviceType deviceType, Pageable pageable);

@Query("SELECT i FROM Item i LEFT JOIN FETCH i.itemDescriptionImage WHERE i.id = :itemId")
Optional<T> findWithImagesById(@Param("itemId") Long itemId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package saphy.saphy.item.domain.repository.custom;

import static org.springframework.util.StringUtils.*;
import static saphy.saphy.image.domain.QItemDescriptionImage.*;
import static saphy.saphy.item.domain.QItem.*;

import java.util.ArrayList;
Expand Down Expand Up @@ -34,6 +35,7 @@ public Slice<Item> findByDeviceTypeAndSortType(SearchParam searchParam, Pageable

JPAQuery<Item> basicQuery = queryFactory
.selectFrom(item)
.leftJoin(item.itemDescriptionImage, itemDescriptionImage).fetchJoin()
.where(
titleContains(searchParam.getQuery()),
descriptionContains(searchParam.getQuery()),
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/saphy/saphy/item/dto/response/ItemResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class ItemResponse {

protected List<ImageResponse> images;

protected ImageResponse descriptionImage;

public ItemResponse(Item item) {
this.id = item.getId();
this.deviceType = item.getDeviceType().getName();
Expand All @@ -40,7 +38,6 @@ public ItemResponse(Item item) {
this.images = item.getImages().stream()
.map(itemImage -> ImageResponse.from(itemImage.getImage()))
.toList();
this.descriptionImage = ImageResponse.from(item.getItemDescriptionImage().getImage());
}

public static ItemResponse from(Item item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import saphy.saphy.image.domain.Image;
import saphy.saphy.image.dto.response.ImageResponse;
import saphy.saphy.item.domain.Item;
import saphy.saphy.item.domain.Laptop;
Expand All @@ -24,6 +25,8 @@ public class LaptopResponse extends ItemResponse {

private String grade;

private ImageResponse descriptionImage;

public static LaptopResponse from(Item item) {
LaptopResponse response = new LaptopResponse();

Expand All @@ -44,6 +47,7 @@ public static LaptopResponse from(Item item) {
response.images = item.getImages().stream()
.map(itemImage -> ImageResponse.from(itemImage.getImage()))
.toList();
response.descriptionImage = ImageResponse.from(Image.of("1", "1", "https://www.frisbeekorea.com/webfile/webedit/202409/20240910174241_w32uchi6j2.jpg"));

return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import saphy.saphy.image.domain.Image;
import saphy.saphy.image.dto.response.ImageResponse;
import saphy.saphy.item.domain.Item;
import saphy.saphy.item.domain.Phone;
Expand All @@ -18,6 +19,8 @@ public class PhoneResponse extends ItemResponse {

private String grade;

protected ImageResponse descriptionImage;

public static PhoneResponse from(Item item) {
PhoneResponse response = new PhoneResponse();

Expand All @@ -35,6 +38,7 @@ public static PhoneResponse from(Item item) {
response.images = item.getImages().stream()
.map(itemImage -> ImageResponse.from(itemImage.getImage()))
.toList();
response.descriptionImage = ImageResponse.from(Image.of("1", "1", "https://www.frisbeekorea.com/webfile/webedit/202409/20240910174241_w32uchi6j2.jpg"));

return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import saphy.saphy.image.domain.Image;
import saphy.saphy.image.dto.response.ImageResponse;
import saphy.saphy.item.domain.Item;
import saphy.saphy.item.domain.Tablet;
Expand All @@ -18,6 +19,8 @@ public class TabletResponse extends ItemResponse{

private String grade;

private ImageResponse descriptionImage;

public static TabletResponse from(Item item) {
TabletResponse response = new TabletResponse();

Expand All @@ -35,6 +38,9 @@ public static TabletResponse from(Item item) {
response.images = item.getImages().stream()
.map(itemImage -> ImageResponse.from(itemImage.getImage()))
.toList();
response.descriptionImage = ImageResponse.from(
Image.of("1", "1", "https://www.frisbeekorea.com/webfile/webedit/202409/20240910174241_w32uchi6j2.jpg"));


return response;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/saphy/saphy/item/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ItemService {
*/
// deviceType 에 따라 각기 다른 응답을 반환하지만, 최종 반환형은 ItemResponse 로 통일. 이후 다시 자식 클래스로 형변환하여 자세한 정보를 전달
public ItemResponse findById(Long itemId) {
Item item = itemRepository.findById(itemId)
Item item = itemRepository.findWithImagesById(itemId)
.orElseThrow(() -> SaphyException.from(ErrorCode.ITEM_NOT_FOUND));

return item.getDeviceType().mapResponse(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public static MemberDetailResponse toDto(Member member) {
.nickName(member.getNickName())
.phoneNumber(member.getPhoneNumber())
.email(member.getEmail())
.address(member.getAddress().getAddress())
.detailAddress(member.getAddress().getDetailAddress())
.bankName(member.getAccount().getBankName())
.accountNumber(member.getAccount().getAccountNumber())
.build();
}
}
Loading