Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#24 - 서비스 로직 테스트 코드 업데이트 및 DTO 재설계, 쿼리 메소드 작성
테스트 코드를 작성하고 연관된 DTO 를 재설계함 테스트가 필요로 하는 repository 쿼리 메소드도 작성 댓글 Repo 에 존재하는 List<ArticleComment> findByArticle_Id(Long articleId); Article 테이블에서 id를 조회 ((_) == `의`)
- Loading branch information
Showing
14 changed files
with
598 additions
and
57 deletions.
There are no files selected for viewing
45 changes: 39 additions & 6 deletions
45
src/main/java/com/example/boardproject/dto/ArticleCommentDto.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,19 +1,52 @@ | ||
package com.example.boardproject.dto; | ||
|
||
|
||
import com.example.boardproject.domain.Article; | ||
import com.example.boardproject.domain.ArticleComment; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ArticleCommentDto( | ||
Long id, | ||
Long articleId, | ||
UserDto userDto, | ||
String content, | ||
LocalDateTime createdAt, | ||
String createdBy, | ||
LocalDateTime modifiedAt, | ||
String modifiedBy, | ||
String content | ||
String modifiedBy | ||
) { | ||
public static ArticleCommentDto of(LocalDateTime createdAt, | ||
|
||
public static ArticleCommentDto of(Long id, | ||
Long articleId, | ||
UserDto userDto, | ||
String content, | ||
LocalDateTime createdAt, | ||
String createdBy, | ||
LocalDateTime modifiedAt, | ||
String modifiedBy, | ||
String content) { | ||
return new ArticleCommentDto(createdAt, createdBy, modifiedAt, modifiedBy, content); | ||
String modifiedBy) { | ||
return new ArticleCommentDto(id, articleId, userDto, content, createdAt, createdBy, modifiedAt, modifiedBy); | ||
} | ||
|
||
public static ArticleCommentDto from(ArticleComment entity) { | ||
return new ArticleCommentDto( | ||
entity.getId(), | ||
entity.getArticle().getId(), | ||
UserDto.from(entity.getUser()), | ||
entity.getContent(), | ||
entity.getCreatedAt(), | ||
entity.getCreatedBy(), | ||
entity.getModifiedAt(), | ||
entity.getModifiedBy() | ||
); | ||
} | ||
|
||
public ArticleComment toEntity(Article entity) { | ||
return ArticleComment.of( | ||
entity, | ||
userDto.toEntity(), | ||
content | ||
); | ||
} | ||
|
||
} |
48 changes: 41 additions & 7 deletions
48
src/main/java/com/example/boardproject/dto/ArticleDto.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,20 +1,54 @@ | ||
package com.example.boardproject.dto; | ||
|
||
import com.example.boardproject.domain.Article; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ArticleDto( | ||
LocalDateTime createdAt, | ||
String createdBy, | ||
Long id, | ||
UserDto userDto, | ||
String title, | ||
String content, | ||
String hashtag | ||
String hashtag, | ||
LocalDateTime createdAt, | ||
String createdBy, | ||
LocalDateTime modifiedAt, | ||
String modifiedBy | ||
) { | ||
public static ArticleDto of(LocalDateTime createdAt, | ||
String createdBy, | ||
public static ArticleDto of(Long id, | ||
UserDto userDto, | ||
String title, | ||
String content, | ||
String hashtag) { | ||
return new ArticleDto(createdAt, createdBy, title, content, hashtag); | ||
String hashtag, | ||
LocalDateTime createdAt, | ||
String createdBy, | ||
LocalDateTime modifiedAt, | ||
String modifiedBy) { | ||
return new ArticleDto(id, userDto, title, content, hashtag, createdAt, createdBy, modifiedAt, modifiedBy); | ||
} | ||
|
||
// 위 아래의 2가지 method 를 통해 dto -> domain 영향을 없앰 | ||
public static ArticleDto from(Article entity) { | ||
return new ArticleDto( | ||
entity.getId(), | ||
UserDto.from(entity.getUser()), | ||
entity.getTitle(), | ||
entity.getContent(), | ||
entity.getHashtag(), | ||
entity.getCreatedAt(), | ||
entity.getCreatedBy(), | ||
entity.getModifiedAt(), | ||
entity.getModifiedBy() | ||
); | ||
} | ||
|
||
public Article toEntity() { | ||
return Article.of( | ||
userDto.toEntity(), | ||
title, | ||
content, | ||
hashtag | ||
); | ||
} | ||
|
||
} |
11 changes: 0 additions & 11 deletions
11
src/main/java/com/example/boardproject/dto/ArticleUpdateDto.java
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
src/main/java/com/example/boardproject/dto/ArticleWithCommentsDto.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.example.boardproject.dto; | ||
|
||
import com.example.boardproject.domain.Article; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public record ArticleWithCommentsDto( | ||
Long id, | ||
UserDto userDto, | ||
Set<ArticleCommentDto> articleCommentDtos, | ||
String title, | ||
String content, | ||
String hashtag, | ||
LocalDateTime createdAt, | ||
String createdBy, | ||
LocalDateTime modifiedAt, | ||
String modifiedBy | ||
) { | ||
|
||
public static ArticleWithCommentsDto of(Long id, | ||
UserDto userAccountDto, | ||
Set<ArticleCommentDto> articleCommentDtos, | ||
String title, | ||
String content, | ||
String hashtag, | ||
LocalDateTime createdAt, | ||
String createdBy, | ||
LocalDateTime modifiedAt, | ||
String modifiedBy) { | ||
return new ArticleWithCommentsDto(id, userAccountDto, articleCommentDtos, title, | ||
content, hashtag, createdAt, createdBy, modifiedAt, modifiedBy); | ||
} | ||
|
||
public static ArticleWithCommentsDto from(Article entity) { | ||
return new ArticleWithCommentsDto( | ||
entity.getId(), | ||
UserDto.from(entity.getUser()), | ||
entity.getArticleComments().stream() | ||
.map(ArticleCommentDto::from) | ||
.collect(Collectors.toCollection(LinkedHashSet::new)), | ||
entity.getTitle(), | ||
entity.getContent(), | ||
entity.getHashtag(), | ||
entity.getCreatedAt(), | ||
entity.getCreatedBy(), | ||
entity.getModifiedAt(), | ||
entity.getModifiedBy() | ||
); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.example.boardproject.dto; | ||
|
||
import com.example.boardproject.domain.User; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record UserDto( | ||
Long id, | ||
String email, | ||
String userPassword, | ||
String nickname, | ||
String memo, | ||
LocalDateTime createdAt, | ||
String createdBy, | ||
LocalDateTime modifiedAt, | ||
String modifiedBy | ||
) { | ||
|
||
public static UserDto of(Long id, | ||
String email, | ||
String userPassword, | ||
String nickname, | ||
String memo, | ||
LocalDateTime createdAt, | ||
String createdBy, | ||
LocalDateTime modifiedAt, | ||
String modifiedBy) { | ||
return new UserDto(id, email, userPassword, nickname, memo, createdAt, createdBy, modifiedAt, modifiedBy); | ||
} | ||
|
||
public static UserDto from(User entity) { | ||
return new UserDto( | ||
entity.getId(), | ||
entity.getEmail(), | ||
entity.getUserPassword(), | ||
entity.getNickname(), | ||
entity.getMemo(), | ||
entity.getCreatedAt(), | ||
entity.getCreatedBy(), | ||
entity.getModifiedAt(), | ||
entity.getModifiedBy() | ||
); | ||
} | ||
|
||
public User toEntity() { | ||
return User.of( | ||
email, | ||
userPassword, | ||
nickname, | ||
memo | ||
); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/example/boardproject/dto/response/ArticleCommentResponse.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.example.boardproject.dto.response; | ||
|
||
import com.example.boardproject.dto.ArticleCommentDto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ArticleCommentResponse( | ||
Long id, | ||
String content, | ||
LocalDateTime createdAt, | ||
String email, | ||
String nickname | ||
) { | ||
|
||
public static ArticleCommentResponse of(Long id, String content, LocalDateTime createdAt, String email, String nickname) { | ||
return new ArticleCommentResponse(id, content, createdAt, email, nickname); | ||
} | ||
|
||
public static ArticleCommentResponse from(ArticleCommentDto dto) { | ||
String nickname = dto.userDto().nickname(); | ||
if (nickname == null || nickname.isBlank()) { | ||
nickname = dto.userDto().email(); | ||
} | ||
|
||
return new ArticleCommentResponse( | ||
dto.id(), | ||
dto.content(), | ||
dto.createdAt(), | ||
dto.userDto().email(), | ||
nickname | ||
); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/boardproject/dto/response/ArticleResponse.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.boardproject.dto.response; | ||
|
||
import com.example.boardproject.dto.ArticleDto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ArticleResponse( | ||
Long id, | ||
String title, | ||
String content, | ||
String hashtag, | ||
LocalDateTime createdAt, | ||
String email, | ||
String nickname | ||
) { | ||
|
||
public static ArticleResponse of(Long id, String title, String content, String hashtag, LocalDateTime createdAt, String email, String nickname) { | ||
return new ArticleResponse(id, title, content, hashtag, createdAt, email, nickname); | ||
} | ||
|
||
public static ArticleResponse from(ArticleDto dto) { | ||
String nickname = dto.userDto().nickname(); | ||
if (nickname == null || nickname.isBlank()) { | ||
nickname = dto.userDto().email(); | ||
} | ||
|
||
return new ArticleResponse( | ||
dto.id(), | ||
dto.title(), | ||
dto.content(), | ||
dto.hashtag(), | ||
dto.createdAt(), | ||
dto.userDto().email(), | ||
nickname | ||
); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/example/boardproject/dto/response/ArticleWithCommentResponse.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.example.boardproject.dto.response; | ||
|
||
import com.example.boardproject.dto.ArticleWithCommentsDto; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public record ArticleWithCommentResponse( | ||
Long id, | ||
String title, | ||
String content, | ||
String hashtag, | ||
LocalDateTime createdAt, | ||
String email, | ||
String nickname, | ||
Set<ArticleCommentResponse> articleCommentResponses | ||
) { | ||
|
||
public static ArticleWithCommentResponse of(Long id, String title, String content, String hashtag, LocalDateTime createdAt, String email, String nickname, Set<ArticleCommentResponse> articleCommentResponses) { | ||
return new ArticleWithCommentResponse(id, title, content, hashtag, createdAt, email, nickname, articleCommentResponses); | ||
} | ||
|
||
public static ArticleWithCommentResponse from(ArticleWithCommentsDto dto) { | ||
String nickname = dto.userDto().nickname(); | ||
if (nickname == null || nickname.isBlank()) { | ||
nickname = dto.userDto().email(); | ||
} | ||
|
||
return new ArticleWithCommentResponse( | ||
dto.id(), | ||
dto.title(), | ||
dto.content(), | ||
dto.hashtag(), | ||
dto.createdAt(), | ||
dto.userDto().email(), | ||
nickname, | ||
dto.articleCommentDtos().stream() | ||
.map(ArticleCommentResponse::from) | ||
.collect(Collectors.toCollection(LinkedHashSet::new)) | ||
); | ||
} | ||
|
||
} |
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
Oops, something went wrong.