diff --git a/src/main/java/EatPic/spring/domain/card/controller/CardController.java b/src/main/java/EatPic/spring/domain/card/controller/CardController.java index 40b43c7..145d239 100644 --- a/src/main/java/EatPic/spring/domain/card/controller/CardController.java +++ b/src/main/java/EatPic/spring/domain/card/controller/CardController.java @@ -1,7 +1,6 @@ package EatPic.spring.domain.card.controller; import EatPic.spring.domain.card.dto.request.CardCreateRequest; -import EatPic.spring.domain.card.dto.response.CardResponse; import EatPic.spring.domain.card.dto.request.CardCreateRequest.CardUpdateRequest; import EatPic.spring.domain.card.dto.response.CardResponse.CardDetailResponse; import EatPic.spring.domain.card.dto.response.CardResponse.CardFeedResponse; @@ -21,7 +20,14 @@ import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequiredArgsConstructor @@ -74,14 +80,6 @@ public ApiResponse getCardFeed(@PathVariable Long cardId) { return ApiResponse.onSuccess(cardService.getCardFeed(cardId, userId)); } - - @GetMapping("/profile/{userId}/cards") - @Operation(summary = "프로필 화면 피드 미리보기", description = "공유한 카드의 번호와 이미지 url 조회 API") - public ApiResponse getProfileCardsList(@PathVariable Long userId, - @RequestParam(required = false) Long cursor, - @RequestParam(defaultValue = "15") int size) { - return ApiResponse.onSuccess(cardService.getProfileCardList(userId,size,cursor)); - @DeleteMapping("/{cardId}") @Operation(summary = "카드 삭제", description = "카드를 소프트 삭제 처리합니다.") public ApiResponse deleteCard(@PathVariable Long cardId) { diff --git a/src/main/java/EatPic/spring/domain/card/converter/CardConverter.java b/src/main/java/EatPic/spring/domain/card/converter/CardConverter.java index c7949c3..d714938 100644 --- a/src/main/java/EatPic/spring/domain/card/converter/CardConverter.java +++ b/src/main/java/EatPic/spring/domain/card/converter/CardConverter.java @@ -12,9 +12,6 @@ import EatPic.spring.domain.card.mapping.CardHashtag; import EatPic.spring.domain.reaction.entity.Reaction; import EatPic.spring.domain.user.entity.User; -import org.springframework.context.annotation.Profile; -import org.springframework.data.domain.Slice; - import java.util.List; import java.util.stream.Collectors; @@ -113,23 +110,6 @@ public static CardResponse.CardFeedResponse toFeedResponse( .build(); } - public static CardResponse.ProfileCardDTO toProfileCardDto(Card card){ - return CardResponse.ProfileCardDTO.builder() - .cardId(card.getId()) - .cardImageUrl(card.getCardImageUrl()) - .build(); - } - - public static CardResponse.profileCardListDTO toProfileCardList(Long userId, Slice cardList){ - return CardResponse.profileCardListDTO.builder() - .hasNext(cardList.hasNext()) - .nextCursor(cardList.hasNext()?cardList.getContent().get(cardList.getContent().size()-1).getId():null) - .userId(userId) - .cardsList(cardList.getContent().stream() - .map(CardConverter::toProfileCardDto) - .toList()) - .build(); - public static TodayCardResponse toTodayCard(Card card) { return TodayCardResponse.builder() .cardId(card.getId()) diff --git a/src/main/java/EatPic/spring/domain/card/dto/response/CardResponse.java b/src/main/java/EatPic/spring/domain/card/dto/response/CardResponse.java index 32e7263..0d71325 100644 --- a/src/main/java/EatPic/spring/domain/card/dto/response/CardResponse.java +++ b/src/main/java/EatPic/spring/domain/card/dto/response/CardResponse.java @@ -188,22 +188,6 @@ public static class CardFeedUserDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class profileCardListDTO{ - private Long userId; - private boolean hasNext; - private Long nextCursor; - private List cardsList; - } - - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class ProfileCardDTO { - private Long cardId; - private String cardImageUrl; - } - @Schema(title = "TodayCardResponse: 오늘의 식사(카드) 현황 응답 dto") public static class TodayCardResponse { @Schema(description = "카드 ID", example = "12") @@ -216,4 +200,7 @@ public static class TodayCardResponse { private Meal meal; } + + + } diff --git a/src/main/java/EatPic/spring/domain/card/repository/CardRepository.java b/src/main/java/EatPic/spring/domain/card/repository/CardRepository.java index 1ff3bde..d3db210 100644 --- a/src/main/java/EatPic/spring/domain/card/repository/CardRepository.java +++ b/src/main/java/EatPic/spring/domain/card/repository/CardRepository.java @@ -25,13 +25,8 @@ public interface CardRepository extends JpaRepository { ORDER BY c.id ASC """) Slice findByCursor(@Param("cursor") Long cursor, Pageable pageable); - boolean existsByUserIdAndMealAndCreatedAtBetween(Long userId, Meal meal, LocalDateTime start, LocalDateTime end); - Long countCardById(Long id); - - Slice findByUserIdAndIsSharedTrueOrderByIdDesc(Long userId, Pageable pageable); - Slice findByUserIdAndIsSharedTrueAndIdLessThanOrderByIdDesc(Long userId, Long cursor, Pageable pageable); Optional findByIdAndIsDeletedFalse(Long id); List findAllByUserAndCreatedAtBetween(User user, LocalDateTime start, LocalDateTime end); diff --git a/src/main/java/EatPic/spring/domain/card/service/CardService.java b/src/main/java/EatPic/spring/domain/card/service/CardService.java index 11bee9f..a7df3ae 100644 --- a/src/main/java/EatPic/spring/domain/card/service/CardService.java +++ b/src/main/java/EatPic/spring/domain/card/service/CardService.java @@ -12,8 +12,7 @@ public interface CardService { CardResponse.CreateCardResponse createNewCard(CardCreateRequest.CreateCardRequest request, Long userId); CardDetailResponse getCardDetail(Long cardId, Long userId); - CardFeedResponse getCardFeed(Long cardId, Long userId) - CardResponse.profileCardListDTO getProfileCardList(Long userId, int size, Long cursor); + CardFeedResponse getCardFeed(Long cardId, Long userId); void deleteCard(Long cardId, Long userId); List getTodayCards(Long userId); CardDetailResponse updateCard(Long cardId, Long userId, CardUpdateRequest request); diff --git a/src/main/java/EatPic/spring/domain/card/service/CardServiceImpl.java b/src/main/java/EatPic/spring/domain/card/service/CardServiceImpl.java index 653c7b5..a495f98 100644 --- a/src/main/java/EatPic/spring/domain/card/service/CardServiceImpl.java +++ b/src/main/java/EatPic/spring/domain/card/service/CardServiceImpl.java @@ -24,12 +24,9 @@ import java.time.LocalTime; import java.util.Comparator; import java.util.List; - +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -149,19 +146,6 @@ public CardFeedResponse getCardFeed(Long cardId, Long userId) { } @Override - @Transactional(readOnly = true) - public CardResponse.profileCardListDTO getProfileCardList(Long userId, int size, Long cursor) { - - Slice cardSlice; - Pageable pageable = PageRequest.of(0, size); - - if (cursor == null) { - cardSlice = cardRepository.findByUserIdAndIsSharedTrueOrderByIdDesc(userId, pageable); - } else { - cardSlice = cardRepository.findByUserIdAndIsSharedTrueAndIdLessThanOrderByIdDesc(userId, cursor, pageable); - } - return CardConverter.toProfileCardList(userId, cardSlice); - @Transactional public void deleteCard(Long cardId, Long userId) { Card card = cardRepository.findByIdAndIsDeletedFalse(cardId) diff --git a/src/main/java/EatPic/spring/domain/user/controller/UserRestController.java b/src/main/java/EatPic/spring/domain/user/controller/UserRestController.java index 91fd6d3..aef675c 100644 --- a/src/main/java/EatPic/spring/domain/user/controller/UserRestController.java +++ b/src/main/java/EatPic/spring/domain/user/controller/UserRestController.java @@ -19,7 +19,7 @@ public class UserRestController { description = "페이지는 1부터 시작하며 total은 전체 항목 수 입니다.") @GetMapping("/users") @Tag(name = "User", description = "사용자 관련 API") - public ApiResponse followingUsersIcon( + public ApiResponse followingUsers( @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "15") int size) { //todo : userId -> 본인 @@ -30,7 +30,7 @@ public ApiResponse followingUsersIcon( summary = "커뮤니티 상단 팔로잉 유저 아이콘(나)") @GetMapping("/me") @Tag(name = "User", description = "사용자 관련 API") - public ApiResponse myIcon() { + public ApiResponse myIcon() { return ApiResponse.onSuccess(userService.getMyIcon()); } @@ -41,19 +41,4 @@ public ApiResponse blockUser(@PathVariable return ApiResponse.onSuccess(userService.blockUser(userId)); } - @Operation(summary = "유저 프로필 조회") - @PostMapping("/{userId}/profile") - @Tag(name = "User", description = "사용자 관련 API") - public ApiResponse getProfile(@PathVariable Long userId) { - return ApiResponse.onSuccess(userService.getProfile(userId)); - } - -// @Operation(summary = "유저 프로필 조회(이미지)") -// @PostMapping("/{userId}/profile/cards") -// @Tag(name = "User", description = "사용자 관련 API") -// public ApiResponse getProfile(@PathVariable Long userId) { -// return ApiResponse.onSuccess(userService.getProfile(userId)); -// } - - } diff --git a/src/main/java/EatPic/spring/domain/user/converter/UserConverter.java b/src/main/java/EatPic/spring/domain/user/converter/UserConverter.java index 68402e0..29f4441 100644 --- a/src/main/java/EatPic/spring/domain/user/converter/UserConverter.java +++ b/src/main/java/EatPic/spring/domain/user/converter/UserConverter.java @@ -11,16 +11,29 @@ import org.springframework.data.domain.Page; public class UserConverter { - public static UserResponseDTO.ProfileIconDto toProfileIconDto(User user) { - return UserResponseDTO.ProfileIconDto.builder() + + public static UserResponseDTO.UserIconListResponseDto toUserIconListResponseDto(Page followingPage){ + return UserResponseDTO.UserIconListResponseDto.builder() + .total((int)followingPage.getTotalElements()) + .page(followingPage.getNumber()+1) + .size(followingPage.getSize()) + .userIconList(followingPage.stream() + .map(UserFollow::getTargetUser) + .map(UserConverter::toProfileIconDto) + .toList()) + .build(); + } + + public static UserResponseDTO.ProfileDto toProfileIconDto(User user){ + return UserResponseDTO.ProfileDto.builder() .userId(user.getId()) .profileImageUrl(user.getProfileImageUrl()) .nameId(user.getNameId()) - .nickname(user.getNickname()) + .isFollowing(true) .build(); } - - public static UserResponseDTO.ProfileDto toProfileDto(User user, Boolean isFollowing) { + // todo: 두개 비슷함 -> 합치기 + public static UserResponseDTO.ProfileDto toProfileDto(User user, Boolean isFollowing){ return UserResponseDTO.ProfileDto.builder() .userId(user.getId()) .profileImageUrl(user.getProfileImageUrl()) @@ -29,38 +42,6 @@ public static UserResponseDTO.ProfileDto toProfileDto(User user, Boolean isFollo .isFollowing(isFollowing) .build(); } - - public static UserResponseDTO.DetailProfileDto toDetailProfileDto( - User user, - Boolean isFollowing, - Long totalCard, - Long totalFollower, - Long totalFollowing) { - - return UserResponseDTO.DetailProfileDto.builder() - .userId(user.getId()) - .profileImageUrl(user.getProfileImageUrl()) - .nameId(user.getNameId()) - .nickname(user.getNickname()) - .isFollowing(isFollowing) - .introduce(user.getIntroduce()) - .totalCard(totalCard) - .totalFollower(totalFollower) - .totalFollowing(totalFollowing) - .build(); -} - - public static UserResponseDTO.UserIconListResponseDto toUserIconListResponseDto(Page followingPage){ - return UserResponseDTO.UserIconListResponseDto.builder() - .total((int)followingPage.getTotalElements()) - .page(followingPage.getNumber()+1) - .size(followingPage.getSize()) - .userIconList(followingPage.stream() - .map(UserFollow::getTargetUser) - .map(UserConverter::toProfileIconDto) - .toList()) - .build(); - } public static ReactionResponseDTO.CardReactionUserListDto toCardReactionUsersListDto(Long cardId, ReactionType reactionType, Page profileList){ return ReactionResponseDTO.CardReactionUserListDto.builder() @@ -89,4 +70,4 @@ public static UserResponseDTO.UserBlockResponseDto toUserBlockResponseDto(UserBl .targetUserId(userBlock.getBlockedUser().getId()) .build(); } -} \ No newline at end of file +} diff --git a/src/main/java/EatPic/spring/domain/user/dto/response/UserResponseDTO.java b/src/main/java/EatPic/spring/domain/user/dto/response/UserResponseDTO.java index 2affc2e..0fb8103 100644 --- a/src/main/java/EatPic/spring/domain/user/dto/response/UserResponseDTO.java +++ b/src/main/java/EatPic/spring/domain/user/dto/response/UserResponseDTO.java @@ -9,19 +9,6 @@ public class UserResponseDTO { - @Getter - @Builder - @AllArgsConstructor - @NoArgsConstructor - public static class ProfileIconDto { - private Long userId; - private String profileImageUrl; - private String nameId; - private String nickname; - private Boolean isFollowing; - private String introduce; - } - @Getter @Builder @AllArgsConstructor @@ -34,23 +21,6 @@ public static class ProfileDto { private Boolean isFollowing; } - @Getter - @Builder - @AllArgsConstructor - @NoArgsConstructor - public static class DetailProfileDto { - private Long userId; - private String profileImageUrl; - private String nameId; - private String nickname; - private Boolean isFollowing; - private String introduce; - private Long totalCard; - private Long totalFollower; - private Long totalFollowing; - } - - @Getter @Builder @AllArgsConstructor @@ -59,7 +29,7 @@ public static class UserIconListResponseDto{ private int page; private int size; private int total; - private List userIconList; + private List userIconList; } @Getter diff --git a/src/main/java/EatPic/spring/domain/user/repository/UserFollowRepository.java b/src/main/java/EatPic/spring/domain/user/repository/UserFollowRepository.java index 21f6502..6dc4d35 100644 --- a/src/main/java/EatPic/spring/domain/user/repository/UserFollowRepository.java +++ b/src/main/java/EatPic/spring/domain/user/repository/UserFollowRepository.java @@ -12,7 +12,4 @@ public interface UserFollowRepository extends JpaRepository { Page findByUser(User user, Pageable pageable); Boolean existsByUserAndTargetUser(User user, User targetUser); - - Long countUserFollowByTargetUser(User targetUser); - Long countUserFollowByUser(User user); } diff --git a/src/main/java/EatPic/spring/domain/user/service/UserService.java b/src/main/java/EatPic/spring/domain/user/service/UserService.java index e6a4e92..4ad8d2b 100644 --- a/src/main/java/EatPic/spring/domain/user/service/UserService.java +++ b/src/main/java/EatPic/spring/domain/user/service/UserService.java @@ -1,6 +1,5 @@ package EatPic.spring.domain.user.service; -import EatPic.spring.domain.card.repository.CardRepository; import EatPic.spring.domain.user.converter.UserConverter; import EatPic.spring.domain.user.dto.response.UserResponseDTO; import EatPic.spring.domain.user.entity.User; @@ -31,7 +30,6 @@ public class UserService { private final UserFollowRepository userFollowRepository; private final PasswordEncoder passwordEncoder; - private final CardRepository cardRepository; public User signup(SignupRequestDTO request) { // 이메일 중복 검사 @@ -87,22 +85,9 @@ public UserResponseDTO.UserIconListResponseDto followingUserIconList(Long userId } @Transactional - public UserResponseDTO.ProfileIconDto getMyIcon() { + public UserResponseDTO.ProfileDto getMyIcon() { User me = userRepository.findUserById(1L); - return UserConverter.toProfileIconDto(me); - } - - public UserResponseDTO.DetailProfileDto getProfile(Long userId) { - // todo: 로그인 사용자 - User me = userRepository.findUserById(1L); - - User user = userRepository.findUserById(userId); - Boolean isFollowing = userFollowRepository.existsByUserAndTargetUser(me, user); - Long totalCard = cardRepository.countCardById(userId); - Long totalFollower = userFollowRepository.countUserFollowByTargetUser(me); - Long totalFollowing = userFollowRepository.countUserFollowByUser(user); - - return UserConverter.toDetailProfileDto(user, isFollowing,totalCard,totalFollower,totalFollowing); + return UserConverter.toProfileDto(me,true); } } \ No newline at end of file