Skip to content

Commit

Permalink
Merge pull request #84 from capstone-five-ai/fix/cache
Browse files Browse the repository at this point in the history
fix: 캐시가 초기화되지 않는 문제 해결
  • Loading branch information
yujamint authored Jul 25, 2024
2 parents 291c73c + 9ee74a0 commit 28a1c9f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public MemberSavedSummaryDto.pdfResponse createCategorizedProblemsPdf(Long categ
}


@CacheEvict(value = "categorizedProblem", key = "#categoryId")
@CacheEvict(value = "categorizedProblem", key = "#result.getCategory().getCategoryId()")
public CategorizedProblem updateCategorizedProblem(Long categorizedProblemId, MemberSavedProblemDto.Patch problemPatchDto) {
CategorizedProblem categorizedProblem = findVerifiedCategorizedProblemByCategorizedProblemId(categorizedProblemId);
problemService.updateProblem(
Expand All @@ -247,16 +247,17 @@ public Page<CategorizedProblem> findCategorizedProblemsByCategoryId(Long categor
return categorizedProblemRepository.findByCategoryCategoryId(categoryId, pageRequest);
}

@CacheEvict(value = "categorizedProblem", key = "#categoryId")
public void deleteCategorizedProblem(Long categorizedProblemID){
@CacheEvict(value = "categorizedProblem", key = "#result")
public Long deleteCategorizedProblem(Long categorizedProblemID) {
CategorizedProblem categorizedProblem = findVerifiedCategorizedProblemByCategorizedProblemId(categorizedProblemID);
categorizedProblemRepository.deleteById(categorizedProblemID);
categorizedProblemRepository.deleteById(categorizedProblem.getCategorizedProblemId());

Problem problem = categorizedProblem.getProblem();
Long problemId = problem.getProblemId();
if (problem.isMemberSavedProblem() && !isProblemUsedInOtherCategorizedProblems(problemId)) {
problemService.deleteProblem(problemId);
}
return categorizedProblem.getCategory().getCategoryId();
}

private boolean isProblemUsedInOtherCategorizedProblems(Long problemId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public SummaryDto.pdfResponse createSummaryPdf(Long categorizedSummaryId) throws
return summaryService.createSummaryPdf(summaryId);
}

@CacheEvict(value = "categorizedSummary", key = "#categoryId")
@CacheEvict(value = "categorizedSummary", key = "#result.getCategory().getCategoryId()")
public CategorizedSummary updateCategorizedSummary(Long categorizedSummaryId, SummaryDto.Patch summaryPatchDto) {
CategorizedSummary categorizedSummary = findVerifiedCategorizedSummaryByCategorizedSummaryId(categorizedSummaryId);
summaryService.updateSummary(
Expand All @@ -87,8 +87,8 @@ public CategorizedSummary updateCategorizedSummary(Long categorizedSummaryId, Su
return categorizedSummaryRepository.save(categorizedSummary);
}

@CacheEvict(value = "categorizedSummary", key = "#categoryId")
public void deleteCategorizedSummary(Long categorizedSummaryId) {
@CacheEvict(value = "categorizedSummary", key = "#result")
public Long deleteCategorizedSummary(Long categorizedSummaryId) {
CategorizedSummary categorizedSummary = findVerifiedCategorizedSummaryByCategorizedSummaryId(categorizedSummaryId);

categorizedSummaryRepository.deleteById(categorizedSummaryId);
Expand All @@ -98,6 +98,8 @@ public void deleteCategorizedSummary(Long categorizedSummaryId) {
if (summary.isMemberSavedSummary() && !isSummaryUsedInOtherCategorizedSummarys(summaryId)) {
summaryRepository.deleteById(summaryId);
}
Long categoryId = categorizedSummary.getCategory().getCategoryId();
return categoryId;
}

private boolean isSummaryUsedInOtherCategorizedSummarys(Long summaryId){
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/app/fake/FakeLoginController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.app.fake;

import com.app.domain.member.constant.MemberType;
import com.app.domain.member.constant.Role;
import com.app.domain.member.entity.Member;
import com.app.domain.member.service.MemberService;
import com.app.global.jwt.dto.JwtTokenDto;
import com.app.global.jwt.service.TokenManager;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@Profile(value = {"local", "test"})
@RestController
public class FakeLoginController {

private final MemberService memberService;
private final TokenManager tokenManager;

@PostMapping("/api/fake/login")
public ResponseEntity<String> fakeSignUp(@RequestBody FakeSignUpRequest request) {
Member member = memberService.findMemberByEmail(request.getEmail()).orElseGet(
() -> memberService.registerMember(Member.builder()
.nickName(request.getNickname())
.email(request.getEmail())
.memberType(MemberType.KAKAO)
.role(Role.USER)
.build())
);

JwtTokenDto jwtTokenDto = tokenManager.createJwtTokenDto(member.getMemberId(), member.getRole());
member.updateRefreshToken(jwtTokenDto);
return ResponseEntity.ok(jwtTokenDto.getAccessToken());
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/app/fake/FakeSignUpRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.app.fake;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class FakeSignUpRequest {

private String nickname;
private String email;

public FakeSignUpRequest(String nickname, String email) {
this.nickname = nickname;
this.email = email;
}
}

0 comments on commit 28a1c9f

Please sign in to comment.