Skip to content

Commit 0cd2d25

Browse files
committed
hotfix : 문제 카테고리를 db table 로 변경 작업 완료
1 parent 3903d81 commit 0cd2d25

File tree

20 files changed

+372
-311
lines changed

20 files changed

+372
-311
lines changed

src/main/java/org/ezcode/codetest/application/problem/dto/response/ProblemDetailResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static ProblemDetailResponse from(Problem problem, List<Category> categor
5959
.creator(problem.getCreator().getNickname())
6060
.title(problem.getTitle())
6161
.description(problem.getDescription())
62-
.categories(categories.stream().map(Category::getCategoryKorName).toList())
62+
.categories(categories.stream().map(Category::getKorName).toList())
6363
.score(problem.getScore())
6464
.difficulty(problem.getDifficulty())
6565
.memoryLimit(problem.getMemoryLimit())

src/main/java/org/ezcode/codetest/application/problem/dto/response/ProblemResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static ProblemResponse from(Problem problem, List<Category> categories) {
4545
return ProblemResponse.builder()
4646
.id(problem.getId())
4747
.creator(problem.getCreator() != null ? problem.getCreator().getNickname() : "존재하지 않는 이름.")
48-
.categories(categories.stream().map(Category::getCategoryKorName).toList())
48+
.categories(categories.stream().map(Category::getKorName).toList())
4949
.title(problem.getTitle())
5050
.score(problem.getScore())
5151
.difficulty(problem.getDifficulty())

src/main/java/org/ezcode/codetest/application/problem/service/ProblemService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.ezcode.codetest.application.problem.dto.request.ProblemUpdateRequest;
1010
import org.ezcode.codetest.application.problem.dto.response.ProblemDetailResponse;
1111
import org.ezcode.codetest.application.problem.dto.response.ProblemResponse;
12+
import org.ezcode.codetest.domain.game.model.character.CategoryStat;
13+
import org.ezcode.codetest.domain.game.util.StatUpdateUtil;
1214
import org.ezcode.codetest.domain.problem.model.ProblemSearchCondition;
1315
import org.ezcode.codetest.domain.problem.model.entity.Category;
1416
import org.ezcode.codetest.domain.problem.model.entity.Problem;
@@ -38,12 +40,15 @@ public class ProblemService {
3840

3941
private final ProblemDomainService problemDomainService;
4042
private final UserDomainService userDomainService;
43+
private final StatUpdateUtil statUpdateUtil;
4144
private final S3Uploader s3Uploader;
4245

4346
@Transactional
4447
public void createCategory(CategoryCreateRequest requestDto) {
4548

46-
problemDomainService.createCategory(requestDto.toCategory());
49+
Category category =problemDomainService.createCategory(requestDto.toCategory());
50+
51+
statUpdateUtil.save(new CategoryStat(category));
4752
}
4853

4954
// 문제 생성 ( 관리자 )

src/main/java/org/ezcode/codetest/application/submission/model/SubmissionContext.java

Lines changed: 103 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.ezcode.codetest.application.submission.dto.event.payload.SubmissionFinalResultPayload;
44
import org.ezcode.codetest.domain.language.model.entity.Language;
55
import org.ezcode.codetest.domain.problem.model.ProblemInfo;
6+
import org.ezcode.codetest.domain.problem.model.entity.Category;
67
import org.ezcode.codetest.domain.problem.model.entity.Problem;
78
import org.ezcode.codetest.domain.problem.model.entity.Testcase;
89
import org.ezcode.codetest.domain.submission.model.SubmissionAggregator;
@@ -17,112 +18,116 @@
1718

1819
public record SubmissionContext(
1920

20-
SubmissionAggregator aggregator,
21+
SubmissionAggregator aggregator,
2122

22-
AtomicInteger passedCount,
23+
AtomicInteger passedCount,
2324

24-
AtomicInteger processedCount,
25+
AtomicInteger processedCount,
2526

26-
AtomicReference<String> message,
27+
AtomicReference<String> message,
2728

28-
CountDownLatch latch,
29+
CountDownLatch latch,
2930

30-
AtomicBoolean notified,
31+
AtomicBoolean notified,
3132

32-
User user,
33+
User user,
3334

34-
Language language,
35+
Language language,
3536

36-
ProblemInfo problemInfo,
37+
ProblemInfo problemInfo,
3738

38-
SubmissionMessage msg
39+
SubmissionMessage msg
3940
) {
40-
public static SubmissionContext initialize(
41-
User user, Language language, ProblemInfo problemInfo, SubmissionMessage msg
42-
) {
43-
return new SubmissionContext(
44-
new SubmissionAggregator(),
45-
new AtomicInteger(0),
46-
new AtomicInteger(0),
47-
new AtomicReference<>("Accepted"),
48-
new CountDownLatch(problemInfo.getTestcaseCount()),
49-
new AtomicBoolean(false),
50-
user,
51-
language,
52-
problemInfo,
53-
msg
54-
);
55-
}
56-
57-
public SubmissionFinalResultPayload toFinalResult() {
58-
return new SubmissionFinalResultPayload(
59-
this.getTestcaseCount(),
60-
this.getPassedCount(),
61-
this.getCurrentMessage()
62-
);
63-
}
64-
65-
public void incrementPassedCount() {
66-
passedCount.incrementAndGet();
67-
}
68-
69-
public void incrementProcessedCount() {
70-
processedCount.incrementAndGet();
71-
}
72-
73-
public int getPassedCount() {
74-
return passedCount.get();
75-
}
76-
77-
public String getCurrentMessage() {
78-
return message.get();
79-
}
80-
81-
public void updateMessage(String message) {
82-
this.message.set(message);
83-
}
84-
85-
public void countDown() {
86-
latch.countDown();
87-
}
88-
89-
public List<Testcase> getTestcases() {
90-
return problemInfo.testcaseList();
91-
}
92-
93-
public int getTestcaseCount() {
94-
return problemInfo.getTestcaseCount();
95-
}
96-
97-
public String getSourceCode() {
98-
return msg.sourceCode();
99-
}
100-
101-
public long getJudge0Id() {
102-
return language.getJudge0Id();
103-
}
104-
105-
public String getInput(int seqId) {
106-
return getTestcases().get(seqId - 1).getInput();
107-
}
108-
109-
public String getExpectedOutput(int seqId) {
110-
return getTestcases().get(seqId - 1).getOutput();
111-
}
112-
113-
public long getTimeLimit() {
114-
return problemInfo.getTimeLimit();
115-
}
116-
117-
public long getMemoryLimit() {
118-
return problemInfo.getMemoryLimit();
119-
}
120-
121-
public String getSessionKey() {
122-
return msg.sessionKey();
123-
}
124-
125-
public Problem getProblem() {
126-
return problemInfo.problem();
127-
}
41+
public static SubmissionContext initialize(
42+
User user, Language language, ProblemInfo problemInfo, SubmissionMessage msg
43+
) {
44+
return new SubmissionContext(
45+
new SubmissionAggregator(),
46+
new AtomicInteger(0),
47+
new AtomicInteger(0),
48+
new AtomicReference<>("Accepted"),
49+
new CountDownLatch(problemInfo.getTestcaseCount()),
50+
new AtomicBoolean(false),
51+
user,
52+
language,
53+
problemInfo,
54+
msg
55+
);
56+
}
57+
58+
public SubmissionFinalResultPayload toFinalResult() {
59+
return new SubmissionFinalResultPayload(
60+
this.getTestcaseCount(),
61+
this.getPassedCount(),
62+
this.getCurrentMessage()
63+
);
64+
}
65+
66+
public void incrementPassedCount() {
67+
passedCount.incrementAndGet();
68+
}
69+
70+
public void incrementProcessedCount() {
71+
processedCount.incrementAndGet();
72+
}
73+
74+
public int getPassedCount() {
75+
return passedCount.get();
76+
}
77+
78+
public String getCurrentMessage() {
79+
return message.get();
80+
}
81+
82+
public void updateMessage(String message) {
83+
this.message.set(message);
84+
}
85+
86+
public void countDown() {
87+
latch.countDown();
88+
}
89+
90+
public List<Testcase> getTestcases() {
91+
return problemInfo.testcaseList();
92+
}
93+
94+
public int getTestcaseCount() {
95+
return problemInfo.getTestcaseCount();
96+
}
97+
98+
public String getSourceCode() {
99+
return msg.sourceCode();
100+
}
101+
102+
public long getJudge0Id() {
103+
return language.getJudge0Id();
104+
}
105+
106+
public String getInput(int seqId) {
107+
return getTestcases().get(seqId - 1).getInput();
108+
}
109+
110+
public String getExpectedOutput(int seqId) {
111+
return getTestcases().get(seqId - 1).getOutput();
112+
}
113+
114+
public long getTimeLimit() {
115+
return problemInfo.getTimeLimit();
116+
}
117+
118+
public long getMemoryLimit() {
119+
return problemInfo.getMemoryLimit();
120+
}
121+
122+
public String getSessionKey() {
123+
return msg.sessionKey();
124+
}
125+
126+
public Problem getProblem() {
127+
return problemInfo.problem();
128+
}
129+
130+
public List<String> getProblemCategories() {
131+
return problemInfo.problemCategories().stream().map(Category::getKorName).toList();
132+
}
128133
}

src/main/java/org/ezcode/codetest/domain/game/exception/GameExceptionCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public enum GameExceptionCode implements ResponseCode {
3131
ENCOUNTER_CHOICE_NOT_EXISTS(false, HttpStatus.BAD_REQUEST, "해당 인카운터 선택지가 존재하지 않습니다."),
3232
ENCOUNTER_TOKEN_EXHAUSTED(false, HttpStatus.BAD_REQUEST, "인카운터 매칭 토큰을 전부 소진했습니다. 6 시간 이후 리필됩니다."),
3333
BATTLE_TOKEN_EXHAUSTED(false, HttpStatus.BAD_REQUEST, "배틀 매칭 토큰을 전부 소진했습니다. 6 시간 이후 리필됩니다."),
34-
PLAYER_TOKEN_BUCKET_NOT_EXISTS(false, HttpStatus.NOT_FOUND, "해당 캐릭터의 매칭 토큰 버킷이 존재하지 않습니다.");
34+
PLAYER_TOKEN_BUCKET_NOT_EXISTS(false, HttpStatus.NOT_FOUND, "해당 캐릭터의 매칭 토큰 버킷이 존재하지 않습니다."),
35+
CATEGORY_STAT_NOT_FOUND(false, HttpStatus.NOT_FOUND, "해당 카테고리에 매칭되는 스텟 상승 비율이 없습니다.");
3536

3637
private final boolean success;
3738
private final HttpStatus status;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.ezcode.codetest.domain.game.model.character;
2+
3+
import java.util.EnumMap;
4+
import java.util.Map;
5+
import java.util.concurrent.ThreadLocalRandom;
6+
7+
import org.ezcode.codetest.domain.problem.model.entity.Category;
8+
import org.hibernate.annotations.OnDelete;
9+
import org.hibernate.annotations.OnDeleteAction;
10+
11+
import jakarta.persistence.CollectionTable;
12+
import jakarta.persistence.Column;
13+
import jakarta.persistence.ElementCollection;
14+
import jakarta.persistence.Entity;
15+
import jakarta.persistence.EnumType;
16+
import jakarta.persistence.FetchType;
17+
import jakarta.persistence.GeneratedValue;
18+
import jakarta.persistence.GenerationType;
19+
import jakarta.persistence.Id;
20+
import jakarta.persistence.JoinColumn;
21+
import jakarta.persistence.MapKeyColumn;
22+
import jakarta.persistence.MapKeyEnumerated;
23+
import jakarta.persistence.OneToOne;
24+
import lombok.AccessLevel;
25+
import lombok.Getter;
26+
import lombok.NoArgsConstructor;
27+
28+
@Getter
29+
@Entity
30+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
31+
public class CategoryStat {
32+
33+
@Id
34+
@GeneratedValue(strategy = GenerationType.IDENTITY)
35+
private Long id;
36+
37+
@OneToOne
38+
@OnDelete(action = OnDeleteAction.CASCADE)
39+
@JoinColumn(name = "category_id", nullable = false, unique = true)
40+
private Category category;
41+
42+
@ElementCollection(fetch = FetchType.LAZY)
43+
@CollectionTable(
44+
name = "category_per_stat_increased_rate",
45+
joinColumns = @JoinColumn(name = "category_stat_id")
46+
)
47+
@MapKeyColumn(name = "stat")
48+
@Column(name = "value")
49+
@MapKeyEnumerated(EnumType.STRING)
50+
private Map<Stat, Double> stats = new EnumMap<>(Stat.class);
51+
52+
public CategoryStat(Category category) {
53+
54+
this.category = category;
55+
56+
for (Stat stat : Stat.values()) {
57+
double randomValue = ThreadLocalRandom.current()
58+
.nextDouble(0.5, 2.0);
59+
stats.put(stat, randomValue);
60+
}
61+
}
62+
63+
}
64+
65+

src/main/java/org/ezcode/codetest/domain/game/model/character/CharacterRealStat.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ public void increase(Stat stat, double rate) {
9494
this.accuracy += rate / 5;
9595
break;
9696
case DEBUGGING:
97-
this.crit += rate / 5;
97+
this.crit += rate / 10;
9898
this.def += rate / 10;
99+
this.atk += rate / 10;
99100
this.stun += rate / 10;
100101
break;
101102
case OPTIMIZATION:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.ezcode.codetest.domain.game.repository;
2+
3+
import java.util.Optional;
4+
5+
import org.ezcode.codetest.domain.game.model.character.CategoryStat;
6+
7+
public interface CategoryStatRepository {
8+
9+
Optional<CategoryStat> findByCategoryId(Long categoryId);
10+
11+
Optional<CategoryStat> findByCategoryName(String name);
12+
13+
CategoryStat save(CategoryStat categoryStat);
14+
}

src/main/java/org/ezcode/codetest/domain/game/service/CharacterStatusDomainService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void gameCharacterLevelUp(Long userId, boolean isProblemSolved, List<Stri
6464

6565
int randomIndex = ThreadLocalRandom.current().nextInt(problemCategory.size());
6666

67-
Map<Stat, Double> increaseStatRate = statUpdateUtil.getStatIncreasePerProblem(problemCategory.get(randomIndex));
67+
Map<Stat, Double> increaseStatRate = statUpdateUtil.getStatIncreasePerProblemCategory(problemCategory.get(randomIndex));
6868

6969
GameCharacter character = characterRepository.findByUserId(userId)
7070
.orElseThrow(() -> new GameException(GameExceptionCode.CHARACTER_NOT_FOUND));

0 commit comments

Comments
 (0)