Skip to content

Commit

Permalink
Merge pull request #126 from ootd-zip/feature/search-clothes
Browse files Browse the repository at this point in the history
Feature/search clothes
  • Loading branch information
kkmin223 authored Mar 1, 2024
2 parents c8689d3 + 739e2fc commit 9a6b41d
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 174 deletions.
28 changes: 23 additions & 5 deletions src/main/java/zip/ootd/ootdzip/category/data/DetailCategory.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
package zip.ootd.ootdzip.category.data;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import zip.ootd.ootdzip.category.domain.Category;

@Data
@AllArgsConstructor
@Getter
@NoArgsConstructor
@Builder
public class DetailCategory {

private Long id;

private String categoryName;

private Long parentCategoryId;

private String parentCategoryName;

@Builder
private DetailCategory(Long id, String categoryName, Long parentCategoryId, String parentCategoryName) {
this.id = id;
this.categoryName = categoryName;
this.parentCategoryId = parentCategoryId;
this.parentCategoryName = parentCategoryName;
}

public static DetailCategory of(Category category) {
return DetailCategory.builder()
.id(category.getId())
.categoryName(category.getName())
.parentCategoryId(category.getParentCategoryId())
.parentCategoryName(category.getParentCategoryName())
.build();
}

}
16 changes: 16 additions & 0 deletions src/main/java/zip/ootd/ootdzip/category/domain/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@ public static Category createDetailCategoryBy(String name, Category parentCatego
.build();
}

public Long getParentCategoryId() {
if (parentCategory == null) {
return 0L;
}

return parentCategory.getId();
}

