Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 캐시가 초기화되지 않는 문제 해결 #84

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading