Skip to content

Commit bebaf38

Browse files
committed
style: category를 categories로 네이밍 변경
issue: #471 pr: #472
1 parent 7279e94 commit bebaf38

File tree

12 files changed

+188
-246
lines changed

12 files changed

+188
-246
lines changed

src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
99
import java.time.LocalDateTime;
1010
import java.util.ArrayList;
11-
import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity;
1211
import keeper.project.homepage.ctf.entity.CtfChallengeEntity;
1312
import keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity;
1413
import keeper.project.homepage.ctf.entity.CtfContestEntity;
@@ -70,7 +69,7 @@ public static CtfChallengeAdminDto toDto(CtfChallengeEntity challenge, Long solv
7069
.title(challenge.getName())
7170
.content(challenge.getDescription())
7271
.contestId(challenge.getCtfContestEntity().getId())
73-
.category(challenge.getCtfChallengeHasCtfChallengeCategoryList().stream()
72+
.categories(challenge.getCtfChallengeHasCtfChallengeCategoryList().stream()
7473
.map(CtfChallengeCategoryDto::toDto)
7574
.collect(toList()))
7675
.type(type)

src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeDto.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static java.util.stream.Collectors.toList;
44

55
import com.fasterxml.jackson.annotation.JsonInclude;
6-
import com.fasterxml.jackson.annotation.JsonInclude.Include;
76
import com.fasterxml.jackson.annotation.JsonProperty;
87
import com.fasterxml.jackson.annotation.JsonProperty.Access;
98
import keeper.project.homepage.ctf.entity.CtfChallengeEntity;
@@ -41,7 +40,7 @@ public static CtfChallengeDto toDto(CtfChallengeEntity challenge, Long solvedTea
4140
.title(challenge.getName())
4241
.content(challenge.getDescription())
4342
.contestId(challenge.getCtfContestEntity().getId())
44-
.category(challenge.getCtfChallengeHasCtfChallengeCategoryList()
43+
.categories(challenge.getCtfChallengeHasCtfChallengeCategoryList()
4544
.stream()
4645
.map(CtfChallengeCategoryDto::toDto)
4746
.collect(toList()))

src/main/java/keeper/project/homepage/ctf/dto/CtfCommonChallengeDto.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.fasterxml.jackson.annotation.Nulls;
99
import java.time.LocalDateTime;
1010
import java.util.List;
11-
import java.util.stream.Collectors;
1211
import javax.validation.constraints.Max;
1312
import javax.validation.constraints.Min;
1413
import keeper.project.homepage.ctf.entity.CtfChallengeEntity;
@@ -32,7 +31,7 @@ public class CtfCommonChallengeDto {
3231

3332
protected String title;
3433
protected Long score;
35-
protected List<CtfChallengeCategoryDto> category;
34+
protected List<CtfChallengeCategoryDto> categories;
3635
protected Long contestId;
3736
@Max(MAX_SUBMIT_COUNT)
3837
@Min(MIN_SUBMIT_COUNT)
@@ -57,7 +56,7 @@ public static CtfCommonChallengeDto toDto(CtfChallengeEntity challenge, Boolean
5756
.challengeId(challenge.getId())
5857
.title(challenge.getName())
5958
.contestId(challenge.getCtfContestEntity().getId())
60-
.category(challenge.getCtfChallengeHasCtfChallengeCategoryList()
59+
.categories(challenge.getCtfChallengeHasCtfChallengeCategoryList()
6160
.stream()
6261
.map(CtfChallengeCategoryDto::toDto)
6362
.collect(toList()))

src/test/java/keeper/project/homepage/ctf/controller/CtfAdminControllerTest.java

Lines changed: 69 additions & 103 deletions
Large diffs are not rendered by default.

src/test/java/keeper/project/homepage/ctf/controller/CtfChallengeControllerTest.java

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import java.time.LocalDateTime;
2222
import java.util.ArrayList;
2323
import java.util.List;
24-
import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto;
2524
import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity;
25+
import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory;
2626
import keeper.project.homepage.ctf.entity.CtfChallengeEntity;
2727
import keeper.project.homepage.ctf.entity.CtfContestEntity;
2828
import keeper.project.homepage.ctf.entity.CtfFlagEntity;
@@ -58,17 +58,14 @@ public void getProblemListSuccess() throws Exception {
5858
CtfContestEntity contest = generateCtfContest(adminEntity, true);
5959

6060
Long score = 1000L;
61-
List<CtfChallengeCategoryDto> category = new ArrayList<>();
62-
category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder()
63-
.id(MISC.getId())
64-
.name(MISC.getName())
65-
.build()));
61+
List<CtfChallengeCategory> categories = new ArrayList<>();
62+
categories.add(MISC);
6663
CtfChallengeEntity dynamicChallenge = generateCtfChallenge(
67-
contest, DYNAMIC, category, score, true);
64+
contest, DYNAMIC, categories, score, true);
6865
CtfChallengeEntity standardChallenge = generateCtfChallenge(
69-
contest, STANDARD, category, score, true);
66+
contest, STANDARD, categories, score, true);
7067
CtfChallengeEntity notSolvable = generateCtfChallenge(
71-
contest, DYNAMIC, category, score, false);
68+
contest, DYNAMIC, categories, score, false);
7269

7370
CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L);
7471

@@ -87,8 +84,8 @@ public void getProblemListSuccess() throws Exception {
8784
.andExpect(jsonPath("$.list[0].content").doesNotExist())
8885
.andExpect(jsonPath("$.list[0].contestId")
8986
.value(dynamicChallenge.getCtfContestEntity().getId()))
90-
.andExpect(jsonPath("$.list[0].category[0].id")
91-
.value(category.get(0).getId()))
87+
.andExpect(jsonPath("$.list[0].categories[0].id")
88+
.value(categories.get(0).getId()))
9289
.andExpect(jsonPath("$.list[0].type.id").doesNotExist())
9390
.andExpect(jsonPath("$.list[0].isSolvable").doesNotExist())
9491
.andExpect(jsonPath("$.list[0].score").value(dynamicChallenge.getScore()))
@@ -99,8 +96,8 @@ public void getProblemListSuccess() throws Exception {
9996
.andExpect(jsonPath("$.list[1].content").doesNotExist())
10097
.andExpect(jsonPath("$.list[1].contestId")
10198
.value(standardChallenge.getCtfContestEntity().getId()))
102-
.andExpect(jsonPath("$.list[1].category[0].id")
103-
.value(category.get(0).getId()))
99+
.andExpect(jsonPath("$.list[1].categories[0].id")
100+
.value(categories.get(0).getId()))
104101
.andExpect(jsonPath("$.list[1].type.id").doesNotExist())
105102
.andExpect(jsonPath("$.list[1].isSolvable").doesNotExist())
106103
.andExpect(jsonPath("$.list[1].score").value(standardChallenge.getScore()))
@@ -124,17 +121,14 @@ public void getProblemListSuccess_lastTryTimeNullable() throws Exception {
124121
CtfContestEntity contest = generateCtfContest(adminEntity, true);
125122

126123
Long score = 1000L;
127-
List<CtfChallengeCategoryDto> category = new ArrayList<>();
124+
List<CtfChallengeCategory> categories = new ArrayList<>();
128125

129-
category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder()
130-
.id(FORENSIC.getId())
131-
.name(FORENSIC.getName())
132-
.build()));
126+
categories.add(FORENSIC);
133127

134128
CtfChallengeEntity dynamicChallenge = generateCtfChallenge(
135-
contest, DYNAMIC, category, score, true);
129+
contest, DYNAMIC, categories, score, true);
136130
CtfChallengeEntity standardChallenge = generateCtfChallenge(
137-
contest, STANDARD, category, score, true);
131+
contest, STANDARD, categories, score, true);
138132

139133
CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L);
140134