public String getParentCategoryName() {
if (parentCategory == null) {
return "";
}

return parentCategory.getName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lombok.RequiredArgsConstructor;
import zip.ootd.ootdzip.clothes.controller.request.FindClothesByUserReq;
import zip.ootd.ootdzip.clothes.controller.request.SaveClothesReq;
import zip.ootd.ootdzip.clothes.controller.request.UpdateClothesIsOpenReq;
import zip.ootd.ootdzip.clothes.controller.request.UpdateClothesIsPrivateReq;
import zip.ootd.ootdzip.clothes.controller.request.UpdateClothesReq;
import zip.ootd.ootdzip.clothes.data.DeleteClothesByIdRes;
import zip.ootd.ootdzip.clothes.data.FindClothesRes;
Expand Down Expand Up @@ -79,11 +79,12 @@ public ApiResponse<SaveClothesRes> updateClothes(

@Operation(summary = "옷 공개여부 수정 API", description = "옷 공개여부 수정")
@PatchMapping("/{id}")
public ApiResponse<SaveClothesRes> updateClothesIsOpen(
public ApiResponse<SaveClothesRes> updateClothesIsPrivate(
@PathVariable(name = "id") @Positive(message = "옷 ID는 양수여야 합니다.") Long id,
@RequestBody @Valid UpdateClothesIsOpenReq request) {
@RequestBody @Valid UpdateClothesIsPrivateReq request) {
return new ApiResponse<>(
clothesService.updateClothesIsOpen(request.toServiceRequest(id), userService.getAuthenticatiedUser()));
clothesService.updateClothesIsPrivate(request.toServiceRequest(id),
userService.getAuthenticatiedUser()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SaveClothesReq {
private List<@Positive(message = "색 ID는 양수여야 합니다.") Long> colorIds;

@NotNull(message = "공개여부는 필수입니다.")
private Boolean isOpen;
private Boolean isPrivate;

@Positive(message = "사이즈 ID는 양수여야 합니다.")
private Long sizeId;
Expand All @@ -52,14 +52,14 @@ public class SaveClothesReq {

@Builder
public SaveClothesReq(String purchaseStore, PurchaseStoreType purchaseStoreType, Long brandId, Long categoryId,
List<Long> colorIds, Boolean isOpen, Long sizeId, String clothesImageUrl, String name, String memo,
List<Long> colorIds, Boolean isPrivate, Long sizeId, String clothesImageUrl, String name, String memo,
String purchaseDate) {
this.purchaseStore = purchaseStore;
this.purchaseStoreType = purchaseStoreType;
this.brandId = brandId;
this.categoryId = categoryId;
this.colorIds = colorIds;
this.isOpen = isOpen;
this.isPrivate = isPrivate;
this.sizeId = sizeId;
this.clothesImageUrl = clothesImageUrl;
this.name = name;
Expand All @@ -74,7 +74,7 @@ public SaveClothesSvcReq toServiceRequest() {
.brandId(this.brandId)
.categoryId(this.categoryId)
.colorIds(this.colorIds)
.isOpen(this.isOpen)
.isPrivate(this.isPrivate)
.sizeId(this.sizeId)
.clothesImageUrl(this.clothesImageUrl)
.memo(this.memo)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package zip.ootd.ootdzip.clothes.controller.request;

import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import zip.ootd.ootdzip.clothes.service.request.UpdateClothesIsPrivateSvcReq;

@Getter
@NoArgsConstructor
public class UpdateClothesIsPrivateReq {

@NotNull(message = "공개여부는 필수입니다.")
private Boolean isPrivate;

@Builder
private UpdateClothesIsPrivateReq(Boolean isPrivate) {
this.isPrivate = isPrivate;
}

public UpdateClothesIsPrivateSvcReq toServiceRequest(Long clothesId) {
return UpdateClothesIsPrivateSvcReq.builder()
.clothesId(clothesId)
.isPrivate(this.isPrivate)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class UpdateClothesReq {
private List<@Positive(message = "색 ID는 양수여야 합니다.") Long> colorIds;

@NotNull(message = "공개여부는 필수입니다.")
private Boolean isOpen;
private Boolean isPrivate;

@Positive(message = "사이즈 ID는 양수여야 합니다.")
private Long sizeId;
Expand All @@ -52,14 +52,14 @@ public class UpdateClothesReq {

@Builder
private UpdateClothesReq(String purchaseStore, PurchaseStoreType purchaseStoreType, Long brandId, Long categoryId,
List<Long> colorIds, Boolean isOpen, Long sizeId, String clothesImageUrl, String memo, String name,
List<Long> colorIds, Boolean isPrivate, Long sizeId, String clothesImageUrl, String memo, String name,
String purchaseDate) {
this.purchaseStore = purchaseStore;
this.purchaseStoreType = purchaseStoreType;
this.brandId = brandId;
this.categoryId = categoryId;
this.colorIds = colorIds;
this.isOpen = isOpen;
this.isPrivate = isPrivate;
this.sizeId = sizeId;
this.clothesImageUrl = clothesImageUrl;
this.memo = memo;
Expand All @@ -75,7 +75,7 @@ public UpdateClothesSvcReq toServiceRequest(Long clothesId) {
.brandId(this.brandId)
.categoryId(this.categoryId)
.colorIds(this.colorIds)
.isOpen(this.isOpen)
.isPrivate(this.isPrivate)
.sizeId(this.sizeId)
.clothesImageUrl(this.clothesImageUrl)
.memo(this.memo)
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/zip/ootd/ootdzip/clothes/data/ClothesColorDto.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
package zip.ootd.ootdzip.clothes.data;

import java.util.List;
import java.util.stream.Collectors;

import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import zip.ootd.ootdzip.clothes.domain.ClothesColor;

@Data
@Builder
@NoArgsConstructor
public class ClothesColorDto {

private Long id;

private String colorCode;

private String name;

@Builder
private ClothesColorDto(Long id, String colorCode, String name) {
this.id = id;
this.colorCode = colorCode;
this.name = name;
}

public static ClothesColorDto createClothesColorDtoBy(ClothesColor clothesColor) {
return ClothesColorDto.builder()
.id(clothesColor.getId())
.id(clothesColor.getColor().getId())
.colorCode(clothesColor.getColor().getColorCode())
.name(clothesColor.getColor().getName())
.build();
}

public static List<ClothesColorDto> createClothesColorDtosBy(List<ClothesColor> clothesColors) {
return clothesColors.stream()
.map(ClothesColorDto::createClothesColorDtoBy)
.collect(Collectors.toList());
.toList();
}
}
14 changes: 5 additions & 9 deletions src/main/java/zip/ootd/ootdzip/clothes/data/FindClothesRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FindClothesRes {

private BrandDto brand;

private Boolean isOpen;
private Boolean isPrivate;

private DetailCategory category;

Expand All @@ -46,15 +46,15 @@ public class FindClothesRes {
private LocalDateTime updatedAt;

@Builder
private FindClothesRes(Long id, String name, String userName, BrandDto brand, Boolean isOpen,
private FindClothesRes(Long id, String name, String userName, BrandDto brand, Boolean isPrivate,
DetailCategory category, SizeRes size, String memo, String purchaseStore,
PurchaseStoreType purchaseStoreType, String purchaseDate, List<ClothesColorDto> colors, String imageUrl,
LocalDateTime createdAt, LocalDateTime updatedAt) {
this.id = id;
this.name = name;
this.userName = userName;
this.brand = brand;
this.isOpen = isOpen;
this.isPrivate = isPrivate;
this.category = category;
this.size = size;
this.memo = memo;
Expand All @@ -73,12 +73,8 @@ public static FindClothesRes of(Clothes clothes) {
.name(clothes.getName())
.userName(clothes.getUser().getName())
.brand(BrandDto.of(clothes.getBrand()))
.isOpen(clothes.getIsOpen())
.category(DetailCategory.builder()
.id(clothes.getCategory().getId())
.categoryName(clothes.getCategory().getName())
.parentCategoryName(clothes.getCategory().getParentCategory().getName())
.build())
.isPrivate(clothes.getIsPrivate())
.category(DetailCategory.of(clothes.getCategory()))
.size(SizeRes.of(clothes.getSize()))
.memo(clothes.getMemo())
.purchaseStore(clothes.getPurchaseStore())
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/zip/ootd/ootdzip/clothes/domain/Clothes.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Clothes extends BaseEntity {
private PurchaseStoreType purchaseStoreType;

@Column(nullable = false)
private Boolean isOpen;
private Boolean isPrivate;

@ManyToOne
@JoinColumn(name = "category_id", nullable = false)
Expand Down Expand Up @@ -81,7 +81,7 @@ public static Clothes createClothes(User user,
String purchaseStore,
PurchaseStoreType purchaseStoreType,
String name,
Boolean isOpen,
Boolean isPrivate,
Category category,
Size size,
String memo,
Expand All @@ -95,7 +95,7 @@ public static Clothes createClothes(User user,
.purchaseStore(purchaseStore)
.purchaseStoreType(purchaseStoreType)
.name(name)
.isOpen(isOpen)
.isPrivate(isPrivate)
.category(category)
.size(size)
.memo(memo)
Expand All @@ -113,7 +113,7 @@ public void updateClothes(Brand brand,
String purchaseStore,
PurchaseStoreType purchaseStoreType,
String name,
Boolean isOpen,
Boolean isPrivate,
Category category,
Size size,
String memo,
Expand All @@ -124,7 +124,7 @@ public void updateClothes(Brand brand,
this.purchaseStore = purchaseStore;
this.purchaseStoreType = purchaseStoreType;
this.name = name;
this.isOpen = isOpen;
this.isPrivate = isPrivate;
this.category = category;
this.size = size;
this.memo = memo;
Expand All @@ -151,8 +151,8 @@ public void increaseReportCount() {
this.reportCount += 1;
}

public void updateIsOpen(Boolean isOpen) {
this.isOpen = isOpen;
public void updateIsPrivate(Boolean isPrivate) {
this.isPrivate = isPrivate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ClothesRepository extends JpaRepository<Clothes, Long> {

List<Clothes> findByUser(User user, Pageable pageable);

List<Clothes> findByUserAndIsOpenTrue(User user, Pageable pageable);
List<Clothes> findByUserAndIsPrivateFalse(User user, Pageable pageable);

@Query("SELECT COUNT(c) "
+ "FROM Clothes c "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import zip.ootd.ootdzip.clothes.data.SaveClothesRes;
import zip.ootd.ootdzip.clothes.service.request.FindClothesByUserSvcReq;
import zip.ootd.ootdzip.clothes.service.request.SaveClothesSvcReq;
import zip.ootd.ootdzip.clothes.service.request.UpdateClothesIsOpenSvcReq;
import zip.ootd.ootdzip.clothes.service.request.UpdateClothesIsPrivateSvcReq;
import zip.ootd.ootdzip.clothes.service.request.UpdateClothesSvcReq;
import zip.ootd.ootdzip.user.domain.User;

Expand Down Expand Up @@ -50,5 +50,5 @@ public interface ClothesService {
*/
SaveClothesRes updateClothes(UpdateClothesSvcReq request, User loginUser);

SaveClothesRes updateClothesIsOpen(UpdateClothesIsOpenSvcReq request, User loginUser);
SaveClothesRes updateClothesIsPrivate(UpdateClothesIsPrivateSvcReq request, User loginUser);
}
Loading

0 comments on commit 9a6b41d

Please sign in to comment.