diff --git a/server/src/main/java/com/main36/pikcha/domain/comment/service/CommentService.java b/server/src/main/java/com/main36/pikcha/domain/comment/service/CommentService.java index cbfe28ee..fd866474 100644 --- a/server/src/main/java/com/main36/pikcha/domain/comment/service/CommentService.java +++ b/server/src/main/java/com/main36/pikcha/domain/comment/service/CommentService.java @@ -11,6 +11,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Optional; + @Service @Transactional @RequiredArgsConstructor @@ -18,36 +20,38 @@ public class CommentService { private final CommentRepository commentRepository; - public Comment createComment(Comment comment){ + public Comment createComment(Comment comment) { return commentRepository.save(comment); } public Comment updateComment(Comment comment){ return commentRepository.save(comment);} + @Transactional(readOnly = true) - public Comment findComment(long commentId){ + public Comment findComment(long commentId) { return findVerifiedComment(commentId); } @Transactional(readOnly = true) public Page findComments(int page, int size) { return commentRepository.findAll(PageRequest.of( - page,size, Sort.by("commentId").ascending() + page, size, Sort.by("commentId").ascending() )); } - public void deleteComment(Comment comment){ + public void deleteComment(Comment comment) { commentRepository.delete(comment); } + @Transactional(readOnly = true) - public Comment findVerifiedComment(long commentId){ + public Comment findVerifiedComment(long commentId) { return commentRepository.findById(commentId) - .orElseThrow(()-> new BusinessLogicException(ExceptionCode.COMMENT_NOT_FOUND)); + .orElseThrow(() -> new BusinessLogicException(ExceptionCode.COMMENT_NOT_FOUND)); } - @Transactional(readOnly = true) + public Comment verifyClientId(long clientId, long commentId) { Comment comment = findComment(commentId); - if (!comment.getMember().getMemberId().equals(clientId)) { + if (!(comment.getMember().getMemberId().equals(clientId))) { throw new BusinessLogicException(ExceptionCode.USER_IS_NOT_EQUAL); } diff --git a/server/src/main/java/com/main36/pikcha/domain/image/entity/PostImage.java b/server/src/main/java/com/main36/pikcha/domain/image/entity/PostImage.java index c52c8fab..acb47136 100644 --- a/server/src/main/java/com/main36/pikcha/domain/image/entity/PostImage.java +++ b/server/src/main/java/com/main36/pikcha/domain/image/entity/PostImage.java @@ -1,12 +1,14 @@ package com.main36.pikcha.domain.image.entity; import com.main36.pikcha.domain.post.entity.Post; -import lombok.Getter; -import lombok.Setter; +import lombok.*; import javax.persistence.*; @Entity +@NoArgsConstructor +@AllArgsConstructor +@Builder @Getter @Setter public class PostImage { @@ -19,4 +21,8 @@ public class PostImage { @Column(nullable = false) private String postImageUrl; + +// @ManyToOne +// @JoinColumn(name = "post_id") +// private Post post; } diff --git a/server/src/main/java/com/main36/pikcha/domain/member/controller/MemberController.java b/server/src/main/java/com/main36/pikcha/domain/member/controller/MemberController.java index c9a34cf9..75d970f2 100644 --- a/server/src/main/java/com/main36/pikcha/domain/member/controller/MemberController.java +++ b/server/src/main/java/com/main36/pikcha/domain/member/controller/MemberController.java @@ -2,6 +2,7 @@ import com.main36.pikcha.domain.member.dto.MemberDto; +import com.main36.pikcha.domain.member.dto.MemberResponseDto; import com.main36.pikcha.domain.member.entity.Member; import com.main36.pikcha.domain.member.mapper.MemberMapper; import com.main36.pikcha.domain.member.service.MemberService; @@ -61,8 +62,8 @@ public ResponseEntity> patchMember(Member loginUser, @LoginUser @GetMapping("/users/profile/{member-id}") - public ResponseEntity> getMemberProfile(Member loginUser, - @PathVariable("member-id") @Positive Long memberId) { + public ResponseEntity> getMemberProfile(Member loginUser, + @PathVariable("member-id") @Positive Long memberId) { Member member = memberService.verifyLoginIdAndMemberId(loginUser.getMemberId(), memberId); return new ResponseEntity<>(new DataResponseDto<>(mapper.memberToProfileHomeDto(member)), diff --git a/server/src/main/java/com/main36/pikcha/domain/member/dto/MemberResponseDto.java b/server/src/main/java/com/main36/pikcha/domain/member/dto/MemberResponseDto.java index 9f9c0cfd..f8aa532d 100644 --- a/server/src/main/java/com/main36/pikcha/domain/member/dto/MemberResponseDto.java +++ b/server/src/main/java/com/main36/pikcha/domain/member/dto/MemberResponseDto.java @@ -1,9 +1,14 @@ package com.main36.pikcha.domain.member.dto; +import com.main36.pikcha.domain.post.dto.PostDto; +import com.main36.pikcha.domain.post.dto.PostResponseDto; +import com.main36.pikcha.domain.save.dto.SaveResponseDto; +import com.main36.pikcha.domain.save.entity.Save; import lombok.Builder; import lombok.Data; import java.time.LocalDateTime; +import java.util.List; public class MemberResponseDto { @@ -31,6 +36,9 @@ public static class Profile { private String email; private int totalMyPosts; private int totalMySaves; + private List posts; + private List saves; + // TODO: save private LocalDateTime createdAt; private LocalDateTime modifiedAt; diff --git a/server/src/main/java/com/main36/pikcha/domain/member/mapper/MemberMapper.java b/server/src/main/java/com/main36/pikcha/domain/member/mapper/MemberMapper.java index bc3cb441..18062544 100644 --- a/server/src/main/java/com/main36/pikcha/domain/member/mapper/MemberMapper.java +++ b/server/src/main/java/com/main36/pikcha/domain/member/mapper/MemberMapper.java @@ -2,11 +2,15 @@ import com.main36.pikcha.domain.member.dto.*; import com.main36.pikcha.domain.member.entity.Member; +import com.main36.pikcha.domain.post.dto.PostResponseDto; +import com.main36.pikcha.domain.save.dto.SaveResponseDto; import com.main36.pikcha.global.security.dto.LoginResponseDto; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingConstants; +import java.util.stream.Collectors; + @Mapper(componentModel = MappingConstants.ComponentModel.SPRING) public interface MemberMapper { @@ -17,9 +21,47 @@ public interface MemberMapper { MemberResponseDto.SignUp memberToSignUpResponseDto(Member member); - @Mapping(target = "totalMyPosts", expression = "java(member.getPosts().size())") - @Mapping(target = "totalMySaves", expression = "java(member.getSaves().size())") - MemberResponseDto.Profile memberToProfileHomeDto(Member member); + // @Mapping(target = "totalMyPosts", expression = "java(member.getPosts().size())") +// @Mapping(target = "totalMySaves", expression = "java(member.getSaves().size())") + default MemberResponseDto.Profile memberToProfileHomeDto(Member member) { + return MemberResponseDto.Profile.builder() + .memberId(member.getMemberId()) + .username(member.getUsername()) + .memberTitle(member.getMemberTitle()) + .phoneNumber(member.getPhoneNumber()) + .address(member.getAddress()) + .picture(member.getPicture()) + .email(member.getEmail()) + .totalMyPosts(member.getPosts().size()) + .totalMySaves(member.getSaves().size()) + .posts(member.getPosts().stream() + .map(post -> { + return PostResponseDto.Profile.builder() + .postId(post.getPostId()) + .postTitle(post.getPostTitle()) + .pictureUrl(post.getPostImages().isEmpty() ? "" : post.getPostImages().get(0).getPostImageUrl()) + .views(post.getViews()) + .likes(post.getLikes()) + .createdAt(post.getCreatedAt()) + .modifiedAt(post.getModifiedAt()) + .build(); + }).collect(Collectors.toList())) + .saves(member.getSaves().stream() + .map(save -> { + return SaveResponseDto.builder() + .attractionId(save.getAttraction().getAttractionId()) + .attractionName(save.getAttraction().getAttractionName()) + .fixedImage(save.getAttraction().getFixedImage()) + .likes(save.getAttraction().getLikes()) + .saves(save.getAttraction().getSaves()) + .build(); + }).collect(Collectors.toList())) + .createdAt(member.getCreatedAt()) + .modifiedAt(member.getModifiedAt()) + .build(); + + } + @Mapping(target = "password", constant = "") @Mapping(target = "phoneNumber", constant = "") diff --git a/server/src/main/java/com/main36/pikcha/domain/member/service/MemberService.java b/server/src/main/java/com/main36/pikcha/domain/member/service/MemberService.java index 0237073f..ff09ac31 100644 --- a/server/src/main/java/com/main36/pikcha/domain/member/service/MemberService.java +++ b/server/src/main/java/com/main36/pikcha/domain/member/service/MemberService.java @@ -91,7 +91,7 @@ private Member verifiedMemberByEmail(String email) { return findMember .orElseThrow(() -> new BusinessLogicException(ExceptionCode.MEMBER_NOT_FOUND)); } - + @Transactional(readOnly = true) public Member findMemberByOauth2Id(String oauthId) { Optional byOauthId = memberRepository.findByOauthId(oauthId); diff --git a/server/src/main/java/com/main36/pikcha/domain/post/controller/PostController.java b/server/src/main/java/com/main36/pikcha/domain/post/controller/PostController.java index 2988e8ca..abb84918 100644 --- a/server/src/main/java/com/main36/pikcha/domain/post/controller/PostController.java +++ b/server/src/main/java/com/main36/pikcha/domain/post/controller/PostController.java @@ -96,6 +96,10 @@ public ResponseEntity> registerPost2(Member loginUser, post.setHashTags(hashTagList); post.setPostContents(postContentList); post.setPostImages(postImageList); + + // post.setPostImages(postImageList); + // PostImages.setPost(post) + post.setAttraction(attractionService.findAttraction(attractionId)); post.setMember(loginUser); post.setComments(new ArrayList<>()); diff --git a/server/src/main/java/com/main36/pikcha/domain/post/dto/PostResponseDto.java b/server/src/main/java/com/main36/pikcha/domain/post/dto/PostResponseDto.java index 555dfab4..8b12881f 100644 --- a/server/src/main/java/com/main36/pikcha/domain/post/dto/PostResponseDto.java +++ b/server/src/main/java/com/main36/pikcha/domain/post/dto/PostResponseDto.java @@ -55,4 +55,16 @@ public static class MapsImageUrlResponse{ } + @Data + @Builder + public static class Profile { + + private Long postId; + private String postTitle; + private String pictureUrl; + private int views; + private int likes; + private LocalDateTime createdAt; + private LocalDateTime modifiedAt; + } } diff --git a/server/src/main/java/com/main36/pikcha/domain/post/mapper/PostMapper.java b/server/src/main/java/com/main36/pikcha/domain/post/mapper/PostMapper.java index be776e76..c77be9e0 100644 --- a/server/src/main/java/com/main36/pikcha/domain/post/mapper/PostMapper.java +++ b/server/src/main/java/com/main36/pikcha/domain/post/mapper/PostMapper.java @@ -76,58 +76,4 @@ default List postListToPostHomeResponseDtoList(List .build(); }).collect(Collectors.toList()); } - /*default PostResponseDto.MapsImageUrlResponse postsToPostMapsResponseDto(List postList){ - if(postList == null) { - return null; - } - - PostResponseDto.MapsImageUrlResponse response = new PostResponseDto.MapsImageUrlResponse(); - response.setImageUrls(new ArrayList<>()); - - postList.forEach(post -> { - post.getPostImages() - .stream() - .forEach(postImage -> { - response.getImageUrls().add(postImage.getPostImageUrl()); - }); - }); - return response; - }*/ - - /*default List postListToPostPageResponseDtoList(List postList) { - - if (postList == null) { - return null; - } - - return postList.stream() - .map(post -> { - return PostResponseDto.Detail.builder() - .postId(post.getPostId()) - .postTitle(post.getPostTitle()) - .postContent(post.getPostContent()) - .hashTagContent(post.getHashTagContent()) - .attractionId(post.getAttraction().getAttractionId()) - .attractionAddress(post.getAttraction().getAttractionAddress()) - .views(post.getViews()) - .likes(post.getLikes()) - .username(post.getMember().getUsername()) - .picture(post.getMember().getPicture()) - .comments(post.getComments().stream() - .map(comment -> { - return CommentResponseDto.builder() - .commentId(comment.getCommentId()) - .memberId(comment.getMember().getMemberId()) - .username(comment.getMember().getUsername()) - .memberPicture(comment.getMember().getPicture()) - .commentContent(comment.getCommentContent()) - .createdAt(comment.getCreatedAt()) - .modifiedAt(comment.getModifiedAt()) - .build(); - }).collect(Collectors.toList())) - .createdAt(post.getCreatedAt()) - .modifiedAt(post.getModifiedAt()) - .build(); - }).collect(Collectors.toList()); - }*/ } diff --git a/server/src/main/java/com/main36/pikcha/domain/save/dto/SaveResponseDto.java b/server/src/main/java/com/main36/pikcha/domain/save/dto/SaveResponseDto.java new file mode 100644 index 00000000..a0b7f612 --- /dev/null +++ b/server/src/main/java/com/main36/pikcha/domain/save/dto/SaveResponseDto.java @@ -0,0 +1,19 @@ +package com.main36.pikcha.domain.save.dto; + +import com.main36.pikcha.domain.attraction.dto.AttractionResponseDto; +import lombok.Builder; +import lombok.Data; + +import java.util.List; + +@Data +@Builder +public class SaveResponseDto { + + private Long attractionId; + private String attractionName; + private String fixedImage; + private Long likes; + private Long saves; + +} diff --git a/server/src/main/java/com/main36/pikcha/global/aop/LoginAspect.java b/server/src/main/java/com/main36/pikcha/global/aop/LoginAspect.java index cb83f656..0448060a 100644 --- a/server/src/main/java/com/main36/pikcha/global/aop/LoginAspect.java +++ b/server/src/main/java/com/main36/pikcha/global/aop/LoginAspect.java @@ -39,7 +39,7 @@ public Object getUserEmail(ProceedingJoinPoint joinPoint) throws Throwable { return joinPoint.proceed(args); - } +} @Around("@annotation(com.main36.pikcha.global.aop.LoginUser)") public Object getUser(ProceedingJoinPoint joinPoint) throws Throwable {