Skip to content

Commit

Permalink
[feat] 판내내역 상품 조회시 컬럼 추가 (#133)
Browse files Browse the repository at this point in the history
* #124 feat: 캐시를 위한 직렬화 인터페이스 구현

* #124 feat: 카테고리 관련 목록 조회 캐싱

* #124 feat: 판매내역 상품 조회시 컬럼 추가
  • Loading branch information
yonghwankim-dev authored Oct 2, 2023
1 parent e3e81fa commit 04dc693
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -17,6 +18,7 @@ public class CategoryQueryService {

private final CategoryRepository categoryRepository;

@Cacheable("categories")
public CategoryListResponse findAll() {
List<Category> categories = categoryRepository.findAll();
return new CategoryListResponse(categories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import codesquard.app.api.category.response.CategoryListResponse;
import codesquard.app.api.response.ApiResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequestMapping("/api/categories")
@RequiredArgsConstructor
@RestController
Expand All @@ -20,6 +22,7 @@ public class CategoryRestController {
@ResponseStatus(HttpStatus.OK)
@GetMapping
public ApiResponse<CategoryListResponse> findAll() {
log.info("카테고리 목록 조회 요청");
return ApiResponse.of(HttpStatus.OK, "카테고리 조회에 성공하였습니다.", categoryQueryService.findAll());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package codesquard.app.api.category.response;

import java.io.Serializable;

import codesquard.app.domain.category.Category;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -9,7 +11,7 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class CategoryItemResponse {
public class CategoryItemResponse implements Serializable {

private Long id;
private String imageUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package codesquard.app.api.category.response;

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

Expand All @@ -10,7 +11,7 @@

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CategoryListResponse {
public class CategoryListResponse implements Serializable {

private List<CategoryItemResponse> categories;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -90,7 +89,6 @@ public void changeItemStatus(Long itemId, ItemStatus status) {
log.info("상품 상태 변경 결과 : item={}", item);
}

@Cacheable(cacheNames = "detailItem")
public ItemDetailResponse findDetailItemBy(Long itemId, Long loginMemberId) {
log.info("상품 상세 조회 서비스 요청, 상품 등록번호 : {}, 로그인 회원의 등록번호 : {}", itemId, loginMemberId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package codesquard.app.api.item.response;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

Expand All @@ -12,7 +13,7 @@

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ItemDetailResponse {
public class ItemDetailResponse implements Serializable {

private Boolean isSeller;
private List<String> imageUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import codesquard.app.domain.oauth.support.Principal;
import codesquard.app.domain.wish.WishStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/api/wishes")
@RequiredArgsConstructor
Expand All @@ -37,6 +39,7 @@ public ApiResponse<ItemResponses> findAll(@RequestParam(required = false) Long c

@GetMapping("/categories")
public ApiResponse<WishCategoryListResponse> readWishCategories(@AuthPrincipal Principal principal) {
log.info("관심 상품들의 카테고리 목록 요청 : {}", principal);
return ApiResponse.ok("관심상품의 카테고리 목록 조회를 완료하였습니다.", wishItemService.readWishCategories(principal));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -71,6 +72,7 @@ public ItemResponses findAll(Long categoryId, int size, Long cursor) {
return PaginationUtils.getItemResponses(itemResponses);
}

@Cacheable("wishCategories")
public WishCategoryListResponse readWishCategories(Principal principal) {
List<Wish> wishes = wishRepository.findAllByMemberId(principal.getMemberId());
List<Category> categories = wishes.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package codesquard.app.api.wishitem.response;

import java.io.Serializable;

import codesquard.app.domain.category.Category;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class WishCategoryItemResponse {
public class WishCategoryItemResponse implements Serializable {
private Long categoryId;
private String categoryName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package codesquard.app.api.wishitem.response;

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

Expand All @@ -8,7 +9,7 @@
import lombok.AllArgsConstructor;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class WishCategoryListResponse {
public class WishCategoryListResponse implements Serializable {
private List<WishCategoryItemResponse> categories;

public static WishCategoryListResponse of(List<Category> categories) {
Expand Down
9 changes: 9 additions & 0 deletions backend/src/main/java/codesquard/app/config/CacheConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package codesquard.app.config;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableCaching
public class CacheConfig {
}
10 changes: 10 additions & 0 deletions backend/src/main/java/codesquard/app/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package codesquard.app.config;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.CacheControl;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.mvc.WebContentInterceptor;

import com.fasterxml.jackson.databind.ObjectMapper;

Expand Down Expand Up @@ -38,6 +41,13 @@ public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LogoutInterceptor())
.excludePathPatterns("/api/*")
.addPathPatterns("/api/auth/logout");

WebContentInterceptor webCacheContentInterceptor = new WebContentInterceptor();
webCacheContentInterceptor.addCacheMapping(
CacheControl.maxAge(3600, TimeUnit.SECONDS).noTransform().mustRevalidate(),
"/api/categories", "/api/wishes/categories");

registry.addInterceptor(webCacheContentInterceptor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ public Slice<ItemResponse> findAll(SalesStatus status, int size, Long cursor) {
item.id.as("itemId"),
item.thumbnailUrl,
item.title,
item.region,
item.region.as("tradingRegion"),
item.createdAt,
item.price,
item.status))
item.status,
item.wishCount,
item.chatCount,
item.member.loginId.as("sellerId")))
.from(item)
.where(itemRepository.lessThanItemId(cursor),
itemRepository.equalsStatus(status))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package codesquard.app.interceptor;

public class CacheInterceptor {

}

0 comments on commit 04dc693

Please sign in to comment.