Skip to content

Commit

Permalink
feat: 피드 생성 결과에 userVoteStatus 필드 추가
Browse files Browse the repository at this point in the history
피드 생성시 로그인 한 사용자의 아고라 투표 여부를 알 수 있습니다.
  • Loading branch information
Hoon9901 committed Nov 20, 2023
1 parent df46436 commit 02f3caa
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.codebase.domain.agora.dto.AgoraParticipantResponseDTO;
import com.example.codebase.domain.agora.entity.Agora;
import com.example.codebase.domain.agora.entity.AgoraMedia;
import com.example.codebase.domain.agora.entity.AgoraWithParticipant;
import com.example.codebase.domain.artwork.entity.Artwork;
import com.example.codebase.domain.artwork.entity.ArtworkMedia;
import com.example.codebase.domain.artwork.entity.ArtworkWithIsLike;
Expand Down Expand Up @@ -76,6 +77,8 @@ public class FeedItemResponseDto {
private String disagreeText;

private String naturalText;

private String userVoteStatus;
//

@Builder.Default
Expand All @@ -90,38 +93,38 @@ public class FeedItemResponseDto {
public static FeedItemResponseDto from(Artwork artwork) {
String thumbnailUrl = artwork.getArtworkMedia().get(0).getMediaUrl();
List<String> mediaUrls = artwork.getArtworkMedia().stream()
.map(ArtworkMedia::getMediaUrl)
.collect(Collectors.toList());
.map(ArtworkMedia::getMediaUrl)
.collect(Collectors.toList());
String authorName = artwork.getMember().getName();
String authorUsername = artwork.getMember().getUsername();
String authorDescription = artwork.getMember().getIntroduction();
String authorProfileImageUrl = artwork.getMember().getPicture();
List<String> tags = Arrays.stream(artwork.getTags().split(","))
.map(String::trim).collect(Collectors.toList());
.map(String::trim).collect(Collectors.toList());

FeedItemResponseDto dto = FeedItemResponseDto.builder()
.id(artwork.getId())
.type(FeedType.artwork)
.title(artwork.getTitle())
.content(artwork.getDescription())
.thumbnailUrl(thumbnailUrl)
.authorName(authorName)
.authorUsername(authorUsername)
.authorIntroduction(authorDescription)
.authorProfileImageUrl(authorProfileImageUrl)
.authorCompanyName(
artwork.getMember().getCompanyName() != null ? artwork.getMember().getCompanyName() : null)
.authorCompanyRole(
artwork.getMember().getCompanyRole() != null ? artwork.getMember().getCompanyRole() : null)
.tags(tags)
.categoryId(FeedType.artwork.name())
.views(artwork.getViews())
.likes(artwork.getLikes())
.comments(artwork.getComments())
.mediaUrls(mediaUrls)
.createdTime(artwork.getCreatedTime())
.updatedTime(artwork.getUpdatedTime())
.build();
.id(artwork.getId())
.type(FeedType.artwork)
.title(artwork.getTitle())
.content(artwork.getDescription())
.thumbnailUrl(thumbnailUrl)
.authorName(authorName)
.authorUsername(authorUsername)
.authorIntroduction(authorDescription)
.authorProfileImageUrl(authorProfileImageUrl)
.authorCompanyName(
artwork.getMember().getCompanyName() != null ? artwork.getMember().getCompanyName() : null)
.authorCompanyRole(
artwork.getMember().getCompanyRole() != null ? artwork.getMember().getCompanyRole() : null)
.tags(tags)
.categoryId(FeedType.artwork.name())
.views(artwork.getViews())
.likes(artwork.getLikes())
.comments(artwork.getComments())
.mediaUrls(mediaUrls)
.createdTime(artwork.getCreatedTime())
.updatedTime(artwork.getUpdatedTime())
.build();
return dto;
}

Expand All @@ -133,31 +136,31 @@ public static FeedItemResponseDto of(Artwork artwork, Boolean isLiked) {

public static FeedItemResponseDto from(Post post) {
List<String> mediaUrls = post.getPostMedias().stream()
.map(PostMedia::getMediaUrl)
.collect(Collectors.toList());
.map(PostMedia::getMediaUrl)
.collect(Collectors.toList());

FeedItemResponseDto dto = FeedItemResponseDto.builder()
.id(post.getId())
.type(FeedType.post)
.title(null)
.content(post.getContent())
.authorName(post.getAuthor().getName())
.authorUsername(post.getAuthor().getUsername())
.authorIntroduction(post.getAuthor().getIntroduction())
.authorProfileImageUrl(post.getAuthor().getPicture())
.authorCompanyName(
post.getAuthor().getCompanyName() != null ? post.getAuthor().getCompanyName() : null)
.authorCompanyRole(
post.getAuthor().getCompanyRole() != null ? post.getAuthor().getCompanyRole() : null)
.tags(null)
.categoryId(FeedType.post.name())
.views(post.getViews())
.likes(post.getLikes())
.comments(post.getComments())
.mediaUrls(mediaUrls)
.createdTime(post.getCreatedTime())
.updatedTime(post.getUpdatedTime())
.build();
.id(post.getId())
.type(FeedType.post)
.title(null)
.content(post.getContent())
.authorName(post.getAuthor().getName())
.authorUsername(post.getAuthor().getUsername())
.authorIntroduction(post.getAuthor().getIntroduction())
.authorProfileImageUrl(post.getAuthor().getPicture())
.authorCompanyName(
post.getAuthor().getCompanyName() != null ? post.getAuthor().getCompanyName() : null)
.authorCompanyRole(
post.getAuthor().getCompanyRole() != null ? post.getAuthor().getCompanyRole() : null)
.tags(null)
.categoryId(FeedType.post.name())
.views(post.getViews())
.likes(post.getLikes())
.comments(post.getComments())
.mediaUrls(mediaUrls)
.createdTime(post.getCreatedTime())
.updatedTime(post.getUpdatedTime())
.build();
return dto;
}

Expand All @@ -169,31 +172,31 @@ public static FeedItemResponseDto from(PostWithIsLiked postWithIsLiked) {

public static FeedItemResponseDto from(Exhibition exhibition) {
FeedItemResponseDto dto =
FeedItemResponseDto.builder()
.id(exhibition.getId())
.type(FeedType.exhibition)
.title(exhibition.getTitle())
.content(exhibition.getDescription())
.authorName(exhibition.getMember().getName())
.authorUsername(exhibition.getMember().getUsername())
.authorIntroduction(exhibition.getMember().getIntroduction())
.authorProfileImageUrl(exhibition.getMember().getPicture())
.authorCompanyName(
exhibition.getMember().getCompanyName() != null
? exhibition.getMember().getCompanyName()
: null)
.authorCompanyRole(
exhibition.getMember().getCompanyRole() != null
? exhibition.getMember().getCompanyRole()
: null)
.tags(null)
.categoryId(FeedType.exhibition.name())
.views(0)
.likes(0)
.comments(0)
.createdTime(exhibition.getCreatedTime())
.updatedTime(exhibition.getUpdatedTime())
.build();
FeedItemResponseDto.builder()
.id(exhibition.getId())
.type(FeedType.exhibition)
.title(exhibition.getTitle())
.content(exhibition.getDescription())
.authorName(exhibition.getMember().getName())
.authorUsername(exhibition.getMember().getUsername())
.authorIntroduction(exhibition.getMember().getIntroduction())
.authorProfileImageUrl(exhibition.getMember().getPicture())
.authorCompanyName(
exhibition.getMember().getCompanyName() != null
? exhibition.getMember().getCompanyName()
: null)
.authorCompanyRole(
exhibition.getMember().getCompanyRole() != null
? exhibition.getMember().getCompanyRole()
: null)
.tags(null)
.categoryId(FeedType.exhibition.name())
.views(0)
.likes(0)
.comments(0)
.createdTime(exhibition.getCreatedTime())
.updatedTime(exhibition.getUpdatedTime())
.build();

if (exhibition.getFirstEventSchedule() != null) {
FeedItemEventResponseDto eventDto =
Expand All @@ -212,9 +215,9 @@ public static FeedItemResponseDto from(Exhibition exhibition) {
if (exhibition.getExhibitionMedias().size() > 0) {
String thumbnailUrl = exhibition.getExhibitionMedias().get(0).getMediaUrl();
List<String> mediaUrls =
exhibition.getExhibitionMedias().stream()
.map(ExhibitionMedia::getMediaUrl)
.collect(Collectors.toList());
exhibition.getExhibitionMedias().stream()
.map(ExhibitionMedia::getMediaUrl)
.collect(Collectors.toList());
dto.setThumbnailUrl(thumbnailUrl);
dto.setMediaUrls(mediaUrls);
}
Expand All @@ -227,6 +230,16 @@ public static FeedItemResponseDto from(ArtworkWithIsLike artworkWithIsLike) {
dto.setIsLiked(artworkWithIsLike.getIsLike());
return dto;
}

public static FeedItemResponseDto from(AgoraWithParticipant agoraWithParticipant) {
FeedItemResponseDto dto = from(agoraWithParticipant.getAgora());
agoraWithParticipant.getAgoraParticipant()
.ifPresent(agoraParticipant -> {
dto.setUserVoteStatus(agoraParticipant.getVote());
});
return dto;
}

public static FeedItemResponseDto from(Agora agora) {
AgoraParticipantResponseDTO agoraParticipantResponseDTO = AgoraParticipantResponseDTO.of(agora.getAuthor(),
agora.getIsAnonymous(), 0);
Expand Down Expand Up @@ -267,4 +280,5 @@ public static FeedItemResponseDto from(Agora agora) {

return dto;
}

}
Loading

0 comments on commit 02f3caa

Please sign in to comment.