Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…Codiary into feature/#146-social-login
  • Loading branch information
lee-haeseung committed Aug 11, 2024
2 parents f03cc74 + e058723 commit 70e4505
Show file tree
Hide file tree
Showing 19 changed files with 522 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ public class CommentConverter {

// 댓글 수정하기
// nickname 관련 could not initialize proxy - no Session 에러
// 위 에러로 인해 DTO 변환을 Controller가 아닌 Service에서 했기 때문에
// 해당 메소드는 이후 수정사항이 없으면 쓰지 않을 듯
public static CommentResponseDTO.PatchCommentResultDTO toPatchCommentResultDTO(Comment comment) {
return CommentResponseDTO.PatchCommentResultDTO.builder()
.commentId(comment.getCommentId())
Expand All @@ -28,7 +26,7 @@ public static CommentResponseDTO.DeleteCommentResultDTO toDeleteCommentResultDTO
.build();
}

// 게시글별 댓글 조회
// 게시글별 댓글 개수 조회
public static CommentResponseDTO.CountCommentsResultDTO toCountCommentsResultDTO(Long postId, int countComments) {
return CommentResponseDTO.CountCommentsResultDTO.builder()
.postId(postId)
Expand Down
116 changes: 116 additions & 0 deletions src/main/java/com/codiary/backend/global/converter/PostConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,120 @@ public static List<PostResponseDTO.CommentDTO> toCommentListDTO(List<Comment> co
.collect(Collectors.toList());
}

// 메인페이지 인기글 전체 리스트 조회
public static PostResponseDTO.PostPopularDTO toPostPopularDTO(Post post) {
return PostResponseDTO.PostPopularDTO.builder()
.postId(post.getPostId())
.memberId(post.getMember().getMemberId())
.fileUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postTitle(post.getPostTitle())
.nickname(post.getMember().getNickname())
.postBody(post.getPostBody())
.createdAt(post.getCreatedAt())
.build();
}

public static PostResponseDTO.PostPopularListDTO toPostPopularListDTO(Page<Post> postPopularList) {
List<PostResponseDTO.PostPopularDTO> postPopularDTOList = postPopularList.stream()
.map(PostConverter::toPostPopularDTO).collect(Collectors.toList());

return PostResponseDTO.PostPopularListDTO.builder()
.isLast(postPopularList.isLast())
.isFirst(postPopularList.isFirst())
.totalPage(postPopularList.getTotalPages())
.totalElements(postPopularList.getTotalElements())
.listSize(postPopularDTOList.size())
.postPopularList(postPopularDTOList)
.build();
}

// 메인페이지 인기글 멤버 관심 카테고리별 리스트 조회
public static PostResponseDTO.PostPopularMemberCategoryDTO toPostPopularMemberCategoryDTO(Post post) {
return PostResponseDTO.PostPopularMemberCategoryDTO.builder()
.postId(post.getPostId())
.memberId(post.getMember().getMemberId())
.fileUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postTitle(post.getPostTitle())
.nickname(post.getMember().getNickname())
.postBody(post.getPostBody())
.createdAt(post.getCreatedAt())
.build();
}

public static PostResponseDTO.PostPopularMemberCategoryListDTO toPostPopularMemberCategoryListDTO(Page<Post> postPopularList) {
List<PostResponseDTO.PostPopularMemberCategoryDTO> postPopularDTOList = postPopularList.stream()
.map(PostConverter::toPostPopularMemberCategoryDTO).collect(Collectors.toList());

return PostResponseDTO.PostPopularMemberCategoryListDTO.builder()
.isLast(postPopularList.isLast())
.isFirst(postPopularList.isFirst())
.totalPage(postPopularList.getTotalPages())
.totalElements(postPopularList.getTotalElements())
.listSize(postPopularDTOList.size())
.postPopularMemberCategoryList(postPopularDTOList)
.build();
}

// 메인페이지 최신글 리스트 조회
public static PostResponseDTO.PostLatestDTO toPostLatestDTO(Post post) {
return PostResponseDTO.PostLatestDTO.builder()
.postId(post.getPostId())
.memberId(post.getMember().getMemberId())
.fileUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postTitle(post.getPostTitle())
.nickname(post.getMember().getNickname())
.postBody(post.getPostBody())
.createdAt(post.getCreatedAt())
.build();
}

public static PostResponseDTO.PostLatestListDTO toPostLatestListDTO(Page<Post> postLatestList) {
List<PostResponseDTO.PostLatestDTO> postLatestDTOList = postLatestList.stream()
.map(PostConverter::toPostLatestDTO).collect(Collectors.toList());

return PostResponseDTO.PostLatestListDTO.builder()
.isLast(postLatestList.isLast())
.isFirst(postLatestList.isFirst())
.totalPage(postLatestList.getTotalPages())
.totalElements(postLatestList.getTotalElements())
.listSize(postLatestDTOList.size())
.postLatestList(postLatestDTOList)
.build();
}

// 메인페이지 팔로잉 게시글 리스트 조회
public static PostResponseDTO.PostFollowingDTO toPostFollowingDTO(Post post) {
return PostResponseDTO.PostFollowingDTO.builder()
.postId(post.getPostId())
.memberId(post.getMember().getMemberId())
.fileUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.postTitle(post.getPostTitle())
.nickname(post.getMember().getNickname())
.postBody(post.getPostBody())
.createdAt(post.getCreatedAt())
.build();
}

public static PostResponseDTO.PostFollowingListDTO toPostFollowingListDTO(Page<Post> postFollowingList) {
List<PostResponseDTO.PostFollowingDTO> postFollowingDTOList = postFollowingList.stream()
.map(PostConverter::toPostFollowingDTO).collect(Collectors.toList());

return PostResponseDTO.PostFollowingListDTO.builder()
.isLast(postFollowingList.isLast())
.isFirst(postFollowingList.isFirst())
.totalPage(postFollowingList.getTotalPages())
.totalElements(postFollowingList.getTotalElements())
.listSize(postFollowingDTOList.size())
.postFollowingList(postFollowingDTOList)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.codiary.backend.global.converter;

import com.codiary.backend.global.domain.entity.Project;
import com.codiary.backend.global.domain.entity.Team;
import com.codiary.backend.global.domain.enums.MemberRole;
import com.codiary.backend.global.web.dto.Team.TeamResponseDTO;
import com.codiary.backend.global.web.dto.TeamMember.TeamMemberResponseDTO;

Expand All @@ -17,40 +15,34 @@ public static TeamResponseDTO.CreateTeamResponseDTO toCreateMemberDTO(Team team)
.name(team.getName())
.intro(team.getIntro())
.bannerImageUrl((team.getBannerImage() != null)
? team.getBannerImage().getImageUrl()
: "")
? team.getBannerImage().getImageUrl()
: "")
.profileImageUrl((team.getProfileImage() != null)
? team.getProfileImage().getImageUrl()
: "")
? team.getProfileImage().getImageUrl()
: "")
.build();
}

