Skip to content

Commit

Permalink
Merge branch 'develop' into KL-183/로그아웃-구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhamma committed Oct 4, 2024
2 parents c6870d5 + 6c8946a commit b5ca77e
Show file tree
Hide file tree
Showing 90 changed files with 512 additions and 441 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import java.util.List;

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.category.CategoryResponse;
import taco.klkl.domain.category.dto.response.category.CategoryDetailResponse;
import taco.klkl.domain.category.service.category.CategoryService;

@Slf4j
Expand All @@ -25,7 +24,7 @@ public class CategoryController {

@GetMapping("/hierarchy")
@Operation(summary = "전체 분류의 계층 정보 조회", description = "전체 분류의 계층 정보를 조회합니다.")
public List<CategoryResponse> getAllCategories() {
public List<CategoryDetailResponse> getAllCategories() {
return categoryService.findAllCategories();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package taco.klkl.domain.category.dto.response.category;

import java.util.List;

import taco.klkl.domain.category.domain.category.Category;
import taco.klkl.domain.category.dto.response.subcategory.SubcategoryDetailResponse;

public record CategoryDetailResponse(
Long id,
String name,
List<SubcategoryDetailResponse> subcategories
) {
public static CategoryDetailResponse from(final Category category) {
List<SubcategoryDetailResponse> subcategories = category.getSubcategories().stream()
.map(SubcategoryDetailResponse::from)
.toList();

return new CategoryDetailResponse(
category.getId(),
category.getName(),
subcategories
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package taco.klkl.domain.category.dto.response.category;

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

public record CategorySimpleResponse(
Long id,
String name
) {
public static CategorySimpleResponse from(final Category category) {
return new CategorySimpleResponse(
category.getId(),
category.getName()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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.TagSimpleResponse;

public record SubcategoryDetailResponse(
Long id,
String name,
List<TagSimpleResponse> tags
) {
public static SubcategoryDetailResponse from(final Subcategory subcategory) {
final List<TagSimpleResponse> tags = subcategory.getSubcategoryTags().stream()
.map(SubcategoryTag::getTag)
.map(TagSimpleResponse::from)
.toList();

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

This file was deleted.

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

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

public record SubcategorySimpleResponse(
Long id,
String name
) {
public static SubcategorySimpleResponse from(final Subcategory subcategory) {
return new SubcategorySimpleResponse(
subcategory.getId(),
subcategory.getName()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package taco.klkl.domain.category.dto.response.tag;

import taco.klkl.domain.category.domain.tag.Tag;

public record TagSimpleResponse(
Long id,
String name
) {
public static TagSimpleResponse from(final Tag tag) {
return new TagSimpleResponse(tag.getId(), tag.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import java.util.List;

import org.springframework.stereotype.Service;
import taco.klkl.domain.category.dto.response.category.CategoryDetailResponse;
import taco.klkl.domain.category.dto.response.category.CategorySimpleResponse;

import taco.klkl.domain.category.dto.response.category.CategoryResponse;

@Service
public interface CategoryService {

List<CategoryResponse> findAllCategories();
List<CategoryDetailResponse> findAllCategories();

List<CategoryResponse> findAllCategoriesByPartialString(final String partialString);
List<CategorySimpleResponse> findAllCategoriesByPartialString(final String partialString);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import lombok.extern.slf4j.Slf4j;
import taco.klkl.domain.category.dao.category.CategoryRepository;
import taco.klkl.domain.category.domain.category.Category;
import taco.klkl.domain.category.dto.response.category.CategoryResponse;
import taco.klkl.domain.category.exception.category.CategoryNotFoundException;
import taco.klkl.domain.category.dto.response.category.CategoryDetailResponse;
import taco.klkl.domain.category.dto.response.category.CategorySimpleResponse;

@Slf4j
@Primary
Expand All @@ -23,21 +23,21 @@ public class CategoryServiceImpl implements CategoryService {
private final CategoryRepository categoryRepository;

@Override
public List<CategoryResponse> findAllCategories() {
public List<CategoryDetailResponse> findAllCategories() {
final List<Category> categories = categoryRepository.findAll();
return categories.stream()
.map(CategoryResponse::from)
.map(CategoryDetailResponse::from)
.toList();
}

@Override
public List<CategoryResponse> findAllCategoriesByPartialString(final String partialString) {
public List<CategorySimpleResponse> findAllCategoriesByPartialString(final String partialString) {
if (partialString == null || partialString.isEmpty()) {
return List.of();
}
final List<Category> categories = categoryRepository.findAllByNameContaining(partialString);
return categories.stream()
.map(CategoryResponse::from)
.map(CategorySimpleResponse::from)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

import java.util.List;

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;
import taco.klkl.domain.category.dto.response.subcategory.SubcategorySimpleResponse;

@Service
public interface SubcategoryService {

List<SubcategoryResponse> findAllSubcategoriesByPartialString(final String partialString);
List<SubcategorySimpleResponse> findAllSubcategoriesByPartialString(final String partialString);

SubcategoryHierarchyResponse findSubcategoryHierarchyById(final Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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.dto.response.subcategory.SubcategorySimpleResponse;
import taco.klkl.domain.category.exception.subcategory.SubcategoryNotFoundException;

@Slf4j
Expand All @@ -24,13 +24,13 @@ public class SubcategoryServiceImpl implements SubcategoryService {
private final SubcategoryRepository subcategoryRepository;

@Override
public List<SubcategoryResponse> findAllSubcategoriesByPartialString(final String partialString) {
public List<SubcategorySimpleResponse> findAllSubcategoriesByPartialString(final String partialString) {
if (partialString == null || partialString.isEmpty()) {
return List.of();
}
final List<Subcategory> subcategories = subcategoryRepository.findAllByNameContaining(partialString);
return subcategories.stream()
.map(SubcategoryResponse::from)
.map(SubcategorySimpleResponse::from)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

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 name,
String content,
@JsonFormat(pattern = DefaultConstants.DEFAULT_DATETIME_FORMAT) LocalDateTime createdAt
LocalDateTime createdAt
) {
public static CommentNotificationResponse from(final Comment comment) {
return new CommentNotificationResponse(
comment.getMember().getName(),
comment.getMember().getDisplayName(),
comment.getContent(),
comment.getCreatedAt()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonFormat;

import taco.klkl.domain.comment.domain.Comment;
import taco.klkl.domain.member.dto.response.MemberSimpleResponse;
import taco.klkl.global.common.constants.DefaultConstants;

public record CommentResponse(
Long id,
MemberSimpleResponse member,
String content,
@JsonFormat(pattern = DefaultConstants.DEFAULT_DATETIME_FORMAT) LocalDateTime createdAt
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 @@ -2,12 +2,9 @@

import java.util.List;

import org.springframework.stereotype.Service;

import taco.klkl.domain.comment.dto.request.CommentCreateUpdateRequest;
import taco.klkl.domain.comment.dto.response.CommentResponse;

@Service
public interface CommentService {

List<CommentResponse> findCommentsByProductId(final Long productId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class CommentServiceImpl implements CommentService {
private final MemberUtil memberUtil;
private final ProductUtil productUtil;

@Override
public List<CommentResponse> findCommentsByProductId(final Long productId) {
validateProductId(productId);
final List<Comment> comments = commentRepository.findByProductIdOrderByCreatedAtDesc(productId);
Expand All @@ -43,17 +44,21 @@ public List<CommentResponse> findCommentsByProductId(final Long productId) {
.toList();
}

@Override
@Transactional
public CommentResponse createComment(
final Long productId,
final CommentCreateUpdateRequest commentCreateRequestDto
) {
final Comment comment = createCommentEntity(productId, commentCreateRequestDto);
commentRepository.save(comment);
notificationService.createNotificationByComment(comment);
if (!isMyProduct(productId)) {
notificationService.createNotificationByComment(comment);
}
return CommentResponse.from(comment);
}

@Override
@Transactional
public CommentResponse updateComment(
final Long productId,
Expand All @@ -70,6 +75,7 @@ public CommentResponse updateComment(
return CommentResponse.from(comment);
}

@Override
@Transactional
public void deleteComment(
final Long productId,
Expand All @@ -96,6 +102,12 @@ private Comment createCommentEntity(
);
}

private boolean isMyProduct(final Long productId) {
final Member me = memberUtil.getCurrentMember();
final Product product = productUtil.findProductEntityById(productId);
return product.getMember().equals(me);
}

private void updateCommentEntity(
final Comment comment,
final CommentCreateUpdateRequest commentCreateUpdateRequest
Expand Down
Loading

0 comments on commit b5ca77e

Please sign in to comment.