Skip to content

Commit

Permalink
feature : 옷 저장, 조회 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmin223 committed Dec 27, 2023
1 parent a92ff05 commit 3ad046e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public class SizeController {

@GetMapping("/")
public List<SizeRes> findByCategory(SizeReq request) {
return sizeService.findByLargeCategory(request);
return sizeService.findByCategory(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import zip.ootd.ootdzip.category.data.CategoryType;
import zip.ootd.ootdzip.category.data.SizeReq;
import zip.ootd.ootdzip.category.data.SizeRes;
import zip.ootd.ootdzip.category.domain.Category;
Expand All @@ -22,14 +21,10 @@ public class SizeService {
private final SizeRepository sizeRepository;
private final CategoryRepository categoryRepository;

public List<SizeRes> findByLargeCategory(SizeReq request) {
public List<SizeRes> findByCategory(SizeReq request) {
Category findCategory = categoryRepository.findById(request.getCategoryId())
.orElseThrow(() -> new IllegalArgumentException("유효하지 않은 카테고리 ID"));

if (!findCategory.getType().equals(CategoryType.LargeCategory)) {
throw new CustomException(ErrorCode.NOT_LARGE_CATEGORY);
}

List<Size> sizes = sizeRepository.findByCategory(findCategory);

if (sizes == null || sizes.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import lombok.Builder;
import lombok.Data;
import zip.ootd.ootdzip.brand.data.BrandDto;
import zip.ootd.ootdzip.category.data.DetailCategory;
import zip.ootd.ootdzip.clothes.domain.Clothes;
import zip.ootd.ootdzip.clothes.domain.ClothesImage;
Expand All @@ -19,7 +20,7 @@ public class FindClothesRes {

private String userName;

private String brandName;
private BrandDto brand;

private Boolean isOpen;

Expand All @@ -42,7 +43,7 @@ public static FindClothesRes createFindClothesRes(Clothes clothes) {
.id(clothes.getId())
.alias(clothes.getAlias())
.userName(clothes.getUser().getName())
.brandName(clothes.getBrand().getName())
.brand(new BrandDto(clothes.getBrand()))
.isOpen(clothes.getIsOpen())
.category(DetailCategory.builder()
.id(clothes.getCategory().getId())
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/zip/ootd/ootdzip/clothes/domain/Clothes.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -49,7 +48,7 @@ public class Clothes extends BaseEntity {
@JoinColumn(name = "category_id", nullable = false)
private Category category;

@OneToOne
@ManyToOne
@JoinColumn(name = "size_id", nullable = false)
private Size size;

Expand All @@ -60,11 +59,11 @@ public class Clothes extends BaseEntity {
private String purchaseDate;

@Builder.Default
@OneToMany(mappedBy = "clothes", fetch = FetchType.LAZY)
@OneToMany(mappedBy = "clothes", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ClothesImage> clothesImages = new ArrayList<>();

@Builder.Default
@OneToMany(mappedBy = "clothes", fetch = FetchType.LAZY)
@OneToMany(mappedBy = "clothes", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ClothesColor> clothesColors = new ArrayList<>();

@Builder.Default
Expand Down

0 comments on commit 3ad046e

Please sign in to comment.