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/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 1fb7b65e..4141056f 100644 --- a/src/main/java/me/snaptime/snap/service/impl/SnapServiceImpl.java +++ b/src/main/java/me/snaptime/snap/service/impl/SnapServiceImpl.java @@ -94,9 +94,11 @@ public SnapDetailInfoResDto findSnap(Long id, String userEmail) { throw new CustomException(ExceptionCode.SNAP_IS_PRIVATE); } } - String snapPhotoUrl = urlComponent.makePhotoURL(foundSnap.getFileName(), foundSnap.isPrivate()); - String profilePhotoUrl = urlComponent.makeProfileURL(foundSnap.getUser().getProfilePhoto().getProfilePhotoId()); - List tagUserFindResDtos = snapTagService.findTagUsers(foundSnap.getId()); + + String snapPhotoUrl = urlComponent.makePhotoURL(foundSnap.getFileName(), foundSnap.isPrivate()); + String profilePhotoUrl = urlComponent.makeProfileURL(foundSnap.getUser().getProfilePhoto().getProfilePhotoId()); + 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/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/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()); } // 삭제된 태그유저 추출 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;