diff --git a/src/main/java/com/example/neoul/controller/BoardController.java b/src/main/java/com/example/neoul/controller/BoardController.java new file mode 100644 index 0000000..3c8868b --- /dev/null +++ b/src/main/java/com/example/neoul/controller/BoardController.java @@ -0,0 +1,32 @@ +package com.example.neoul.controller; + + +import com.example.neoul.dto.board.BoardRes; +import com.example.neoul.global.entity.ApiResponse; +import com.example.neoul.global.exception.BadRequestException; +import com.example.neoul.service.BoardService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@Api(tags={"04.board"}) +@RequestMapping("/board") +public class BoardController { + + private final BoardService boardService; + + @ApiOperation(value = "카테고리별로 상품 조회하기", notes = "의류(1), 소품(2), 악세사리(3), 잡화(4), 기타(5) | 추천순, 인기순, 신상품순, 낮은 가격순, 높은 가격순") + @GetMapping("/{categoryId}") + public ApiResponse> getCategoryList(@PathVariable Long categoryId, + @RequestParam(required = false) Integer option){ + return new ApiResponse<>(boardService.getCategoryList(categoryId, 1)); + } + + + +} diff --git a/src/main/java/com/example/neoul/controller/BrandController.java b/src/main/java/com/example/neoul/controller/BrandController.java index 10b43b5..d0b5dc5 100644 --- a/src/main/java/com/example/neoul/controller/BrandController.java +++ b/src/main/java/com/example/neoul/controller/BrandController.java @@ -16,16 +16,17 @@ public class BrandController { private final BrandService brandService; - // 브랜드 list - @GetMapping("/list") - public ApiResponse> list(){ - return new ApiResponse(brandService.list()); - } - - // 브랜드 상세조회 - @GetMapping("/{brandId}") - public ApiResponse brandInfo(@PathVariable("brandId") Long brandId){ - return new ApiResponse<>(brandService.info(brandId)); - } +// +// // 브랜드 list +// @GetMapping("/list") +// public ApiResponse> list(){ +// return new ApiResponse(brandService.list()); +// } +// +// // 브랜드 상세조회 +// @GetMapping("/{brandId}") +// public ApiResponse brandInfo(@PathVariable("brandId") Long brandId){ +// return new ApiResponse<>(brandService.info(brandId)); +// } } diff --git a/src/main/java/com/example/neoul/controller/StoryController.java b/src/main/java/com/example/neoul/controller/StoryController.java index de9e251..58d78ef 100644 --- a/src/main/java/com/example/neoul/controller/StoryController.java +++ b/src/main/java/com/example/neoul/controller/StoryController.java @@ -20,15 +20,17 @@ public class StoryController { private final StoryService storyService; // 스토리 list - @GetMapping("/list") - public ApiResponse> list(){ - return new ApiResponse(storyService.list()); - } +// @GetMapping("/list") +// public ApiResponse> list(){ +// return new ApiResponse(storyService.list()); +// } +// +// // 스토리 상세조회 +// @GetMapping("/{storyId}") +// public ApiResponse storyInfo(@PathVariable("storyId") Long storyId){ +// return new ApiResponse<>(storyService.info(storyId)); +// } + - // 스토리 상세조회 - @GetMapping("/{storyId}") - public ApiResponse storyInfo(@PathVariable("storyId") Long storyId){ - return new ApiResponse<>(storyService.info(storyId)); - } } diff --git a/src/main/java/com/example/neoul/dto/board/BoardRes.java b/src/main/java/com/example/neoul/dto/board/BoardRes.java index 670c56d..514c0a2 100644 --- a/src/main/java/com/example/neoul/dto/board/BoardRes.java +++ b/src/main/java/com/example/neoul/dto/board/BoardRes.java @@ -28,6 +28,23 @@ public static class QABoardRes { } + @Builder + @NoArgsConstructor + @AllArgsConstructor + @Setter + @Getter + public static class CategoryBoardSimple { + private Long productId; + private Long categoryId; + private String brandName; + private String productName; + private Integer price; + //private String deliveryInfo; + private String productUrl; + } + + + diff --git a/src/main/java/com/example/neoul/entity/brand/Brand.java b/src/main/java/com/example/neoul/entity/brand/Brand.java index d77fab4..700f1bd 100644 --- a/src/main/java/com/example/neoul/entity/brand/Brand.java +++ b/src/main/java/com/example/neoul/entity/brand/Brand.java @@ -28,7 +28,7 @@ public class Brand extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "vcategory_id") - private CategoryV brandVCategory; + private CategoryV categoryV; @Column(name = "name") private String name; diff --git a/src/main/java/com/example/neoul/entity/brand/Product.java b/src/main/java/com/example/neoul/entity/brand/Product.java index 4fe6a6c..9c8da11 100644 --- a/src/main/java/com/example/neoul/entity/brand/Product.java +++ b/src/main/java/com/example/neoul/entity/brand/Product.java @@ -40,7 +40,7 @@ public class Product extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "pcategory_id") - private CategoryP brandPCategory; + private CategoryP categoryP; private String name; diff --git a/src/main/java/com/example/neoul/entity/brand/Story.java b/src/main/java/com/example/neoul/entity/brand/Story.java index e500101..f94f3a3 100644 --- a/src/main/java/com/example/neoul/entity/brand/Story.java +++ b/src/main/java/com/example/neoul/entity/brand/Story.java @@ -28,7 +28,7 @@ public class Story extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "vcategory_id") - private CategoryV storyVCategory; + private CategoryV categoryV; @Column(name = "img") private String img; diff --git a/src/main/java/com/example/neoul/entity/category/CategoryP.java b/src/main/java/com/example/neoul/entity/category/CategoryP.java index c077993..7c1ce7b 100644 --- a/src/main/java/com/example/neoul/entity/category/CategoryP.java +++ b/src/main/java/com/example/neoul/entity/category/CategoryP.java @@ -21,8 +21,8 @@ public class CategoryP { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "pcatogery_id") - private Long pcategoryId; + @Column(name = "id") + private Long id; @Column(name = "name") private String name; diff --git a/src/main/java/com/example/neoul/entity/category/CategoryV.java b/src/main/java/com/example/neoul/entity/category/CategoryV.java index 4fe60c5..bc0272c 100644 --- a/src/main/java/com/example/neoul/entity/category/CategoryV.java +++ b/src/main/java/com/example/neoul/entity/category/CategoryV.java @@ -25,8 +25,8 @@ public class CategoryV { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "vcategory_id") - private Long vcategoryId; + @Column(name = "id") + private Long id; @Column(name = "name") private String name; @@ -35,14 +35,14 @@ public class CategoryV { //이건 그냥 리포지토리에서 ALL로 불러와도 될 듯! - // story 들에 대한 관계 - @OneToMany(mappedBy = "storyVCategory") - private List stories = new ArrayList(); - - // brand 들에 대한 관계 - @OneToMany(mappedBy = "brandVCategory") - private List brands = new ArrayList(); - +// // story 들에 대한 관계 +// @OneToMany(mappedBy = "categoryV") +// private List stories = new ArrayList(); +// +// // brand 들에 대한 관계 +// @OneToMany(mappedBy = "categoryV") +// private List brands = new ArrayList(); +// diff --git a/src/main/java/com/example/neoul/repository/CategoryPRepository.java b/src/main/java/com/example/neoul/repository/CategoryPRepository.java new file mode 100644 index 0000000..e57db4e --- /dev/null +++ b/src/main/java/com/example/neoul/repository/CategoryPRepository.java @@ -0,0 +1,12 @@ +package com.example.neoul.repository; + +import com.example.neoul.entity.category.CategoryP; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface CategoryPRepository extends JpaRepository { + + Optional findById(Long pcategoryId); + +} diff --git a/src/main/java/com/example/neoul/repository/ProductRepository.java b/src/main/java/com/example/neoul/repository/ProductRepository.java index 4228c0e..9c8df75 100644 --- a/src/main/java/com/example/neoul/repository/ProductRepository.java +++ b/src/main/java/com/example/neoul/repository/ProductRepository.java @@ -3,6 +3,7 @@ import com.example.neoul.entity.brand.Brand; import com.example.neoul.entity.brand.Product; +import com.example.neoul.entity.category.CategoryP; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -12,4 +13,6 @@ @Repository public interface ProductRepository extends JpaRepository { List findAllByBrand(Brand brand); + + List findAllByCategoryP(CategoryP categoryP); } diff --git a/src/main/java/com/example/neoul/service/BoardService.java b/src/main/java/com/example/neoul/service/BoardService.java new file mode 100644 index 0000000..43652eb --- /dev/null +++ b/src/main/java/com/example/neoul/service/BoardService.java @@ -0,0 +1,54 @@ +package com.example.neoul.service; + +import com.example.neoul.dto.board.BoardRes; +import com.example.neoul.entity.brand.Product; +import com.example.neoul.entity.category.CategoryP; +import com.example.neoul.global.exception.NotFoundException; +import com.example.neoul.repository.CategoryPRepository; +import com.example.neoul.repository.ProductRepository; +import lombok.RequiredArgsConstructor; +import org.hibernate.cfg.CreateKeySecondPass; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class BoardService { + + private final ProductRepository productRepository; + private final CategoryPRepository categoryPRepository; + + public CategoryP getCategoryPByCategoryId(Long categoryId){ + Optional optionalCategoryP = categoryPRepository.findById(categoryId); + if(optionalCategoryP.isEmpty()) { + throw new NotFoundException("존재하지 않는 브랜드 카테고리입니다"); + } + return optionalCategoryP.get(); + } + + + public List getCategoryList(Long categoryId, int option) { + CategoryP categoryP = getCategoryPByCategoryId(categoryId); + List productList = productRepository.findAllByCategoryP(categoryP); + List result = new ArrayList<>(); + + for(Product product : productList){ + BoardRes.CategoryBoardSimple e = BoardRes.CategoryBoardSimple.builder() + .productId(product.getProductId()) + .categoryId(categoryId) + .brandName(product.getBrand().getName()) + .productName(product.getName()) + .price(product.getPrice()) + .productUrl(product.getProductUrl()) + .build(); + + result.add(e); + } + + + return result; + } +} diff --git a/src/main/java/com/example/neoul/service/BrandService.java b/src/main/java/com/example/neoul/service/BrandService.java index 67e6a9e..596ec35 100644 --- a/src/main/java/com/example/neoul/service/BrandService.java +++ b/src/main/java/com/example/neoul/service/BrandService.java @@ -16,45 +16,45 @@ public class BrandService { private final BrandRepository brandRepository; private final ProductRepository productRepository; - public List list(){ - List brandList= brandRepository.findAll(); - return makeBrandList(brandList); - } - - public List makeBrandList(List brandList){ - List responseList = new ArrayList<>(); - for(Brand brand : brandList){ - BrandRes.BrandListRes brandListRes = BrandRes.BrandListRes.builder() - .bid(brand.getBrandId()) - .categoryVId(brand.getBrandVCategory().getVcategoryId()) - .categoryVName(brand.getBrandVCategory().getName()) - .bName(brand.getName()) - .bIntro(brand.getIntro()) - .bProfileImg(brand.getProfileImg()) - .products(productRepository.findAllByBrand(brand)) - .build(); - responseList.add(brandListRes); - } - return responseList; - } - - public BrandRes.BrandInfoRes info(Long brandId){ - Brand brand = brandRepository.findById(brandId).get(); // 실패시 exception 발생 - BrandRes.BrandInfoRes brandInfo = BrandRes.BrandInfoRes.builder() - .bid(brand.getBrandId()) - .categoryVId(brand.getBrandVCategory().getVcategoryId()) - .categoryVName(brand.getBrandVCategory().getName()) - .bName(brand.getName()) - .bIntro(brand.getIntro()) - .bProfileImg(brand.getProfileImg()) - .products(productRepository.findAllByBrand(brand)) -// .hashTag() // 해시태그 내용 -// .bCreatedAt() -// .bLikeCNT() // 찜개수 -// .bHearted() // 찜 여부 - .build(); - - return brandInfo; - - } +// public List list(){ +// List brandList= brandRepository.findAll(); +// return makeBrandList(brandList); +// } + +// public List makeBrandList(List brandList){ +// List responseList = new ArrayList<>(); +// for(Brand brand : brandList){ +// BrandRes.BrandListRes brandListRes = BrandRes.BrandListRes.builder() +// .bid(brand.getBrandId()) +// .categoryVId(brand.getCategoryV().getVcategoryId()) +// .categoryVName(brand.getCategoryV().getName()) +// .bName(brand.getName()) +// .bIntro(brand.getIntro()) +// .bProfileImg(brand.getProfileImg()) +// .products(productRepository.findAllByBrand(brand)) +// .build(); +// responseList.add(brandListRes); +// } +// return responseList; +// } +// +// public BrandRes.BrandInfoRes info(Long brandId){ +// Brand brand = brandRepository.findById(brandId).get(); // 실패시 exception 발생 +// BrandRes.BrandInfoRes brandInfo = BrandRes.BrandInfoRes.builder() +// .bid(brand.getBrandId()) +// .categoryVId(brand.getCategoryV().getVcategoryId()) +// .categoryVName(brand.getCategoryV().getName()) +// .bName(brand.getName()) +// .bIntro(brand.getIntro()) +// .bProfileImg(brand.getProfileImg()) +// .products(productRepository.findAllByBrand(brand)) +//// .hashTag() // 해시태그 내용 +//// .bCreatedAt() +//// .bLikeCNT() // 찜개수 +//// .bHearted() // 찜 여부 +// .build(); +// +// return brandInfo; +// +// } } \ No newline at end of file diff --git a/src/main/java/com/example/neoul/service/StoryService.java b/src/main/java/com/example/neoul/service/StoryService.java index c8f1daa..5a3a8e8 100644 --- a/src/main/java/com/example/neoul/service/StoryService.java +++ b/src/main/java/com/example/neoul/service/StoryService.java @@ -1,6 +1,5 @@ package com.example.neoul.service; -import com.example.neoul.service.BrandService; import com.example.neoul.dto.Story.StoryRes; import com.example.neoul.entity.brand.Brand; import com.example.neoul.entity.brand.Story; @@ -22,40 +21,40 @@ public class StoryService { private final CategoryVRepository categoryVRepository; private final BrandService brandService; - public List list() { - List vCategoryList = categoryVRepository.findAll(); - List responseList = new ArrayList<>(); - for (CategoryV vCategory : vCategoryList) { - Story story = vCategory.getStories().stream().findAny() - .orElseThrow(() -> new NotFoundException("스토리가 존재하지 않습니다.")); - StoryRes.StoryListRes StoryListRes = StoryRes.StoryListRes.builder() - .sid(story.getStoryId()) - .categoryVName(story.getStoryVCategory().getName()) - .preImg(story.getImg()) - .title(story.getTitle()) - .createdAt(story.getCreatedAt()) - .build(); - responseList.add(StoryListRes); - } - return responseList; - } - - public StoryRes.StoryInfoRes info(Long storyId) { - Story story = storyRepository.findById(storyId). - orElseThrow(() -> new NotFoundException("스토리가 존재하지 않습니다.")); - List brandList = story.getStoryVCategory().getBrands(); - // 응답 리스트 - StoryRes.StoryInfoRes responseList = StoryRes.StoryInfoRes.builder() - .sid(storyId) - .categoryVName(story.getStoryVCategory().getName()) - .preImg(story.getImg()) - .title(story.getTitle()) - .content(story.getContent()) - .createdAt(story.getCreatedAt()) - .brandListRes(brandService.makeBrandList(brandList)) - .build(); - - return responseList; - } +// public List list() { +// List vCategoryList = categoryVRepository.findAll(); +// List responseList = new ArrayList<>(); +// for (CategoryV vCategory : vCategoryList) { +// Story story = vCategory.getStories().stream().findAny() +// .orElseThrow(() -> new NotFoundException("스토리가 존재하지 않습니다.")); +// StoryRes.StoryListRes StoryListRes = StoryRes.StoryListRes.builder() +// .sid(story.getStoryId()) +// .categoryVName(story.getCategoryV().getName()) +// .preImg(story.getImg()) +// .title(story.getTitle()) +// .createdAt(story.getCreatedAt()) +// .build(); +// responseList.add(StoryListRes); +// } +// return responseList; +// } +// +// public StoryRes.StoryInfoRes info(Long storyId) { +// Story story = storyRepository.findById(storyId). +// orElseThrow(() -> new NotFoundException("스토리가 존재하지 않습니다.")); +// List brandList = story.getCategoryV().getBrands(); +// // 응답 리스트 +// StoryRes.StoryInfoRes responseList = StoryRes.StoryInfoRes.builder() +// .sid(storyId) +// .categoryVName(story.getCategoryV().getName()) +// .preImg(story.getImg()) +// .title(story.getTitle()) +// .content(story.getContent()) +// .createdAt(story.getCreatedAt()) +// .brandListRes(brandService.makeBrandList(brandList)) +// .build(); +// +// return responseList; +// } }