-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#109
- Loading branch information
Showing
10 changed files
with
78 additions
and
66 deletions.
There are no files selected for viewing
20 changes: 14 additions & 6 deletions
20
...in/java/com/developer/wiki/question/command/application/comment/CommentCreateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
src/main/java/com/developer/wiki/question/command/application/dto/CreateCommentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 10 additions & 6 deletions
16
src/main/java/com/developer/wiki/question/util/CommentConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
package com.developer.wiki.question.util; | ||
|
||
import com.developer.wiki.common.exception.BadRequestException; | ||
import com.developer.wiki.oauth.User; | ||
import com.developer.wiki.question.command.application.dto.CreateCommentRequest; | ||
import com.developer.wiki.question.command.domain.Comment; | ||
import com.developer.wiki.question.command.domain.Question; | ||
import com.developer.wiki.question.query.application.SummaryCommentResponse; | ||
|
||
import java.util.Objects; | ||
|
||
public class CommentConverter { | ||
|
||
public static Comment toComment(CreateCommentRequest createCommentRequest, Question question) { | ||
if (Objects.isNull(createCommentRequest.getNickname()) || Objects.isNull( | ||
createCommentRequest.getPassword())) { | ||
throw new BadRequestException("익명으로 등록시엔 nickname, password를 입력해야 합니다."); | ||
} | ||
return new Comment(createCommentRequest.getNickname(), | ||
PasswordEncrypter.encrypt(createCommentRequest.getPassword()), | ||
createCommentRequest.getContent(), question); | ||
} | ||
|
||
public static Comment toCommentByUser(CreateCommentRequest createCommentRequest, | ||
Question question, Long userId) { | ||
return new Comment(createCommentRequest.getNickname(), | ||
PasswordEncrypter.encrypt(createCommentRequest.getPassword()), | ||
createCommentRequest.getContent(), question, userId); | ||
Question question, User user) { | ||
return new Comment(createCommentRequest.getContent(), question, user); | ||
} | ||
|
||
public static SummaryCommentResponse ofSummary(Comment comment) { | ||
return SummaryCommentResponse.builder().id(comment.getId()).username(comment.getNickname()) | ||
.role(comment.getCommentRole().name()) | ||
.userId(Objects.isNull(comment.getId()) ? null : comment.getUserId()) | ||
.userId(Objects.isNull(comment.getUser()) ? null : comment.getUser().getId()) | ||
.profileUrl(Objects.isNull(comment.getUser()) ? null : comment.getUser().getProfileUrl()) | ||
.content(comment.getContent()).createdAt(comment.getCreatedAt()).build(); | ||
} | ||
} |