Skip to content

Commit

Permalink
Merge pull request #88 from Media-XI/feat/feed-userVoteStatus
Browse files Browse the repository at this point in the history
Feat/feed user vote status
  • Loading branch information
Hoon9901 authored Nov 21, 2023
2 parents aee84a5 + 03695e2 commit dd5d4eb
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void delete() {
}

public String getAuthorVote() {
return this.author.getVoteText();
return this.author.getVote();
}

public Integer getAuthorSequence() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ public boolean isSameVote(String vote) {
return isVoted() && this.vote.equals(vote);
}

public String getVoteText() {
return this.vote;
}

public String getMemberUsername() {
return this.member.getUsername();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.codebase.domain.agora.entity;

import java.util.Optional;

public interface AgoraWithParticipant {
Agora getAgora();

Optional<AgoraParticipant> getAgoraParticipant();

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.example.codebase.domain.agora.repository;

import com.example.codebase.domain.agora.entity.Agora;
import com.example.codebase.domain.agora.entity.AgoraWithParticipant;
import com.example.codebase.domain.member.entity.Member;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

Expand All @@ -11,4 +15,8 @@ public interface AgoraRepository extends JpaRepository<Agora, Long> {
@Query("select a from Agora a where a.id = :id and a.isDeleted = false")
Optional<Agora> findById(Long id);

@Query("SELECT a AS agora, ap AS agoraParticipant " +
"FROM Agora a LEFT JOIN AgoraParticipant ap ON (a = ap.agora AND ap.member = :member) " +
"WHERE a.isDeleted = false")
Page<AgoraWithParticipant> findAllAgoraAndParticipantByMember(Member member, Pageable pageable);
}
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 @@ -211,9 +214,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 @@ -226,6 +229,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 @@ -266,4 +279,5 @@ public static FeedItemResponseDto from(Agora agora) {

return dto;
}

}
Loading

0 comments on commit dd5d4eb

Please sign in to comment.