Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -1,5 +1,7 @@
package org.ezcode.codetest.application.problem.dto.request;

import java.util.List;

import org.ezcode.codetest.domain.problem.model.entity.Problem;
import org.ezcode.codetest.domain.problem.model.enums.Category;
import org.ezcode.codetest.domain.problem.model.enums.Difficulty;
Expand All @@ -14,7 +16,7 @@ public record ProblemCreateRequest(

@NotNull(message = "카테고리를 설정해야 합니다.")
@Schema(description = "카테고리", example = "FOR_BEGINNER")
Category category,
List<Category> categories,
Comment on lines 17 to +19
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

검증 메시지와 스키마 설명을 복수형으로 업데이트해야 합니다.

필드는 복수 카테고리(List<Category> categories)로 변경되었지만, 검증 메시지와 스키마 설명이 여전히 단수형("카테고리를 설정해야 합니다", "카테고리")으로 되어 있어 일관성이 부족합니다.

다음과 같이 수정하여 일관성을 맞춰주세요:

-	@NotNull(message = "카테고리를 설정해야 합니다.")
-	@Schema(description = "카테고리", example = "FOR_BEGINNER")
+	@NotNull(message = "카테고리들을 설정해야 합니다.")
+	@Schema(description = "카테고리 목록", example = "[\"FOR_BEGINNER\", \"ALGORITHM\"]")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@NotNull(message = "카테고리를 설정해야 합니다.")
@Schema(description = "카테고리", example = "FOR_BEGINNER")
Category category,
List<Category> categories,
@NotNull(message = "카테고리들을 설정해야 합니다.")
@Schema(description = "카테고리 목록", example = "[\"FOR_BEGINNER\", \"ALGORITHM\"]")
List<Category> categories,
🤖 Prompt for AI Agents
In
src/main/java/org/ezcode/codetest/application/problem/dto/request/ProblemCreateRequest.java
lines 17 to 19, update the validation message and schema description to plural
form to match the List<Category> categories field. Change the validation message
to indicate multiple categories are required and update the schema description
to use the plural form for consistency.


@NotBlank(message = "문제 제목을 입력하세요.")
@Schema(description = "제목", example = "A+B")
Expand Down Expand Up @@ -47,7 +49,7 @@ public static Problem toEntity(ProblemCreateRequest request, User user) {

return Problem.builder()
.creator(user)
.category(request.category)
.categories(request.categories)
.title(request.title)
.description(request.description)
.difficulty(request.difficulty.getDifficulty())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ezcode.codetest.application.problem.dto.request;

import java.util.List;

import org.ezcode.codetest.domain.problem.model.entity.Problem;
import org.ezcode.codetest.domain.problem.model.enums.Category;
import org.ezcode.codetest.domain.problem.model.enums.Difficulty;
Expand All @@ -11,7 +13,7 @@
public record ProblemUpdateRequest(

@Schema(description = "카테고리", example = "FOR_BEGINNER")
Category category,
List<Category> categories,

@Schema(description = "제목", example = "A+B")
String title,
Expand All @@ -37,7 +39,7 @@ public static Problem from(ProblemUpdateRequest request, User user) {

return Problem.builder()
.creator(user)
.category(request.category)
.categories(request.categories)
.title(request.title)
.description(request.description)
.difficulty(request.difficulty.getDifficulty())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ezcode.codetest.application.problem.dto.response;

import java.time.LocalDateTime;
import java.util.List;

import org.ezcode.codetest.domain.problem.model.entity.Problem;
import org.ezcode.codetest.domain.problem.model.enums.Category;
Expand All @@ -19,7 +20,7 @@ public record ProblemDetailResponse(
String creator,

@Schema(description = "카테고리", example = "FOR_BEGINNER")
Category category,
List<Category> categories,

@Schema(description = "제목", example = "A+B")
String title,
Expand Down Expand Up @@ -55,7 +56,7 @@ public static ProblemDetailResponse from(Problem problem) {
return ProblemDetailResponse.builder()
.id(problem.getId())
.creator(problem.getCreator().getNickname())
.category(problem.getCategory())
.categories(problem.getCategories())
.title(problem.getTitle())
.description(problem.getDescription())
.score(problem.getScore())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ezcode.codetest.application.problem.dto.response;

import java.util.List;

import org.ezcode.codetest.domain.problem.model.entity.Problem;
import org.ezcode.codetest.domain.problem.model.enums.Category;
import org.ezcode.codetest.domain.problem.model.enums.Reference;
Expand All @@ -17,7 +19,7 @@ public record ProblemResponse(
String creator,

@Schema(description = "카테고리", example = "FOR_BEGINNER")
Category category,
List<Category> categories,

@Schema(description = "제목", example = "A+B")
String title,
Expand All @@ -42,7 +44,7 @@ public static ProblemResponse from(Problem problem) {
return ProblemResponse.builder()
.id(problem.getId())
.creator(problem.getCreator() != null ? problem.getCreator().getNickname() : "존재하지 않는 이름.")
.category(problem.getCategory())
.categories(problem.getCategories())
.title(problem.getTitle())
.score(problem.getScore())
.difficulty(problem.getDifficulty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static ProblemSearchResponse from(ProblemSearchDocument document) {
return ProblemSearchResponse.builder()
.id(document.getId())
.title(document.getTitle())
.category(document.getCategory().toString())
.category(document.getCategories().toString())
.difficulty(document.getDifficulty())
.reference(document.getReference().toString())
.description(document.getDescription())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ezcode.codetest.application.problem.service;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand All @@ -21,20 +22,39 @@ public class ProblemSearchService {

public Set<String> getProblemSuggestions(String keyword) {

Set<ProblemSearchDocument> result = searchDomainService.getSuggestionsByKeyword(keyword);

return result.stream()
.flatMap(doc -> Stream.of(
Optional.ofNullable(doc.getTitle()),
Optional.ofNullable(doc.getReference()).map(Enum::toString),
Optional.ofNullable(doc.getDifficulty()),
Optional.ofNullable(doc.getCategory()).map(Enum::toString),
Optional.ofNullable(doc.getDescription()),
Optional.ofNullable(doc.getCategoryKor()),
Optional.ofNullable(doc.getDifficultyEn()).map(Enum::toString),
return searchDomainService
.getSuggestionsByKeyword(keyword)
.stream()
.flatMap(doc -> {
Stream.Builder<String> searchedKeyword = Stream.builder();

Optional.ofNullable(doc.getTitle()).ifPresent(searchedKeyword::add);
Optional.ofNullable(doc.getReference())
.map(Enum::toString)
.ifPresent(searchedKeyword::add);
Optional.ofNullable(doc.getDifficulty())
.ifPresent(searchedKeyword::add);
Optional.ofNullable(doc.getDescription())
.ifPresent(searchedKeyword::add);
Optional.ofNullable(doc.getDifficultyEn())
.map(Enum::toString)
.ifPresent(searchedKeyword::add);
Optional.ofNullable(doc.getReferenceKor())
))
.flatMap(Optional::stream)
.ifPresent(searchedKeyword::add);

Optional.ofNullable(doc.getCategories())
.stream()
.flatMap(Collection::stream)
.map(Enum::toString)
.forEach(searchedKeyword::add);

Optional.ofNullable(doc.getCategoriesKor())
.stream()
.flatMap(Collection::stream)
.forEach(searchedKeyword::add);

return searchedKeyword.build();
})
.map(String::toUpperCase)
.collect(Collectors.toSet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ProblemDetailResponse modifyProblem(Long problemId, ProblemUpdateRequest

findProblem.update(
findProblem.getCreator(),
request.category(),
request.categories(),
request.title(),
request.description(),
request.difficulty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Stream;

import org.ezcode.codetest.domain.game.exception.GameException;
Expand Down Expand Up @@ -56,12 +57,14 @@ public GameCharacter getGameCharacter(Long userId) {
.orElseThrow(() -> new GameException(GameExceptionCode.CHARACTER_NOT_FOUND));
}

public void gameCharacterLevelUp(Long userId, boolean isProblemSolved, String problemCategory) {
public void gameCharacterLevelUp(Long userId, boolean isProblemSolved, List<String> problemCategory) {

if (!isProblemSolved)
return;

Map<Stat, Double> increaseStatRate = statUpdateUtil.getStatIncreasePerProblem(problemCategory);
int randomIndex = ThreadLocalRandom.current().nextInt(problemCategory.size());

Map<Stat, Double> increaseStatRate = statUpdateUtil.getStatIncreasePerProblem(problemCategory.get(randomIndex));

GameCharacter character = characterRepository.findByUserId(userId)
.orElseThrow(() -> new GameException(GameExceptionCode.CHARACTER_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.ezcode.codetest.domain.user.model.entity.User;

import jakarta.persistence.CascadeType;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -40,10 +41,6 @@ public class Problem extends BaseEntity {
@JoinColumn(name = "creator_id", nullable = false)
private User creator;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Category category;

@Column(nullable = false)
private String title;

Expand Down Expand Up @@ -81,11 +78,21 @@ public class Problem extends BaseEntity {
@ElementCollection(fetch = FetchType.LAZY)
private List<String> imageUrl = new ArrayList<>();

@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(
name = "problem_categories",
joinColumns = @JoinColumn(name = "problem_id")
)
@Column(name = "category")
@Enumerated(EnumType.STRING)
private List<Category> categories = new ArrayList<>();

@Builder
public Problem(User creator, Category category, String title, String description, int score, String difficulty,
public Problem(User creator, List<Category> categories, String title, String description, int score,
String difficulty,
Long memoryLimit, Long timeLimit, Reference reference) {
this.creator = creator;
this.category = category;
this.categories = categories;
this.title = title;
this.description = description;
this.score = score;
Expand All @@ -99,12 +106,13 @@ public Problem(User creator, Category category, String title, String description
}

// 여러개를 하나의 객체로 만드는 것
public static Problem of(User creator, Category category, String title, String description, int score, String difficulty,
public static Problem of(User creator, List<Category> categories, String title, String description, int score,
String difficulty,
Long memoryLimit, Long timeLimit, Reference reference) {

return Problem.builder()
.creator(creator)
.category(category)
.categories(categories)
.title(title)
.description(description)
.score(score)
Expand All @@ -116,20 +124,27 @@ public static Problem of(User creator, Category category, String title, String d
}

// 문제 수정 로직
public void update(User creator, Category category, String title, String description, Difficulty difficulty,
public void update(User creator, List<Category> categories, String title, String description, Difficulty difficulty,
Long memoryLimit, Long timeLimit, Reference reference) {

if (creator != null) this.creator = creator;
if (category != null) this.category = category;
if (title != null) this.title = title;
if (description != null) this.description = description;
if (creator != null)
this.creator = creator;
if (categories != null)
this.categories = categories;
if (title != null)
this.title = title;
if (description != null)
this.description = description;
if (difficulty != null) {
this.difficulty = difficulty.getDifficulty();
this.score = difficulty.getScore();
}
if (memoryLimit != null)this.memoryLimit = memoryLimit;
if (timeLimit != null) this.timeLimit = timeLimit;
if (reference != null) this.reference = reference;
if (memoryLimit != null)
this.memoryLimit = memoryLimit;
if (timeLimit != null)
this.timeLimit = timeLimit;
if (reference != null)
this.reference = reference;
}

public void softDelete() {
Expand All @@ -145,7 +160,6 @@ public void addImage(String image) {
if (imageUrl.contains(image)) {
return; // 중복된 URL 무시
}

imageUrl.add(image);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ezcode.codetest.domain.problem.model.entity;

import java.util.*;

import org.ezcode.codetest.domain.problem.model.enums.Category;
import org.ezcode.codetest.domain.problem.model.enums.Difficulty;
import org.ezcode.codetest.domain.problem.model.enums.Reference;
Expand Down Expand Up @@ -56,7 +58,7 @@ public class ProblemSearchDocument {
)
}
)
private Category category;
private List<Category> categories;

@MultiField(
mainField = @Field(
Expand All @@ -71,7 +73,7 @@ public class ProblemSearchDocument {
)
}
)
private String categoryKor;
private List<String> categoriesKor;

@MultiField(
mainField = @Field(
Expand Down Expand Up @@ -153,23 +155,23 @@ public class ProblemSearchDocument {
public ProblemSearchDocument(
Long id,
String title,
Category category,
List<Category> categories,
String difficulty,
Reference reference,
String description,
String categoryKor,
List<String> categoriesKor,
Difficulty difficultyEn,
String referenceKor,
int score,
Boolean isDeleted
) {
this.id = id;
this.title = title;
this.category = category;
this.categories = categories;
this.difficulty = difficulty;
this.reference = reference;
this.description = description;
this.categoryKor = categoryKor;
this.categoriesKor = categoriesKor;
this.difficultyEn = difficultyEn;
this.referenceKor = referenceKor;
this.score = score;
Expand All @@ -180,12 +182,12 @@ public static ProblemSearchDocument from(Problem problem) {
return ProblemSearchDocument.builder()
.id(problem.getId())
.title(problem.getTitle())
.category(problem.getCategory())
.categories(problem.getCategories())
.difficulty(problem.getDifficulty())
.reference(problem.getReference())
.description(problem.getDescription())
.score(problem.getScore())
.categoryKor(problem.getCategory().getDescription())
.categoriesKor(problem.getCategories().stream().map(Category::getDescription).toList())
.difficultyEn(Difficulty.getDifficultyFromKor(problem.getDifficulty()))
.referenceKor(problem.getReference().getDescription())
.isDeleted(problem.getIsDeleted())
Expand All @@ -199,7 +201,7 @@ public void softDelete() {
public void update(Problem problem) {
if (problem.getId().equals(this.id)) {
this.title = problem.getTitle();
this.category = problem.getCategory();
this.categories = problem.getCategories();
this.difficulty = problem.getDifficulty();
this.reference = problem.getReference();
this.description = problem.getDescription();
Expand Down
Loading