Skip to content

Commit

Permalink
Merge pull request #64 from taco-official/KL-163/프론트-요구사항-처리
Browse files Browse the repository at this point in the history
feat(KL-163): handle fe requirements
  • Loading branch information
ohhamma authored Sep 12, 2024
2 parents 398ee9e + 6e430c2 commit d9f5554
Show file tree
Hide file tree
Showing 108 changed files with 863 additions and 1,740 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ public class CategoryController {

private final CategoryService categoryService;

@GetMapping
@Operation(summary = "전체 카테고리 목록 조회", description = "전체 카테고리 목록을 조회합니다.")
public List<CategoryResponse> findAllCategories() {
@GetMapping("/hierarchy")
@Operation(summary = "전체 분류의 계층 정보 조회", description = "전체 분류의 계층 정보를 조회합니다.")
public List<CategoryResponse> getAllCategories() {
return categoryService.findAllCategories();
}

@GetMapping("/{categoryId}/subcategories")
@Operation(summary = "대분류의 소분류 목록 조회", description = "Category에 포함된 Subcategory 반환")
public CategoryResponse findSubCategoriesByCategoryId(@PathVariable Long categoryId) {
return categoryService.findSubCategoriesByCategoryId(categoryId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package taco.klkl.domain.category.controller.subcategory;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import taco.klkl.domain.category.dto.response.subcategory.SubcategoryHierarchyResponse;
import taco.klkl.domain.category.service.subcategory.SubcategoryService;

@Slf4j
@RestController
@Tag(name = "6. 카테고리", description = "카테고리 관련 API")
@RequestMapping("/v1/subcategories")
@RequiredArgsConstructor
public class SubcategoryController {

private final SubcategoryService subcategoryService;

@GetMapping("/{subcategoryId}/hierarchy")
@Operation(summary = "특정 소분류의 계층 정보 조회", description = "특정 소분류의 계층 정보를 조회합니다.")
public SubcategoryHierarchyResponse getSubcategoryHierarchy(@PathVariable final Long subcategoryId) {
return subcategoryService.findSubcategoryHierarchyById(subcategoryId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Transient;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -19,6 +20,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Category {

@Transient
private CategoryType categoryType;

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Transient;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -23,6 +24,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Subcategory {

@Transient
private SubcategoryType subcategoryType;

@Id
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/taco/klkl/domain/category/domain/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Transient;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -22,6 +23,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Tag {

@Transient
private TagType tagType;

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package taco.klkl.domain.category.dto.response.subcategory;

import taco.klkl.domain.category.domain.category.Category;
import taco.klkl.domain.category.domain.subcategory.Subcategory;

public record SubcategoryHierarchyResponse(
Long subcategoryId,
Long categoryId
) {
public static SubcategoryHierarchyResponse from(final Subcategory subcategory) {
final Category category = subcategory.getCategory();

return new SubcategoryHierarchyResponse(
subcategory.getId(),
category.getId()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
package taco.klkl.domain.category.dto.response.subcategory;

import java.util.List;

import taco.klkl.domain.category.domain.SubcategoryTag;
import taco.klkl.domain.category.domain.subcategory.Subcategory;
import taco.klkl.domain.category.dto.response.tag.TagResponse;

public record SubcategoryResponse(
Long id,
String name
String name,
List<TagResponse> tags
) {
public static SubcategoryResponse from(final Subcategory subcategory) {
return new SubcategoryResponse(subcategory.getId(), subcategory.getName());
final List<TagResponse> tags = subcategory.getSubcategoryTags().stream()
.map(SubcategoryTag::getTag)
.map(TagResponse::from)
.toList();

return new SubcategoryResponse(
subcategory.getId(),
subcategory.getName(),
tags
);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ public interface CategoryService {

List<CategoryResponse> findAllCategories();

CategoryResponse findSubCategoriesByCategoryId(final Long categoryId);

List<CategoryResponse> findAllCategoriesByPartialString(final String partialString);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ public List<CategoryResponse> findAllCategories() {
.toList();
}

@Override
public CategoryResponse findSubCategoriesByCategoryId(final Long categoryId) {
final Category category = categoryRepository.findById(categoryId)
.orElseThrow(CategoryNotFoundException::new);
return CategoryResponse.from(category);
}

@Override
public List<CategoryResponse> findAllCategoriesByPartialString(final String partialString) {
if (partialString == null || partialString.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import org.springframework.stereotype.Service;

import taco.klkl.domain.category.domain.subcategory.Subcategory;
import taco.klkl.domain.category.dto.response.subcategory.SubcategoryHierarchyResponse;
import taco.klkl.domain.category.dto.response.subcategory.SubcategoryResponse;

@Service
public interface SubcategoryService {

List<SubcategoryResponse> findAllSubcategoriesByPartialString(final String partialString);

List<Subcategory> findSubcategoriesBySubcategoryIds(final List<Long> subcategoryIds);
SubcategoryHierarchyResponse findSubcategoryHierarchyById(final Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.extern.slf4j.Slf4j;
import taco.klkl.domain.category.dao.subcategory.SubcategoryRepository;
import taco.klkl.domain.category.domain.subcategory.Subcategory;
import taco.klkl.domain.category.dto.response.subcategory.SubcategoryHierarchyResponse;
import taco.klkl.domain.category.dto.response.subcategory.SubcategoryResponse;
import taco.klkl.domain.category.exception.subcategory.SubcategoryNotFoundException;

Expand All @@ -34,15 +35,9 @@ public List<SubcategoryResponse> findAllSubcategoriesByPartialString(final Strin
}

@Override
public List<Subcategory> findSubcategoriesBySubcategoryIds(final List<Long> subcategoryIds) {
final List<Subcategory> subcategories = subcategoryRepository.findAllById(subcategoryIds);
validateSubcategories(subcategoryIds.size(), subcategories.size());
return subcategories;
}

private void validateSubcategories(final int request, final int result) {
if (request != result) {
throw new SubcategoryNotFoundException();
}
public SubcategoryHierarchyResponse findSubcategoryHierarchyById(final Long id) {
final Subcategory subcategory = subcategoryRepository.findById(id)
.orElseThrow(SubcategoryNotFoundException::new);
return SubcategoryHierarchyResponse.from(subcategory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
import taco.klkl.domain.comment.domain.Comment;

public interface CommentRepository extends JpaRepository<Comment, Long> {
List<Comment> findAllByProduct_Id(Long productId);
List<Comment> findByProductIdOrderByCreatedAtDesc(final Long productId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonFormat;

import taco.klkl.domain.comment.domain.Comment;
import taco.klkl.global.common.constants.DefaultConstants;

public record CommentNotificationResponse(
String userName,
String content,
LocalDateTime createdAt
@JsonFormat(pattern = DefaultConstants.DEFAULT_DATETIME_FORMAT) LocalDateTime createdAt
) {
public static CommentNotificationResponse from(final Comment comment) {
return new CommentNotificationResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonFormat;

import taco.klkl.domain.comment.domain.Comment;
import taco.klkl.domain.user.dto.response.UserSimpleResponse;
import taco.klkl.global.common.constants.DefaultConstants;

public record CommentResponse(
Long id,
UserSimpleResponse user,
String content,
LocalDateTime createdAt
@JsonFormat(pattern = DefaultConstants.DEFAULT_DATETIME_FORMAT) LocalDateTime createdAt
) {
public static CommentResponse from(final Comment comment) {
return new CommentResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import taco.klkl.global.error.exception.CustomException;
import taco.klkl.global.error.exception.ErrorCode;

public class CommentProductNotMatch extends CustomException {
public CommentProductNotMatch() {
public class CommentProductNotMatchException extends CustomException {
public CommentProductNotMatchException() {
super(ErrorCode.COMMENT_PRODUCT_NOT_MATCH);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package taco.klkl.domain.comment.exception;

import taco.klkl.global.error.exception.CustomException;
import taco.klkl.global.error.exception.ErrorCode;

public class CommentUserNotMatchException extends CustomException {
public CommentUserNotMatchException() {
super(ErrorCode.COMMENT_USER_NOT_MATCH);
}
}
Loading

0 comments on commit d9f5554

Please sign in to comment.