Skip to content

Commit cc35521

Browse files
committed
♻️ refactor : 메서드 Quiz 내부로 리팩토링
1 parent 96525ff commit cc35521

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

backend/src/main/java/io/f1/backend/domain/quiz/entity/Quiz.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,22 @@ public void changeDescription(String description) {
8181
public void changeThumbnailUrl(String thumbnailUrl) {
8282
this.thumbnailUrl = thumbnailUrl;
8383
}
84+
85+
public Long getUserIdIfExists() {
86+
Long userId = null;
87+
if (this.creator != null) {
88+
userId = this.creator.getId();
89+
}
90+
91+
return userId;
92+
}
93+
94+
public String getUserNicknameIfExists() {
95+
String nickname = null;
96+
if (this.creator != null) {
97+
nickname = this.creator.getNickname();
98+
}
99+
100+
return nickname;
101+
}
84102
}

backend/src/main/java/io/f1/backend/domain/quiz/mapper/QuizMapper.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,21 @@ public static Quiz quizCreateRequestToQuiz(
3333

3434
public static QuizCreateResponse quizToQuizCreateResponse(Quiz quiz) {
3535
// TODO : creatorId 넣어주는 부분에서 Getter를 안 쓰고, 현재 로그인한 유저의 id를 담는 식으로 바꿔도 될 듯
36-
getUserIdIfExists(quiz);
3736
return new QuizCreateResponse(
3837
quiz.getId(),
3938
quiz.getTitle(),
4039
quiz.getQuizType(),
4140
quiz.getDescription(),
4241
quiz.getThumbnailUrl(),
43-
getUserIdIfExists(quiz));
44-
}
45-
46-
private static Long getUserIdIfExists(Quiz quiz) {
47-
Long userId = null;
48-
if (quiz.getCreator() != null) {
49-
userId = quiz.getCreator().getId();
50-
}
51-
52-
return userId;
53-
}
54-
55-
private static String getUserNicknameIfExists(Quiz quiz) {
56-
String nickname = null;
57-
if (quiz.getCreator() != null) {
58-
nickname = quiz.getCreator().getNickname();
59-
}
60-
61-
return nickname;
42+
quiz.getUserIdIfExists());
6243
}
6344

6445
public static QuizListResponse quizToQuizListResponse(Quiz quiz) {
6546
return new QuizListResponse(
6647
quiz.getId(),
6748
quiz.getTitle(),
6849
quiz.getDescription(),
69-
getUserNicknameIfExists(quiz),
50+
quiz.getUserNicknameIfExists(),
7051
quiz.getQuestions().size(),
7152
quiz.getThumbnailUrl());
7253
}
@@ -98,7 +79,7 @@ public static QuizQuestionListResponse quizToQuizQuestionListResponse(Quiz quiz)
9879
return new QuizQuestionListResponse(
9980
quiz.getTitle(),
10081
quiz.getQuizType(),
101-
getUserIdIfExists(quiz),
82+
quiz.getUserIdIfExists(),
10283
quiz.getDescription(),
10384
quiz.getThumbnailUrl(),
10485
quiz.getQuestions().size(),

0 commit comments

Comments
 (0)