From 6e693bf755b93ce582dd8cd960800faccf0d64b7 Mon Sep 17 00:00:00 2001 From: parseyong Date: Sun, 29 Sep 2024 01:33:43 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Feat]=20=EC=8A=A4=EB=83=85=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=ED=83=9C=EA=B7=B8=EB=90=9C=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=EC=9D=98=20=ED=94=84=EB=A1=9C=ED=95=84,=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84,=20=ED=8C=94=EB=A1=9C=EC=9A=B0=EC=97=AC=EB=B6=80?= =?UTF-8?q?=EB=A5=BC=20=EA=B0=99=EC=9D=B4=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20#151?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SnapPagingServiceImpl.java | 2 +- .../snap/service/impl/SnapServiceImpl.java | 2 +- .../snapTag/dto/res/TagUserFindResDto.java | 10 ++++++++-- .../snapTag/service/SnapTagService.java | 2 +- .../service/impl/SnapTagServiceImpl.java | 17 +++++++++++++++-- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/snaptime/snap/service/impl/SnapPagingServiceImpl.java b/src/main/java/me/snaptime/snap/service/impl/SnapPagingServiceImpl.java index 724e19fa..13abb1a3 100644 --- a/src/main/java/me/snaptime/snap/service/impl/SnapPagingServiceImpl.java +++ b/src/main/java/me/snaptime/snap/service/impl/SnapPagingServiceImpl.java @@ -51,7 +51,7 @@ public SnapPagingResDto findSnapPage(String reqEmail, Long pageNum){ String snapPhotoURL = urlComponent.makePhotoURL(tuple.get(snap.fileName),false); return SnapDetailInfoResDto.toDto(tuple,profilePhotoURL,snapPhotoURL, - snapTagService.findTagUsers(snapId), + snapTagService.findTagUsers(snapId, reqEmail), snapLikeService.findSnapLikeCnt(snapId), snapLikeService.isLikedSnap(snapId, reqEmail)); }).collect(Collectors.toList()); diff --git a/src/main/java/me/snaptime/snap/service/impl/SnapServiceImpl.java b/src/main/java/me/snaptime/snap/service/impl/SnapServiceImpl.java index 44337b87..18b7de23 100644 --- a/src/main/java/me/snaptime/snap/service/impl/SnapServiceImpl.java +++ b/src/main/java/me/snaptime/snap/service/impl/SnapServiceImpl.java @@ -96,7 +96,7 @@ public SnapDetailInfoResDto findSnap(Long id, String userEmail) { } String snapPhotoUrl = urlComponent.makePhotoURL(foundSnap.getFileName(), foundSnap.isPrivate()); String profilePhotoUrl = urlComponent.makeProfileURL(foundSnap.getUser().getProfilePhoto().getProfilePhotoId()); - List tagUserFindResDtos = snapTagService.findTagUsers(foundSnap.getId()); + List tagUserFindResDtos = snapTagService.findTagUsers(foundSnap.getId(), userEmail); Long likeCnt = snapLikeService.findSnapLikeCnt(foundSnap.getId()); boolean isLikedSnap = snapLikeService.isLikedSnap(foundSnap.getId(), userEmail); return SnapDetailInfoResDto.toDto(foundSnap, profilePhotoUrl, snapPhotoUrl, tagUserFindResDtos, likeCnt, isLikedSnap); diff --git a/src/main/java/me/snaptime/snapTag/dto/res/TagUserFindResDto.java b/src/main/java/me/snaptime/snapTag/dto/res/TagUserFindResDto.java index 5087ea9c..779261f5 100644 --- a/src/main/java/me/snaptime/snapTag/dto/res/TagUserFindResDto.java +++ b/src/main/java/me/snaptime/snapTag/dto/res/TagUserFindResDto.java @@ -7,13 +7,19 @@ public record TagUserFindResDto( String tagUserEmail, - String tagUserName + String tagUserName, + String tagName, + String tagUserProfileUrl, + boolean isFollow ) { - public static TagUserFindResDto toDto(SnapTag snapTag){ + public static TagUserFindResDto toDto(SnapTag snapTag, String tagUserProfileUrl, boolean isFollow){ return TagUserFindResDto.builder() .tagUserEmail(snapTag.getTagUser().getEmail()) .tagUserName(snapTag.getTagUser().getName()) + .tagName(snapTag.getTagUser().getName()) + .tagUserProfileUrl(tagUserProfileUrl) + .isFollow(isFollow) .build(); } } diff --git a/src/main/java/me/snaptime/snapTag/service/SnapTagService.java b/src/main/java/me/snaptime/snapTag/service/SnapTagService.java index 256ef462..98c75fcd 100644 --- a/src/main/java/me/snaptime/snapTag/service/SnapTagService.java +++ b/src/main/java/me/snaptime/snapTag/service/SnapTagService.java @@ -17,5 +17,5 @@ public interface SnapTagService { void deleteAllTagUser(Snap snap); // 스냅에 태그된 유저들의 정보를 가져옵니다. - List findTagUsers(Long snapId); + List findTagUsers(Long snapId, String reqEmail); } diff --git a/src/main/java/me/snaptime/snapTag/service/impl/SnapTagServiceImpl.java b/src/main/java/me/snaptime/snapTag/service/impl/SnapTagServiceImpl.java index bc0b27ea..92873e57 100644 --- a/src/main/java/me/snaptime/snapTag/service/impl/SnapTagServiceImpl.java +++ b/src/main/java/me/snaptime/snapTag/service/impl/SnapTagServiceImpl.java @@ -3,8 +3,10 @@ import lombok.RequiredArgsConstructor; import me.snaptime.alarm.common.AlarmType; import me.snaptime.alarm.service.AlarmAddService; +import me.snaptime.component.url.UrlComponent; import me.snaptime.exception.CustomException; import me.snaptime.exception.ExceptionCode; +import me.snaptime.friend.service.FriendService; import me.snaptime.snap.domain.Snap; import me.snaptime.snap.repository.SnapRepository; import me.snaptime.snapTag.domain.SnapTag; @@ -30,6 +32,8 @@ public class SnapTagServiceImpl implements SnapTagService { private final UserRepository userRepository; private final SnapRepository snapRepository; private final AlarmAddService alarmAddService; + private final UrlComponent urlComponent; + private final FriendService friendService; @Override @Transactional @@ -79,12 +83,21 @@ public void deleteAllTagUser(Snap snap){ } @Override - public List findTagUsers(Long snapId){ + public List findTagUsers(Long snapId, String reqEmail){ Snap snap = snapRepository.findById(snapId) .orElseThrow(() -> new CustomException(ExceptionCode.SNAP_NOT_EXIST)); + User reqUser = userRepository.findByEmail(reqEmail) + .orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST)); List snapTags = snapTagRepository.findBySnap(snap); - return snapTags.stream().map( snapTag -> TagUserFindResDto.toDto(snapTag)).collect(Collectors.toList()); + + return snapTags.stream().map( snapTag ->{ + User tagUser = snapTag.getTagUser(); + + String tagUserProfileUrl = urlComponent.makeProfileURL(tagUser.getProfilePhoto().getProfilePhotoId()); + boolean isFollow = friendService.checkIsFollow(reqUser, tagUser); + return TagUserFindResDto.toDto(snapTag, tagUserProfileUrl, isFollow); + }).collect(Collectors.toList()); } // 삭제된 태그유저 추출 From 25fa1aa939622d391d9a05853d6a03646f12900c Mon Sep 17 00:00:00 2001 From: parseyong Date: Sun, 29 Sep 2024 01:53:56 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Refactor]=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=ED=86=A0=EA=B8=80=20=EC=8B=9C=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=EB=8F=84=20=EA=B0=99=EC=9D=B4=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20#151?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- null0929014445235_720910390_profile | 0 .../email/contoller/EmailController.java | 1 - .../controller/SnapLikeController.java | 7 ++++--- .../snapLike/dto/res/SnapLikeResDto.java | 18 ++++++++++++++++++ .../snapLike/service/SnapLikeService.java | 4 +++- .../service/impl/SnapLikeServiceImpl.java | 7 ++++--- .../SnapPagingRepositoryImplTest.java | 1 - .../repository/FriendPagingRepositoryTest.java | 1 - 8 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 null0929014445235_720910390_profile create mode 100644 src/main/java/me/snaptime/snapLike/dto/res/SnapLikeResDto.java diff --git a/null0929014445235_720910390_profile b/null0929014445235_720910390_profile new file mode 100644 index 00000000..e69de29b diff --git a/src/main/java/me/snaptime/email/contoller/EmailController.java b/src/main/java/me/snaptime/email/contoller/EmailController.java index ef46aecd..92669019 100644 --- a/src/main/java/me/snaptime/email/contoller/EmailController.java +++ b/src/main/java/me/snaptime/email/contoller/EmailController.java @@ -7,7 +7,6 @@ import lombok.extern.slf4j.Slf4j; import me.snaptime.common.CommonResponseDto; import me.snaptime.email.service.EmailService; -import me.snaptime.profile.dto.res.UserProfileResDto; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; diff --git a/src/main/java/me/snaptime/snapLike/controller/SnapLikeController.java b/src/main/java/me/snaptime/snapLike/controller/SnapLikeController.java index e5abf262..733b798a 100644 --- a/src/main/java/me/snaptime/snapLike/controller/SnapLikeController.java +++ b/src/main/java/me/snaptime/snapLike/controller/SnapLikeController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import me.snaptime.common.CommonResponseDto; +import me.snaptime.snapLike.dto.res.SnapLikeResDto; import me.snaptime.snapLike.service.SnapLikeService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -28,11 +29,11 @@ public class SnapLikeController { "특정 유저가 특정스냅에 좋아요를 눌렀다면 좋아요가 취소됩니다.
"+ "좋아요를 누르지 않았다면 좋아요가 추가됩니다.") @Parameter(name = "snapId", description = "snap아이디를 입력해주세요.") - public ResponseEntity> toggleSnapLike( + public ResponseEntity> toggleSnapLike( @AuthenticationPrincipal final UserDetails userDetails, @RequestParam final Long snapId){ - String message = snapLikeService.toggleSnapLike(userDetails.getUsername(), snapId); - return ResponseEntity.status(HttpStatus.OK).body(new CommonResponseDto(message,null)); + return ResponseEntity.status(HttpStatus.OK) + .body(new CommonResponseDto("좋아요 토글 성공",snapLikeService.toggleSnapLike(userDetails.getUsername(), snapId))); } } diff --git a/src/main/java/me/snaptime/snapLike/dto/res/SnapLikeResDto.java b/src/main/java/me/snaptime/snapLike/dto/res/SnapLikeResDto.java new file mode 100644 index 00000000..000c0bc3 --- /dev/null +++ b/src/main/java/me/snaptime/snapLike/dto/res/SnapLikeResDto.java @@ -0,0 +1,18 @@ +package me.snaptime.snapLike.dto.res; + +import lombok.Builder; + +@Builder +public record SnapLikeResDto( + String message, + Long likeCnt +) { + + public static SnapLikeResDto toDto(String message, Long likeCnt){ + + return SnapLikeResDto.builder() + .message(message) + .likeCnt(likeCnt) + .build(); + } +} diff --git a/src/main/java/me/snaptime/snapLike/service/SnapLikeService.java b/src/main/java/me/snaptime/snapLike/service/SnapLikeService.java index a8c1a4d7..9925b196 100644 --- a/src/main/java/me/snaptime/snapLike/service/SnapLikeService.java +++ b/src/main/java/me/snaptime/snapLike/service/SnapLikeService.java @@ -1,9 +1,11 @@ package me.snaptime.snapLike.service; +import me.snaptime.snapLike.dto.res.SnapLikeResDto; + public interface SnapLikeService { // 스냅 좋아요 토글기능 - String toggleSnapLike(String reqLoginId, Long snapId); + SnapLikeResDto toggleSnapLike(String reqLoginId, Long snapId); // 스냅에 달린 좋아요 개수 조회 Long findSnapLikeCnt(Long snapId); diff --git a/src/main/java/me/snaptime/snapLike/service/impl/SnapLikeServiceImpl.java b/src/main/java/me/snaptime/snapLike/service/impl/SnapLikeServiceImpl.java index 13f4454e..9e81005b 100644 --- a/src/main/java/me/snaptime/snapLike/service/impl/SnapLikeServiceImpl.java +++ b/src/main/java/me/snaptime/snapLike/service/impl/SnapLikeServiceImpl.java @@ -8,6 +8,7 @@ import me.snaptime.snap.domain.Snap; import me.snaptime.snap.repository.SnapRepository; import me.snaptime.snapLike.domain.SnapLike; +import me.snaptime.snapLike.dto.res.SnapLikeResDto; import me.snaptime.snapLike.repository.SnapLikeRepository; import me.snaptime.snapLike.service.SnapLikeService; import me.snaptime.user.domain.User; @@ -29,7 +30,7 @@ public class SnapLikeServiceImpl implements SnapLikeService { @Override @Transactional - public String toggleSnapLike(String reqEmail, Long snapId){ + public SnapLikeResDto toggleSnapLike(String reqEmail, Long snapId){ User reqUser = userRepository.findByEmail(reqEmail) .orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST)); @@ -46,11 +47,11 @@ public String toggleSnapLike(String reqEmail, Long snapId){ .build() ); alarmAddService.createSnapAlarm(reqUser,snap.getUser(),snap, AlarmType.LIKE); - return "좋아요를 눌렀습니다."; + return SnapLikeResDto.toDto("좋아요를 눌렀습니다.", findSnapLikeCnt(snapId)); } else{ snapLikeRepository.delete(snapLikeOptional.get()); - return "좋아요를 취소하였습니다."; + return SnapLikeResDto.toDto("좋아요를 취소하였습니다.", findSnapLikeCnt(snapId)); } } diff --git a/src/test/java/me/snaptime/snap/repository/SnapPagingRepositoryImplTest.java b/src/test/java/me/snaptime/snap/repository/SnapPagingRepositoryImplTest.java index 8ded6a2a..ec378d97 100644 --- a/src/test/java/me/snaptime/snap/repository/SnapPagingRepositoryImplTest.java +++ b/src/test/java/me/snaptime/snap/repository/SnapPagingRepositoryImplTest.java @@ -24,7 +24,6 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.TestPropertySource; -import java.time.LocalDateTime; import java.util.List; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/src/test/java/me/snaptime/social/repository/FriendPagingRepositoryTest.java b/src/test/java/me/snaptime/social/repository/FriendPagingRepositoryTest.java index 9eecb154..c724787c 100644 --- a/src/test/java/me/snaptime/social/repository/FriendPagingRepositoryTest.java +++ b/src/test/java/me/snaptime/social/repository/FriendPagingRepositoryTest.java @@ -21,7 +21,6 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.TestPropertySource; -import java.time.LocalDateTime; import java.util.List; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;