//팀 조회
public static TeamResponseDTO.TeamCheckResponseDTO toTeamCheckDTO(Team team, Long currentMemberId) {
public static TeamResponseDTO.TeamCheckResponseDTO toTeamCheckResponseDTO(Team team) {
List<TeamMemberResponseDTO.TeamMemberDTO> members = team.getTeamMemberList().stream()
.map(TeamMemberConverter::toTeamMemberDTO)
.collect(Collectors.toList());

// 현재 사용자가 관리자인지 확인
boolean isAdmin = team.getTeamMemberList().stream()
.anyMatch(member -> member.getMember().getMemberId().equals(currentMemberId) &&
member.getTeamMemberRole() == MemberRole.ADMIN);

return TeamResponseDTO.TeamCheckResponseDTO.builder()
.teamId(team.getTeamId())
.name(team.getName())
.intro(team.getIntro())
.bannerImageUrl((team.getBannerImage() != null)
? team.getBannerImage().getImageUrl()
: "")
? team.getBannerImage().getImageUrl()
: "")
.profileImageUrl((team.getProfileImage() != null)
? team.getProfileImage().getImageUrl()
: "")
? team.getProfileImage().getImageUrl()
: "")
.github(team.getGithub())
.email(team.getEmail())
.linkedIn(team.getLinkedin())
.members(members)
.isAdmin(isAdmin)
.build();
}

Expand All @@ -60,23 +52,15 @@ public static TeamResponseDTO.UpdateTeamDTO toUpdateTeamDTO(Team team) {
.name(team.getName())
.intro(team.getIntro())
.bannerImageUrl((team.getBannerImage() != null)
? team.getBannerImage().getImageUrl()
: "")
? team.getBannerImage().getImageUrl()
: "")
.profileImageUrl((team.getProfileImage() != null)
? team.getProfileImage().getImageUrl()
: "")
? team.getProfileImage().getImageUrl()
: "")
.github(team.getGithub())
.linkedIn(team.getLinkedin())
.discord(team.getDiscord())
.instagram(team.getInstagram())
.build();
}

