-
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.
feat : 조회용 DTO 추가, QueryDSL JOIN 최적화, 스타페이지 조회 API 표현, 응용 계층 개발 (#53)
- Loading branch information
1 parent
2942f36
commit 881672b
Showing
41 changed files
with
923 additions
and
97 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
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
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
40 changes: 40 additions & 0 deletions
40
...her/src/main/java/com/neo/needeachother/starpage/application/StarPageViewDataService.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,40 @@ | ||
package com.neo.needeachother.starpage.application; | ||
|
||
import com.neo.needeachother.starpage.application.dto.StarPageTopViewData; | ||
import com.neo.needeachother.starpage.application.dto.StarPageViewData; | ||
import com.neo.needeachother.starpage.application.mapper.StarPageViewDataMapper; | ||
import com.neo.needeachother.starpage.domain.StarPage; | ||
import com.neo.needeachother.starpage.domain.StarPageId; | ||
import com.neo.needeachother.starpage.domain.dto.LayoutHeadLine; | ||
import com.neo.needeachother.starpage.domain.repository.StarPageRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
import static com.neo.needeachother.starpage.application.StarPageServiceHelper.*; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class StarPageViewDataService { | ||
|
||
private final StarPageRepository starPageRepository; | ||
private final StarPageViewDataMapper starPageViewDataMapper; | ||
|
||
public StarPageTopViewData getStarPageTopViewData(String starPageId){ | ||
// 스타페이지 정보 포함된 스타페이지 | ||
StarPage foundStarPage = findExistingStarPageWithTopViewInformation(starPageRepository, new StarPageId(starPageId)); | ||
|
||
return starPageViewDataMapper.mapToTopViewData(foundStarPage); | ||
} | ||
|
||
public StarPageViewData getStarPageLayoutViewData(String starPageId){ | ||
// 레이아웃이 조인된 스타페이지 | ||
StarPage foundStarPage = findExistingStarPageWithLayout(starPageRepository, new StarPageId(starPageId)); | ||
|
||
// 레이아웃 순서에 따른 순차적인 뷰를 구성하는 데이터 | ||
List<LayoutHeadLine> starPageViewLayoutList = foundStarPage.getLayoutHeadLines(starPageRepository); | ||
|
||
return starPageViewDataMapper.mapToViewData(foundStarPage.getStarPageId(), starPageViewLayoutList); | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
...chother/src/main/java/com/neo/needeachother/starpage/application/StarPageViewService.java
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
.../src/main/java/com/neo/needeachother/starpage/application/dto/StarPageLayoutViewData.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,15 @@ | ||
package com.neo.needeachother.starpage.application.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Getter | ||
@Builder | ||
public class StarPageLayoutViewData { | ||
private String layoutTitle; | ||
private boolean hasTap; | ||
private Map<String, List<StarPageLayoutViewTileData>> layoutTileDataWithTap; | ||
} |
27 changes: 27 additions & 0 deletions
27
.../main/java/com/neo/needeachother/starpage/application/dto/StarPageLayoutViewTileData.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,27 @@ | ||
package com.neo.needeachother.starpage.application.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Map; | ||
|
||
@Getter | ||
@Builder | ||
public class StarPageLayoutViewTileData { | ||
private Long postId; | ||
private int likeCount; | ||
private String categoryType; | ||
private String categoryTitle; | ||
private String author; | ||
private String title; | ||
private String representativeImage; | ||
private String question; | ||
private String leftExample; | ||
private String rightExample; | ||
private int leftCount; | ||
private int rightCount; | ||
private int leftRate; | ||
private int rightRate; | ||
private Map<String, Integer> optionCount; | ||
} |
20 changes: 20 additions & 0 deletions
20
...her/src/main/java/com/neo/needeachother/starpage/application/dto/StarPageTopViewData.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,20 @@ | ||
package com.neo.needeachother.starpage.application.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Getter | ||
@Builder | ||
public class StarPageTopViewData { | ||
private String starPageId; | ||
private String hostActiveName; | ||
private String starPageIntroduce; | ||
private List<String> starTypes; | ||
private Map<String, String> starUrl; | ||
private String topRepresentativeImageUrl; | ||
private String profileImageUrl; | ||
} |
14 changes: 14 additions & 0 deletions
14
...hother/src/main/java/com/neo/needeachother/starpage/application/dto/StarPageViewData.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,14 @@ | ||
package com.neo.needeachother.starpage.application.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
public class StarPageViewData { | ||
private String starPageId; | ||
private List<StarPageLayoutViewData> layoutViewData; | ||
} |
5 changes: 5 additions & 0 deletions
5
needeachother/src/main/java/com/neo/needeachother/starpage/application/mapper/Mapper.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,5 @@ | ||
package com.neo.needeachother.starpage.application.mapper; | ||
|
||
public interface Mapper<IN, OUT>{ | ||
OUT map(IN input); | ||
} |
52 changes: 52 additions & 0 deletions
52
.../java/com/neo/needeachother/starpage/application/mapper/StarPageLayoutViewDataMapper.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,52 @@ | ||
package com.neo.needeachother.starpage.application.mapper; | ||
|
||
import com.neo.needeachother.starpage.application.dto.StarPageLayoutViewData; | ||
import com.neo.needeachother.starpage.application.dto.StarPageLayoutViewTileData; | ||
import com.neo.needeachother.starpage.domain.dto.LayoutHeadLine; | ||
import com.neo.needeachother.starpage.domain.dto.RepresentativeArticleHeadLine; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class StarPageLayoutViewDataMapper implements Mapper<LayoutHeadLine, StarPageLayoutViewData> { | ||
|
||
private final StarPageLayoutViewTileDataMapper starPageLayoutViewTileDataMapper; | ||
|
||
@Override | ||
public StarPageLayoutViewData map(LayoutHeadLine input) { | ||
boolean hasTap = input.getLayoutContents().get(0) instanceof RepresentativeArticleHeadLine; | ||
return StarPageLayoutViewData.builder() | ||
.layoutTitle(input.getLayoutTitle()) | ||
.hasTap(hasTap) | ||
.layoutTileDataWithTap(getStarPageLayoutViewTileDataMap(hasTap, input)) | ||
.build(); | ||
} | ||
|
||
private Map<String, List<StarPageLayoutViewTileData>> getStarPageLayoutViewTileDataMap(boolean hasTap, LayoutHeadLine layoutHeadLine) { | ||
Map<String, List<StarPageLayoutViewTileData>> tileMap = new HashMap<>(); | ||
if (hasTap) { | ||
layoutHeadLine.getLayoutContents() | ||
.stream() | ||
.map(starPageHeadLine -> (RepresentativeArticleHeadLine) starPageHeadLine) | ||
.forEach(representativeArticleHeadLine -> { | ||
List<StarPageLayoutViewTileData> dataList = tileMap.getOrDefault(representativeArticleHeadLine.getTapName(), new ArrayList<>()); | ||
dataList.add(starPageLayoutViewTileDataMapper.map(representativeArticleHeadLine)); | ||
tileMap.put(representativeArticleHeadLine.getTapName(), dataList); | ||
}); | ||
} else { | ||
tileMap.put(layoutHeadLine.getLayoutTitle(), layoutHeadLine.getLayoutContents() | ||
.stream() | ||
.map(starPageLayoutViewTileDataMapper::map) | ||
.toList()); | ||
} | ||
return tileMap; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...a/com/neo/needeachother/starpage/application/mapper/StarPageLayoutViewTileDataMapper.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.neo.needeachother.starpage.application.mapper; | ||
|
||
import com.neo.needeachother.starpage.application.dto.StarPageLayoutViewTileData; | ||
import com.neo.needeachother.starpage.domain.dto.*; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class StarPageLayoutViewTileDataMapper implements Mapper<StarPageHeadLine, StarPageLayoutViewTileData> { | ||
|
||
@Override | ||
public StarPageLayoutViewTileData map(StarPageHeadLine input) { | ||
StarPageLayoutViewTileData.StarPageLayoutViewTileDataBuilder builder = StarPageLayoutViewTileData | ||
.builder() | ||
.postId(input.getPostId()) | ||
.likeCount(input.getLikeCount()) | ||
.categoryType(input.getCategoryType()); | ||
|
||
if (input instanceof CommonPostHeadLine) { | ||
builder.author(((CommonPostHeadLine) input).getAuthor()) | ||
.title(((CommonPostHeadLine) input).getTitle()) | ||
.representativeImage(((CommonPostHeadLine) input).getRepresentativeImage()); | ||
} else if (input instanceof GoldBalancePostHeadLine) { | ||
builder.question(((GoldBalancePostHeadLine) input).getQuestion()) | ||
.leftExample(((GoldBalancePostHeadLine) input).getLeftExample()) | ||
.rightExample(((GoldBalancePostHeadLine) input).getRightExample()) | ||
.leftCount(((GoldBalancePostHeadLine) input).getLeftCount()) | ||
.rightCount(((GoldBalancePostHeadLine) input).getRightCount()) | ||
.leftRate(((GoldBalancePostHeadLine) input).getLeftRate()) | ||
.rightRate(((GoldBalancePostHeadLine) input).getRightRate()); | ||
} else if (input instanceof ImagePostHeadLine) { | ||
builder.representativeImage(((ImagePostHeadLine) input).getRepresentativeImage()); | ||
} else if (input instanceof VotePostHeadLine) { | ||
builder.question(((VotePostHeadLine) input).getQuestion()) | ||
.optionCount(((VotePostHeadLine) input).getOptionCount()); | ||
} else if (input instanceof RepresentativeArticleHeadLine) { | ||
builder.author(((RepresentativeArticleHeadLine) input).getAuthor()) | ||
.categoryTitle(((RepresentativeArticleHeadLine) input).getCategoryTitle()) | ||
.title(((RepresentativeArticleHeadLine) input).getTitle()) | ||
.representativeImage(((RepresentativeArticleHeadLine) input).getRepresentativeImage()); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.