@@ -162,14 +156,11 @@ public void checkFlagSuccess() throws Exception {
162156
Long maxScore = 1234L;
163157
Long minScore = 567L;
164158

165-
List<CtfChallengeCategoryDto> category = new ArrayList<>();
166-
category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder()
167-
.id(FORENSIC.getId())
168-
.name(FORENSIC.getName())
169-
.build()));
159+
List<CtfChallengeCategory> categories = new ArrayList<>();
160+
categories.add(FORENSIC);
170161

171162
CtfChallengeEntity dynamicChallenge = generateCtfChallenge(
172-
contest, DYNAMIC, category, score, true);
163+
contest, DYNAMIC, categories, score, true);
173164
generateDynamicChallengeInfo(dynamicChallenge, maxScore, minScore);
174165

175166
CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L);
@@ -213,13 +204,10 @@ public void checkFlagFailedByNotEnoughSubmitCount() throws Exception {
213204
Long score = 1000L;
214205
Long maxScore = 1234L;
215206
Long minScore = 567L;
216-
List<CtfChallengeCategoryDto> category = new ArrayList<>();
217-
category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder()
218-
.id(FORENSIC.getId())
219-
.name(FORENSIC.getName())
220-
.build()));
207+
List<CtfChallengeCategory> categories = new ArrayList<>();
208+
categories.add(FORENSIC);
221209
CtfChallengeEntity dynamicChallenge = generateCtfChallenge(
222-
contest, DYNAMIC, category, score, true);
210+
contest, DYNAMIC, categories, score, true);
223211
generateDynamicChallengeInfo(dynamicChallenge, maxScore, minScore);
224212
CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L);
225213
CtfFlagEntity flag = generateCtfFlag(team, dynamicChallenge, false, 0L);
@@ -244,13 +232,10 @@ public void getProblemDetailSuccess() throws Exception {
244232
CtfContestEntity contest = generateCtfContest(adminEntity, true);
245233

246234
Long score = 1000L;
247-
List<CtfChallengeCategoryDto> category = new ArrayList<>();
248-
category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder()
249-
.id(FORENSIC.getId())
250-
.name(FORENSIC.getName())
251-
.build()));
235+
List<CtfChallengeCategory> categories = new ArrayList<>();
236+
categories.add(FORENSIC);
252237
CtfChallengeEntity dynamicChallenge = generateCtfChallenge(
253-
contest, DYNAMIC, category, score, true);
238+
contest, DYNAMIC, categories, score, true);
254239
generateFileInChallenge(dynamicChallenge);
255240

