Skip to content

Commit

Permalink
Merge pull request #82 from capstone-five-ai/dev
Browse files Browse the repository at this point in the history
fix: AI 생성 문제 기반의 CategorizedProblem 삭제 및 카테고리 문제,요약 캐싱 버그 수정
  • Loading branch information
yujamint authored Jul 10, 2024
2 parents c6af5b7 + 291c73c commit db6ef45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import com.app.domain.category.service.CategoryService;
import com.app.domain.member.entity.Member;
import com.app.domain.member.service.MemberService;
import com.app.domain.problem.aigeneratedproblem.service.AiGeneratedProblemService;
import com.app.domain.problem.entity.Problem;
import com.app.domain.problem.membersavedproblem.dto.MemberSavedProblemDto;
import com.app.domain.problem.membersavedproblem.mapper.MemberSavedProblemMapper;
import com.app.domain.problem.membersavedproblem.service.MemberSavedProblemService;
import com.app.domain.problem.service.ProblemService;
import com.app.domain.summary.membersavedsummary.dto.MemberSavedSummaryDto;
import com.app.global.config.ENUM.ProblemType;
Expand All @@ -27,6 +25,7 @@
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -39,8 +38,6 @@
public class CategorizedProblemService {
private final CategoryService categoryService;

private final MemberSavedProblemService memberSavedProblemService;

private final MemberService memberService;

private final MemberSavedProblemMapper memberSavedProblemMapper;
Expand All @@ -49,6 +46,7 @@ public class CategorizedProblemService {

private final ProblemService problemService;

@CacheEvict(value = "categorizedProblem", key = "#categoryId")
public CategorizedProblem createCategorizedProblem(Long categoryId, Long problemId) {
checkForDuplicateCategorizedProblem(categoryId, problemId);

Expand Down Expand Up @@ -232,7 +230,7 @@ public MemberSavedSummaryDto.pdfResponse createCategorizedProblemsPdf(Long categ
}



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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -39,6 +40,7 @@ public class CategorizedSummaryService {

private final SummaryRepository summaryRepository;

@CacheEvict(value = "categorizedSummary", key = "#categoryId")
public CategorizedSummary createCategorizedSummary(Long categoryId, Long summaryId) {
checkForDuplicateCategorizedProblem(categoryId, summaryId);

Expand Down Expand Up @@ -74,6 +76,7 @@ public SummaryDto.pdfResponse createSummaryPdf(Long categorizedSummaryId) throws
return summaryService.createSummaryPdf(summaryId);
}

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.app.domain.problem.service;

import com.app.domain.problem.entity.Problem;
import com.app.domain.problem.membersavedproblem.entity.MemberSavedProblem;
import com.app.domain.problem.repository.ProblemRepository;
import com.app.global.error.ErrorCode;
import com.app.global.error.exception.EntityNotFoundException;
Expand Down Expand Up @@ -38,4 +39,10 @@ public Problem findVerifiedProblemByProblemId(Long problemId) {
.orElseThrow(() -> new EntityNotFoundException(ErrorCode.PROBLEM_NOT_EXISTS));
}

public void deleteProblem(Long problemId){
Problem problem = findVerifiedProblemByProblemId(problemId);

problemRepository.deleteById(problemId);
}

}

0 comments on commit db6ef45

Please sign in to comment.