Skip to content
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 @@ -11,7 +11,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2025-03-24T01:02:22+0900",
date = "2025-03-30T15:17:55+0900",
comments = "version: 1.6.3, compiler: javac, environment: Java 17.0.10 (JetBrains s.r.o.)"
)
@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2025-03-24T01:02:22+0900",
date = "2025-03-30T15:17:55+0900",
comments = "version: 1.6.3, compiler: javac, environment: Java 17.0.10 (JetBrains s.r.o.)"
)
@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class QProblemSet extends EntityPathBase<ProblemSet> {

public final NumberPath<Long> id = createNumber("id", Long.class);

public final BooleanPath isDeleted = createBoolean("isDeleted");

public final ListPath<Long, NumberPath<Long>> problemIds = this.<Long, NumberPath<Long>>createList("problemIds", Long.class, NumberPath.class, PathInits.DIRECT2);

public final QTitle title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SoftDelete;

@Getter
@Entity
@SoftDelete
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Publish extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.SoftDelete;

@Getter
@Entity
@SoftDelete
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ChildProblem extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SoftDelete;

@Getter
@Entity
@SoftDelete
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Problem extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.moplus.moplus_server.domain.problem.service;

import com.moplus.moplus_server.admin.problem.dto.request.ProblemPostRequest;
import com.moplus.moplus_server.admin.problem.dto.response.ProblemPostResponse;
import com.moplus.moplus_server.domain.problem.domain.practiceTest.PracticeTestTag;
import com.moplus.moplus_server.domain.problem.domain.problem.Problem;
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemAdminIdService;
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemCustomId;
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemType;
import com.moplus.moplus_server.admin.problem.dto.request.ProblemPostRequest;
import com.moplus.moplus_server.admin.problem.dto.response.ProblemPostResponse;
import com.moplus.moplus_server.domain.problem.repository.PracticeTestTagRepository;
import com.moplus.moplus_server.domain.problem.repository.ProblemRepository;
import com.moplus.moplus_server.domain.problem.service.mapper.ProblemMapper;
Expand All @@ -28,12 +27,13 @@ public ProblemPostResponse createProblem(ProblemPostRequest request) {
PracticeTestTag practiceTestTag = getPracticeTestTag(request);
ProblemCustomId problemCustomId = createProblemCustomId(request);
Problem problem = createProblem(request, problemCustomId, practiceTestTag);

return ProblemPostResponse.of(problemRepository.save(problem));
}

private Problem createProblem(ProblemPostRequest request, ProblemCustomId problemCustomId, PracticeTestTag practiceTestTag) {
if (request.problemType().isCreationProblem()) {
private Problem createProblem(ProblemPostRequest request, ProblemCustomId problemCustomId,
PracticeTestTag practiceTestTag) {
if (!request.problemType().isCreationProblem()) {
return problemMapper.from(request, problemCustomId, practiceTestTag);
}
return problemMapper.from(request.problemType(), problemCustomId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SoftDelete;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SoftDelete
public class ProblemSet extends BaseEntity {

@Id
Expand All @@ -37,9 +39,6 @@ public class ProblemSet extends BaseEntity {
@Embedded
private Title title;

@Column(nullable = false)
private boolean isDeleted;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private ProblemSetConfirmStatus confirmStatus;
Expand All @@ -53,7 +52,6 @@ public class ProblemSet extends BaseEntity {
@Builder
public ProblemSet(String title, List<Long> problemIds) {
this.title = new Title(title);
this.isDeleted = false;
this.confirmStatus = ProblemSetConfirmStatus.NOT_CONFIRMED;
this.problemIds = problemIds;
}
Expand All @@ -69,10 +67,6 @@ public void updateProblemOrder(List<Long> newProblems) {
this.problemIds = new ArrayList<>(newProblems);
}

public void deleteProblemSet() {
this.isDeleted = true;
}

public void toggleConfirm(List<Problem> problems) {
if (this.confirmStatus == ProblemSetConfirmStatus.NOT_CONFIRMED) {
if (problems.isEmpty()) {
Expand Down Expand Up @@ -111,4 +105,5 @@ public boolean isProblemsChanged(List<Long> newProblems) {
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.moplus.moplus_server.domain.problemset.domain.ProblemSet;
import com.moplus.moplus_server.domain.problemset.domain.ProblemSetConfirmStatus;
import com.moplus.moplus_server.global.error.exception.ErrorCode;
import com.moplus.moplus_server.global.error.exception.InvalidValueException;
import com.moplus.moplus_server.global.error.exception.NotFoundException;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -16,11 +15,6 @@ default ProblemSet findByIdElseThrow(Long problemSetId) {
default void validatePublishableProblemSet(Long problemSetId) {
ProblemSet problemSet = findByIdElseThrow(problemSetId);

//이거 soft delete 어노테이션으로 자동화 해야함(리팩토링 필요)
if (problemSet.isDeleted()) {
throw new InvalidValueException(ErrorCode.PROBLEM_SET_DELETED);
}

if (!ProblemSetConfirmStatus.CONFIRMED.equals(problemSet.getConfirmStatus())) {
throw new NotFoundException(ErrorCode.PROBLEM_SET_NOT_CONFIRMED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public List<ProblemSetSearchGetResponse> search(String problemSetTitle, String p
.from(problemSet)
.leftJoin(problem).on(problem.id.in(problemSet.problemIds)) // 문제 세트 내 포함된 문항과 조인
.where(
problemSet.isDeleted.isFalse(),
containsProblemSetTitle(problemSetTitle),
containsProblemTitle(problemTitle)
)
Expand All @@ -51,7 +50,6 @@ public List<ProblemSetSearchGetResponse> confirmSearch(String problemSetTitle, S
.from(problemSet)
.leftJoin(problem).on(problem.id.in(problemSet.problemIds)) // 문제 세트 내 포함된 문항과 조인
.where(
problemSet.isDeleted.isFalse(),
problemSet.confirmStatus.eq(CONFIRMED),
containsProblemSetTitle(problemSetTitle),
containsProblemTitle(problemTitle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ProblemSetDeleteService {
@Transactional
public void deleteProblemSet(Long problemSetId) {
ProblemSet problemSet = problemSetRepository.findByIdElseThrow(problemSetId);
problemSet.deleteProblemSet();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import com.moplus.moplus_server.domain.problemset.domain.ProblemSet;
import com.moplus.moplus_server.domain.problemset.repository.ProblemSetRepository;
import com.moplus.moplus_server.domain.publish.repository.PublishRepository;
import com.moplus.moplus_server.global.error.exception.BusinessException;
import com.moplus.moplus_server.global.error.exception.ErrorCode;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -33,9 +31,7 @@ public class ProblemSetGetService {
@Transactional(readOnly = true)
public ProblemSetGetResponse getProblemSet(Long problemSetId) {
ProblemSet problemSet = problemSetRepository.findByIdElseThrow(problemSetId);
if (problemSet.isDeleted()) {
throw new BusinessException(ErrorCode.DELETE_PROBLEM_SET_GET_ERROR);
}

List<LocalDate> publishedDates = publishRepository.findByProblemSetId(problemSetId).stream()
.map(Publish::getPublishedDate)
.toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.moplus.moplus_server.domain.problemset.service;

import com.moplus.moplus_server.admin.problemset.dto.request.ProblemReorderRequest;
import com.moplus.moplus_server.admin.problemset.dto.request.ProblemSetUpdateRequest;
import com.moplus.moplus_server.admin.publish.domain.Publish;
import com.moplus.moplus_server.domain.problem.domain.problem.Problem;
import com.moplus.moplus_server.domain.problem.repository.ProblemRepository;
import com.moplus.moplus_server.domain.problemset.domain.ProblemSet;
import com.moplus.moplus_server.domain.problemset.domain.ProblemSetConfirmStatus;
import com.moplus.moplus_server.admin.problemset.dto.request.ProblemReorderRequest;
import com.moplus.moplus_server.admin.problemset.dto.request.ProblemSetUpdateRequest;
import com.moplus.moplus_server.domain.problemset.repository.ProblemSetRepository;
import com.moplus.moplus_server.admin.publish.domain.Publish;
import com.moplus.moplus_server.domain.publish.repository.PublishRepository;
import com.moplus.moplus_server.global.error.exception.BusinessException;
import com.moplus.moplus_server.global.error.exception.ErrorCode;
import com.moplus.moplus_server.global.error.exception.InvalidValueException;
import java.util.ArrayList;
Expand Down Expand Up @@ -39,9 +38,6 @@ public void reorderProblems(Long problemSetId, ProblemReorderRequest request) {
@Transactional
public void updateProblemSet(Long problemSetId, ProblemSetUpdateRequest request) {
ProblemSet problemSet = problemSetRepository.findByIdElseThrow(problemSetId);
if (problemSet.isDeleted()) {
throw new BusinessException(ErrorCode.DELETE_PROBLEM_SET_UPDATE_ERROR);
}

if (problemSet.isConfirmed() && problemSet.isProblemsChanged(request.problemIds())) {
throw new InvalidValueException(ErrorCode.CONFIRMED_PROBLEM_SET_UPDATE_ERROR);
Expand All @@ -59,9 +55,7 @@ public void updateProblemSet(Long problemSetId, ProblemSetUpdateRequest request)
@Transactional
public ProblemSetConfirmStatus toggleConfirmProblemSet(Long problemSetId) {
ProblemSet problemSet = problemSetRepository.findByIdElseThrow(problemSetId);
if (problemSet.isDeleted()) {
throw new BusinessException(ErrorCode.DELETE_PROBLEM_SET_TOGGLE_ERROR);
}

List<Publish> publishes = publishRepository.findByProblemSetId(problemSetId);
if (!publishes.isEmpty()) {
throw new InvalidValueException(ErrorCode.ALREADY_PUBLISHED_ERROR);
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/insert-problem-set.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ DELETE
FROM problem_set;

-- 문제 세트 추가
INSERT INTO problem_set (problem_set_id, title, is_deleted, confirm_status)
INSERT INTO problem_set (problem_set_id, title, deleted, confirm_status)
VALUES (1, '2025년 5월 고2 모의고사 문제 세트', false, 'NOT_CONFIRMED');
INSERT INTO problem_set (problem_set_id, title, is_deleted, confirm_status)
INSERT INTO problem_set (problem_set_id, title, deleted, confirm_status)
VALUES (2, '2025년 5월 고3 모의고사 문제 세트', false, 'CONFIRMED');

-- 문제 세트에 포함된 문제 추가
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/insert-problem-set2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DELETE FROM problem_set_problems;
DELETE FROM problem_set;

-- 문제 세트 추가
INSERT INTO problem_set (problem_set_id, title, is_deleted, confirm_status)
INSERT INTO problem_set (problem_set_id, title, deleted, confirm_status)
VALUES (1, '2025년 5월 고2 모의고사 문제 세트', false, 'CONFIRMED');

-- 문제 세트에 포함된 문제 추가
Expand Down
17 changes: 10 additions & 7 deletions src/test/resources/insert-problem.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ INSERT INTO problem (problem_id,
answer_type,
is_confirmed,
recommended_minute,
recommended_second)
recommended_second,
deleted)
VALUES (1, '1224052001', 1, 1, 'GICHUL_PROBLEM', '제목1', '1', 5, '기존 문제 설명 1',
'mainProblem.png1', 'mainAnalysis.png1', 'readingTip.png1', 'seniorTip.png1',
'prescription.png1', 'MULTIPLE_CHOICE', false, 30, 45),
'prescription.png1', 'MULTIPLE_CHOICE', false, 30, 45, false),
(2, '1224052002', 1, 1, 'GICHUL_PROBLEM', '제목2', '1', 5, '기존 문제 설명 2',
'mainProblem.png2', 'mainAnalysis.png2', 'readingTip.png2', 'seniorTip.png2',
'prescription.png2', 'MULTIPLE_CHOICE', false, 25, 30);
'prescription.png2', 'MULTIPLE_CHOICE', false, 25, 30, false);

-- 자식 문제 테이블 생성
CREATE TABLE IF NOT EXISTS child_problem (
Expand All @@ -36,7 +37,8 @@ CREATE TABLE IF NOT EXISTS child_problem (
image_url VARCHAR(255),
answer_type VARCHAR(50),
answer VARCHAR(255),
sequence INT
sequence INT,
deleted BOOLEAN
);

-- 자식 문제 데이터 삽입
Expand All @@ -45,9 +47,10 @@ INSERT INTO child_problem (child_problem_id,
image_url,
answer_type,
answer,
sequence)
VALUES (1, 1, 'child1.png', 'MULTIPLE_CHOICE', '1', 0),
(2, 1, 'child2.png', 'SHORT_ANSWER', '정답2', 1);
sequence,
deleted)
VALUES (1, 1, 'child1.png', 'MULTIPLE_CHOICE', '1', 0, false),
(2, 1, 'child2.png', 'SHORT_ANSWER', '정답2', 1, false);

-- 문제-컨셉 태그 연결 테이블 생성
CREATE TABLE IF NOT EXISTS problem_concept (
Expand Down
30 changes: 17 additions & 13 deletions src/test/resources/insert-problem2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ INSERT INTO problem (problem_id,
answer_type,
is_confirmed,
recommended_minute,
recommended_second)
recommended_second,
deleted)
VALUES (1, '24052001001', 1, 1, 'GICHUL_PROBLEM', '제목1', '1', 5, '기존 문제 설명',
'mainProblem.png', 'mainAnalysis.png', 'mainHandwriting1.png', 'readingTip.png', 'seniorTip.png',
'prescription1.png, prescription2.png', 'MULTIPLE_CHOICE', false,
30, 0),
30, 0, false),

(2, '24052001002', 1, 2, 'GICHUL_PROBLEM', '제목2', '2', 4, '문제 2 설명',
'mainProblem2.png', 'mainAnalysis2.png', 'mainHandwriting2.png', 'readingTip2.png', 'seniorTip2.png',
'prescription3.png, prescription4.png', 'MULTIPLE_CHOICE', false,
20, 30),
20, 30, false),

(3, '24052001003', 1, 3, 'GICHUL_PROBLEM', '제목3', '3', 3, '문제 3 설명',
'mainProblem3.png', 'mainAnalysis3.png', 'mainHandwriting3.png', 'readingTip3.png', 'seniorTip3.png',
'prescription5.png, prescription6.png', 'SHORT_ANSWER', true,
15, 45);
15, 45, false);

-- 자식 문제 데이터 삽입
INSERT INTO child_problem (child_problem_id,
Expand All @@ -49,11 +50,12 @@ INSERT INTO child_problem (child_problem_id,
answer_type,
answer,
sequence,
prescription_image_urls)
VALUES (1, 1, 'child1.png', 'MULTIPLE_CHOICE', '1', 0, 'child1_prescription1.png, child1_prescription2.png'),
(2, 1, 'child2.png', 'SHORT_ANSWER', '정답2', 1, 'child2_prescription1.png, child2_prescription2.png'),
(3, 2, 'child3.png', 'MULTIPLE_CHOICE', '2', 0, 'child3_prescription1.png, child3_prescription2.png'),
(4, 3, 'child4.png', 'SHORT_ANSWER', '3', 0, 'child4_prescription1.png, child4_prescription2.png');
prescription_image_urls,
deleted)
VALUES (1, 1, 'child1.png', 'MULTIPLE_CHOICE', '1', 0, 'child1_prescription1.png, child1_prescription2.png', false),
(2, 1, 'child2.png', 'SHORT_ANSWER', '정답2', 1, 'child2_prescription1.png, child2_prescription2.png', false),
(3, 2, 'child3.png', 'MULTIPLE_CHOICE', '2', 0, 'child3_prescription1.png, child3_prescription2.png', false),
(4, 3, 'child4.png', 'SHORT_ANSWER', '3', 0, 'child4_prescription1.png, child4_prescription2.png', false);

-- 문제-컨셉 태그 연결
INSERT INTO problem_concept (problem_id, concept_tag_id)
Expand Down Expand Up @@ -94,20 +96,22 @@ INSERT INTO problem (problem_id,
answer_type,
is_confirmed,
recommended_minute,
recommended_second)
recommended_second,
deleted)
VALUES (4, '24052001004', 1, 4, 'GICHUL_PROBLEM', '제목4', '4', 1, '유효한 문제로 수정',
'mainProblem4.png', 'mainAnalysis4.png', 'mainHandwriting4.png', 'readingTip4.png', 'seniorTip4.png',
'prescription7.png, prescription8.png', 'MULTIPLE_CHOICE', false,
20, 0);
20, 0, false);

-- problem 4에 대한 자식 문제 추가
INSERT INTO child_problem (child_problem_id,
problem_id,
image_url,
answer_type,
answer,
sequence)
VALUES (5, 4, 'child5.png', 'MULTIPLE_CHOICE', '4', 0);
sequence,
deleted)
VALUES (5, 4, 'child5.png', 'MULTIPLE_CHOICE', '4', 0, false);

-- problem 4와 자식 문제에 대한 컨셉 태그 추가
INSERT INTO problem_concept (problem_id, concept_tag_id)
Expand Down