Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
L-U-Ready committed Nov 28, 2024
2 parents 9d09187 + bbebde7 commit 9295f73
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,17 @@ private ReportCategory setDefaultCategory(Report report, String categoryType) {

private void setReportArticleDefaultCategory(Report report, ReportArticle reportArticle, CategoryType categoryType) {

ReportCategory defaultCategory = reportCategoryRepository.findByReportAndCategoryTypeAndIsDefault(report, categoryType, true);
ReportCategory defaultCategory = findReportCategoryDefault(report, categoryType);

// // 기본 ReportCategory 설정
// reportArticle.setReportCategory(defaultCategory);
// reportArticleRepository.save(reportArticle);

defaultCategory.addReportArticle(reportArticle);

report.addReportCategory(defaultCategory);
reportRepository.save(report);

// 기본 ReportCategory 설정
reportArticle.setReportCategory(defaultCategory);
reportArticleRepository.save(reportArticle);

}

Expand Down Expand Up @@ -642,4 +648,9 @@ private List<Long> getArticleIdsByReportCreateRequest(ReportCreateRequest reques

}

private ReportCategory findReportCategoryDefault(Report report, CategoryType categoryType) {
return reportCategoryRepository.findByReportAndCategoryTypeAndName(report, categoryType, "default")
.orElseThrow(() -> new ApiException(ErrorStatus._REPORT_CATEGORY_NOT_FOUND));
}

}
5 changes: 5 additions & 0 deletions src/main/java/the_monitor/domain/model/ReportCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public void addReportArticles(List<ReportArticle> reportArticles) {
reportArticles.forEach(reportArticle -> reportArticle.setReportCategory(this)); // 양방향 연관 관계 설정
}

public void addReportArticle(ReportArticle reportArticle) {
this.reportArticles.add(reportArticle); // 리스트에 개별 ReportArticle 추가
reportArticle.setReportCategory(this); // 양방향 연관 관계 설정
}

public void setCategoryType(CategoryType categoryType) {
this.categoryType = categoryType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import the_monitor.domain.model.ReportCategory;

import java.util.List;
import java.util.Optional;

@Repository
public interface ReportCategoryRepository extends JpaRepository<ReportCategory, Long> {
Expand All @@ -18,4 +19,6 @@ public interface ReportCategoryRepository extends JpaRepository<ReportCategory,

ReportCategory findByReportAndCategoryTypeAndIsDefault(Report report, CategoryType categoryType, boolean isDefault);

Optional<ReportCategory> findByReportAndCategoryTypeAndName(Report report, CategoryType categoryType, String reportCategoryName);

}

0 comments on commit 9295f73

Please sign in to comment.