Skip to content

Commit

Permalink
feat: Redis 도입을 통한 좋아요 캐싱 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
dltjdgh0428 committed Apr 8, 2024
1 parent 5ad48f5 commit 3bc22a3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {
runtimeOnly 'com.h2database:h2'

}
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ['-parameters']
sourceCompatibility = '17'
targetCompatibility = '17'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// .addFilterAfter(new JwtFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class)
.addFilterAfter(new JwtFilter(jwtProvider), OAuth2LoginAuthenticationFilter.class)
.authorizeHttpRequests((authorizeRequests) -> authorizeRequests

.requestMatchers("/").permitAll()
// 테스트 관련 url
.requestMatchers("/api/**").permitAll()
// .requestMatchers("/api/**").permitAll()
.requestMatchers("/health", "/env", "/test/**", "/swagger-ui/**").permitAll()
.requestMatchers("/api/reviews").permitAll()
// 비회원도 볼수있는 url
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/book_everywhere/common/jwt/filter/JwtFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
String authorization = null;

Cookie[] cookies = request.getCookies();
StringBuilder message = new StringBuilder();
message.append("Request Method: ").append(request.getMethod())
.append(", URL: ").append(request.getRequestURL());

// 헤더 정보 로깅
Collections.list(request.getHeaderNames()).forEach(headerName ->
message.append(", ").append(headerName).append(": ").append(request.getHeader(headerName))
);

// 파라미터 정보 로깅 (선택적)
request.getParameterMap().forEach((key, value) ->
message.append(", ").append(key).append(": ").append(Arrays.toString(value))
);

logger.info(message.toString());
if (cookies != null) {
for (Cookie cookie : cookies) {
logger.info(cookie.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

Expand All @@ -19,7 +18,7 @@ public class LikesCachingServiceImpl implements LikesCachingService {
@Override
@Cacheable(value = "likesCount", key = "#reviewId")
public Long 좋아요캐시업데이트(Long reviewId) {
logger.info(reviewId+"의 캐시가 없데이트 되었습니다.");
logger.info(reviewId+"의 캐시가 업데이트 되었습니다.");
return likesRepository.countByReviewId(reviewId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.book_everywhere.domain.review.controller;


import com.book_everywhere.domain.book.service.BookService;
import com.book_everywhere.domain.likes.service.LikesService;
import com.book_everywhere.domain.pin.service.PinService;
Expand Down Expand Up @@ -58,29 +57,29 @@ public CMRespDto<?> addReview(@RequestBody ReviewRespDto reviewRespDto) {
//공개 독후감 조회
@Operation(summary = "모든 독후감 조회", description = "조건에 없이 모든 독후감을 조회합니다 return = List<ReviewDto>")
@GetMapping("/api/reviews")
public CMRespDto<?> publicReviews(@RequestParam Long socialId) {
public CMRespDto<?> publicReviews(@RequestParam(value = "socialId") Long socialId) {
List<ReviewDto> result = reviewService.모든독후감조회(socialId);
return new CMRespDto<>(HttpStatus.OK, result, "전체 공유 독후감 조회");
}

@Operation(summary = "모든 공유 독후감 조회", description = "공유 독후감을 조회합니다 return = List<ReviewDto>")
@GetMapping("/api/review/public")
public CMRespDto<?> findPublicReviews(@RequestParam Long socialId) {
public CMRespDto<?> findPublicReviews(@RequestParam(value = "socialId") Long socialId) {
List<ReviewDto> result = reviewService.모든공유독후감조회(socialId);
return new CMRespDto<>(HttpStatus.OK, result, "모든 공유 독후감 조회 완료");
}

@Operation(summary = "단일 책 독후감 조회", description = "단일 책 독후감을 조회합니다 return = List<ReviewDto>")
@GetMapping("/api/detail/{bookId}")
public CMRespDto<?> bookReviews(@RequestParam Long socialId, @PathVariable Long bookId) {
public CMRespDto<?> bookReviews(@RequestParam(value = "socialId") Long socialId, @PathVariable Long bookId) {
List<ReviewDto> result = reviewService.책에따른모든리뷰(socialId, bookId);
return new CMRespDto<>(HttpStatus.OK, result, "책에 따른 전체 독후감 조회");
}

//수정
@Operation(summary = "단일 독후감 조회", description = "특정 독후감을 조회합니다 return = ReviewDto")
@GetMapping("/api/review/{reviewId}")
public CMRespDto<?> getReview(@RequestParam Long socialId, @PathVariable Long reviewId) {
public CMRespDto<?> getReview(@RequestParam(value = "socialId") Long socialId, @PathVariable Long reviewId) {
ReviewDto reviewDto = reviewService.단일독후감조회(socialId, reviewId);
return new CMRespDto<>(HttpStatus.OK, reviewDto, "단일 독후감 조회");
}
Expand Down

0 comments on commit 3bc22a3

Please sign in to comment.