-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 다른 유저 공개 서재 전체(전체보기 페이지) API 구현, 다른 유저 공개 서재들 불러오기 API 구현, 다른 유저 프로필 조회 및 팔로잉 여부 조회 API 철회 #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
[FEAT] 다른 유저 공개 서재 전체(전체보기 페이지) API 구현, 다른 유저 공개 서재들 불러오기 API 구현, 다른 유저 프로필 조회 및 팔로잉 여부 조회 API 철회 #121
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
06f72bc
마이페이지 다른 사용자의 프로필 서제,북로그 제외한 데이터 GET api 구현
icarus0616 689857d
다른 유저의 서재 및 도서 확인 api 구현중
icarus0616 f076af4
dto 정리 및 저자 불러오기 로직 구현
icarus0616 5370a52
Merge branch 'dev' of https://github.com/Project-BookLog/BookLog-Back…
icarus0616 5415860
에러 등답 통일 리펙토링
icarus0616 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...rc/main/java/com/example/booklog/domain/users/controller/UserPublicShelvesController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.example.booklog.domain.users.controller; | ||
|
|
||
| import com.example.booklog.domain.users.dto.UserPublicShelfListResponse; | ||
| import com.example.booklog.domain.users.service.UserPublicShelvesService; | ||
| import com.example.booklog.domain.users.service.UserPublicShelvesService.PublicShelfBookSort; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.responses.*; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @Tag( | ||
| name = "다른 유저 공개 서재", | ||
| description = "다른 유저의 공개 서재 목록/서재 도서 목록 조회 API" | ||
| ) | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/users/{userId}/shelves") | ||
| public class UserPublicShelvesController { | ||
|
|
||
| private final UserPublicShelvesService userPublicShelvesService; | ||
|
|
||
| @Operation( | ||
| summary = "다른 유저 공개 서재 목록 + 서재별 top3", | ||
| description = """ | ||
| 다른 유저의 서재 중 isPublic=true 서재만 반환합니다. | ||
| 각 서재 카드에는 최근 담은 책 3권(사진/출판사/저자)을 포함합니다. | ||
| - 인증: 필요 없음(공개 서재만 조회) | ||
| """ | ||
| ) | ||
| @ApiResponses({ | ||
| @ApiResponse(responseCode = "200", description = "성공"), | ||
| @ApiResponse(responseCode = "404", description = "유저 없음 또는 공개 서재 없음") | ||
| }) | ||
| @GetMapping | ||
| public UserPublicShelfListResponse listPublicShelves( | ||
| @PathVariable Long userId | ||
| ) { | ||
| return userPublicShelvesService.listPublicShelves(userId); | ||
| } | ||
|
|
||
| @Operation( | ||
| summary = "공개 서재의 전체 도서 목록(정렬만)", | ||
| description = """ | ||
| 특정 공개 서재의 전체 도서 목록을 반환합니다. | ||
| - Query: | ||
| - sort: LATEST/OLDEST/TITLE/AUTHOR (기본 LATEST) | ||
| - 응답 항목: 사진(thumbnailUrl), 출판사(publisherName), 저자(authorName) | ||
| - 인증: 필요 없음(공개 서재만 조회) | ||
| """ | ||
| ) | ||
| @ApiResponses({ | ||
| @ApiResponse(responseCode = "200", description = "성공"), | ||
| @ApiResponse(responseCode = "404", description = "서재 없음 또는 비공개") | ||
| }) | ||
| @GetMapping("/{shelfId}/books") | ||
| public UserPublicShelfListResponse.UserPublicShelfBooksResponse listPublicShelfBooks( | ||
| @PathVariable Long userId, | ||
| @PathVariable Long shelfId, | ||
| @RequestParam(defaultValue = "LATEST") PublicShelfBookSort sort | ||
| ) { | ||
| return userPublicShelvesService.listPublicShelfBooks(userId, shelfId, sort); | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
...log/src/main/java/com/example/booklog/domain/users/controller/UsersProfileController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package com.example.booklog.domain.users.controller; | ||
|
|
||
| import com.example.booklog.domain.users.dto.UserProfileResponse; | ||
| import com.example.booklog.domain.users.service.UserProfileService; | ||
| import com.example.booklog.global.auth.security.CustomUserDetails; | ||
| import com.example.booklog.global.common.apiPayload.ApiResponse; | ||
| import com.example.booklog.global.common.apiPayload.code.status.SuccessStatus; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @Tag( | ||
| name = "유저 프로필", | ||
| description = "다른 유저 프로필(요약/카운트/팔로잉 여부) 조회 API" | ||
| ) | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/users") | ||
| public class UsersProfileController { | ||
|
|
||
| private final UserProfileService userProfileService; | ||
|
|
||
| @Operation( | ||
| summary = "다른 유저 프로필 조회", | ||
| description = """ | ||
| 다른 유저의 프로필 정보를 조회합니다. | ||
| - 인증: Access Token(Bearer) | ||
| - PathVariable: userId (조회 대상 유저) | ||
| - 응답: | ||
| - 유저 기본 정보(닉네임/이메일/프로필 이미지 등) | ||
| - 카운트(팔로워/팔로잉/저장한 책/완독/북로그/북마크) | ||
| - 팔로잉 여부(isFollowing): 로그인한 사용자(me)가 대상 유저를 팔로우 중인지 여부 | ||
| """ | ||
| ) | ||
| @ApiResponses({ | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "200", | ||
| description = "조회 성공", | ||
| content = @Content(schema = @Schema(implementation = UserProfileResponse.class)) | ||
| ), | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "404", | ||
| description = "대상 유저를 찾을 수 없음" | ||
| ), | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "401", | ||
| description = "인증 실패(토큰 없음/만료/유효하지 않음)" | ||
| ) | ||
| }) | ||
| @GetMapping("/{userId}/profile") | ||
| public ApiResponse<UserProfileResponse> getUserProfile( | ||
| @AuthenticationPrincipal CustomUserDetails principal, | ||
| @Parameter(description = "조회 대상 유저 ID", example = "42", required = true) | ||
| @PathVariable Long userId | ||
| ) { | ||
| Long meId = principal.getUserId(); // 로그인한 사용자 ID | ||
| UserProfileResponse data = userProfileService.getProfile(meId, userId); // 조회 대상 userId | ||
|
|
||
| return ApiResponse.onSuccess(SuccessStatus.OK, data); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
booklog/src/main/java/com/example/booklog/domain/users/dto/UserProfileResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.example.booklog.domain.users.dto; | ||
|
|
||
| public record UserProfileResponse( | ||
| Long userId, | ||
| String nickname, | ||
| String email, | ||
| String avatarUrl, | ||
|
|
||
| long followerCount, | ||
| long followingCount, | ||
|
|
||
| long savedBookCount, // ✅ user_books 전체 권수 (상태 무관) | ||
| long completedBookCount, // (UI에 있으면) 완독 수 | ||
| long booklogCount, // ✅ 작성한 북로그 수 (posts) | ||
| long bookmarkCount, // ✅ 북마크 수 (post_bookmarks: user가 한 북마크) | ||
|
|
||
| boolean isFollowing, // me -> target 팔로잉 여부 | ||
|
|
||
| boolean isShelfPublic, // 공개 토글(프로필에서 보여주면) | ||
| boolean isBooklogPublic | ||
| ) {} | ||
39 changes: 39 additions & 0 deletions
39
booklog/src/main/java/com/example/booklog/domain/users/dto/UserPublicShelfListResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.example.booklog.domain.users.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** 공개 서재 목록 응답(대표 3권 포함) */ | ||
| public record UserPublicShelfListResponse( | ||
| int totalCount, | ||
| List<UserPublicShelfItem> items | ||
| ) { | ||
| /** 서재 카드 1개 */ | ||
| public record UserPublicShelfItem( | ||
| Long shelfId, | ||
| String name, | ||
| int bookCount, | ||
| List<ShelfBookPreview> topBooks | ||
| ) {} | ||
|
|
||
| /** 서재 카드에 보여줄 책 프리뷰 1개 */ | ||
| public record ShelfBookPreview( | ||
| Long bookId, | ||
| String thumbnailUrl, | ||
| String publisherName, | ||
| String authorName | ||
| ) {} | ||
|
|
||
| /** 특정 서재 도서 전체 목록 응답(페이징 없음) */ | ||
| public record UserPublicShelfBooksResponse( | ||
| int totalCount, | ||
| List<UserPublicShelfBookItem> items | ||
| ) {} | ||
|
|
||
| /** 서재 내 도서 1개(상태 없음) */ | ||
| public record UserPublicShelfBookItem( | ||
| Long bookId, | ||
| String thumbnailUrl, | ||
| String publisherName, | ||
| String authorName | ||
| ) {} | ||
| } |
64 changes: 64 additions & 0 deletions
64
...src/main/java/com/example/booklog/domain/users/repository/UserProfileQueryRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.example.booklog.domain.users.repository; | ||
|
|
||
| import com.example.booklog.domain.users.entity.Users; | ||
| import com.example.booklog.domain.users.repository.projection.UserProfileSummaryProjection; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface UserProfileQueryRepository extends JpaRepository<Users, Long> { | ||
|
|
||
| @Query(value = """ | ||
| SELECT | ||
| u.user_id AS userId, | ||
| u.nickname AS nickname, | ||
| ( | ||
| SELECT aa.email | ||
| FROM auth_accounts aa | ||
| WHERE aa.user_id = u.user_id | ||
| ORDER BY aa.id ASC | ||
| LIMIT 1 | ||
| ) AS email, | ||
| u.profile_image_url AS avatarUrl, | ||
|
|
||
| (SELECT COUNT(*) FROM user_follows f WHERE f.followee_id = u.user_id) AS followerCount, | ||
| (SELECT COUNT(*) FROM user_follows f WHERE f.follower_id = u.user_id) AS followingCount, | ||
|
|
||
| (SELECT COUNT(*) FROM user_books ub WHERE ub.user_id = u.user_id) AS savedBookCount, | ||
| (SELECT COUNT(*) FROM user_books ub WHERE ub.user_id = u.user_id AND ub.status = 'COMPLETED') AS completedBookCount, | ||
|
|
||
| (SELECT COUNT(*) FROM booklog_posts bp WHERE bp.user_id = u.user_id) AS booklogCount, | ||
| (SELECT COUNT(*) FROM booklog_bookmark bb WHERE bb.user_id = u.user_id) AS bookmarkCount, | ||
|
|
||
| CASE | ||
| WHEN EXISTS( | ||
| SELECT 1 | ||
| FROM user_follows f2 | ||
| WHERE f2.follower_id = :meId | ||
| AND f2.followee_id = u.user_id | ||
| ) | ||
| THEN TRUE | ||
| ELSE FALSE | ||
| END AS isFollowing, | ||
|
|
||
| CASE | ||
| WHEN COALESCE(us.is_shelf_public, 0) = 1 THEN TRUE | ||
| ELSE FALSE | ||
| END AS isShelfPublic, | ||
|
|
||
| CASE | ||
| WHEN COALESCE(us.is_post_public, 0) = 1 THEN TRUE | ||
| ELSE FALSE | ||
| END AS isBooklogPublic | ||
|
|
||
| FROM users u | ||
| LEFT JOIN user_settings us ON us.user_id = u.user_id | ||
| WHERE u.user_id = :targetUserId | ||
| """, nativeQuery = true) | ||
| Optional<UserProfileSummaryProjection> findUserProfileSummary( | ||
| @Param("meId") Long meId, | ||
| @Param("targetUserId") Long targetUserId | ||
| ); | ||
| } |
20 changes: 20 additions & 0 deletions
20
.../com/example/booklog/domain/users/repository/projection/UserProfileSummaryProjection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.example.booklog.domain.users.repository.projection; | ||
|
|
||
| public interface UserProfileSummaryProjection { | ||
| Long getUserId(); | ||
| String getNickname(); | ||
| String getEmail(); | ||
| String getAvatarUrl(); | ||
|
|
||
| Long getFollowerCount(); | ||
| Long getFollowingCount(); | ||
| Long getSavedBookCount(); | ||
| Long getCompletedBookCount(); | ||
| Long getBooklogCount(); | ||
| Long getBookmarkCount(); | ||
|
|
||
| // ✅ 여기 3개를 Boolean -> Long | ||
| Long getIsFollowing(); | ||
| Long getIsShelfPublic(); | ||
| Long getIsBooklogPublic(); | ||
| } |
52 changes: 52 additions & 0 deletions
52
booklog/src/main/java/com/example/booklog/domain/users/service/UserProfileService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.example.booklog.domain.users.service; | ||
|
|
||
| import com.example.booklog.domain.users.dto.UserProfileResponse; | ||
| import com.example.booklog.domain.users.repository.UserProfileQueryRepository; | ||
| import com.example.booklog.domain.users.repository.projection.UserProfileSummaryProjection; | ||
| import com.example.booklog.global.common.apiPayload.code.status.ErrorStatus; | ||
| import com.example.booklog.global.common.apiPayload.exception.GeneralException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class UserProfileService { | ||
|
|
||
| private final UserProfileQueryRepository userProfileQueryRepository; | ||
|
|
||
| public UserProfileResponse getProfile(Long meId, Long targetUserId) { | ||
| UserProfileSummaryProjection p = userProfileQueryRepository | ||
| .findUserProfileSummary(meId, targetUserId) | ||
| .orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); | ||
|
|
||
| return new UserProfileResponse( | ||
| p.getUserId(), | ||
| p.getNickname(), | ||
| p.getEmail(), | ||
| p.getAvatarUrl(), | ||
|
|
||
| safeLong(p.getFollowerCount()), | ||
| safeLong(p.getFollowingCount()), | ||
|
|
||
| safeLong(p.getSavedBookCount()), | ||
| safeLong(p.getCompletedBookCount()), | ||
| safeLong(p.getBooklogCount()), | ||
| safeLong(p.getBookmarkCount()), | ||
|
|
||
| // ✅ 0/1(Long) -> boolean | ||
| toBool(p.getIsFollowing()), | ||
| toBool(p.getIsShelfPublic()), | ||
| toBool(p.getIsBooklogPublic()) | ||
| ); | ||
| } | ||
|
|
||
| private long safeLong(Long v) { | ||
| return v == null ? 0L : v; | ||
| } | ||
|
|
||
| private boolean toBool(Long v) { | ||
| return v != null && v == 1L; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not expose email in other-user profiles.
The PR targets public/other-user profile viewing; returning
emailis a PII leak and a compliance/privacy risk. Remove it from the public response or gate it to “self only.”🔐 Proposed fix (public response)
public record UserProfileResponse( Long userId, String nickname, - String email, String avatarUrl,📝 Committable suggestion
🤖 Prompt for AI Agents