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 @@ -10,7 +10,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2025-02-18T17:01:34+0900",
date = "2025-02-20T02:36:18+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-02-18T21:41:47+0900",
date = "2025-02-20T02:36:19+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
Expand Up @@ -24,7 +24,7 @@ public class ImageUploadController {
@Operation(summary = "이미지 업로드를 위한 presigned URL 발급")
@GetMapping("/problem/{problemId}/presigned-url")
public ResponseEntity<PresignedUrlResponse> getProblemImagePresignedUrl(
@PathVariable("problemId") String problemId,
@PathVariable("problemId") Long problemId,
@RequestParam(value = "image-type") ProblemImageType imageType) {
String presignedUrl = imageUploadService.generateProblemImagePresignedUrl(problemId, imageType);
return ResponseEntity.ok(PresignedUrlResponse.of(presignedUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void validateByType(String answer, AnswerType answerType) {
throw new InvalidValueException(ErrorCode.INVALID_MULTIPLE_CHOICE_ANSWER);
}
}
if (answerType == AnswerType.SHORT_NUMBER_ANSWER) {
if (answerType == AnswerType.SHORT_ANSWER) {
try {
int numericAnswer = Integer.parseInt(answer);
if (numericAnswer < 0 || numericAnswer > 999) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ChildProblem(Long id, String imageUrl, AnswerType answerType, String answ
public static ChildProblem createEmptyChildProblem() {
return ChildProblem.builder()
.imageUrl("")
.answerType(AnswerType.SHORT_STRING_ANSWER)
.answerType(AnswerType.SHORT_ANSWER)
.answer("")
.conceptTagIds(Set.of())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,8 @@
@RequiredArgsConstructor
public enum AnswerType {
MULTIPLE_CHOICE("객관식"),
SHORT_NUMBER_ANSWER("주관식_숫자"),
SHORT_STRING_ANSWER("주관식_문자");
SHORT_ANSWER("주관식");


private final String name;

public static AnswerType getTypeForProblem(String subject, int number) {

// 미적분, 기하, 확률과 통계
if (subject.equals("미적분") || subject.equals("기하") || subject.equals("확률과통계")) {
if ((number >= 1 && number <= 15) || (number >= 23 && number <= 28)) {
return MULTIPLE_CHOICE;
} else if ((number >= 16 && number <= 22) || number == 29 || number == 30) {
return SHORT_NUMBER_ANSWER;
}
}

// 고1, 고2
if (subject.equals("고1") || subject.equals("고2")) {
if (number >= 1 && number <= 21) {
return MULTIPLE_CHOICE;
} else if (number >= 22 && number <= 30) {
return SHORT_NUMBER_ANSWER;
}
}

// 기본값: 객관식
return MULTIPLE_CHOICE;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.moplus.moplus_server.domain.problem.dto.request;

import com.moplus.moplus_server.domain.problem.domain.problem.AnswerType;
import jakarta.validation.constraints.NotNull;
import java.util.Set;

public record ChildProblemPostRequest(
String imageUrl,
AnswerType answerType,
String answer,
@NotNull(message = "컬렉션 값은 필수입니다.")
Set<Long> conceptTagIds,
int sequence
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.moplus.moplus_server.domain.problem.dto.request;

import com.moplus.moplus_server.domain.problem.domain.problem.AnswerType;
import jakarta.validation.constraints.NotNull;
import java.util.Set;

public record ChildProblemUpdateRequest(
Long id,
String imageUrl,
AnswerType answerType,
String answer,
@NotNull(message = "컬렉션 값은 필수입니다.")
Set<Long> conceptTagIds
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public record ProblemUpdateRequest(
ProblemType problemType,
Long practiceTestId,
int number,
@NotNull(message = "컬렉션 값은 필수입니다.")
Set<Long> conceptTagIds,
String answer,
String title,
Expand All @@ -23,6 +24,7 @@ public record ProblemUpdateRequest(
String seniorTipImageUrl,
List<String> prescriptionImageUrls,
AnswerType answerType,
@NotNull(message = "컬렉션 값은 필수입니다.")
List<ChildProblemUpdateRequest> updateChildProblems,
Integer recommendedMinute,
Integer recommendedSecond
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public record ChildProblemGetResponse(
String imageUrl,
AnswerType answerType,
String answer,
@NotNull(message = "컬렉션 값은 필수입니다.")
Set<Long> conceptTagIds
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public record ProblemGetResponse(
Long id,
@NotNull(message = "문항 custom ID는 필수입니다")
String problemCustomId,
@NotNull(message = "컬렉션 값은 필수입니다.")
Set<Long> conceptTagIds,
Long practiceTestId,
int number,
Expand All @@ -28,7 +29,9 @@ public record ProblemGetResponse(
String mainAnalysisImageUrl,
String readingTipImageUrl,
String seniorTipImageUrl,
@NotNull(message = "컬렉션 값은 필수입니다.")
List<String> prescriptionImageUrls,
@NotNull(message = "컬렉션 값은 필수입니다.")
List<ChildProblemGetResponse> childProblems,
Integer recommendedMinute,
Integer recommendedSecond
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
@Getter
@NoArgsConstructor
public class ProblemSearchGetResponse {
private Long id;
@NotNull(message = "문항 ID는 필수입니다")
private String problemId;
private String problemCustomId;
private String memo;
private String mainProblemImageUrl;
@NotNull(message = "개념 태그리스트는 필수입니다")
private Set<ConceptTagSearchResponse> conceptTagResponses;

public ProblemSearchGetResponse(String problemId, String memo, String mainProblemImageUrl,
public ProblemSearchGetResponse(Long id, String problemCustomId, String memo, String mainProblemImageUrl,
Set<ConceptTagSearchResponse> conceptTagResponses) {
this.problemId = problemId;
this.id = id;
this.problemCustomId = problemCustomId;
this.memo = memo;
this.mainProblemImageUrl = mainProblemImageUrl;
this.conceptTagResponses = conceptTagResponses;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.moplus.moplus_server.domain.problem.repository;

import static com.moplus.moplus_server.domain.concept.domain.QConceptTag.conceptTag;
import static com.moplus.moplus_server.domain.problem.domain.childProblem.QChildProblem.childProblem;
import static com.moplus.moplus_server.domain.problem.domain.problem.QProblem.problem;

import com.moplus.moplus_server.domain.problem.dto.response.ConceptTagSearchResponse;
import com.moplus.moplus_server.domain.problem.dto.response.ProblemSearchGetResponse;
import com.querydsl.core.group.GroupBy;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,15 +25,18 @@ public List<ProblemSearchGetResponse> search(String problemId, String memo, List
return queryFactory
.select(problem.problemCustomId.id, problem.memo, problem.mainProblemImageUrl)
.from(problem)
.leftJoin(childProblem).on(childProblem.in(problem.childProblems))
.leftJoin(conceptTag).on(conceptTag.id.in(problem.conceptTagIds)
.or(conceptTag.id.in(childProblem.conceptTagIds)))
.where(
containsProblemId(problemId),
containsName(memo),
inConceptTagIds(conceptTagIds)
hasConceptTags(conceptTagIds)
)
.leftJoin(conceptTag).on(conceptTag.id.in(problem.conceptTagIds)).fetchJoin()
.distinct()
.transform(GroupBy.groupBy(problem.id).list(
Projections.constructor(ProblemSearchGetResponse.class,
problem.id,
problem.problemCustomId.id,
problem.memo,
problem.mainProblemImageUrl,
Expand All @@ -45,6 +50,30 @@ public List<ProblemSearchGetResponse> search(String problemId, String memo, List
));
}

private BooleanExpression hasConceptTags(List<Long> conceptTagIds) {
if (conceptTagIds == null || conceptTagIds.isEmpty()) {
return null;
}

return problem.id.in(
JPAExpressions
.selectFrom(problem)
.where(
problem.conceptTagIds.any().in(conceptTagIds)
.or(
problem.id.in(
JPAExpressions
.select(childProblem.id)
.from(childProblem)
.where(childProblem.conceptTagIds.any()
.in(conceptTagIds))
)
)
)
.select(problem.id)
);
}

//problemCustomId 일부 포함 검색
private BooleanExpression containsProblemId(String problemId) {
return (problemId == null || problemId.isEmpty()) ? null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.moplus.moplus_server.domain.problem.service;

import com.amazonaws.HttpMethod;
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemCustomId;
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemImageType;
import com.moplus.moplus_server.domain.problem.repository.ProblemRepository;
import com.moplus.moplus_server.global.utils.s3.S3Util;
Expand All @@ -17,15 +16,15 @@ public class ImageUploadService {
private final S3Util s3Util;
private final ProblemRepository problemRepository;

public String generateProblemImagePresignedUrl(String problemId, ProblemImageType imageType) {
problemRepository.existsByProblemAdminIdElseThrow(new ProblemCustomId(problemId));
public String generateProblemImagePresignedUrl(Long problemId, ProblemImageType imageType) {
problemRepository.existsByIdElseThrow(problemId);
String fileName = generateProblemImageFileName(problemId, imageType);
return s3Util.getS3PresignedUrl(fileName, HttpMethod.PUT);
}

private String generateProblemImageFileName(String problemId, ProblemImageType imageType) {
private String generateProblemImageFileName(Long problemId, ProblemImageType imageType) {
String uuid = UUID.randomUUID().toString();
return String.format("%s%s/%s/%s.jpg",
return String.format("%s%d/%s/%s.jpg",
PROBLEM_IMAGE_PREFIX,
problemId,
imageType.getType(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.moplus.moplus_server.domain.problemset.dto.request;

import jakarta.validation.constraints.NotNull;
import java.util.List;

public record ProblemReorderRequest(
@NotNull(message = "컬렉션 값은 필수입니다.")
List<Long> newProblems
) {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.moplus.moplus_server.domain.problemset.dto.request;

import com.moplus.moplus_server.domain.problemset.domain.ProblemSet;
import jakarta.validation.constraints.NotNull;
import java.util.List;

public record ProblemSetPostRequest(
String problemSetTitle,
@NotNull(message = "컬렉션 값은 필수입니다.")
List<Long> problems
) {
public ProblemSet toEntity(List<Long> problemIdList) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.moplus.moplus_server.domain.problemset.dto.request;

import jakarta.validation.constraints.NotNull;
import java.util.List;

public record ProblemSetUpdateRequest(
String problemSetTitle,
@NotNull(message = "컬렉션 값은 필수입니다.")
List<Long> problemIds
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.moplus.moplus_server.domain.problemset.domain.ProblemSet;
import com.moplus.moplus_server.domain.problemset.domain.ProblemSetConfirmStatus;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.List;
import lombok.Builder;
Expand All @@ -12,9 +13,11 @@ public record ProblemSetGetResponse(
String title,
ProblemSetConfirmStatus confirmStatus,
LocalDate publishedDate,
@NotNull(message = "컬렉션 값은 필수입니다.")
List<ProblemSummaryResponse> problemSummaries
) {
public static ProblemSetGetResponse of(ProblemSet problemSet, LocalDate publishedDate, List<ProblemSummaryResponse> problemSummaries) {
public static ProblemSetGetResponse of(ProblemSet problemSet, LocalDate publishedDate,
List<ProblemSummaryResponse> problemSummaries) {

return ProblemSetGetResponse.builder()
.id(problemSet.getId())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moplus.moplus_server.domain.problemset.dto.response;

import com.moplus.moplus_server.domain.problemset.domain.ProblemSetConfirmStatus;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.List;
import lombok.Getter;
Expand All @@ -12,10 +13,12 @@ public class ProblemSetSearchGetResponse {
private String problemSetTitle;
private ProblemSetConfirmStatus confirmStatus;
private LocalDate publishedDate;
@NotNull(message = "컬렉션 값은 필수입니다.")
private List<ProblemThumbnailResponse> problemThumbnailResponses;

public ProblemSetSearchGetResponse(
String problemSetTitle, ProblemSetConfirmStatus confirmStatus, LocalDate publishedDate, List<ProblemThumbnailResponse> problemThumbnailResponses
String problemSetTitle, ProblemSetConfirmStatus confirmStatus, LocalDate publishedDate,
List<ProblemThumbnailResponse> problemThumbnailResponses
) {
this.problemSetTitle = problemSetTitle;
this.confirmStatus = confirmStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moplus.moplus_server.domain.problemset.dto.response;

import com.moplus.moplus_server.domain.problem.domain.problem.Problem;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.Builder;

Expand All @@ -11,6 +12,7 @@ public record ProblemSummaryResponse(
String practiceTestName,
String memo,
String mainProblemImageUrl,
@NotNull(message = "컬렉션 값은 필수입니다.")
List<String> tagNames
) {
public static ProblemSummaryResponse of(Problem problem, String practiceTestName, List<String> tagNames) {
Expand Down
Loading
Loading