//프로젝트 생성
public static TeamResponseDTO.ProjectDTO toProjectDTO(Project project) {
return TeamResponseDTO.ProjectDTO.builder()
.projectId(project.getProjectId())
.projectName(project.getProjectName())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.codiary.backend.global.repository;

import com.codiary.backend.global.domain.entity.Member;
import com.codiary.backend.global.domain.entity.Post;
import com.codiary.backend.global.domain.entity.Project;
import com.codiary.backend.global.domain.entity.Team;
import com.codiary.backend.global.domain.entity.*;
import com.codiary.backend.global.domain.entity.mapping.MemberCategory;
import com.codiary.backend.global.web.dto.Post.PostResponseDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down Expand Up @@ -44,4 +43,28 @@ public interface PostRepository extends JpaRepository<Post, Long> {

@Query("SELECT p FROM Post p LEFT JOIN p.authorsList a LEFT JOIN p.project j WHERE (p.member = :member OR a.member = :member) AND j.projectId = :projectId ORDER BY p.createdAt DESC")
Page<Post> findPostsByMemberOrAuthorAndProjectId(@Param("member") Member member, @Param("projectId") Long projectId, Pageable pageable);

// 메인페이지 인기글 전체 리스트 조회
@Query("SELECT p FROM Post p " +
"LEFT JOIN p.bookmarkList b " +
"LEFT JOIN p.commentList c " +
"GROUP BY p " +
"ORDER BY (COUNT(b) + COUNT(c)) DESC")
Page<Post> findAllByBookmarkAndCommentCount(Pageable pageable);

// 메인페이지 인기글 멤버 관심 카테고리별 리스트 조회
@Query("SELECT p FROM Post p " +
"JOIN p.categoriesList c " +
"JOIN c.memberCategoryList mc " +
"WHERE mc = :memberCategory " +
"GROUP BY p " +
"ORDER BY (SIZE(p.bookmarkList) + SIZE(p.commentList)) DESC")
Page<Post> findPostsByMemberCategorySorted(MemberCategory memberCategory, Pageable pageable);

// 메인페이지 최신글 리스트 조회
// Page<Post> findAllByOrderByCreatedAtDesc(Pageable pageable);

// 메인페이지 팔로잉 게시글 리스트 조회
Page<Post> findAllByMemberOrderByCreatedAtDesc(Member toMember, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@

public interface TeamMemberRepository extends JpaRepository<TeamMember, Long> {
Optional<TeamMember> findByTeamAndMember(Team team, Member member);

Optional<TeamMember> findByTeam_TeamIdAndMember_MemberId(Long teamId, Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
public interface CommentCommandService {

// 댓글 수정하기
// Comment patchComment(Long commentId, CommentRequestDTO.PatchCommentDTO request);
CommentResponseDTO.PatchCommentResultDTO patchComment(Long commentId, CommentRequestDTO.PatchCommentDTO request);
Comment patchComment(Long commentId, CommentRequestDTO.PatchCommentDTO request);

// 댓글 삭제하기
void deleteComment(Long commentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.codiary.backend.global.apiPayload.code.status.ErrorStatus;
import com.codiary.backend.global.apiPayload.exception.GeneralException;
import com.codiary.backend.global.converter.CommentConverter;
import com.codiary.backend.global.domain.entity.Comment;
import com.codiary.backend.global.domain.entity.Post;
import com.codiary.backend.global.repository.CommentRepository;
Expand All @@ -24,8 +25,7 @@ public class CommentCommandServiceImpl implements CommentCommandService {

// 댓글 수정하기
@Override
// public Comment patchComment(Long commentId, CommentRequestDTO.PatchCommentDTO request) {
public CommentResponseDTO.PatchCommentResultDTO patchComment(Long commentId, CommentRequestDTO.PatchCommentDTO request) {
public Comment patchComment(Long commentId, CommentRequestDTO.PatchCommentDTO request) {

Comment comment = commentRepository.findById(commentId)
.orElseThrow(() -> new GeneralException(ErrorStatus.COMMENT_NOT_FOUND));
Expand All @@ -34,8 +34,9 @@ public CommentResponseDTO.PatchCommentResultDTO patchComment(Long commentId, Com
comment.patchComment(request.getCommentBody());
}

// return commentRepository.save(comment);
return new CommentResponseDTO.PatchCommentResultDTO(comment);
CommentConverter.toPatchCommentResultDTO(comment);

return commentRepository.save(comment);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ public List<PostResponseDTO.CommentDTO> getCommentList(Long postId) {
.map(PostResponseDTO.CommentDTO::new)
.collect(Collectors.toList());

// return commentList;
return commentList;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codiary.backend.global.service.PostService;

import com.codiary.backend.global.domain.entity.Post;
import com.codiary.backend.global.web.dto.Post.PostResponseDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

Expand All @@ -20,4 +21,14 @@ public interface PostQueryService {
Post.PostAdjacent findAdjacentPosts(Long postId);

List<Post> getPostsByMonth(Long memberId, YearMonth yearMonth);

// 메인페이지 인기글 전체 리스트 조회
Page<Post> getPostPopularList(Integer page);
// 메인페이지 인기글 멤버 관심 카테고리별 리스트 조회
Page<Post> getPostPopularMemberCategoryList(Long memberCategoryId, Integer page);
// 메인페이지 최신글 리스트 조회
Page<Post> getPostLatestList(Integer page);
// 메인페이지 팔로잉 게시글 리스트 조회
Page<Post> getPostFollowingList(Long followId, Integer page);

}
Loading

0 comments on commit 70e4505

Please sign in to comment.