-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#65] feat: 기존 Response 객체 구조 변경 및 ArticlesResponse 생성
- inner class 를 갖게하고, 해당 inner class 객체를 JsonProperty 로 json 객체 네임 변경으로 변경
- Loading branch information
1 parent
03d9ecf
commit 99cb81a
Showing
6 changed files
with
140 additions
and
117 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/study/realworld/article/controller/response/ArticlesResponse.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,35 @@ | ||
package com.study.realworld.article.controller.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.study.realworld.article.controller.response.ArticleResponse.ArticleResponseNested; | ||
import com.study.realworld.article.domain.Article; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.springframework.data.domain.Page; | ||
|
||
public class ArticlesResponse { | ||
|
||
@JsonProperty("articles") | ||
private List<ArticleResponseNested> articleResponseNesteds; | ||
|
||
@JsonProperty("articlesCount") | ||
private int articlesCount; | ||
|
||
ArticlesResponse() { | ||
} | ||
|
||
private ArticlesResponse(List<ArticleResponseNested> articleResponseNesteds, int articlesCount) { | ||
this.articleResponseNesteds = articleResponseNesteds; | ||
this.articlesCount = articlesCount; | ||
} | ||
|
||
public static ArticlesResponse fromPageArticles(Page<Article> articles) { | ||
return new ArticlesResponse( | ||
articles.getContent().stream() | ||
.map(ArticleResponseNested::fromArticle) | ||
.collect(Collectors.toList()), | ||
articles.getSize() | ||
); | ||
} | ||
|
||
} |
76 changes: 37 additions & 39 deletions
76
src/main/java/com/study/realworld/user/controller/response/ProfileResponse.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,62 +1,60 @@ | ||
package com.study.realworld.user.controller.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.study.realworld.user.domain.Bio; | ||
import com.study.realworld.user.domain.Image; | ||
import com.study.realworld.user.domain.Profile; | ||
import com.study.realworld.user.domain.Username; | ||
|
||
@JsonTypeName("profile") | ||
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) | ||
public class ProfileResponse { | ||
|
||
@JsonProperty("username") | ||
private Username username; | ||
@JsonProperty("profile") | ||
private ProfileResponseNested profileResponseNested; | ||
|
||
@JsonProperty("bio") | ||
private Bio bio; | ||
|
||
@JsonProperty("image") | ||
private Image image; | ||
|
||
@JsonProperty("following") | ||
private boolean following; | ||
|
||
protected ProfileResponse() { | ||
ProfileResponse() { | ||
} | ||
|
||
private ProfileResponse(Username username, Bio bio, Image image, boolean following) { | ||
this.username = username; | ||
this.bio = bio; | ||
this.image = image; | ||
this.following = following; | ||
private ProfileResponse(ProfileResponseNested profileResponseNested) { | ||
this.profileResponseNested = profileResponseNested; | ||
} | ||
|
||
public Username getUsername() { | ||
return username; | ||
public static ProfileResponse ofProfile(Profile profile) { | ||
return new ProfileResponse(ProfileResponseNested.ofProfile(profile)); | ||
} | ||
|
||
public Bio getBio() { | ||
return bio; | ||
} | ||
public static class ProfileResponseNested { | ||
|
||
public Image getImage() { | ||
return image; | ||
} | ||
@JsonProperty("username") | ||
private Username username; | ||
|
||
public boolean isFollowing() { | ||
return following; | ||
} | ||
@JsonProperty("bio") | ||
private Bio bio; | ||
|
||
@JsonProperty("image") | ||
private Image image; | ||
|
||
@JsonProperty("following") | ||
private boolean following; | ||
|
||
ProfileResponseNested() { | ||
} | ||
|
||
private ProfileResponseNested(Username username, Bio bio, Image image, boolean following) { | ||
this.username = username; | ||
this.bio = bio; | ||
this.image = image; | ||
this.following = following; | ||
} | ||
|
||
public static ProfileResponseNested ofProfile(Profile profile) { | ||
return new ProfileResponseNested ( | ||
profile.username(), | ||
profile.bio(), | ||
profile.image(), | ||
profile.isFollow() | ||
); | ||
} | ||
|
||
public static ProfileResponse ofProfile(Profile profile) { | ||
return new ProfileResponse( | ||
profile.username(), | ||
profile.bio(), | ||
profile.image(), | ||
profile.isFollow() | ||
); | ||
} | ||
|
||
} |
8 changes: 2 additions & 6 deletions
8
src/test/java/com/study/realworld/article/controller/response/ArticleResponseTest.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,18 +1,14 @@ | ||
package com.study.realworld.article.controller.response; | ||
|
||
import com.study.realworld.article.controller.response.ArticleResponse.AuthorProfile; | ||
import com.study.realworld.article.controller.response.ArticleResponse.ArticleResponseNested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ArticleResponseTest { | ||
|
||
@Test | ||
void articleResponseTest() { | ||
ArticleResponse articleResponse = new ArticleResponse(); | ||
} | ||
|
||
@Test | ||
void authorProfileTest() { | ||
AuthorProfile authorProfile = new AuthorProfile(); | ||
ArticleResponseNested articleResponseNested = new ArticleResponseNested(); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/test/java/com/study/realworld/article/controller/response/ArticlesResponseTest.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,12 @@ | ||
package com.study.realworld.article.controller.response; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class ArticlesResponseTest { | ||
|
||
@Test | ||
void articlesResponseTest() { | ||
ArticlesResponse articlesResponse = new ArticlesResponse(); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
src/test/java/com/study/realworld/user/controller/response/ProfileResponseTest.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,12 +1,14 @@ | ||
package com.study.realworld.user.controller.response; | ||
|
||
import com.study.realworld.user.controller.response.ProfileResponse.ProfileResponseNested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ProfileResponseTest { | ||
|
||
@Test | ||
void profileResponseTest() { | ||
ProfileResponse profileResponse = new ProfileResponse(); | ||
ProfileResponseNested profileResponseNested = new ProfileResponseNested(); | ||
} | ||
|
||
} |