diff --git a/src/main/java/com/tukorea/planding/domain/user/controller/UserController.java b/src/main/java/com/tukorea/planding/domain/user/controller/UserController.java index 1a7a126..1c56d24 100644 --- a/src/main/java/com/tukorea/planding/domain/user/controller/UserController.java +++ b/src/main/java/com/tukorea/planding/domain/user/controller/UserController.java @@ -2,10 +2,17 @@ import com.tukorea.planding.common.CommonResponse; import com.tukorea.planding.common.CommonUtils; +import com.tukorea.planding.domain.group.dto.response.GroupFavoriteResponse; +import com.tukorea.planding.domain.group.entity.GroupRoom; +import com.tukorea.planding.domain.schedule.dto.ScheduleRequest; +import com.tukorea.planding.domain.schedule.dto.ScheduleResponse; import com.tukorea.planding.domain.user.dto.AndroidLoginRequest; import com.tukorea.planding.domain.user.dto.AndroidLoginResponse; +import com.tukorea.planding.domain.user.dto.ProfileResponse; import com.tukorea.planding.domain.user.dto.UserInfo; +import com.tukorea.planding.domain.user.entity.User; import com.tukorea.planding.domain.user.service.AndroidLoginService; +import com.tukorea.planding.domain.user.service.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -14,6 +21,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import java.util.List; + @Tag(name = "User", description = "회원 API 문서") @RestController @RequestMapping("/api/v1") @@ -21,6 +30,7 @@ public class UserController { private final AndroidLoginService androidLoginService; + private final UserService userService; @Operation(summary = "유저 정보 가져오기") @GetMapping("/userInfo") @@ -34,4 +44,24 @@ public CommonResponse signupApp(@RequestBody AndroidLoginR AndroidLoginResponse response = androidLoginService.signupApp(androidLoginRequest); return CommonUtils.success(response); } + + @Operation(summary = "프로필 가져오기", description = "즐겨찾는 그룹, 그룹요청") + @GetMapping("/profile") + public CommonResponse getProfile(@AuthenticationPrincipal UserInfo userInfo) { + ProfileResponse profile = userService.getProfile(userInfo); + return CommonUtils.success(profile); + } + + @Operation(summary = "즐겨찾기 그룹 조회") + @GetMapping() + public CommonResponse> searchFavorite(@AuthenticationPrincipal UserInfo userInfo) { + return CommonUtils.success(userService.findFavoriteGroupsByUserId(userInfo)); + } + + @Operation(summary = "오늘 스케줄 조회") + @GetMapping("/today") + public CommonResponse> showTodaySchedule(@AuthenticationPrincipal UserInfo userInfo) { + List responses = userService.showTodaySchedule(userInfo); + return CommonUtils.success(responses); + } } diff --git a/src/main/java/com/tukorea/planding/domain/user/dto/ProfileResponse.java b/src/main/java/com/tukorea/planding/domain/user/dto/ProfileResponse.java new file mode 100644 index 0000000..d96209e --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/user/dto/ProfileResponse.java @@ -0,0 +1,10 @@ +package com.tukorea.planding.domain.user.dto; + +import lombok.Builder; + +@Builder +public record ProfileResponse( + Long groupFavorite, + Long groupRequest +) { +} diff --git a/src/main/java/com/tukorea/planding/domain/user/entity/User.java b/src/main/java/com/tukorea/planding/domain/user/entity/User.java index ea11297..9823a88 100644 --- a/src/main/java/com/tukorea/planding/domain/user/entity/User.java +++ b/src/main/java/com/tukorea/planding/domain/user/entity/User.java @@ -3,9 +3,9 @@ import com.tukorea.planding.domain.group.entity.GroupFavorite; import com.tukorea.planding.domain.group.entity.UserGroup; import com.tukorea.planding.domain.notify.entity.Notification; +import com.tukorea.planding.domain.schedule.entity.Schedule; import com.tukorea.planding.global.audit.BaseEntity; import com.tukorea.planding.global.oauth.details.Role; -import com.tukorea.planding.domain.schedule.entity.Schedule; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; diff --git a/src/main/java/com/tukorea/planding/domain/user/repository/UserCustomRepository.java b/src/main/java/com/tukorea/planding/domain/user/repository/UserCustomRepository.java new file mode 100644 index 0000000..8dede20 --- /dev/null +++ b/src/main/java/com/tukorea/planding/domain/user/repository/UserCustomRepository.java @@ -0,0 +1,7 @@ +package com.tukorea.planding.domain.user.repository; + +import org.springframework.stereotype.Repository; + +@Repository +public interface UserCustomRepository { +} diff --git a/src/main/java/com/tukorea/planding/domain/user/repository/UserRepository.java b/src/main/java/com/tukorea/planding/domain/user/repository/UserRepository.java index 5269f81..8ed7133 100644 --- a/src/main/java/com/tukorea/planding/domain/user/repository/UserRepository.java +++ b/src/main/java/com/tukorea/planding/domain/user/repository/UserRepository.java @@ -3,6 +3,7 @@ import com.tukorea.planding.domain.user.entity.SocialType;import com.tukorea.planding.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface UserRepository extends JpaRepository { diff --git a/src/main/java/com/tukorea/planding/domain/user/service/UserQueryService.java b/src/main/java/com/tukorea/planding/domain/user/service/UserQueryService.java index de566c3..30e1376 100644 --- a/src/main/java/com/tukorea/planding/domain/user/service/UserQueryService.java +++ b/src/main/java/com/tukorea/planding/domain/user/service/UserQueryService.java @@ -6,9 +6,14 @@ import com.tukorea.planding.global.error.BusinessException; import com.tukorea.planding.global.error.ErrorCode; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.stream.Collectors; + @Service +@Slf4j @RequiredArgsConstructor public class UserQueryService { private final UserRepository userRepository; @@ -17,13 +22,8 @@ public User save(User user) { return userRepository.save(user); } - public User getByUserInfo(String userCode) { + public User getUserByUserCode(String userCode) { return userRepository.findByUserCode(userCode) .orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND)); } - - public User getUserByUserCode(UserInfo userInfo) { - return userRepository.findByUserCode(userInfo.getUserCode()) - .orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND)); - } } diff --git a/src/main/java/com/tukorea/planding/domain/user/service/UserService.java b/src/main/java/com/tukorea/planding/domain/user/service/UserService.java index 50bfe94..a42b855 100644 --- a/src/main/java/com/tukorea/planding/domain/user/service/UserService.java +++ b/src/main/java/com/tukorea/planding/domain/user/service/UserService.java @@ -1,21 +1,45 @@ package com.tukorea.planding.domain.user.service; +import com.tukorea.planding.domain.group.dto.response.GroupFavoriteResponse; +import com.tukorea.planding.domain.group.entity.GroupFavorite; +import com.tukorea.planding.domain.group.entity.GroupRoom; +import com.tukorea.planding.domain.group.entity.InviteStatus; +import com.tukorea.planding.domain.group.service.query.GroupFavoriteQueryService; +import com.tukorea.planding.domain.group.service.query.GroupInviteQueryService; +import com.tukorea.planding.domain.schedule.dto.ScheduleResponse; +import com.tukorea.planding.domain.schedule.entity.Schedule; +import com.tukorea.planding.domain.schedule.service.ScheduleQueryService; import com.tukorea.planding.domain.user.dto.AndroidLoginRequest; +import com.tukorea.planding.domain.user.dto.ProfileResponse; import com.tukorea.planding.domain.user.dto.UserInfo; import com.tukorea.planding.domain.user.entity.SocialType; import com.tukorea.planding.domain.user.entity.User; import com.tukorea.planding.domain.user.repository.UserRepository; -import com.tukorea.planding.global.error.BusinessException; -import com.tukorea.planding.global.error.ErrorCode; import com.tukorea.planding.global.oauth.details.Role; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class UserService { - private final UserRepository userRepository; + private final UserQueryService userQueryService; + private final ScheduleQueryService scheduleQueryService; + private final GroupInviteQueryService groupInviteQueryService; + private final GroupFavoriteQueryService groupFavoriteQueryService; + + @Transactional(readOnly = true) + public List findFavoriteGroupsByUserId(UserInfo userInfo) { + User user = userQueryService.getUserByUserCode(userInfo.getUserCode()); + // 즐겨찾기된 그룹 목록을 반환 + return user.getGroupFavorites().stream() + .map(GroupFavorite::getGroupRoom) // GroupFavorite 엔티티에서 GroupRoom을 가져오는 메서드 가정 + .collect(Collectors.toList()); + } public User createUserFromRequest(AndroidLoginRequest androidLoginRequest) { User user = User.builder() @@ -28,14 +52,24 @@ public User createUserFromRequest(AndroidLoginRequest androidLoginRequest) { .role(Role.USER) .build(); - return userRepository.save(user); + return userQueryService.save(user); + } + + //TODO 즐겨찾는 그룹, 그룹 요청 + public ProfileResponse getProfile(UserInfo userInfo) { + Long groupInvite = groupInviteQueryService.countInvitation(userInfo.getUserCode(), InviteStatus.PENDING); + Long groupFavorite = groupFavoriteQueryService.countMyFavoriteGroup(userInfo.getUserCode()); + return ProfileResponse.builder() + .groupRequest(groupInvite) + .groupFavorite(groupFavorite) + .build(); } - /* - DB 접근 메서드 - */ - public User getByUserInfo(String userCode) { - return userRepository.findByUserCode(userCode) - .orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND)); + public List showTodaySchedule(UserInfo userInfo) { + User user = userQueryService.getUserByUserCode(userInfo.getUserCode()); + List schedules = scheduleQueryService.showTodaySchedule(user.getId()); + return schedules.stream() + .map(ScheduleResponse::from) + .collect(Collectors.toList()); } }