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

Refactor/#83 problem 조회 쿼리 개선 및 코드 리팩토링 #95

Merged
merged 12 commits into from
Mar 23, 2025
Merged
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moplus.moplus_server.domain.publish.domain;
package com.moplus.moplus_server.admin.publish.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

Expand All @@ -15,7 +15,7 @@
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QPublish extends EntityPathBase<Publish> {

private static final long serialVersionUID = 1565569153L;
private static final long serialVersionUID = 1641302032L;

public static final QPublish publish = new QPublish("publish");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.moplus.moplus_server.client.submit.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QChildProblemSubmit is a Querydsl query type for ChildProblemSubmit
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QChildProblemSubmit extends EntityPathBase<ChildProblemSubmit> {

private static final long serialVersionUID = -1656142683L;

public static final QChildProblemSubmit childProblemSubmit = new QChildProblemSubmit("childProblemSubmit");

public final com.moplus.moplus_server.global.common.QBaseEntity _super = new com.moplus.moplus_server.global.common.QBaseEntity(this);

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

//inherited
public final DateTimePath<java.time.LocalDateTime> createdDate = _super.createdDate;

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

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

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

public final EnumPath<ChildProblemSubmitStatus> status = createEnum("status", ChildProblemSubmitStatus.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedDate = _super.updatedDate;

public QChildProblemSubmit(String variable) {
super(ChildProblemSubmit.class, forVariable(variable));
}

public QChildProblemSubmit(Path<? extends ChildProblemSubmit> path) {
super(path.getType(), path.getMetadata());
}

public QChildProblemSubmit(PathMetadata metadata) {
super(ChildProblemSubmit.class, metadata);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.moplus.moplus_server.client.submit.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QProblemSubmit is a Querydsl query type for ProblemSubmit
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QProblemSubmit extends EntityPathBase<ProblemSubmit> {

private static final long serialVersionUID = 1682818189L;

public static final QProblemSubmit problemSubmit = new QProblemSubmit("problemSubmit");

public final com.moplus.moplus_server.global.common.QBaseEntity _super = new com.moplus.moplus_server.global.common.QBaseEntity(this);

//inherited
public final DateTimePath<java.time.LocalDateTime> createdDate = _super.createdDate;

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

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

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

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

public final EnumPath<ProblemSubmitStatus> status = createEnum("status", ProblemSubmitStatus.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedDate = _super.updatedDate;

public QProblemSubmit(String variable) {
super(ProblemSubmit.class, forVariable(variable));
}

public QProblemSubmit(Path<? extends ProblemSubmit> path) {
super(path.getType(), path.getMetadata());
}

public QProblemSubmit(PathMetadata metadata) {
super(ProblemSubmit.class, metadata);
}

}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.moplus.moplus_server.domain.problem.service.mapper;

import com.moplus.moplus_server.admin.problem.dto.request.ChildProblemUpdateRequest;
import com.moplus.moplus_server.domain.problem.domain.childProblem.ChildProblem;
import com.moplus.moplus_server.domain.problem.dto.request.ChildProblemUpdateRequest;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
Expand All @@ -11,7 +11,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2025-03-03T17:28:35+0900",
date = "2025-03-14T20:25:51+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
@@ -1,11 +1,11 @@
package com.moplus.moplus_server.domain.problem.service.mapper;

import com.moplus.moplus_server.admin.problem.dto.request.ProblemPostRequest;
import com.moplus.moplus_server.admin.problem.dto.request.ProblemUpdateRequest;
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.ProblemCustomId;
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemType;
import com.moplus.moplus_server.domain.problem.dto.request.ProblemPostRequest;
import com.moplus.moplus_server.domain.problem.dto.request.ProblemUpdateRequest;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
Expand All @@ -15,7 +15,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2025-03-03T17:28:35+0900",
date = "2025-03-15T21:23:23+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 @@ -37,7 +37,7 @@ public class QIncorrectProblem extends EntityPathBase<IncorrectProblem> {

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

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

public final StringPath problemNumber = createString("problemNumber");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class QProblemImageForTest extends EntityPathBase<ProblemImageForTest> {

public final StringPath imageUrl = createString("imageUrl");

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

public QProblemImageForTest(String variable) {
super(ProblemImageForTest.class, forVariable(variable));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moplus.moplus_server.domain.member.domain;
package com.moplus.moplus_server.member.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

Expand All @@ -15,7 +15,7 @@
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QMember extends EntityPathBase<Member> {

private static final long serialVersionUID = -705761779L;
private static final long serialVersionUID = -1541748259L;

public static final QMember member = new QMember("member1");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.moplus.moplus_server.statistic.member;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QCorrectConceptTagStatistics is a Querydsl query type for CorrectConceptTagStatistics
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QCorrectConceptTagStatistics extends EntityPathBase<CorrectConceptTagStatistics> {

private static final long serialVersionUID = -313521578L;

public static final QCorrectConceptTagStatistics correctConceptTagStatistics = new QCorrectConceptTagStatistics("correctConceptTagStatistics");

public final com.moplus.moplus_server.global.common.QBaseEntity _super = new com.moplus.moplus_server.global.common.QBaseEntity(this);

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

public final NumberPath<Integer> correctCount = createNumber("correctCount", Integer.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> createdDate = _super.createdDate;

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

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedDate = _super.updatedDate;

public QCorrectConceptTagStatistics(String variable) {
super(CorrectConceptTagStatistics.class, forVariable(variable));
}

public QCorrectConceptTagStatistics(Path<? extends CorrectConceptTagStatistics> path) {
super(path.getType(), path.getMetadata());
}

public QCorrectConceptTagStatistics(PathMetadata metadata) {
super(CorrectConceptTagStatistics.class, metadata);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.moplus.moplus_server.statistic.member;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QIncorrectConceptTagStatistics is a Querydsl query type for IncorrectConceptTagStatistics
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QIncorrectConceptTagStatistics extends EntityPathBase<IncorrectConceptTagStatistics> {

private static final long serialVersionUID = 1288752209L;

public static final QIncorrectConceptTagStatistics incorrectConceptTagStatistics = new QIncorrectConceptTagStatistics("incorrectConceptTagStatistics");

public final com.moplus.moplus_server.global.common.QBaseEntity _super = new com.moplus.moplus_server.global.common.QBaseEntity(this);

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

//inherited
public final DateTimePath<java.time.LocalDateTime> createdDate = _super.createdDate;

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

public final NumberPath<Integer> incorrectCount = createNumber("incorrectCount", Integer.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedDate = _super.updatedDate;

public QIncorrectConceptTagStatistics(String variable) {
super(IncorrectConceptTagStatistics.class, forVariable(variable));
}

public QIncorrectConceptTagStatistics(Path<? extends IncorrectConceptTagStatistics> path) {
super(path.getType(), path.getMetadata());
}

public QIncorrectConceptTagStatistics(PathMetadata metadata) {
super(IncorrectConceptTagStatistics.class, metadata);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;

@Getter
@Entity
Expand All @@ -34,6 +35,7 @@ public class ChildProblem extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "child_problem_id")
Long id;
@BatchSize(size = 100)
@ElementCollection
@CollectionTable(name = "child_problem_concept", joinColumns = @JoinColumn(name = "child_problem_id"))
@Column(name = "concept_tag_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class Problem extends BaseEntity {
@Convert(converter = StringListConverter.class)
@Column(columnDefinition = "TEXT")
List<String> prescriptionImageUrls;

@ElementCollection
@CollectionTable(name = "problem_concept", joinColumns = @JoinColumn(name = "problem_id"))
@Column(name = "concept_tag_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ public enum ProblemType {

private final String name;
private final int code;

public boolean isCreationProblem() {
return this == CREATION_PROBLEM;
}

public boolean requiresPracticeTest() {
return !isCreationProblem();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemCustomId;
import com.moplus.moplus_server.global.error.exception.ErrorCode;
import com.moplus.moplus_server.global.error.exception.NotFoundException;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ProblemRepository extends JpaRepository<Problem, Long> {

Expand All @@ -16,14 +19,16 @@ default void existsByIdElseThrow(Long id) {
}
}

default void existsByProblemAdminIdElseThrow(ProblemCustomId problemCustomId) {
if (!existsByProblemCustomId(problemCustomId)) {
throw new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND);
}
}
@Query("SELECT DISTINCT p FROM Problem p " +
"LEFT JOIN FETCH p.childProblems c " +
"WHERE p.id = :id")
Optional<Problem> findByIdWithFetchJoin(@Param("id") Long id);
Comment on lines +22 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그럼 hibernate6부터는 해당 distinct를 제거해도 내부적으로 추가되는 걸까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 맞습니다


default Problem findByIdElseThrow(Long id) {
return findById(id).orElseThrow(() -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND));
}

default Problem findByIdWithFetchJoinElseThrow(Long id) {
return findByIdWithFetchJoin(id).orElseThrow(() -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND));
}
}
Loading