256241
CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L);
@@ -267,8 +252,8 @@ public void getProblemDetailSuccess() throws Exception {
267252
.andExpect(jsonPath("$.data.content").value(dynamicChallenge.getDescription()))
268253
.andExpect(jsonPath("$.data.contestId")
269254
.value(dynamicChallenge.getCtfContestEntity().getId()))
270-
.andExpect(jsonPath("$.data.category[0].id")
271-
.value(category.get(0).getId()))
255+
.andExpect(jsonPath("$.data.categories[0].id")
256+
.value(categories.get(0).getId()))
272257
.andExpect(jsonPath("$.data.type.id").doesNotExist())
273258
.andExpect(jsonPath("$.data.isSolvable").doesNotExist())
274259
.andExpect(

src/test/java/keeper/project/homepage/ctf/controller/CtfSpringTestHelper.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import java.util.Arrays;
1212
import java.util.List;
1313
import keeper.project.homepage.ApiControllerTestHelper;
14-
import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto;
1514
import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity;
15+
import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory;
1616
import keeper.project.homepage.ctf.entity.CtfChallengeEntity;
1717
import keeper.project.homepage.ctf.entity.CtfChallengeHasCtfChallengeCategoryEntity;
1818
import keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity;
@@ -188,7 +188,7 @@ protected CtfTeamEntity generateCtfTeam(CtfContestEntity ctfContestEntity, Membe
188188
protected CtfChallengeEntity generateCtfChallenge(
189189
CtfContestEntity ctfContestEntity,
190190
CtfChallengeType ctfChallengeType,
191-
List<CtfChallengeCategoryDto> category,
191+
List<CtfChallengeCategory> category,
192192
Long score,
193193
boolean isSolvable) {
194194
final long epochTime = System.nanoTime();
@@ -210,8 +210,14 @@ protected CtfChallengeEntity generateCtfChallenge(
210210
.build();
211211
ctfChallengeRepository.save(entity);
212212

213-
List<CtfChallengeCategoryEntity> ctfChallengeCategoryEntityList = category.stream()
214-
.map(CtfChallengeCategoryDto::toEntity).toList();
213+
List<CtfChallengeCategoryEntity> ctfChallengeCategoryEntityList = category
214+
.stream()
215+
.map(ctfChallengeCategory -> CtfChallengeCategoryEntity
216+
.builder()
217+
.id(ctfChallengeCategory.getId())
218+
.name(ctfChallengeCategory.getName())
219+
.build())
220+
.toList();
215221

216222
for (CtfChallengeCategoryEntity ctfChallengeCategory : ctfChallengeCategoryEntityList) {
217223
CtfChallengeHasCtfChallengeCategoryEntity save = ctfChallengeHasCtfChallengeCategoryRepository.save(
@@ -302,8 +308,8 @@ protected List<FieldDescriptor> generateChallengeCommonDtoResponseFields(Respons
302308
commonFields.addAll(Arrays.asList(
303309
fieldWithPath(prefix + ".challengeId").description("해당 문제의 Id"),
304310
fieldWithPath(prefix + ".title").description("문제 제목"),
305-
fieldWithPath(prefix + ".category[].id").description("문제가 속한 카테고리의 id"),
306-
fieldWithPath(prefix + ".category[].name").description("문제가 속한 카테고리의 이름"),
311+
fieldWithPath(prefix + ".categories[].id").description("문제가 속한 카테고리의 id"),
312+
fieldWithPath(prefix + ".categories[].name").description("문제가 속한 카테고리의 이름"),
307313
fieldWithPath(prefix + ".score").description("문제의 점수"),
308314
fieldWithPath(prefix + ".isSolved").description("내가 풀었는 지"),
309315
fieldWithPath(prefix + ".maxSubmitCount").description("최대 제출 횟수"),
@@ -333,8 +339,8 @@ protected List<FieldDescriptor> generateChallengeAdminDtoResponseFields(Response
333339
fieldWithPath(prefix + ".challengeId").description("해당 문제의 Id"),
334340
fieldWithPath(prefix + ".title").description("문제 제목"),
335341
fieldWithPath(prefix + ".content").description("문제 설명"),
336-
fieldWithPath(prefix + ".category[].id").description("문제가 속한 카테고리의 id"),
337-
fieldWithPath(prefix + ".category[].name").description("문제가 속한 카테고리의 이름"),
342+
fieldWithPath(prefix + ".categories[].id").description("문제가 속한 카테고리의 id"),
343+
fieldWithPath(prefix + ".categories[].name").description("문제가 속한 카테고리의 이름"),
338344
fieldWithPath(prefix + ".type.id").description("문제가 속한 타입의 id"),
339345
fieldWithPath(prefix + ".type.name").description("문제가 속한 타입의 이름"),
340346
fieldWithPath(prefix + ".flag").description("문제에 설정 된 flag (현재는 모든 팀이 동일한 flag를 가집니다."),
@@ -388,8 +394,8 @@ protected List<FieldDescriptor> generateChallengeDtoResponseFields(ResponseType
388394
fieldWithPath(prefix + ".challengeId").description("해당 문제의 Id"),
389395
fieldWithPath(prefix + ".title").description("문제 제목"),
390396
fieldWithPath(prefix + ".content").description("문제 설명"),
391-
fieldWithPath(prefix + ".category[].id").description("문제가 속한 카테고리의 id"),
392-
fieldWithPath(prefix + ".category[].name").description("문제가 속한 카테고리의 이름"),
397+
fieldWithPath(prefix + ".categories[].id").description("문제가 속한 카테고리의 id"),
398+
fieldWithPath(prefix + ".categories[].name").description("문제가 속한 카테고리의 이름"),
393399
fieldWithPath(prefix + ".score").description("문제의 점수"),
394400
fieldWithPath(prefix + ".creatorName").description("문제 생성자 이름"),
395401
fieldWithPath(prefix + ".contestId").description("문제의 대회 Id"),

src/test/java/keeper/project/homepage/ctf/controller/CtfTeamControllerTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
import java.util.ArrayList;
2222
import java.util.List;
23-
import keeper.project.homepage.ctf.controller.CtfSpringTestHelper;
24-
import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto;
25-
import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity;
23+
import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory;
2624
import keeper.project.homepage.ctf.entity.CtfChallengeEntity;
2725
import keeper.project.homepage.ctf.entity.CtfContestEntity;
2826
import keeper.project.homepage.ctf.entity.CtfTeamEntity;
@@ -194,12 +192,9 @@ void getTeamDetail() throws Exception {
194192
.build();
195193
ctfTeamHasMemberRepository.save(teamHasMemberEntity);
196194
team.getCtfTeamHasMemberEntityList().add(teamHasMemberEntity);
197-
List<CtfChallengeCategoryDto> category = new ArrayList<>();
198-
category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder()
199-
.id(MISC.getId())
200-
.name(MISC.getName())
201-
.build()));
202-
CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, category, 1234L,
195+
List<CtfChallengeCategory> categories = new ArrayList<>();
196+
categories.add(MISC);
197+
CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, categories, 1234L,
203198
false);
204199
generateCtfFlag(team, challenge, true);
205200

0 commit comments

Comments
 (0)