From 1845269f260158991dabde5e6d15f107c7c31e84 Mon Sep 17 00:00:00 2001 From: TTaiJin Date: Wed, 2 Apr 2025 17:25:39 +0900 Subject: [PATCH 01/16] =?UTF-8?q?fix:=20Enum=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=A6=9D=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=ED=95=B4=EA=B2=B0(NotBlank=20->=20NotNull)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/log4u/domain/diary/dto/DiaryRequestDto.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/log4u/domain/diary/dto/DiaryRequestDto.java b/src/main/java/com/example/log4u/domain/diary/dto/DiaryRequestDto.java index 51acb3f6..eb979839 100644 --- a/src/main/java/com/example/log4u/domain/diary/dto/DiaryRequestDto.java +++ b/src/main/java/com/example/log4u/domain/diary/dto/DiaryRequestDto.java @@ -8,6 +8,7 @@ import com.example.log4u.domain.media.dto.MediaRequestDto; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; public record DiaryRequestDto( @NotBlank(message = "제목은 필수입니다.") @@ -17,7 +18,7 @@ public record DiaryRequestDto( Double latitude, Double longitude, WeatherInfo weatherInfo, - @NotBlank(message = "공개 범위는 필수입니다.") + @NotNull(message = "공개 범위는 필수입니다.") VisibilityType visibility, List mediaList ) { From 195d3f5305e43ba78e9d92d2d1c8eb30921ca10d Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Mon, 31 Mar 2025 09:36:42 +0900 Subject: [PATCH 02/16] =?UTF-8?q?feat:=20MyPage=20=EC=9A=A9=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mypage/controller/MyPageController.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java diff --git a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java new file mode 100644 index 00000000..87656755 --- /dev/null +++ b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java @@ -0,0 +1,34 @@ +package com.example.log4u.domain.user.mypage.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.example.log4u.common.dto.PageResponse; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +public class MyPageController { + + @GetMapping("/users/me/likes") + public ResponseEntity getMyLikesPage() { + } + + @GetMapping("/users/me/followings") + public ResponseEntity> getMyFollowingPage() { + } + + @GetMapping("/users/me/followers") + public ResponseEntity> getMyFollowerPage() { + } + + @GetMapping("/users/me/diaries") + public ResponseEntity> getMyDiaryPage() { + } + + @GetMapping("/users/me/subscriptions") + public ResponseEntity> getMySubscriptionsPage() { + } +} From 239fc75cb563ce54f15a5c30152bfabab085afee Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Mon, 31 Mar 2025 11:24:43 +0900 Subject: [PATCH 03/16] =?UTF-8?q?feat:=20=EB=82=B4=20=ED=8C=94=EB=A1=9C?= =?UTF-8?q?=EC=9A=B0=20/=20=ED=8C=94=EB=A1=9C=EC=9E=89=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../log4u/common/entity/BaseEntity.java | 1 - .../log4u/common/util/PageableUtil.java | 20 ++++++ .../follow/repository/FollowQuerydsl.java | 69 +++++++++++++++++++ .../user/dto/UserThumbnailResponseDto.java | 11 +++ .../mypage/controller/MyPageController.java | 11 +-- .../user/mypage/service/MyPageService.java | 54 +++++++++++++++ 6 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/example/log4u/common/util/PageableUtil.java create mode 100644 src/main/java/com/example/log4u/domain/follow/repository/FollowQuerydsl.java create mode 100644 src/main/java/com/example/log4u/domain/user/dto/UserThumbnailResponseDto.java create mode 100644 src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java diff --git a/src/main/java/com/example/log4u/common/entity/BaseEntity.java b/src/main/java/com/example/log4u/common/entity/BaseEntity.java index cf6bf0a2..b0de1104 100644 --- a/src/main/java/com/example/log4u/common/entity/BaseEntity.java +++ b/src/main/java/com/example/log4u/common/entity/BaseEntity.java @@ -21,6 +21,5 @@ abstract public class BaseEntity { private LocalDateTime createdAt; @LastModifiedDate - @Column(nullable = false) private LocalDateTime updatedAt; } \ No newline at end of file diff --git a/src/main/java/com/example/log4u/common/util/PageableUtil.java b/src/main/java/com/example/log4u/common/util/PageableUtil.java new file mode 100644 index 00000000..1599d1d4 --- /dev/null +++ b/src/main/java/com/example/log4u/common/util/PageableUtil.java @@ -0,0 +1,20 @@ +package com.example.log4u.common.util; + +import java.util.List; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; + +public class PageableUtil { + public static Slice checkAndCreateSlice(List content, Pageable pageable) { + boolean hasNext = content.size() > pageable.getPageSize(); + + // 다음 페이지가 있으면 마지막 항목 제거 + if (hasNext) { + content.remove(content.size() - 1); // removeLast() 대신 인덱스로 처리 + } + + return new SliceImpl<>(content, pageable, hasNext); + } +} diff --git a/src/main/java/com/example/log4u/domain/follow/repository/FollowQuerydsl.java b/src/main/java/com/example/log4u/domain/follow/repository/FollowQuerydsl.java new file mode 100644 index 00000000..2bfb9527 --- /dev/null +++ b/src/main/java/com/example/log4u/domain/follow/repository/FollowQuerydsl.java @@ -0,0 +1,69 @@ +package com.example.log4u.domain.follow.repository; + +import java.util.List; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; +import org.springframework.stereotype.Repository; + +import com.example.log4u.common.util.PageableUtil; +import com.example.log4u.domain.follow.entitiy.Follow; +import com.example.log4u.domain.follow.entitiy.QFollow; +import com.example.log4u.domain.user.dto.UserThumbnailResponseDto; +import com.example.log4u.domain.user.entity.QUser; +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.NumberPath; + +@Repository +public class FollowQuerydsl extends QuerydslRepositorySupport { + private final QFollow follow = QFollow.follow; + private final QUser user = QUser.user; + + public FollowQuerydsl() { + super(Follow.class); + } + + private NumberPath getNumberPath(boolean isFollowerQuery) { + return isFollowerQuery ? follow.followerId : follow.followingId; + } + + private BooleanBuilder getBooleanBuilder(boolean isFollowerQuery, Long userId, Long cursorId) { + BooleanBuilder builder = new BooleanBuilder(); + builder.and(getNumberPath(isFollowerQuery).eq(userId)); + + if (cursorId != null) { + builder.and(follow.id.lt(cursorId)); + } + + return builder; + } + + private List getContent(boolean isFollowerQuery, Long userId, Long cursorId) { + BooleanBuilder builder = getBooleanBuilder(isFollowerQuery, userId, cursorId); + + return from(follow) + .select(Projections.constructor(UserThumbnailResponseDto.class, + getNumberPath(!isFollowerQuery), + user.nickname, + user.nickname)) + .where(builder) + .distinct() + .fetch(); + } + + //내 팔로워 아이디 슬라이스 + public Slice getFollowerSliceByUserId(Long userId, Long cursorId, Pageable pageable) { + boolean isFollowerQuery = true; + List content = getContent(isFollowerQuery, userId, cursorId); + return PageableUtil.checkAndCreateSlice(content, pageable); + } + + // 내가 팔로잉하는 아이디 슬라이스 + public Slice getFollowingSliceByUserId(Long userId, Long cursorId, Pageable pageable) { + boolean isFollowerQuery = false; + List content = getContent(isFollowerQuery, userId, cursorId); + return PageableUtil.checkAndCreateSlice(content, pageable); + } +} diff --git a/src/main/java/com/example/log4u/domain/user/dto/UserThumbnailResponseDto.java b/src/main/java/com/example/log4u/domain/user/dto/UserThumbnailResponseDto.java new file mode 100644 index 00000000..4453e2d3 --- /dev/null +++ b/src/main/java/com/example/log4u/domain/user/dto/UserThumbnailResponseDto.java @@ -0,0 +1,11 @@ +package com.example.log4u.domain.user.dto; + +import lombok.Builder; + +@Builder +public record UserThumbnailResponseDto( + Long userId, + String nickname, + String thumbnailUrl +) { +} diff --git a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java index 87656755..9f741d6e 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java @@ -5,6 +5,7 @@ import org.springframework.web.bind.annotation.RestController; import com.example.log4u.common.dto.PageResponse; +import com.example.log4u.domain.diary.dto.DiaryResponseDto; import lombok.RequiredArgsConstructor; @@ -12,8 +13,12 @@ @RequiredArgsConstructor public class MyPageController { + @GetMapping("/users/me/diaries") + public ResponseEntity> getMyDiaryPage() { + } + @GetMapping("/users/me/likes") - public ResponseEntity getMyLikesPage() { + public ResponseEntity> getMyLikesPage() { } @GetMapping("/users/me/followings") @@ -24,10 +29,6 @@ public ResponseEntity> getMyFollowingPage() { public ResponseEntity> getMyFollowerPage() { } - @GetMapping("/users/me/diaries") - public ResponseEntity> getMyDiaryPage() { - } - @GetMapping("/users/me/subscriptions") public ResponseEntity> getMySubscriptionsPage() { } diff --git a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java new file mode 100644 index 00000000..1d5f1efd --- /dev/null +++ b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java @@ -0,0 +1,54 @@ +package com.example.log4u.domain.user.mypage.service; + +import static com.example.log4u.domain.diary.service.DiaryService.*; + +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.example.log4u.common.dto.PageResponse; +import com.example.log4u.domain.diary.dto.DiaryResponseDto; +import com.example.log4u.domain.diary.service.DiaryService; +import com.example.log4u.domain.follow.repository.FollowQuerydsl; +import com.example.log4u.domain.user.dto.UserThumbnailResponseDto; + +import lombok.RequiredArgsConstructor; + +@Service +@Transactional +@RequiredArgsConstructor +public class MyPageService { + + private final DiaryService diaryService; + private final FollowQuerydsl followQuerydsl; + + @Transactional(readOnly = true) + public PageResponse getMyDiariesByCursor(Long userId, Long cursorId) { + return diaryService.getDiariesByCursor(userId, userId, cursorId); + } + + @Transactional(readOnly = true) + public PageResponse getMyFollowers(Long userId, Long cursorId) { + Slice slice = followQuerydsl.getFollowerSliceByUserId( + userId, + cursorId, + PageRequest.of(0, CURSOR_PAGE_SIZE)); + + Long nextCursor = !slice.isEmpty() ? slice.getContent().getLast().userId() : null; + + return PageResponse.of(slice, nextCursor); + } + + @Transactional(readOnly = true) + public PageResponse getMyFollowings(Long userId, Long cursorId) { + Slice slice = followQuerydsl.getFollowingSliceByUserId( + userId, + cursorId, + PageRequest.of(0, CURSOR_PAGE_SIZE)); + + Long nextCursor = !slice.isEmpty() ? slice.getContent().getLast().userId() : null; + + return PageResponse.of(slice, nextCursor); + } +} From b71c57b05592851a892380ce104a2534161f035a Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Mon, 31 Mar 2025 11:33:29 +0900 Subject: [PATCH 04/16] =?UTF-8?q?feat:=20=EB=82=B4=20=ED=8C=94=EB=A1=9C?= =?UTF-8?q?=EC=9A=B0=20/=20=ED=8C=94=EB=A1=9C=EC=9E=89=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=B0=8F=20=EB=82=B4=EA=B0=80=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=ED=95=9C=20=EB=8B=A4=EC=9D=B4=EC=96=B4=EB=A6=AC=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EB=A7=A4=ED=95=91=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mypage/controller/MyPageController.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java index 9f741d6e..271280fb 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java @@ -2,19 +2,27 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.example.log4u.common.dto.PageResponse; import com.example.log4u.domain.diary.dto.DiaryResponseDto; +import com.example.log4u.domain.user.dto.UserThumbnailResponseDto; +import com.example.log4u.domain.user.mypage.service.MyPageService; import lombok.RequiredArgsConstructor; @RestController @RequiredArgsConstructor public class MyPageController { + private final MyPageService myPageService; @GetMapping("/users/me/diaries") - public ResponseEntity> getMyDiaryPage() { + public ResponseEntity> getMyDiaryPage( + @RequestParam(required = false) Long cursorId + ) { + Long userId = 1L; + return ResponseEntity.ok(myPageService.getMyDiariesByCursor(userId, cursorId)); } @GetMapping("/users/me/likes") @@ -22,11 +30,19 @@ public ResponseEntity> getMyLikesPage() { } @GetMapping("/users/me/followings") - public ResponseEntity> getMyFollowingPage() { + public ResponseEntity> getMyFollowingPage( + @RequestParam(required = false) Long cursorId + ) { + Long userId = 1L; + return ResponseEntity.ok(myPageService.getMyFollowings(userId, cursorId)); } @GetMapping("/users/me/followers") - public ResponseEntity> getMyFollowerPage() { + public ResponseEntity> getMyFollowerPage( + @RequestParam(required = false) Long cursorId + ) { + Long userId = 1L; + return ResponseEntity.ok(myPageService.getMyFollowers(userId, cursorId)); } @GetMapping("/users/me/subscriptions") From d1cde3073181b3262a2327171c446e9c1923cf85 Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Tue, 1 Apr 2025 10:07:40 +0900 Subject: [PATCH 05/16] =?UTF-8?q?feat:=20=EB=82=B4=EA=B0=80=20=EC=A2=8B?= =?UTF-8?q?=EC=95=84=EC=9A=94=20=EB=82=A8=EA=B8=B4=20=EB=8B=A4=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/CustomDiaryRepository.java | 6 ++++ .../repository/CustomDiaryRepositoryImpl.java | 33 ++++++++++++++++++- .../mypage/controller/MyPageController.java | 12 ++++--- .../user/mypage/service/MyPageService.java | 9 ++++- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/log4u/domain/diary/repository/CustomDiaryRepository.java b/src/main/java/com/example/log4u/domain/diary/repository/CustomDiaryRepository.java index 343daef6..61a060f8 100644 --- a/src/main/java/com/example/log4u/domain/diary/repository/CustomDiaryRepository.java +++ b/src/main/java/com/example/log4u/domain/diary/repository/CustomDiaryRepository.java @@ -24,4 +24,10 @@ Slice findByUserIdAndVisibilityInAndCursorId( Long cursorId, Pageable pageable ); + + Slice getLikeDiarySliceByUserId( + Long userId, + List visibilities, + Long cursorId, + Pageable pageable); } diff --git a/src/main/java/com/example/log4u/domain/diary/repository/CustomDiaryRepositoryImpl.java b/src/main/java/com/example/log4u/domain/diary/repository/CustomDiaryRepositoryImpl.java index 27af5de2..d201fe8f 100644 --- a/src/main/java/com/example/log4u/domain/diary/repository/CustomDiaryRepositoryImpl.java +++ b/src/main/java/com/example/log4u/domain/diary/repository/CustomDiaryRepositoryImpl.java @@ -13,6 +13,7 @@ import com.example.log4u.domain.diary.VisibilityType; import com.example.log4u.domain.diary.entity.Diary; import com.example.log4u.domain.diary.entity.QDiary; +import com.example.log4u.domain.like.entity.QLike; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQuery; @@ -24,6 +25,9 @@ public class CustomDiaryRepositoryImpl implements CustomDiaryRepository { private final JPAQueryFactory queryFactory; + private final QDiary diary = QDiary.diary; + private final QLike like = QLike.like; + @Override public Page searchDiaries( String keyword, @@ -31,7 +35,7 @@ public Page searchDiaries( SortType sort, Pageable pageable ) { - QDiary diary = QDiary.diary; + // QDiary diary = QDiary.diary; // 조건 생성 BooleanExpression condition = createCondition(diary, keyword, visibilities, null); @@ -132,4 +136,31 @@ private Slice checkAndCreateSlice(List content, Pageable pageable) return new SliceImpl<>(content, pageable, hasNext); } + + @Override + public Slice getLikeDiarySliceByUserId( + Long userId, + List visibilities, + Long cursorId, + Pageable pageable) { + QDiary diary = QDiary.diary; + + // 조건 생성 + BooleanExpression condition = createCondition(diary, null, visibilities, userId); + + // limit + 1로 다음 페이지 존재 여부 확인 + List content = queryFactory + .selectFrom(diary) + .innerJoin(like) + .on(like.diaryId.eq(diary.diaryId)) + .where(like.userId.eq(userId) + .and(condition) + .and(like.likeId.lt(cursorId))) + .orderBy(like.createdAt.desc()) + .limit(pageable.getPageSize() + 1) + .fetch(); + + // 다음 페이지 여부를 계산하여 반환 + return checkAndCreateSlice(content, pageable); + } } diff --git a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java index 271280fb..f7b8b408 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java @@ -26,7 +26,11 @@ public ResponseEntity> getMyDiaryPage( } @GetMapping("/users/me/likes") - public ResponseEntity> getMyLikesPage() { + public ResponseEntity> getMyLikesPage( + @RequestParam(required = false) Long cursorId + ) { + Long userId = 1L; + return ResponseEntity.ok(myPageService.getLikeDiariesByCursor(userId, cursorId)); } @GetMapping("/users/me/followings") @@ -45,7 +49,7 @@ public ResponseEntity> getMyFollowerPage( return ResponseEntity.ok(myPageService.getMyFollowers(userId, cursorId)); } - @GetMapping("/users/me/subscriptions") - public ResponseEntity> getMySubscriptionsPage() { - } + // @GetMapping("/users/me/subscriptions") + // public ResponseEntity> getMySubscriptionsPage() { + // } } diff --git a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java index 1d5f1efd..6564f166 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java @@ -25,7 +25,14 @@ public class MyPageService { @Transactional(readOnly = true) public PageResponse getMyDiariesByCursor(Long userId, Long cursorId) { - return diaryService.getDiariesByCursor(userId, userId, cursorId); + return diaryService.getDiariesByCursor(userId, userId, + cursorId); // 일단 로직 자체가 구현 그대로 돼있길래 그대로 갖다 썼는데 이래도 구조가 괜찮을 지 모르겠습니다. + } + + @Transactional(readOnly = true) + public PageResponse getLikeDiariesByCursor(Long userId, Long cursorId) { + return diaryService.getLikeDiariesByCursor(userId, userId, + cursorId); } @Transactional(readOnly = true) From 52d6b8ac0a8645618aa16c08754729383e40a960 Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Thu, 3 Apr 2025 02:07:36 +0900 Subject: [PATCH 06/16] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B2=A0=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=9D=B4=ED=9B=84,=20=EC=A2=8B=EC=95=84=EC=9A=94?= =?UTF-8?q?=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/diary/service/DiaryService.java | 19 +++++++++++++++++++ .../user/mypage/service/MyPageService.java | 12 +++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/log4u/domain/diary/service/DiaryService.java b/src/main/java/com/example/log4u/domain/diary/service/DiaryService.java index 8a7891a8..3a20be33 100644 --- a/src/main/java/com/example/log4u/domain/diary/service/DiaryService.java +++ b/src/main/java/com/example/log4u/domain/diary/service/DiaryService.java @@ -217,4 +217,23 @@ public void checkDiaryExists(Long diaryId) { throw new NotFoundDiaryException(); } } + + @Transactional(readOnly = true) + public PageResponse getLikeDiariesByCursor(Long userId, Long targetUserId, Long cursorId, + int size) { + List visibilities = determineAccessibleVisibilities(userId, targetUserId); + + Slice diaries = diaryRepository.getLikeDiarySliceByUserId( + targetUserId, + visibilities, + cursorId != null ? cursorId : Long.MAX_VALUE, + PageRequest.of(0, size) + ); + + Slice dtoSlice = mapToDtoSlice(diaries); + + Long nextCursor = !dtoSlice.isEmpty() ? dtoSlice.getContent().getLast().diaryId() : null; + + return PageResponse.of(dtoSlice, nextCursor); + } } diff --git a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java index 6564f166..4a8775a0 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java @@ -1,7 +1,5 @@ package com.example.log4u.domain.user.mypage.service; -import static com.example.log4u.domain.diary.service.DiaryService.*; - import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; @@ -19,20 +17,20 @@ @Transactional @RequiredArgsConstructor public class MyPageService { - + private final int defaultPageSize = 6; private final DiaryService diaryService; private final FollowQuerydsl followQuerydsl; @Transactional(readOnly = true) public PageResponse getMyDiariesByCursor(Long userId, Long cursorId) { return diaryService.getDiariesByCursor(userId, userId, - cursorId); // 일단 로직 자체가 구현 그대로 돼있길래 그대로 갖다 썼는데 이래도 구조가 괜찮을 지 모르겠습니다. + cursorId, defaultPageSize); // 일단 로직 자체가 구현 그대로 돼있길래 그대로 갖다 썼는데 이래도 구조가 괜찮을 지 모르겠습니다. } @Transactional(readOnly = true) public PageResponse getLikeDiariesByCursor(Long userId, Long cursorId) { return diaryService.getLikeDiariesByCursor(userId, userId, - cursorId); + cursorId, defaultPageSize); } @Transactional(readOnly = true) @@ -40,7 +38,7 @@ public PageResponse getMyFollowers(Long userId, Long c Slice slice = followQuerydsl.getFollowerSliceByUserId( userId, cursorId, - PageRequest.of(0, CURSOR_PAGE_SIZE)); + PageRequest.of(0, defaultPageSize)); Long nextCursor = !slice.isEmpty() ? slice.getContent().getLast().userId() : null; @@ -52,7 +50,7 @@ public PageResponse getMyFollowings(Long userId, Long Slice slice = followQuerydsl.getFollowingSliceByUserId( userId, cursorId, - PageRequest.of(0, CURSOR_PAGE_SIZE)); + PageRequest.of(0, defaultPageSize)); Long nextCursor = !slice.isEmpty() ? slice.getContent().getLast().userId() : null; From 4e2ca6e47a3c9b9c005c5fe86e89dd9891c17d7a Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Thu, 3 Apr 2025 11:11:22 +0900 Subject: [PATCH 07/16] =?UTF-8?q?feat:=20=EA=B5=AC=EB=8F=85=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EC=A1=B0=ED=9A=8C=EC=9A=A9=20DTO=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mypage/dto/SubscriptionResponseDto.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/com/example/log4u/domain/user/mypage/dto/SubscriptionResponseDto.java diff --git a/src/main/java/com/example/log4u/domain/user/mypage/dto/SubscriptionResponseDto.java b/src/main/java/com/example/log4u/domain/user/mypage/dto/SubscriptionResponseDto.java new file mode 100644 index 00000000..3c16bd03 --- /dev/null +++ b/src/main/java/com/example/log4u/domain/user/mypage/dto/SubscriptionResponseDto.java @@ -0,0 +1,18 @@ +package com.example.log4u.domain.user.mypage.dto; + +import java.time.LocalDateTime; + +import jakarta.annotation.Nullable; +import lombok.Builder; + +@Builder +public record SubscriptionResponseDto( + boolean isSubscriptionActive, + + @Nullable + LocalDateTime startDate, + + @Nullable + LocalDateTime endDate +) { +} From 25799958e19b8237d84e7563bd42c3a8d919e5d3 Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Thu, 3 Apr 2025 12:48:37 +0900 Subject: [PATCH 08/16] =?UTF-8?q?feat:=20=EA=B5=AC=EB=8F=85=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1=20(=EA=B2=B0=EC=A0=9C?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=EC=9D=B4=20=EC=96=B4=EB=96=BB=EA=B2=8C=20?= =?UTF-8?q?=EB=B6=99=EC=9D=84=20=EC=A7=80=20=EB=AA=B0=EB=9D=BC=20=EA=B0=84?= =?UTF-8?q?=EB=9E=B5=ED=9E=88=20=EC=84=A4=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/log4u/domain/subscription/entity/Subscription.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java diff --git a/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java b/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java new file mode 100644 index 00000000..754e559d --- /dev/null +++ b/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java @@ -0,0 +1,2 @@ +package com.example.log4u.domain.subscription.entity;public class Subscription { +} From 3d1e8455e2a828688f7f3bcbb6ff390ca5ad234b Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Thu, 3 Apr 2025 12:48:51 +0900 Subject: [PATCH 09/16] =?UTF-8?q?feat:=20=EA=B5=AC=EB=8F=85=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1=20(=EA=B2=B0=EC=A0=9C?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=EC=9D=B4=20=EC=96=B4=EB=96=BB=EA=B2=8C=20?= =?UTF-8?q?=EB=B6=99=EC=9D=84=20=EC=A7=80=20=EB=AA=B0=EB=9D=BC=20=EA=B0=84?= =?UTF-8?q?=EB=9E=B5=ED=9E=88=20=EC=84=A4=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subscription/entity/Subscription.java | 36 ++++++++++++++++++- .../user/mypage/service/MyPageService.java | 6 ++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java b/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java index 754e559d..3e4942a2 100644 --- a/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java +++ b/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java @@ -1,2 +1,36 @@ -package com.example.log4u.domain.subscription.entity;public class Subscription { +package com.example.log4u.domain.subscription.entity; + +import java.time.LocalDateTime; + +import com.example.log4u.common.entity.BaseEntity; + +import jakarta.persistence.AttributeOverride; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PACKAGE) + +@Entity +@AttributeOverride(name = "createdAt", column = @Column(name = "START_TIME")) +public class Subscription extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private Long userId; + + private Long price; + + private LocalDateTime endTime; } diff --git a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java index 4a8775a0..5aa15225 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java @@ -10,6 +10,7 @@ import com.example.log4u.domain.diary.service.DiaryService; import com.example.log4u.domain.follow.repository.FollowQuerydsl; import com.example.log4u.domain.user.dto.UserThumbnailResponseDto; +import com.example.log4u.domain.user.mypage.dto.SubscriptionResponseDto; import lombok.RequiredArgsConstructor; @@ -56,4 +57,9 @@ public PageResponse getMyFollowings(Long userId, Long return PageResponse.of(slice, nextCursor); } + + @Transactional(readOnly = true) + public SubscriptionResponseDto getMySubscription(Long userId) { + + } } From 744e7ca450fba37c242970ecfc78d4a2df947824 Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Thu, 3 Apr 2025 16:28:06 +0900 Subject: [PATCH 10/16] =?UTF-8?q?feat:=20=EB=82=B4=20=EA=B5=AC=EB=8F=85=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/SubscriptionResponseDto.java | 2 +- .../repository/SubscriptionRepository.java | 13 +++++++++++ .../mypage/controller/MyPageController.java | 9 +++++--- .../user/mypage/service/MyPageService.java | 23 +++++++++++++++++-- 4 files changed, 41 insertions(+), 6 deletions(-) rename src/main/java/com/example/log4u/domain/{user/mypage => subscription}/dto/SubscriptionResponseDto.java (83%) create mode 100644 src/main/java/com/example/log4u/domain/subscription/repository/SubscriptionRepository.java diff --git a/src/main/java/com/example/log4u/domain/user/mypage/dto/SubscriptionResponseDto.java b/src/main/java/com/example/log4u/domain/subscription/dto/SubscriptionResponseDto.java similarity index 83% rename from src/main/java/com/example/log4u/domain/user/mypage/dto/SubscriptionResponseDto.java rename to src/main/java/com/example/log4u/domain/subscription/dto/SubscriptionResponseDto.java index 3c16bd03..9e592c05 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/dto/SubscriptionResponseDto.java +++ b/src/main/java/com/example/log4u/domain/subscription/dto/SubscriptionResponseDto.java @@ -1,4 +1,4 @@ -package com.example.log4u.domain.user.mypage.dto; +package com.example.log4u.domain.subscription.dto; import java.time.LocalDateTime; diff --git a/src/main/java/com/example/log4u/domain/subscription/repository/SubscriptionRepository.java b/src/main/java/com/example/log4u/domain/subscription/repository/SubscriptionRepository.java new file mode 100644 index 00000000..7d6aedd0 --- /dev/null +++ b/src/main/java/com/example/log4u/domain/subscription/repository/SubscriptionRepository.java @@ -0,0 +1,13 @@ +package com.example.log4u.domain.subscription.repository; + +import java.time.LocalDateTime; +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.example.log4u.domain.subscription.entity.Subscription; + +public interface SubscriptionRepository extends JpaRepository { + List findByUserIdAndEndTimeAfter(Long userId, LocalDateTime now); +} + diff --git a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java index f7b8b408..40506a4d 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java @@ -7,6 +7,7 @@ import com.example.log4u.common.dto.PageResponse; import com.example.log4u.domain.diary.dto.DiaryResponseDto; +import com.example.log4u.domain.subscription.dto.SubscriptionResponseDto; import com.example.log4u.domain.user.dto.UserThumbnailResponseDto; import com.example.log4u.domain.user.mypage.service.MyPageService; @@ -49,7 +50,9 @@ public ResponseEntity> getMyFollowerPage( return ResponseEntity.ok(myPageService.getMyFollowers(userId, cursorId)); } - // @GetMapping("/users/me/subscriptions") - // public ResponseEntity> getMySubscriptionsPage() { - // } + @GetMapping("/users/me/subscriptions") + public ResponseEntity getMySubscriptions() { + Long userId = 1L; + return ResponseEntity.ok(myPageService.getMySubscription(userId)); + } } diff --git a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java index 5aa15225..0230d2b7 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java @@ -1,5 +1,8 @@ package com.example.log4u.domain.user.mypage.service; +import java.time.LocalDateTime; +import java.util.List; + import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; @@ -9,8 +12,10 @@ import com.example.log4u.domain.diary.dto.DiaryResponseDto; import com.example.log4u.domain.diary.service.DiaryService; import com.example.log4u.domain.follow.repository.FollowQuerydsl; +import com.example.log4u.domain.subscription.dto.SubscriptionResponseDto; +import com.example.log4u.domain.subscription.entity.Subscription; +import com.example.log4u.domain.subscription.repository.SubscriptionRepository; import com.example.log4u.domain.user.dto.UserThumbnailResponseDto; -import com.example.log4u.domain.user.mypage.dto.SubscriptionResponseDto; import lombok.RequiredArgsConstructor; @@ -21,6 +26,7 @@ public class MyPageService { private final int defaultPageSize = 6; private final DiaryService diaryService; private final FollowQuerydsl followQuerydsl; + private final SubscriptionRepository subscriptionRepository; @Transactional(readOnly = true) public PageResponse getMyDiariesByCursor(Long userId, Long cursorId) { @@ -60,6 +66,19 @@ public PageResponse getMyFollowings(Long userId, Long @Transactional(readOnly = true) public SubscriptionResponseDto getMySubscription(Long userId) { - + List subscriptions = subscriptionRepository.findByUserIdAndEndTimeAfter(userId, + LocalDateTime.now()); + if (subscriptions.isEmpty()) { + return SubscriptionResponseDto.builder() + .isSubscriptionActive(false) + .build(); + } else { + Subscription subscription = subscriptions.getFirst(); + return SubscriptionResponseDto.builder() + .isSubscriptionActive(true) + .startDate(subscription.getCreatedAt()) + .endDate(subscription.getEndTime()) + .build(); + } } } From ca39cfe858185068dd85067288cf48f8ebe312b8 Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Thu, 3 Apr 2025 23:59:33 +0900 Subject: [PATCH 11/16] =?UTF-8?q?refactor:=20Subscription=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20Mypage?= =?UTF-8?q?=EC=9D=98=20=EA=B5=AC=EB=8F=85=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/subscription/PaymentProvider.java | 7 ++++++ .../domain/subscription/PaymentStatus.java | 7 ++++++ .../dto/SubscriptionResponseDto.java | 6 +++-- .../subscription/entity/Subscription.java | 23 ++++++++++++++----- .../repository/SubscriptionRepository.java | 7 ++++-- .../user/mypage/service/MyPageService.java | 15 +++++++----- 6 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/example/log4u/domain/subscription/PaymentProvider.java create mode 100644 src/main/java/com/example/log4u/domain/subscription/PaymentStatus.java diff --git a/src/main/java/com/example/log4u/domain/subscription/PaymentProvider.java b/src/main/java/com/example/log4u/domain/subscription/PaymentProvider.java new file mode 100644 index 00000000..e9218c18 --- /dev/null +++ b/src/main/java/com/example/log4u/domain/subscription/PaymentProvider.java @@ -0,0 +1,7 @@ +package com.example.log4u.domain.subscription; + +public enum PaymentProvider { + TOSS, + KAKAO, + NAVER +} diff --git a/src/main/java/com/example/log4u/domain/subscription/PaymentStatus.java b/src/main/java/com/example/log4u/domain/subscription/PaymentStatus.java new file mode 100644 index 00000000..1307e7dc --- /dev/null +++ b/src/main/java/com/example/log4u/domain/subscription/PaymentStatus.java @@ -0,0 +1,7 @@ +package com.example.log4u.domain.subscription; + +public enum PaymentStatus { + SUCCESS, // 결제 완료 + FAILED, // 결제 실패 + REFUNDED // 환불 완료 +} diff --git a/src/main/java/com/example/log4u/domain/subscription/dto/SubscriptionResponseDto.java b/src/main/java/com/example/log4u/domain/subscription/dto/SubscriptionResponseDto.java index 9e592c05..da861973 100644 --- a/src/main/java/com/example/log4u/domain/subscription/dto/SubscriptionResponseDto.java +++ b/src/main/java/com/example/log4u/domain/subscription/dto/SubscriptionResponseDto.java @@ -2,6 +2,8 @@ import java.time.LocalDateTime; +import com.example.log4u.domain.subscription.PaymentProvider; + import jakarta.annotation.Nullable; import lombok.Builder; @@ -10,9 +12,9 @@ public record SubscriptionResponseDto( boolean isSubscriptionActive, @Nullable - LocalDateTime startDate, + PaymentProvider paymentProvider, @Nullable - LocalDateTime endDate + LocalDateTime startDate ) { } diff --git a/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java b/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java index 3e4942a2..363131ff 100644 --- a/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java +++ b/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java @@ -1,12 +1,13 @@ package com.example.log4u.domain.subscription.entity; -import java.time.LocalDateTime; - import com.example.log4u.common.entity.BaseEntity; +import com.example.log4u.domain.subscription.PaymentProvider; +import com.example.log4u.domain.subscription.PaymentStatus; -import jakarta.persistence.AttributeOverride; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -22,15 +23,25 @@ @AllArgsConstructor(access = AccessLevel.PACKAGE) @Entity -@AttributeOverride(name = "createdAt", column = @Column(name = "START_TIME")) public class Subscription extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(nullable = false) private Long userId; - private Long price; + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private PaymentProvider paymentProvider; + + @Column(nullable = false) + private Long amount; + + @Column(nullable = false, unique = true) + private String paymentKey; - private LocalDateTime endTime; + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private PaymentStatus paymentStatus; } diff --git a/src/main/java/com/example/log4u/domain/subscription/repository/SubscriptionRepository.java b/src/main/java/com/example/log4u/domain/subscription/repository/SubscriptionRepository.java index 7d6aedd0..1fe12bd7 100644 --- a/src/main/java/com/example/log4u/domain/subscription/repository/SubscriptionRepository.java +++ b/src/main/java/com/example/log4u/domain/subscription/repository/SubscriptionRepository.java @@ -1,13 +1,16 @@ package com.example.log4u.domain.subscription.repository; import java.time.LocalDateTime; -import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import com.example.log4u.domain.subscription.PaymentStatus; import com.example.log4u.domain.subscription.entity.Subscription; public interface SubscriptionRepository extends JpaRepository { - List findByUserIdAndEndTimeAfter(Long userId, LocalDateTime now); + Optional findByUserIdAndCreatedAtBeforeAndPaymentStatusOrderByCreatedAtDesc(Long userId, + LocalDateTime now, + PaymentStatus paymentStatus); } diff --git a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java index 0230d2b7..1fe197c5 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java @@ -1,7 +1,7 @@ package com.example.log4u.domain.user.mypage.service; import java.time.LocalDateTime; -import java.util.List; +import java.util.Optional; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; @@ -12,6 +12,7 @@ import com.example.log4u.domain.diary.dto.DiaryResponseDto; import com.example.log4u.domain.diary.service.DiaryService; import com.example.log4u.domain.follow.repository.FollowQuerydsl; +import com.example.log4u.domain.subscription.PaymentStatus; import com.example.log4u.domain.subscription.dto.SubscriptionResponseDto; import com.example.log4u.domain.subscription.entity.Subscription; import com.example.log4u.domain.subscription.repository.SubscriptionRepository; @@ -66,18 +67,20 @@ public PageResponse getMyFollowings(Long userId, Long @Transactional(readOnly = true) public SubscriptionResponseDto getMySubscription(Long userId) { - List subscriptions = subscriptionRepository.findByUserIdAndEndTimeAfter(userId, - LocalDateTime.now()); - if (subscriptions.isEmpty()) { + Optional optionalSubscription = subscriptionRepository + .findByUserIdAndCreatedAtBeforeAndPaymentStatusOrderByCreatedAtDesc( + userId, + LocalDateTime.now(), PaymentStatus.SUCCESS); + if (optionalSubscription.isEmpty()) { return SubscriptionResponseDto.builder() .isSubscriptionActive(false) .build(); } else { - Subscription subscription = subscriptions.getFirst(); + Subscription subscription = optionalSubscription.get(); return SubscriptionResponseDto.builder() .isSubscriptionActive(true) + .paymentProvider(subscription.getPaymentProvider()) .startDate(subscription.getCreatedAt()) - .endDate(subscription.getEndTime()) .build(); } } From 666b9938326930f0ca953a2d8da1389e08bb3676 Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Sat, 5 Apr 2025 23:48:51 +0900 Subject: [PATCH 12/16] =?UTF-8?q?test:=20MyPageService=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../log4u/common/entity/BaseEntity.java | 7 + .../subscription/entity/Subscription.java | 4 +- .../mypage/service/MyPageServiceTest.java | 150 ++++++++++++++++++ 3 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java diff --git a/src/main/java/com/example/log4u/common/entity/BaseEntity.java b/src/main/java/com/example/log4u/common/entity/BaseEntity.java index b0de1104..ff310046 100644 --- a/src/main/java/com/example/log4u/common/entity/BaseEntity.java +++ b/src/main/java/com/example/log4u/common/entity/BaseEntity.java @@ -9,8 +9,15 @@ import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +@SuperBuilder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PACKAGE) @Getter @MappedSuperclass @EntityListeners(AuditingEntityListener.class) diff --git a/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java b/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java index 363131ff..22d99607 100644 --- a/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java +++ b/src/main/java/com/example/log4u/domain/subscription/entity/Subscription.java @@ -13,11 +13,11 @@ import jakarta.persistence.Id; import lombok.AccessLevel; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; -@Builder +@SuperBuilder @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PACKAGE) diff --git a/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java b/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java new file mode 100644 index 00000000..da145771 --- /dev/null +++ b/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java @@ -0,0 +1,150 @@ +package com.example.log4u.domain.user.mypage.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.SliceImpl; + +import com.example.log4u.common.dto.PageResponse; +import com.example.log4u.domain.diary.dto.DiaryResponseDto; +import com.example.log4u.domain.diary.service.DiaryService; +import com.example.log4u.domain.follow.repository.FollowQuerydsl; +import com.example.log4u.domain.subscription.PaymentProvider; +import com.example.log4u.domain.subscription.PaymentStatus; +import com.example.log4u.domain.subscription.dto.SubscriptionResponseDto; +import com.example.log4u.domain.subscription.entity.Subscription; +import com.example.log4u.domain.subscription.repository.SubscriptionRepository; +import com.example.log4u.domain.user.dto.UserThumbnailResponseDto; +import com.example.log4u.fixture.DiaryFixture; + +@ExtendWith(MockitoExtension.class) +public class MyPageServiceTest { + @InjectMocks + private MyPageService myPageService; + + @Mock + private DiaryService diaryService; + + @Mock + private FollowQuerydsl followQuerydsl; + + @Mock + private SubscriptionRepository subscriptionRepository; + + private final Long userId = 1L; + private final Long cursorId = 10L; + + private List diaries; + + @BeforeEach + public void setUp() { + diaries = DiaryFixture.createDiariesFixture() + .stream() + .map(diary -> DiaryResponseDto.of(diary, new ArrayList<>())) + .toList(); + } + + @DisplayName("성공 테스트 : 내 다이어리 조회") + @Test + void getMyDiariesByCursor_returnsCorrectData() { + PageResponse mockResponse = PageResponse.of( + new SliceImpl<>(diaries), null + ); + + when(diaryService.getDiariesByCursor(userId, userId, cursorId, 6)).thenReturn(mockResponse); + + PageResponse result = myPageService.getMyDiariesByCursor(userId, cursorId); + + assertThat(result).isNotNull(); + verify(diaryService).getDiariesByCursor(userId, userId, cursorId, 6); + } + + @DisplayName("성공 테스트 : 좋아요한 다이어리 조회") + @Test + void getLikeDiariesByCursor_returnsCorrectData() { + PageResponse mockResponse = PageResponse.of( + new SliceImpl<>(diaries), null + ); + + when(diaryService.getLikeDiariesByCursor(userId, userId, cursorId, 6)).thenReturn(mockResponse); + + PageResponse result = myPageService.getLikeDiariesByCursor(userId, cursorId); + + assertThat(result).isNotNull(); + verify(diaryService).getLikeDiariesByCursor(userId, userId, cursorId, 6); + } + + @DisplayName("성공 테스트 : 내 팔로워 조회") + @Test + void getMyFollowers_returnsCorrectData() { + var slice = new SliceImpl<>(List.of(new UserThumbnailResponseDto(userId, "nick", "image"))); + + when(followQuerydsl.getFollowerSliceByUserId(eq(userId), eq(cursorId), any(PageRequest.class))) + .thenReturn(slice); + + PageResponse result = myPageService.getMyFollowers(userId, cursorId); + + assertThat(result).isNotNull(); + } + + @DisplayName("성공 테스트 : 내 팔로잉 조회") + @Test + void getMyFollowings_returnsCorrectData() { + var slice = new SliceImpl<>(List.of(new UserThumbnailResponseDto(userId, "nick", "image"))); + + when(followQuerydsl.getFollowingSliceByUserId(eq(userId), eq(cursorId), any(PageRequest.class))) + .thenReturn(slice); + + PageResponse result = myPageService.getMyFollowings(userId, cursorId); + + assertThat(result).isNotNull(); + } + + @DisplayName("구독 정보 조회 - 구독이 있을 때") + @Test + void getMySubscription_whenExists_returnsActiveSubscription() { + LocalDateTime createdAt = LocalDateTime.now().minusDays(1); + Subscription subscription = Subscription.builder() + .id(1L) + .userId(userId) + .createdAt(createdAt) + .paymentProvider(PaymentProvider.KAKAO) + .paymentStatus(PaymentStatus.SUCCESS) + .build(); + + when(subscriptionRepository.findByUserIdAndCreatedAtBeforeAndPaymentStatusOrderByCreatedAtDesc( + eq(userId), any(LocalDateTime.class), eq(PaymentStatus.SUCCESS))) + .thenReturn(Optional.of(subscription)); + + SubscriptionResponseDto result = myPageService.getMySubscription(userId); + + assertThat(result.isSubscriptionActive()).isTrue(); + assertThat(result.startDate()).isEqualTo(createdAt); + assertThat(result.paymentProvider()).isEqualTo(PaymentProvider.KAKAO); + } + + @DisplayName("구독 정보 조회 - 구독이 없을 때") + @Test + void getMySubscription_whenNotExists_returnsInactive() { + when(subscriptionRepository.findByUserIdAndCreatedAtBeforeAndPaymentStatusOrderByCreatedAtDesc( + anyLong(), any(), eq(PaymentStatus.SUCCESS))) + .thenReturn(Optional.empty()); + + SubscriptionResponseDto result = myPageService.getMySubscription(userId); + + assertThat(result.isSubscriptionActive()).isFalse(); + } +} From 2bb5977c6002ef178af231a27ea4e484756b4e5a Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:18:41 +0900 Subject: [PATCH 13/16] =?UTF-8?q?refactor:=20=EB=82=B4=20=EB=8B=A4?= =?UTF-8?q?=EC=9D=B4=EC=96=B4=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20?= =?UTF-8?q?=EA=B3=B5=EA=B0=9C=20=EB=B2=94=EC=9C=84=EB=A5=BC=20=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=ED=8B=B0=EB=A8=B8=EB=A1=9C=20=EB=B0=9B=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/diary/service/DiaryService.java | 21 +++++++++++++++++++ .../mypage/controller/MyPageController.java | 4 +++- .../user/mypage/service/MyPageService.java | 8 ++++--- .../mypage/service/MyPageServiceTest.java | 4 +++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/log4u/domain/diary/service/DiaryService.java b/src/main/java/com/example/log4u/domain/diary/service/DiaryService.java index 3a20be33..d36f4de0 100644 --- a/src/main/java/com/example/log4u/domain/diary/service/DiaryService.java +++ b/src/main/java/com/example/log4u/domain/diary/service/DiaryService.java @@ -218,6 +218,27 @@ public void checkDiaryExists(Long diaryId) { } } + @Transactional(readOnly = true) + public PageResponse getMyDiariesByCursor(Long userId, VisibilityType visibilityType, + Long cursorId, int size) { + List visibilities = + visibilityType == null ? List.of(VisibilityType.PUBLIC, VisibilityType.PRIVATE, VisibilityType.FOLLOWER) : + List.of(visibilityType); + + Slice diaries = diaryRepository.findByUserIdAndVisibilityInAndCursorId( + userId, + visibilities, + cursorId != null ? cursorId : Long.MAX_VALUE, + PageRequest.of(0, size) + ); + + Slice dtoSlice = mapToDtoSlice(diaries); + + Long nextCursor = !dtoSlice.isEmpty() ? dtoSlice.getContent().getLast().diaryId() : null; + + return PageResponse.of(dtoSlice, nextCursor); + } + @Transactional(readOnly = true) public PageResponse getLikeDiariesByCursor(Long userId, Long targetUserId, Long cursorId, int size) { diff --git a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java index 40506a4d..8f3e69b4 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RestController; import com.example.log4u.common.dto.PageResponse; +import com.example.log4u.domain.diary.VisibilityType; import com.example.log4u.domain.diary.dto.DiaryResponseDto; import com.example.log4u.domain.subscription.dto.SubscriptionResponseDto; import com.example.log4u.domain.user.dto.UserThumbnailResponseDto; @@ -20,10 +21,11 @@ public class MyPageController { @GetMapping("/users/me/diaries") public ResponseEntity> getMyDiaryPage( + @RequestParam(required = false) VisibilityType visibilityType, @RequestParam(required = false) Long cursorId ) { Long userId = 1L; - return ResponseEntity.ok(myPageService.getMyDiariesByCursor(userId, cursorId)); + return ResponseEntity.ok(myPageService.getMyDiariesByCursor(userId, visibilityType, cursorId)); } @GetMapping("/users/me/likes") diff --git a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java index 1fe197c5..457181b9 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java @@ -9,6 +9,7 @@ import org.springframework.transaction.annotation.Transactional; import com.example.log4u.common.dto.PageResponse; +import com.example.log4u.domain.diary.VisibilityType; import com.example.log4u.domain.diary.dto.DiaryResponseDto; import com.example.log4u.domain.diary.service.DiaryService; import com.example.log4u.domain.follow.repository.FollowQuerydsl; @@ -30,9 +31,10 @@ public class MyPageService { private final SubscriptionRepository subscriptionRepository; @Transactional(readOnly = true) - public PageResponse getMyDiariesByCursor(Long userId, Long cursorId) { - return diaryService.getDiariesByCursor(userId, userId, - cursorId, defaultPageSize); // 일단 로직 자체가 구현 그대로 돼있길래 그대로 갖다 썼는데 이래도 구조가 괜찮을 지 모르겠습니다. + public PageResponse getMyDiariesByCursor(Long userId, VisibilityType visibilityType, + Long cursorId) { + return diaryService.getMyDiariesByCursor(userId, visibilityType, cursorId, + defaultPageSize); // 일단 로직 자체가 구현 그대로 돼있길래 그대로 갖다 썼는데 이래도 구조가 괜찮을 지 모르겠습니다. } @Transactional(readOnly = true) diff --git a/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java b/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java index da145771..39648800 100644 --- a/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java +++ b/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java @@ -19,6 +19,7 @@ import org.springframework.data.domain.SliceImpl; import com.example.log4u.common.dto.PageResponse; +import com.example.log4u.domain.diary.VisibilityType; import com.example.log4u.domain.diary.dto.DiaryResponseDto; import com.example.log4u.domain.diary.service.DiaryService; import com.example.log4u.domain.follow.repository.FollowQuerydsl; @@ -66,7 +67,8 @@ void getMyDiariesByCursor_returnsCorrectData() { when(diaryService.getDiariesByCursor(userId, userId, cursorId, 6)).thenReturn(mockResponse); - PageResponse result = myPageService.getMyDiariesByCursor(userId, cursorId); + PageResponse result = myPageService.getMyDiariesByCursor(userId, VisibilityType.PUBLIC, + cursorId); assertThat(result).isNotNull(); verify(diaryService).getDiariesByCursor(userId, userId, cursorId, 6); From a8084a4c0643f40ba5ae013b5d7276d137ef2152 Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:24:11 +0900 Subject: [PATCH 14/16] =?UTF-8?q?refactor:=20requestParam=20=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../log4u/domain/user/mypage/controller/MyPageController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java index 8f3e69b4..5ed23205 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java @@ -21,7 +21,7 @@ public class MyPageController { @GetMapping("/users/me/diaries") public ResponseEntity> getMyDiaryPage( - @RequestParam(required = false) VisibilityType visibilityType, + @RequestParam(required = false, name = "visibilityType") VisibilityType visibilityType, @RequestParam(required = false) Long cursorId ) { Long userId = 1L; From 88de81df8226da1ca74fef0085c140b9c7e56772 Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:30:19 +0900 Subject: [PATCH 15/16] =?UTF-8?q?refacotr:=20Auth=EC=97=90=EC=84=9C=20id?= =?UTF-8?q?=20=EB=B0=9B=EC=95=84=EC=98=A4=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reports/controller/ReportsController.java | 14 +++++++++---- .../controller/SupportController.java | 11 +++++++--- .../mypage/controller/MyPageController.java | 20 +++++++++++++------ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/example/log4u/domain/reports/controller/ReportsController.java b/src/main/java/com/example/log4u/domain/reports/controller/ReportsController.java index f23911f5..8bb630e7 100644 --- a/src/main/java/com/example/log4u/domain/reports/controller/ReportsController.java +++ b/src/main/java/com/example/log4u/domain/reports/controller/ReportsController.java @@ -2,12 +2,14 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.example.log4u.common.oauth2.dto.CustomOAuth2User; import com.example.log4u.domain.reports.dto.ReportCreateRequestDto; import com.example.log4u.domain.reports.service.ReportService; @@ -21,18 +23,22 @@ public class ReportsController { @PostMapping("/diaries/{diaryId}") public ResponseEntity createReportForDiary( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User, @RequestBody ReportCreateRequestDto reportCreateRequestDto, - @PathVariable Long diaryId) { - long reporterId = 1L; // SecurityContextHolder 에서 온다고 가정 + @PathVariable Long diaryId + ) { + long reporterId = customOAuth2User.getUserId(); reportService.createDiaryReport(reporterId, reportCreateRequestDto, diaryId); return new ResponseEntity<>(HttpStatus.CREATED); } @PostMapping("/comments/{commentId}") public ResponseEntity createReport( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User, @RequestBody ReportCreateRequestDto reportCreateRequestDto, - @PathVariable Long commentId) { - long reporterId = 1L; + @PathVariable Long commentId + ) { + long reporterId = customOAuth2User.getUserId(); reportService.createCommentReport(reporterId, reportCreateRequestDto, commentId); return new ResponseEntity<>(HttpStatus.CREATED); } diff --git a/src/main/java/com/example/log4u/domain/supports/controller/SupportController.java b/src/main/java/com/example/log4u/domain/supports/controller/SupportController.java index 60077d51..00a9c437 100644 --- a/src/main/java/com/example/log4u/domain/supports/controller/SupportController.java +++ b/src/main/java/com/example/log4u/domain/supports/controller/SupportController.java @@ -3,6 +3,7 @@ import org.springframework.data.domain.Page; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.example.log4u.common.oauth2.dto.CustomOAuth2User; import com.example.log4u.domain.supports.dto.SupportCreateRequestDto; import com.example.log4u.domain.supports.dto.SupportGetResponseDto; import com.example.log4u.domain.supports.dto.SupportOverviewGetResponseDto; @@ -28,19 +30,21 @@ public class SupportController { @PostMapping public ResponseEntity createSupport( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User, @RequestBody @Valid SupportCreateRequestDto supportCreateRequestDto ) { - long requesterId = 1L; + long requesterId = customOAuth2User.getUserId(); supportService.createSupport(requesterId, supportCreateRequestDto); return new ResponseEntity<>(HttpStatus.CREATED); } @GetMapping public ResponseEntity> getSupportOverviewPage( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User, @RequestParam(defaultValue = "1") int page, @RequestParam(required = false) SupportType supportType ) { - long requesterId = 1L; + long requesterId = customOAuth2User.getUserId(); Page supportOverviewPage = supportService.getSupportPage(requesterId, page, supportType); return ResponseEntity.ok().body(supportOverviewPage); @@ -48,8 +52,9 @@ public ResponseEntity> getSupportOverviewPag @GetMapping("/{supportId}") public ResponseEntity getSupportBySupportId( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User, @PathVariable Long supportId) { - long requesterId = 1L; + long requesterId = customOAuth2User.getUserId(); SupportGetResponseDto supportGetResponseDto = supportService.getSupportById(requesterId, supportId); return ResponseEntity.ok().body(supportGetResponseDto); } diff --git a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java index 5ed23205..ec1f9e41 100644 --- a/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java +++ b/src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java @@ -1,11 +1,13 @@ package com.example.log4u.domain.user.mypage.controller; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.example.log4u.common.dto.PageResponse; +import com.example.log4u.common.oauth2.dto.CustomOAuth2User; import com.example.log4u.domain.diary.VisibilityType; import com.example.log4u.domain.diary.dto.DiaryResponseDto; import com.example.log4u.domain.subscription.dto.SubscriptionResponseDto; @@ -21,40 +23,46 @@ public class MyPageController { @GetMapping("/users/me/diaries") public ResponseEntity> getMyDiaryPage( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User, @RequestParam(required = false, name = "visibilityType") VisibilityType visibilityType, @RequestParam(required = false) Long cursorId ) { - Long userId = 1L; + long userId = customOAuth2User.getUserId(); return ResponseEntity.ok(myPageService.getMyDiariesByCursor(userId, visibilityType, cursorId)); } @GetMapping("/users/me/likes") public ResponseEntity> getMyLikesPage( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User, @RequestParam(required = false) Long cursorId ) { - Long userId = 1L; + long userId = customOAuth2User.getUserId(); return ResponseEntity.ok(myPageService.getLikeDiariesByCursor(userId, cursorId)); } @GetMapping("/users/me/followings") public ResponseEntity> getMyFollowingPage( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User, @RequestParam(required = false) Long cursorId ) { - Long userId = 1L; + long userId = customOAuth2User.getUserId(); return ResponseEntity.ok(myPageService.getMyFollowings(userId, cursorId)); } @GetMapping("/users/me/followers") public ResponseEntity> getMyFollowerPage( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User, @RequestParam(required = false) Long cursorId ) { - Long userId = 1L; + long userId = customOAuth2User.getUserId(); return ResponseEntity.ok(myPageService.getMyFollowers(userId, cursorId)); } @GetMapping("/users/me/subscriptions") - public ResponseEntity getMySubscriptions() { - Long userId = 1L; + public ResponseEntity getMySubscriptions( + @AuthenticationPrincipal CustomOAuth2User customOAuth2User + ) { + long userId = customOAuth2User.getUserId(); return ResponseEntity.ok(myPageService.getMySubscription(userId)); } } From f7c45bfb4bc45b7d67b62a08818a7b62cfcaa14f Mon Sep 17 00:00:00 2001 From: injunKang <149602262+InJunKangW@users.noreply.github.com> Date: Tue, 8 Apr 2025 17:14:27 +0900 Subject: [PATCH 16/16] =?UTF-8?q?test:=20=EC=8B=A4=ED=8C=A8=ED=95=98?= =?UTF-8?q?=EB=8D=98=20=EB=82=B4=20=EB=8B=A4=EC=9D=B4=EC=96=B4=EB=A6=AC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../log4u/domain/user/mypage/service/MyPageServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java b/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java index 39648800..2c0253c7 100644 --- a/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java +++ b/src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java @@ -65,13 +65,13 @@ void getMyDiariesByCursor_returnsCorrectData() { new SliceImpl<>(diaries), null ); - when(diaryService.getDiariesByCursor(userId, userId, cursorId, 6)).thenReturn(mockResponse); + when(diaryService.getMyDiariesByCursor(userId, VisibilityType.PUBLIC, cursorId, 6)).thenReturn(mockResponse); PageResponse result = myPageService.getMyDiariesByCursor(userId, VisibilityType.PUBLIC, cursorId); assertThat(result).isNotNull(); - verify(diaryService).getDiariesByCursor(userId, userId, cursorId, 6); + verify(diaryService).getMyDiariesByCursor(userId, VisibilityType.PUBLIC, cursorId, 6); } @DisplayName("성공 테스트 : 좋아요한 다이어리 조회")