From 5e022f6b6583de69f57de938dcca65f51557e54c Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Wed, 6 Nov 2024 01:24:36 +0900 Subject: [PATCH 01/20] =?UTF-8?q?refactor=20:=20=EC=A0=95=EC=82=B0=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=BD=94=EB=93=9C=20domain=20=EB=94=94?= =?UTF-8?q?=EB=A0=89=ED=86=A0=EB=A6=AC=20=ED=95=98=EC=9C=84=EB=A1=9C=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SpaceController.java | 7 +++---- .../space_spring/dao/CommentLikeDao.java | 2 +- .../space/space_spring/dao/PostLikeDao.java | 1 + .../space/space_spring/dao/UserSpaceDao.java | 2 +- .../dao/chat/UserChatRoomRepository.java | 2 +- .../chat/custom/ChatRoomRepositoryCustom.java | 2 +- .../chat/custom/ChatRoomRepositoryImpl.java | 2 +- .../OAuth/controller/OAuthController.java | 2 +- .../OAuth/service/OAuthService.java | 2 +- .../auth/service/AuthService.java | 4 ++-- .../jwt/controller/JwtController.java | 1 - .../model}/entity/RefreshTokenStorage.java | 3 ++- .../jwt/repository/JwtRepository.java | 4 ++-- .../authorization/jwt/service/JwtService.java | 4 ++-- .../pay}/controller/PayController.java | 20 +++++++++---------- .../pay/model}/dto/PayReceiveInfoDto.java | 2 +- .../pay/model}/dto/PayRequestInfoDto.java | 2 +- .../pay/model}/dto/PayTargetInfoDto.java | 2 +- .../dto/RecentPayRequestBankInfoDto.java | 2 +- .../pay/model}/dto/TotalPayInfoDto.java | 2 +- .../pay/model}/entity/PayRequest.java | 5 ++++- .../pay/model}/entity/PayRequestTarget.java | 3 ++- .../request/PostPayCompleteRequest.java | 2 +- .../model}/request/PostPayCreateRequest.java | 2 +- .../model}/response/GetPayViewResponse.java | 6 +++--- .../response/GetReceivePayViewResponse.java | 4 ++-- .../GetRecentPayRequestBankInfoResponse.java | 4 ++-- .../response/GetRequestPayViewResponse.java | 4 ++-- .../response/PostPayCompleteResponse.java | 2 +- .../pay/repository}/PayDao.java | 12 +++++------ .../{ => domain/pay}/service/PayService.java | 15 ++++++++------ .../{ => domain/user/model}/entity/User.java | 4 ++-- .../domain/user/repository/UserDao.java | 2 +- .../user/repository/UserRepository.java | 2 +- .../domain/user/service/UserService.java | 2 +- .../comment/request/CreateCommentRequest.java | 3 +-- .../dto/post/request/CreatePostRequest.java | 2 +- .../dto/space/GetSpaceHomeDto.java | 5 ++--- .../space/space_spring/entity/Comment.java | 1 + .../space_spring/entity/CommentLike.java | 1 + .../java/space/space_spring/entity/Post.java | 1 + .../space/space_spring/entity/PostLike.java | 2 +- .../space_spring/entity/UserChatRoom.java | 1 + .../space/space_spring/entity/UserSpace.java | 1 + .../UserSpaceValidationInterceptor.java | 2 +- .../space_spring/service/ChatRoomService.java | 1 + .../space_spring/service/CommentService.java | 2 +- .../space_spring/service/LikeService.java | 1 + .../space_spring/service/PostService.java | 1 + .../space_spring/service/SpaceService.java | 2 +- .../service/VoiceRoomService.java | 5 +---- .../space/space_spring/util/pay/PayUtils.java | 6 +++--- .../space_spring/util/user/UserUtils.java | 2 +- .../util/userSpace/MemoryUserSpaceUtils.java | 2 +- .../util/userSpace/UserSpaceUtils.java | 1 - .../VoiceRoom/VoiceRoomServiceTest.java | 6 +++--- .../jwt/service/JwtServiceTest.java | 4 ++-- .../repository/ChatRoomRepositoryTest.java | 2 +- .../repository/UserChatRoomDaoTest.java | 2 +- .../space_spring/service/PayServiceTest.java | 15 +++++++------- 60 files changed, 108 insertions(+), 100 deletions(-) rename src/main/java/space/space_spring/{ => domain/authorization/jwt/model}/entity/RefreshTokenStorage.java (89%) rename src/main/java/space/space_spring/{ => domain/pay}/controller/PayController.java (94%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/dto/PayReceiveInfoDto.java (85%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/dto/PayRequestInfoDto.java (89%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/dto/PayTargetInfoDto.java (85%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/dto/RecentPayRequestBankInfoDto.java (80%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/dto/TotalPayInfoDto.java (92%) rename src/main/java/space/space_spring/{ => domain/pay/model}/entity/PayRequest.java (89%) rename src/main/java/space/space_spring/{ => domain/pay/model}/entity/PayRequestTarget.java (91%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/request/PostPayCompleteRequest.java (80%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/request/PostPayCreateRequest.java (95%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/response/GetPayViewResponse.java (64%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/response/GetReceivePayViewResponse.java (74%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/response/GetRecentPayRequestBankInfoResponse.java (69%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/response/GetRequestPayViewResponse.java (74%) rename src/main/java/space/space_spring/{dto/pay => domain/pay/model}/response/PostPayCompleteResponse.java (82%) rename src/main/java/space/space_spring/{dao => domain/pay/repository}/PayDao.java (92%) rename src/main/java/space/space_spring/{ => domain/pay}/service/PayService.java (94%) rename src/main/java/space/space_spring/{ => domain/user/model}/entity/User.java (94%) diff --git a/src/main/java/space/space_spring/controller/SpaceController.java b/src/main/java/space/space_spring/controller/SpaceController.java index d304bbf7..95b4df6a 100644 --- a/src/main/java/space/space_spring/controller/SpaceController.java +++ b/src/main/java/space/space_spring/controller/SpaceController.java @@ -10,8 +10,8 @@ import space.space_spring.argumentResolver.userSpace.CheckUserSpace; import space.space_spring.argumentResolver.userSpace.UserSpaceAuth; import space.space_spring.argumentResolver.userSpace.UserSpaceId; -import space.space_spring.dto.pay.dto.PayReceiveInfoDto; -import space.space_spring.dto.pay.dto.PayRequestInfoDto; +import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import space.space_spring.dto.space.GetSpaceHomeDto; import space.space_spring.dto.space.GetSpaceJoinDto; import space.space_spring.dto.space.PostSpaceJoinDto; @@ -23,7 +23,7 @@ import space.space_spring.entity.Space; import space.space_spring.exception.CustomException; import space.space_spring.response.BaseResponse; -import space.space_spring.service.PayService; +import space.space_spring.domain.pay.service.PayService; import space.space_spring.service.PostService; import space.space_spring.service.S3Uploader; import space.space_spring.service.SpaceService; @@ -31,7 +31,6 @@ import java.io.IOException; import java.util.List; -import java.util.Optional; import static space.space_spring.response.status.BaseExceptionResponseStatus.*; import static space.space_spring.util.bindingResult.BindingResultUtils.getErrorMessage; diff --git a/src/main/java/space/space_spring/dao/CommentLikeDao.java b/src/main/java/space/space_spring/dao/CommentLikeDao.java index 9f8c3f2a..a8bfce9d 100644 --- a/src/main/java/space/space_spring/dao/CommentLikeDao.java +++ b/src/main/java/space/space_spring/dao/CommentLikeDao.java @@ -4,7 +4,7 @@ import org.springframework.stereotype.Repository; import space.space_spring.entity.Comment; import space.space_spring.entity.CommentLike; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import java.util.Optional; diff --git a/src/main/java/space/space_spring/dao/PostLikeDao.java b/src/main/java/space/space_spring/dao/PostLikeDao.java index b06f1e2e..f0a1e36c 100644 --- a/src/main/java/space/space_spring/dao/PostLikeDao.java +++ b/src/main/java/space/space_spring/dao/PostLikeDao.java @@ -1,6 +1,7 @@ package space.space_spring.dao; import org.springframework.data.jpa.repository.JpaRepository; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.*; import java.util.Optional; diff --git a/src/main/java/space/space_spring/dao/UserSpaceDao.java b/src/main/java/space/space_spring/dao/UserSpaceDao.java index 147e4175..90092d77 100644 --- a/src/main/java/space/space_spring/dao/UserSpaceDao.java +++ b/src/main/java/space/space_spring/dao/UserSpaceDao.java @@ -9,7 +9,7 @@ import space.space_spring.domain.user.model.dto.SpaceChoiceViewDto; import space.space_spring.dto.userSpace.UserInfoInSpace; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSpaceAuth; diff --git a/src/main/java/space/space_spring/dao/chat/UserChatRoomRepository.java b/src/main/java/space/space_spring/dao/chat/UserChatRoomRepository.java index c50c3a28..d87348a8 100644 --- a/src/main/java/space/space_spring/dao/chat/UserChatRoomRepository.java +++ b/src/main/java/space/space_spring/dao/chat/UserChatRoomRepository.java @@ -2,7 +2,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import space.space_spring.entity.ChatRoom; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.UserChatRoom; import space.space_spring.entity.enumStatus.BaseStatusType; diff --git a/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryCustom.java b/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryCustom.java index 24b3c2ef..9407cf21 100644 --- a/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryCustom.java +++ b/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryCustom.java @@ -2,7 +2,7 @@ import space.space_spring.entity.ChatRoom; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import java.util.List; diff --git a/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryImpl.java b/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryImpl.java index ee38d3fe..89a22a36 100644 --- a/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryImpl.java +++ b/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryImpl.java @@ -4,7 +4,7 @@ import lombok.RequiredArgsConstructor; import space.space_spring.entity.ChatRoom; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import java.util.List; import space.space_spring.entity.enumStatus.BaseStatusType; diff --git a/src/main/java/space/space_spring/domain/authorization/OAuth/controller/OAuthController.java b/src/main/java/space/space_spring/domain/authorization/OAuth/controller/OAuthController.java index 410350d4..2ab7c4fa 100644 --- a/src/main/java/space/space_spring/domain/authorization/OAuth/controller/OAuthController.java +++ b/src/main/java/space/space_spring/domain/authorization/OAuth/controller/OAuthController.java @@ -9,7 +9,7 @@ import space.space_spring.domain.authorization.jwt.service.JwtService; import space.space_spring.domain.authorization.jwt.model.TokenPairDTO; import space.space_spring.dto.oAuth.KakaoInfo; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.domain.authorization.OAuth.service.OAuthService; import java.io.IOException; diff --git a/src/main/java/space/space_spring/domain/authorization/OAuth/service/OAuthService.java b/src/main/java/space/space_spring/domain/authorization/OAuth/service/OAuthService.java index e4934b5c..f32d1cdf 100644 --- a/src/main/java/space/space_spring/domain/authorization/OAuth/service/OAuthService.java +++ b/src/main/java/space/space_spring/domain/authorization/OAuth/service/OAuthService.java @@ -15,7 +15,7 @@ import org.springframework.web.client.RestTemplate; import space.space_spring.domain.user.repository.UserDao; import space.space_spring.dto.oAuth.KakaoInfo; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.util.user.UserUtils; import static space.space_spring.entity.enumStatus.UserSignupType.KAKAO; diff --git a/src/main/java/space/space_spring/domain/authorization/auth/service/AuthService.java b/src/main/java/space/space_spring/domain/authorization/auth/service/AuthService.java index 87fb127f..f42c8c45 100644 --- a/src/main/java/space/space_spring/domain/authorization/auth/service/AuthService.java +++ b/src/main/java/space/space_spring/domain/authorization/auth/service/AuthService.java @@ -9,8 +9,8 @@ import space.space_spring.domain.authorization.jwt.model.TokenType; import space.space_spring.domain.authorization.jwt.repository.JwtRepository; import space.space_spring.domain.user.model.PostLoginDto; -import space.space_spring.entity.RefreshTokenStorage; -import space.space_spring.entity.User; +import space.space_spring.domain.authorization.jwt.model.entity.RefreshTokenStorage; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.exception.CustomException; import space.space_spring.domain.authorization.jwt.model.JwtLoginProvider; import space.space_spring.util.user.UserUtils; diff --git a/src/main/java/space/space_spring/domain/authorization/jwt/controller/JwtController.java b/src/main/java/space/space_spring/domain/authorization/jwt/controller/JwtController.java index 8a597dbc..b20630d9 100644 --- a/src/main/java/space/space_spring/domain/authorization/jwt/controller/JwtController.java +++ b/src/main/java/space/space_spring/domain/authorization/jwt/controller/JwtController.java @@ -8,7 +8,6 @@ import org.springframework.web.bind.annotation.RestController; import space.space_spring.domain.authorization.jwt.service.JwtService; import space.space_spring.domain.authorization.jwt.model.TokenPairDTO; -import space.space_spring.entity.User; import space.space_spring.response.BaseResponse; import java.io.IOException; diff --git a/src/main/java/space/space_spring/entity/RefreshTokenStorage.java b/src/main/java/space/space_spring/domain/authorization/jwt/model/entity/RefreshTokenStorage.java similarity index 89% rename from src/main/java/space/space_spring/entity/RefreshTokenStorage.java rename to src/main/java/space/space_spring/domain/authorization/jwt/model/entity/RefreshTokenStorage.java index d79f3bef..6d81c0c7 100644 --- a/src/main/java/space/space_spring/entity/RefreshTokenStorage.java +++ b/src/main/java/space/space_spring/domain/authorization/jwt/model/entity/RefreshTokenStorage.java @@ -1,9 +1,10 @@ -package space.space_spring.entity; +package space.space_spring.domain.authorization.jwt.model.entity; import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import space.space_spring.domain.user.model.entity.User; @Entity @Table(name = "Token_Storage") diff --git a/src/main/java/space/space_spring/domain/authorization/jwt/repository/JwtRepository.java b/src/main/java/space/space_spring/domain/authorization/jwt/repository/JwtRepository.java index 85654bcf..8230cd2c 100644 --- a/src/main/java/space/space_spring/domain/authorization/jwt/repository/JwtRepository.java +++ b/src/main/java/space/space_spring/domain/authorization/jwt/repository/JwtRepository.java @@ -6,8 +6,8 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; -import space.space_spring.entity.RefreshTokenStorage; -import space.space_spring.entity.User; +import space.space_spring.domain.authorization.jwt.model.entity.RefreshTokenStorage; +import space.space_spring.domain.user.model.entity.User; import java.util.Optional; diff --git a/src/main/java/space/space_spring/domain/authorization/jwt/service/JwtService.java b/src/main/java/space/space_spring/domain/authorization/jwt/service/JwtService.java index 9a2ba721..dace10b6 100644 --- a/src/main/java/space/space_spring/domain/authorization/jwt/service/JwtService.java +++ b/src/main/java/space/space_spring/domain/authorization/jwt/service/JwtService.java @@ -8,8 +8,8 @@ import space.space_spring.domain.authorization.jwt.model.*; import space.space_spring.domain.authorization.jwt.repository.JwtRepository; import space.space_spring.domain.user.repository.UserRepository; -import space.space_spring.entity.RefreshTokenStorage; -import space.space_spring.entity.User; +import space.space_spring.domain.authorization.jwt.model.entity.RefreshTokenStorage; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.exception.CustomException; import space.space_spring.exception.jwt.unauthorized.JwtExpiredTokenException; import space.space_spring.exception.jwt.unauthorized.JwtUnauthorizedTokenException; diff --git a/src/main/java/space/space_spring/controller/PayController.java b/src/main/java/space/space_spring/domain/pay/controller/PayController.java similarity index 94% rename from src/main/java/space/space_spring/controller/PayController.java rename to src/main/java/space/space_spring/domain/pay/controller/PayController.java index 879066ca..13308c0c 100644 --- a/src/main/java/space/space_spring/controller/PayController.java +++ b/src/main/java/space/space_spring/domain/pay/controller/PayController.java @@ -1,4 +1,4 @@ -package space.space_spring.controller; +package space.space_spring.domain.pay.controller; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -7,17 +7,17 @@ import org.springframework.web.bind.annotation.*; import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; import space.space_spring.argumentResolver.userSpace.CheckUserSpace; -import space.space_spring.dto.pay.dto.PayReceiveInfoDto; -import space.space_spring.dto.pay.dto.PayRequestInfoDto; -import space.space_spring.dto.pay.dto.TotalPayInfoDto; -import space.space_spring.dto.pay.request.PostPayCompleteRequest; -import space.space_spring.dto.pay.request.PostPayCreateRequest; -import space.space_spring.dto.pay.response.*; -import space.space_spring.entity.PayRequestTarget; -import space.space_spring.entity.User; +import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; +import space.space_spring.domain.pay.model.dto.TotalPayInfoDto; +import space.space_spring.domain.pay.model.request.PostPayCompleteRequest; +import space.space_spring.domain.pay.model.request.PostPayCreateRequest; +import space.space_spring.domain.pay.model.response.*; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.exception.CustomException; import space.space_spring.response.BaseResponse; -import space.space_spring.service.PayService; +import space.space_spring.domain.pay.service.PayService; import space.space_spring.util.pay.PayUtils; import space.space_spring.util.user.UserUtils; import space.space_spring.util.userSpace.UserSpaceUtils; diff --git a/src/main/java/space/space_spring/dto/pay/dto/PayReceiveInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java similarity index 85% rename from src/main/java/space/space_spring/dto/pay/dto/PayReceiveInfoDto.java rename to src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java index cce7ba60..f0b45533 100644 --- a/src/main/java/space/space_spring/dto/pay/dto/PayReceiveInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.pay.dto; +package space.space_spring.domain.pay.model.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/dto/pay/dto/PayRequestInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java similarity index 89% rename from src/main/java/space/space_spring/dto/pay/dto/PayRequestInfoDto.java rename to src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java index 4c289bd2..3b421060 100644 --- a/src/main/java/space/space_spring/dto/pay/dto/PayRequestInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.pay.dto; +package space.space_spring.domain.pay.model.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/dto/pay/dto/PayTargetInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java similarity index 85% rename from src/main/java/space/space_spring/dto/pay/dto/PayTargetInfoDto.java rename to src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java index 971e84c3..a6408735 100644 --- a/src/main/java/space/space_spring/dto/pay/dto/PayTargetInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.pay.dto; +package space.space_spring.domain.pay.model.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/dto/pay/dto/RecentPayRequestBankInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/RecentPayRequestBankInfoDto.java similarity index 80% rename from src/main/java/space/space_spring/dto/pay/dto/RecentPayRequestBankInfoDto.java rename to src/main/java/space/space_spring/domain/pay/model/dto/RecentPayRequestBankInfoDto.java index 3c070998..1d7bd41a 100644 --- a/src/main/java/space/space_spring/dto/pay/dto/RecentPayRequestBankInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/RecentPayRequestBankInfoDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.pay.dto; +package space.space_spring.domain.pay.model.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/dto/pay/dto/TotalPayInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/TotalPayInfoDto.java similarity index 92% rename from src/main/java/space/space_spring/dto/pay/dto/TotalPayInfoDto.java rename to src/main/java/space/space_spring/domain/pay/model/dto/TotalPayInfoDto.java index 944fb01a..fc7e0eef 100644 --- a/src/main/java/space/space_spring/dto/pay/dto/TotalPayInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/TotalPayInfoDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.pay.dto; +package space.space_spring.domain.pay.model.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java similarity index 89% rename from src/main/java/space/space_spring/entity/PayRequest.java rename to src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index 8a9c058a..4ffb7465 100644 --- a/src/main/java/space/space_spring/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -1,7 +1,10 @@ -package space.space_spring.entity; +package space.space_spring.domain.pay.model.entity; import jakarta.persistence.*; import lombok.Getter; +import space.space_spring.domain.user.model.entity.User; +import space.space_spring.entity.BaseEntity; +import space.space_spring.entity.Space; @Getter @Entity diff --git a/src/main/java/space/space_spring/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java similarity index 91% rename from src/main/java/space/space_spring/entity/PayRequestTarget.java rename to src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index c2495833..afebddb7 100644 --- a/src/main/java/space/space_spring/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -1,7 +1,8 @@ -package space.space_spring.entity; +package space.space_spring.domain.pay.model.entity; import jakarta.persistence.*; import lombok.Getter; +import space.space_spring.entity.BaseEntity; @Entity @Getter diff --git a/src/main/java/space/space_spring/dto/pay/request/PostPayCompleteRequest.java b/src/main/java/space/space_spring/domain/pay/model/request/PostPayCompleteRequest.java similarity index 80% rename from src/main/java/space/space_spring/dto/pay/request/PostPayCompleteRequest.java rename to src/main/java/space/space_spring/domain/pay/model/request/PostPayCompleteRequest.java index bfb53dd0..edcd3286 100644 --- a/src/main/java/space/space_spring/dto/pay/request/PostPayCompleteRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/request/PostPayCompleteRequest.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.pay.request; +package space.space_spring.domain.pay.model.request; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/dto/pay/request/PostPayCreateRequest.java b/src/main/java/space/space_spring/domain/pay/model/request/PostPayCreateRequest.java similarity index 95% rename from src/main/java/space/space_spring/dto/pay/request/PostPayCreateRequest.java rename to src/main/java/space/space_spring/domain/pay/model/request/PostPayCreateRequest.java index ea13ea84..d117385a 100644 --- a/src/main/java/space/space_spring/dto/pay/request/PostPayCreateRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/request/PostPayCreateRequest.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.pay.request; +package space.space_spring.domain.pay.model.request; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/space/space_spring/dto/pay/response/GetPayViewResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/GetPayViewResponse.java similarity index 64% rename from src/main/java/space/space_spring/dto/pay/response/GetPayViewResponse.java rename to src/main/java/space/space_spring/domain/pay/model/response/GetPayViewResponse.java index a3904f4d..d8f488ee 100644 --- a/src/main/java/space/space_spring/dto/pay/response/GetPayViewResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/GetPayViewResponse.java @@ -1,9 +1,9 @@ -package space.space_spring.dto.pay.response; +package space.space_spring.domain.pay.model.response; import lombok.AllArgsConstructor; import lombok.Getter; -import space.space_spring.dto.pay.dto.PayReceiveInfoDto; -import space.space_spring.dto.pay.dto.PayRequestInfoDto; +import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/space/space_spring/dto/pay/response/GetReceivePayViewResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/GetReceivePayViewResponse.java similarity index 74% rename from src/main/java/space/space_spring/dto/pay/response/GetReceivePayViewResponse.java rename to src/main/java/space/space_spring/domain/pay/model/response/GetReceivePayViewResponse.java index e9f7e3f3..9f2abcb6 100644 --- a/src/main/java/space/space_spring/dto/pay/response/GetReceivePayViewResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/GetReceivePayViewResponse.java @@ -1,8 +1,8 @@ -package space.space_spring.dto.pay.response; +package space.space_spring.domain.pay.model.response; import lombok.AllArgsConstructor; import lombok.Getter; -import space.space_spring.dto.pay.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/space/space_spring/dto/pay/response/GetRecentPayRequestBankInfoResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/GetRecentPayRequestBankInfoResponse.java similarity index 69% rename from src/main/java/space/space_spring/dto/pay/response/GetRecentPayRequestBankInfoResponse.java rename to src/main/java/space/space_spring/domain/pay/model/response/GetRecentPayRequestBankInfoResponse.java index 2e2f9ef0..02f20bdf 100644 --- a/src/main/java/space/space_spring/dto/pay/response/GetRecentPayRequestBankInfoResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/GetRecentPayRequestBankInfoResponse.java @@ -1,8 +1,8 @@ -package space.space_spring.dto.pay.response; +package space.space_spring.domain.pay.model.response; import lombok.AllArgsConstructor; import lombok.Getter; -import space.space_spring.dto.pay.dto.RecentPayRequestBankInfoDto; +import space.space_spring.domain.pay.model.dto.RecentPayRequestBankInfoDto; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/space/space_spring/dto/pay/response/GetRequestPayViewResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/GetRequestPayViewResponse.java similarity index 74% rename from src/main/java/space/space_spring/dto/pay/response/GetRequestPayViewResponse.java rename to src/main/java/space/space_spring/domain/pay/model/response/GetRequestPayViewResponse.java index 82b83ada..d6aad38d 100644 --- a/src/main/java/space/space_spring/dto/pay/response/GetRequestPayViewResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/GetRequestPayViewResponse.java @@ -1,8 +1,8 @@ -package space.space_spring.dto.pay.response; +package space.space_spring.domain.pay.model.response; import lombok.AllArgsConstructor; import lombok.Getter; -import space.space_spring.dto.pay.dto.PayRequestInfoDto; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/space/space_spring/dto/pay/response/PostPayCompleteResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/PostPayCompleteResponse.java similarity index 82% rename from src/main/java/space/space_spring/dto/pay/response/PostPayCompleteResponse.java rename to src/main/java/space/space_spring/domain/pay/model/response/PostPayCompleteResponse.java index e2399a43..9842fee0 100644 --- a/src/main/java/space/space_spring/dto/pay/response/PostPayCompleteResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/PostPayCompleteResponse.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.pay.response; +package space.space_spring.domain.pay.model.response; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/dao/PayDao.java b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java similarity index 92% rename from src/main/java/space/space_spring/dao/PayDao.java rename to src/main/java/space/space_spring/domain/pay/repository/PayDao.java index d280faf7..30480ff2 100644 --- a/src/main/java/space/space_spring/dao/PayDao.java +++ b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java @@ -1,16 +1,14 @@ -package space.space_spring.dao; +package space.space_spring.domain.pay.repository; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import jakarta.persistence.TypedQuery; import org.springframework.stereotype.Repository; -import space.space_spring.dto.pay.dto.PayRequestInfoDto; -import space.space_spring.dto.pay.dto.RecentPayRequestBankInfoDto; -import space.space_spring.dto.pay.dto.TotalPayInfoDto; -import space.space_spring.entity.PayRequest; -import space.space_spring.entity.PayRequestTarget; +import space.space_spring.domain.pay.model.dto.RecentPayRequestBankInfoDto; +import space.space_spring.domain.pay.model.entity.PayRequest; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/space/space_spring/service/PayService.java b/src/main/java/space/space_spring/domain/pay/service/PayService.java similarity index 94% rename from src/main/java/space/space_spring/service/PayService.java rename to src/main/java/space/space_spring/domain/pay/service/PayService.java index 74b2eec6..d476bfa9 100644 --- a/src/main/java/space/space_spring/service/PayService.java +++ b/src/main/java/space/space_spring/domain/pay/service/PayService.java @@ -1,15 +1,18 @@ -package space.space_spring.service; +package space.space_spring.domain.pay.service; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import space.space_spring.dao.PayDao; +import space.space_spring.domain.pay.model.entity.PayRequest; +import space.space_spring.domain.pay.model.dto.*; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.pay.repository.PayDao; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.domain.user.repository.UserDao; import space.space_spring.dao.UserSpaceDao; -import space.space_spring.dto.pay.dto.*; -import space.space_spring.dto.pay.request.PostPayCreateRequest; -import space.space_spring.dto.pay.response.GetRecentPayRequestBankInfoResponse; -import space.space_spring.dto.pay.response.PostPayCompleteResponse; +import space.space_spring.domain.pay.model.request.PostPayCreateRequest; +import space.space_spring.domain.pay.model.response.GetRecentPayRequestBankInfoResponse; +import space.space_spring.domain.pay.model.response.PostPayCompleteResponse; import space.space_spring.entity.*; import space.space_spring.exception.CustomException; import space.space_spring.util.space.SpaceUtils; diff --git a/src/main/java/space/space_spring/entity/User.java b/src/main/java/space/space_spring/domain/user/model/entity/User.java similarity index 94% rename from src/main/java/space/space_spring/entity/User.java rename to src/main/java/space/space_spring/domain/user/model/entity/User.java index ee6a88b1..b58ef710 100644 --- a/src/main/java/space/space_spring/entity/User.java +++ b/src/main/java/space/space_spring/domain/user/model/entity/User.java @@ -1,10 +1,10 @@ -package space.space_spring.entity; +package space.space_spring.domain.user.model.entity; -import jakarta.annotation.Nullable; import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import space.space_spring.entity.BaseEntity; import space.space_spring.entity.enumStatus.UserSignupType; @Entity diff --git a/src/main/java/space/space_spring/domain/user/repository/UserDao.java b/src/main/java/space/space_spring/domain/user/repository/UserDao.java index 503657ce..d994423f 100644 --- a/src/main/java/space/space_spring/domain/user/repository/UserDao.java +++ b/src/main/java/space/space_spring/domain/user/repository/UserDao.java @@ -5,7 +5,7 @@ import jakarta.persistence.PersistenceContext; import jakarta.persistence.TypedQuery; import org.springframework.stereotype.Repository; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.enumStatus.UserSignupType; import java.util.Optional; diff --git a/src/main/java/space/space_spring/domain/user/repository/UserRepository.java b/src/main/java/space/space_spring/domain/user/repository/UserRepository.java index 60d0dc3e..58d35588 100644 --- a/src/main/java/space/space_spring/domain/user/repository/UserRepository.java +++ b/src/main/java/space/space_spring/domain/user/repository/UserRepository.java @@ -3,7 +3,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import java.util.Optional; diff --git a/src/main/java/space/space_spring/domain/user/service/UserService.java b/src/main/java/space/space_spring/domain/user/service/UserService.java index e743db8e..76ee0d76 100644 --- a/src/main/java/space/space_spring/domain/user/service/UserService.java +++ b/src/main/java/space/space_spring/domain/user/service/UserService.java @@ -14,7 +14,7 @@ import space.space_spring.entity.enumStatus.UserSignupType; import space.space_spring.exception.CustomException; import space.space_spring.domain.user.repository.UserDao; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.util.user.UserUtils; import java.util.ArrayList; diff --git a/src/main/java/space/space_spring/dto/comment/request/CreateCommentRequest.java b/src/main/java/space/space_spring/dto/comment/request/CreateCommentRequest.java index b45393d2..ad02dde1 100644 --- a/src/main/java/space/space_spring/dto/comment/request/CreateCommentRequest.java +++ b/src/main/java/space/space_spring/dto/comment/request/CreateCommentRequest.java @@ -1,11 +1,10 @@ package space.space_spring.dto.comment.request; -import com.mongodb.lang.Nullable; import jakarta.validation.constraints.NotBlank; import lombok.*; import space.space_spring.entity.Comment; import space.space_spring.entity.Post; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; public class CreateCommentRequest { diff --git a/src/main/java/space/space_spring/dto/post/request/CreatePostRequest.java b/src/main/java/space/space_spring/dto/post/request/CreatePostRequest.java index 3c590555..17b1ae07 100644 --- a/src/main/java/space/space_spring/dto/post/request/CreatePostRequest.java +++ b/src/main/java/space/space_spring/dto/post/request/CreatePostRequest.java @@ -5,7 +5,7 @@ import space.space_spring.entity.Post; import space.space_spring.entity.PostImage; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import java.util.List; diff --git a/src/main/java/space/space_spring/dto/space/GetSpaceHomeDto.java b/src/main/java/space/space_spring/dto/space/GetSpaceHomeDto.java index aac016b0..8d656790 100644 --- a/src/main/java/space/space_spring/dto/space/GetSpaceHomeDto.java +++ b/src/main/java/space/space_spring/dto/space/GetSpaceHomeDto.java @@ -2,9 +2,8 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; -import space.space_spring.dto.pay.dto.PayReceiveInfoDto; -import space.space_spring.dto.pay.dto.PayRequestInfoDto; +import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import java.util.List; public class GetSpaceHomeDto { diff --git a/src/main/java/space/space_spring/entity/Comment.java b/src/main/java/space/space_spring/entity/Comment.java index 52a2f92a..26a9ebda 100644 --- a/src/main/java/space/space_spring/entity/Comment.java +++ b/src/main/java/space/space_spring/entity/Comment.java @@ -4,6 +4,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import space.space_spring.domain.user.model.entity.User; @Entity @Table(name = "Post_Comment") diff --git a/src/main/java/space/space_spring/entity/CommentLike.java b/src/main/java/space/space_spring/entity/CommentLike.java index 6e764d0c..9c558a86 100644 --- a/src/main/java/space/space_spring/entity/CommentLike.java +++ b/src/main/java/space/space_spring/entity/CommentLike.java @@ -4,6 +4,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import space.space_spring.domain.user.model.entity.User; @Entity @Table(name = "Comment_Like") diff --git a/src/main/java/space/space_spring/entity/Post.java b/src/main/java/space/space_spring/entity/Post.java index 6bde05a7..fc23b1c1 100644 --- a/src/main/java/space/space_spring/entity/Post.java +++ b/src/main/java/space/space_spring/entity/Post.java @@ -4,6 +4,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import space.space_spring.domain.user.model.entity.User; import java.util.List; diff --git a/src/main/java/space/space_spring/entity/PostLike.java b/src/main/java/space/space_spring/entity/PostLike.java index 677214e2..188ae585 100644 --- a/src/main/java/space/space_spring/entity/PostLike.java +++ b/src/main/java/space/space_spring/entity/PostLike.java @@ -4,7 +4,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; +import space.space_spring.domain.user.model.entity.User; @Entity @Table(name = "Post_Like") diff --git a/src/main/java/space/space_spring/entity/UserChatRoom.java b/src/main/java/space/space_spring/entity/UserChatRoom.java index d30e363d..14bf2575 100644 --- a/src/main/java/space/space_spring/entity/UserChatRoom.java +++ b/src/main/java/space/space_spring/entity/UserChatRoom.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.Comment; +import space.space_spring.domain.user.model.entity.User; import java.time.LocalDateTime; diff --git a/src/main/java/space/space_spring/entity/UserSpace.java b/src/main/java/space/space_spring/entity/UserSpace.java index 337dc14c..e2e04105 100644 --- a/src/main/java/space/space_spring/entity/UserSpace.java +++ b/src/main/java/space/space_spring/entity/UserSpace.java @@ -3,6 +3,7 @@ import jakarta.annotation.Nullable; import jakarta.persistence.*; import lombok.Getter; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.enumStatus.UserSpaceAuth; @Entity diff --git a/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java b/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java index 8775541a..9fe94cd2 100644 --- a/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java +++ b/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java @@ -12,7 +12,7 @@ import space.space_spring.domain.user.repository.UserDao; import space.space_spring.dao.UserSpaceDao; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.UserSpace; import space.space_spring.exception.CustomException; diff --git a/src/main/java/space/space_spring/service/ChatRoomService.java b/src/main/java/space/space_spring/service/ChatRoomService.java index 4d44a7d2..fc4a8271 100644 --- a/src/main/java/space/space_spring/service/ChatRoomService.java +++ b/src/main/java/space/space_spring/service/ChatRoomService.java @@ -8,6 +8,7 @@ import space.space_spring.dao.chat.ChatRoomRepository; import space.space_spring.dao.chat.ChattingRepository; import space.space_spring.dao.chat.UserChatRoomRepository; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.dto.chat.dto.LastMessageInfoDto; import space.space_spring.dto.chat.request.JoinChatRoomRequest; import space.space_spring.dto.chat.response.*; diff --git a/src/main/java/space/space_spring/service/CommentService.java b/src/main/java/space/space_spring/service/CommentService.java index 9c249730..b1701a2f 100644 --- a/src/main/java/space/space_spring/service/CommentService.java +++ b/src/main/java/space/space_spring/service/CommentService.java @@ -11,7 +11,7 @@ import space.space_spring.dto.comment.response.ReadCommentsResponse; import space.space_spring.entity.Post; import space.space_spring.entity.Comment; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.UserSpace; import space.space_spring.exception.CustomException; import space.space_spring.util.user.UserUtils; diff --git a/src/main/java/space/space_spring/service/LikeService.java b/src/main/java/space/space_spring/service/LikeService.java index e268b933..e173e7e4 100644 --- a/src/main/java/space/space_spring/service/LikeService.java +++ b/src/main/java/space/space_spring/service/LikeService.java @@ -8,6 +8,7 @@ import space.space_spring.dao.CommentLikeDao; import space.space_spring.dao.PostLikeDao; import space.space_spring.dao.PostDao; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.*; import space.space_spring.exception.CustomException; import space.space_spring.util.user.UserUtils; diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java index 04cf90af..47953599 100644 --- a/src/main/java/space/space_spring/service/PostService.java +++ b/src/main/java/space/space_spring/service/PostService.java @@ -8,6 +8,7 @@ import space.space_spring.dao.CommentDao; import space.space_spring.dao.PostDao; import space.space_spring.dao.UserSpaceDao; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.dto.comment.response.ReadCommentsResponse; import space.space_spring.dto.post.request.CreatePostRequest; import space.space_spring.dto.post.response.ReadPostDetailResponse; diff --git a/src/main/java/space/space_spring/service/SpaceService.java b/src/main/java/space/space_spring/service/SpaceService.java index c92f02a8..48138291 100644 --- a/src/main/java/space/space_spring/service/SpaceService.java +++ b/src/main/java/space/space_spring/service/SpaceService.java @@ -13,7 +13,7 @@ import space.space_spring.dto.userSpace.GetUserProfileInSpaceDto; import space.space_spring.dto.userSpace.PutUserProfileInSpaceDto; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSpaceAuth; import space.space_spring.exception.CustomException; diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index 738b24cc..133fe6a6 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -11,7 +11,7 @@ import space.space_spring.dao.VoiceRoomRepository; import space.space_spring.dto.VoiceRoom.*; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.VoiceRoom; import space.space_spring.util.LiveKitUtils; import space.space_spring.util.space.SpaceUtils; @@ -19,9 +19,6 @@ import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Optional; - import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; diff --git a/src/main/java/space/space_spring/util/pay/PayUtils.java b/src/main/java/space/space_spring/util/pay/PayUtils.java index 7b95d84f..9e59a80e 100644 --- a/src/main/java/space/space_spring/util/pay/PayUtils.java +++ b/src/main/java/space/space_spring/util/pay/PayUtils.java @@ -3,9 +3,9 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import space.space_spring.dao.PayDao; -import space.space_spring.entity.PayRequest; -import space.space_spring.entity.PayRequestTarget; +import space.space_spring.domain.pay.repository.PayDao; +import space.space_spring.domain.pay.model.entity.PayRequest; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; import space.space_spring.exception.CustomException; import static space.space_spring.response.status.BaseExceptionResponseStatus.PAY_REQUEST_NOT_FOUND; diff --git a/src/main/java/space/space_spring/util/user/UserUtils.java b/src/main/java/space/space_spring/util/user/UserUtils.java index 7414eabd..19aac85c 100644 --- a/src/main/java/space/space_spring/util/user/UserUtils.java +++ b/src/main/java/space/space_spring/util/user/UserUtils.java @@ -4,7 +4,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import space.space_spring.domain.user.repository.UserDao; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.enumStatus.UserSignupType; import space.space_spring.exception.CustomException; diff --git a/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java b/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java index 80b06393..1ec0b953 100644 --- a/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java +++ b/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java @@ -7,7 +7,7 @@ import space.space_spring.domain.user.repository.UserDao; import space.space_spring.dao.UserSpaceDao; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSpaceAuth; import space.space_spring.exception.CustomException; diff --git a/src/main/java/space/space_spring/util/userSpace/UserSpaceUtils.java b/src/main/java/space/space_spring/util/userSpace/UserSpaceUtils.java index 27864592..28dfef47 100644 --- a/src/main/java/space/space_spring/util/userSpace/UserSpaceUtils.java +++ b/src/main/java/space/space_spring/util/userSpace/UserSpaceUtils.java @@ -1,6 +1,5 @@ package space.space_spring.util.userSpace; -import space.space_spring.entity.User; import space.space_spring.entity.UserSpace; import java.util.Optional; diff --git a/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java b/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java index b7c88409..2be67d81 100644 --- a/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java +++ b/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java @@ -6,12 +6,14 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito.*; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.test.util.ReflectionTestUtils; import space.space_spring.dao.UserSpaceDao; import space.space_spring.dao.VoiceRoomDao; import space.space_spring.dao.VoiceRoomRepository; +import space.space_spring.domain.pay.model.entity.PayRequest; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.dto.VoiceRoom.PostVoiceRoomDto; import space.space_spring.entity.*; import space.space_spring.entity.enumStatus.UserSignupType; @@ -21,8 +23,6 @@ import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) diff --git a/src/test/java/space/space_spring/domain/authorization/jwt/service/JwtServiceTest.java b/src/test/java/space/space_spring/domain/authorization/jwt/service/JwtServiceTest.java index 8c1fe0fb..8d9abe31 100644 --- a/src/test/java/space/space_spring/domain/authorization/jwt/service/JwtServiceTest.java +++ b/src/test/java/space/space_spring/domain/authorization/jwt/service/JwtServiceTest.java @@ -18,8 +18,8 @@ import space.space_spring.domain.authorization.jwt.model.JwtLoginTokenResolver; import space.space_spring.domain.authorization.jwt.repository.JwtRepository; import space.space_spring.domain.user.repository.UserRepository; -import space.space_spring.entity.RefreshTokenStorage; -import space.space_spring.entity.User; +import space.space_spring.domain.authorization.jwt.model.entity.RefreshTokenStorage; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.enumStatus.UserSignupType; import space.space_spring.exception.jwt.unauthorized.JwtExpiredTokenException; import space.space_spring.exception.jwt.unauthorized.JwtUnauthorizedTokenException; diff --git a/src/test/java/space/space_spring/repository/ChatRoomRepositoryTest.java b/src/test/java/space/space_spring/repository/ChatRoomRepositoryTest.java index 3c0d120b..4f8fdceb 100644 --- a/src/test/java/space/space_spring/repository/ChatRoomRepositoryTest.java +++ b/src/test/java/space/space_spring/repository/ChatRoomRepositoryTest.java @@ -9,7 +9,7 @@ import space.space_spring.dao.chat.UserChatRoomRepository; import space.space_spring.entity.ChatRoom; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.UserChatRoom; import space.space_spring.entity.enumStatus.BaseStatusType; import space.space_spring.entity.enumStatus.UserSignupType; diff --git a/src/test/java/space/space_spring/repository/UserChatRoomDaoTest.java b/src/test/java/space/space_spring/repository/UserChatRoomDaoTest.java index c3e6ef50..686c391d 100644 --- a/src/test/java/space/space_spring/repository/UserChatRoomDaoTest.java +++ b/src/test/java/space/space_spring/repository/UserChatRoomDaoTest.java @@ -9,7 +9,7 @@ //import space.space_spring.dao.chat.UserChatRoomDao; //import space.space_spring.entity.ChatRoom; //import space.space_spring.entity.Space; -//import space.space_spring.entity.User; +//import space.space_spring.domain.user.model.entity.User; //import space.space_spring.entity.UserChatRoom; //import space.space_spring.entity.enumStatus.UserSignupType; // diff --git a/src/test/java/space/space_spring/service/PayServiceTest.java b/src/test/java/space/space_spring/service/PayServiceTest.java index f2c191bd..dd461dfb 100644 --- a/src/test/java/space/space_spring/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/service/PayServiceTest.java @@ -7,14 +7,15 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import space.space_spring.dao.PayDao; -import space.space_spring.dto.pay.dto.PayReceiveInfoDto; -import space.space_spring.dto.pay.dto.PayRequestInfoDto; -import space.space_spring.dto.pay.request.PostPayCreateRequest; -import space.space_spring.entity.PayRequest; -import space.space_spring.entity.PayRequestTarget; +import space.space_spring.domain.pay.repository.PayDao; +import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; +import space.space_spring.domain.pay.model.request.PostPayCreateRequest; +import space.space_spring.domain.pay.model.entity.PayRequest; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.pay.service.PayService; import space.space_spring.entity.Space; -import space.space_spring.entity.User; +import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.enumStatus.UserSignupType; import space.space_spring.util.space.SpaceUtils; import space.space_spring.util.user.UserUtils; From 612c464cae4e89dac7e82f3640a62365ab8eac61 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Wed, 6 Nov 2024 23:07:12 +0900 Subject: [PATCH 02/20] =?UTF-8?q?refactor=20:=20=EC=A0=95=EC=82=B0=20?= =?UTF-8?q?=ED=99=88=20view=20api=20=EC=84=9C=EB=B9=84=EC=8A=A4=EB=8B=A8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8E=99=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=EB=B0=8F=20repository=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/dao/SpaceRepository.java | 15 ++++ .../space_spring/dao/UserSpaceRepository.java | 1 + .../authorization/jwt/service/JwtService.java | 2 +- .../domain/pay/controller/PayController.java | 29 ++++--- .../domain/pay/model/entity/PayRequest.java | 28 ++++++ .../pay/model/entity/PayRequestTarget.java | 12 +++ ...Response.java => PayHomeViewResponse.java} | 2 +- .../pay/repository/PayRequestRepository.java | 24 ++++++ .../PayRequestTargetRepository.java | 20 +++++ .../domain/pay/service/PayService.java | 86 ++++++++++--------- .../user/repository/UserRepository.java | 3 +- 11 files changed, 167 insertions(+), 55 deletions(-) create mode 100644 src/main/java/space/space_spring/dao/SpaceRepository.java rename src/main/java/space/space_spring/domain/pay/model/response/{GetPayViewResponse.java => PayHomeViewResponse.java} (93%) create mode 100644 src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java create mode 100644 src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java diff --git a/src/main/java/space/space_spring/dao/SpaceRepository.java b/src/main/java/space/space_spring/dao/SpaceRepository.java new file mode 100644 index 00000000..3eee1c63 --- /dev/null +++ b/src/main/java/space/space_spring/dao/SpaceRepository.java @@ -0,0 +1,15 @@ +package space.space_spring.dao; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; +import space.space_spring.entity.Space; + +import java.util.Optional; + +@Repository +public interface SpaceRepository extends JpaRepository { + + @Query("SELECT s FROM Space s WHERE s.spaceId = :id AND s.status = 'ACTIVE'") + Optional findById(Long id); +} diff --git a/src/main/java/space/space_spring/dao/UserSpaceRepository.java b/src/main/java/space/space_spring/dao/UserSpaceRepository.java index 6e3383c9..e6e64b68 100644 --- a/src/main/java/space/space_spring/dao/UserSpaceRepository.java +++ b/src/main/java/space/space_spring/dao/UserSpaceRepository.java @@ -10,6 +10,7 @@ import java.util.Optional; public interface UserSpaceRepository extends JpaRepository { + @Query("SELECT r FROM UserSpace r WHERE r.user.userId = :userId AND r.space.spaceId = :spaceId AND r.status = 'ACTIVE'") Optional findUserSpaceByUserAndSpace(@Param("userId") Long userId, @Param("spaceId") Long spaceId); diff --git a/src/main/java/space/space_spring/domain/authorization/jwt/service/JwtService.java b/src/main/java/space/space_spring/domain/authorization/jwt/service/JwtService.java index dace10b6..b9c170a2 100644 --- a/src/main/java/space/space_spring/domain/authorization/jwt/service/JwtService.java +++ b/src/main/java/space/space_spring/domain/authorization/jwt/service/JwtService.java @@ -44,7 +44,7 @@ public TokenPairDTO updateTokenPair(HttpServletRequest request) { private User getUserByAccessToken(String accessToken) { Long userIdFromToken = jwtLoginProvider.getUserIdFromAccessToken(accessToken); - return userRepository.findByUserId(userIdFromToken) + return userRepository.findById(userIdFromToken) .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); } diff --git a/src/main/java/space/space_spring/domain/pay/controller/PayController.java b/src/main/java/space/space_spring/domain/pay/controller/PayController.java index 13308c0c..f86647c3 100644 --- a/src/main/java/space/space_spring/domain/pay/controller/PayController.java +++ b/src/main/java/space/space_spring/domain/pay/controller/PayController.java @@ -41,19 +41,22 @@ public class PayController { * 정산 홈 view */ @GetMapping("/space/{spaceId}/pay") - public BaseResponse showPayListForUser(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { - // TODO 1. 유저가 스페이스에 속하는 지 검증 - validateIsUserInSpace(userId, spaceId); - - // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get - // 현재 진행중인 정산 -> isComplete = false - List payRequestInfoDtoList = payService.getPayRequestInfoForUser(userId, spaceId, false); - - // TODO 3. 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 get - // 현재 진행중인 정산 -> isComplete = false - List payReceiveInfoDtoList = payService.getPayReceiveInfoForUser(userId, spaceId, false); - - return new BaseResponse<>(new GetPayViewResponse(payRequestInfoDtoList, payReceiveInfoDtoList)); + public BaseResponse showPayHome(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { + + return new BaseResponse<>(payService.getPayHomeInfos(userId, spaceId)); + +// // TODO 1. 유저가 스페이스에 속하는 지 검증 +// validateIsUserInSpace(userId, spaceId); +// +// // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get +// // 현재 진행중인 정산 -> isComplete = false +// List payRequestInfoDtoList = payService.getPayRequestInfoForUser(userId, spaceId, false); +// +// // TODO 3. 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 get +// // 현재 진행중인 정산 -> isComplete = false +// List payReceiveInfoDtoList = payService.getPayReceiveInfoForUser(userId, spaceId, false); +// +// return new BaseResponse<>(new PayHomeViewResponse(payRequestInfoDtoList, payReceiveInfoDtoList)); } private void validateIsUserInSpace(Long userId, Long spaceId) { diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index 4ffb7465..a765b280 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -2,10 +2,14 @@ import jakarta.persistence.*; import lombok.Getter; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.BaseEntity; import space.space_spring.entity.Space; +import java.util.ArrayList; +import java.util.List; + @Getter @Entity @Table(name = "Pay_Request") @@ -39,6 +43,9 @@ public class PayRequest extends BaseEntity { @Column(name = "is_complete") private boolean isComplete; + @OneToMany(mappedBy = "payRequest") + private List payRequestTargets = new ArrayList<>(); + public void savePayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum, int unRequestedAmount, boolean isComplete) { this.payCreateUser = payCreateUser; this.space = space; @@ -52,4 +59,25 @@ public void savePayRequest(User payCreateUser, Space space, int totalAmount, Str public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } + + public PayRequestInfoDto createPayRequestInfo() { + int totalAmount = this.totalAmount; + int receiveAmount = 0; + int totalTargetNum = 0; + int receiveTargetNum = 0; + + for (PayRequestTarget payRequestTarget : this.payRequestTargets) { + if (payRequestTarget.isComplete()) { + // 해당 타겟이 돈을 낸 경우 + receiveAmount += payRequestTarget.getRequestAmount(); + receiveTargetNum++; + } + + totalTargetNum++; + } + + return new PayRequestInfoDto( + this.payRequestId, totalAmount, receiveAmount, totalTargetNum, receiveTargetNum + ); + } } diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index afebddb7..1d583e97 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -2,6 +2,7 @@ import jakarta.persistence.*; import lombok.Getter; +import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; import space.space_spring.entity.BaseEntity; @Entity @@ -36,4 +37,15 @@ public void savePayRequestTarget(PayRequest payRequest, Long targetUserId, int r public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } + + public PayReceiveInfoDto createPayReceiveInfo() { + String payCreatorName = payRequest.getPayCreateUser().getUserName(); // 리펙토링 필요 + int requestAmount = this.requestAmount; + + // 정산 생성자가 요청한 은행 정보도 response에 추가 + String bankName = payRequest.getBankName(); + String bankAccountNum = payRequest.getBankAccountNum(); + + return new PayReceiveInfoDto(this.payRequestTargetId, payCreatorName, requestAmount, bankName, bankAccountNum); + } } diff --git a/src/main/java/space/space_spring/domain/pay/model/response/GetPayViewResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java similarity index 93% rename from src/main/java/space/space_spring/domain/pay/model/response/GetPayViewResponse.java rename to src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java index d8f488ee..75095db4 100644 --- a/src/main/java/space/space_spring/domain/pay/model/response/GetPayViewResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java @@ -10,7 +10,7 @@ @Getter @AllArgsConstructor -public class GetPayViewResponse { +public class PayHomeViewResponse { private List payRequestInfoDtoList = new ArrayList<>(); diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java b/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java new file mode 100644 index 00000000..8b93fec7 --- /dev/null +++ b/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java @@ -0,0 +1,24 @@ +package space.space_spring.domain.pay.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; +import space.space_spring.domain.pay.model.entity.PayRequest; +import space.space_spring.domain.user.model.entity.User; +import space.space_spring.entity.Space; + +import java.util.List; +import java.util.Optional; + +@Repository +//@RequiredArgsConstructor +public interface PayRequestRepository extends JpaRepository { + +// private final JPAQueryFactory jpaQueryFactory; + + @Query("select pr from PayRequest pr where pr.payCreateUser = :user and pr.space = :space and pr.isComplete = :isComplete and pr.status = 'ACTIVE'") + List> findByUserAndSpace(User user, Space space, boolean isComplete); + +} diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java b/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java new file mode 100644 index 00000000..6bb3f214 --- /dev/null +++ b/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java @@ -0,0 +1,20 @@ +package space.space_spring.domain.pay.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.user.model.entity.User; +import space.space_spring.entity.Space; + +import java.util.List; +import java.util.Optional; + +@Repository +public interface PayRequestTargetRepository extends JpaRepository { + + @Query("select prt from PayRequestTarget prt where prt.targetUserId = :userId and prt.payRequest.space = :space and prt.payRequest.isComplete = :isComplete and prt.status = 'ACTIVE'") + List> findByUserAndSpace(Long userId, Space space, boolean isComplete); + + +} diff --git a/src/main/java/space/space_spring/domain/pay/service/PayService.java b/src/main/java/space/space_spring/domain/pay/service/PayService.java index d476bfa9..784693c7 100644 --- a/src/main/java/space/space_spring/domain/pay/service/PayService.java +++ b/src/main/java/space/space_spring/domain/pay/service/PayService.java @@ -3,10 +3,14 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import space.space_spring.dao.UserSpaceRepository; import space.space_spring.domain.pay.model.entity.PayRequest; import space.space_spring.domain.pay.model.dto.*; import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.pay.model.response.PayHomeViewResponse; import space.space_spring.domain.pay.repository.PayDao; +import space.space_spring.domain.pay.repository.PayRequestRepository; +import space.space_spring.domain.pay.repository.PayRequestTargetRepository; import space.space_spring.domain.user.model.entity.User; import space.space_spring.domain.user.repository.UserDao; import space.space_spring.dao.UserSpaceDao; @@ -21,11 +25,13 @@ import java.time.ZoneId; import java.util.ArrayList; import java.util.List; +import java.util.Optional; -import static space.space_spring.response.status.BaseExceptionResponseStatus.USER_IS_NOT_IN_SPACE; +import static space.space_spring.response.status.BaseExceptionResponseStatus.*; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class PayService { private final PayDao payDao; @@ -34,6 +40,43 @@ public class PayService { private final UserDao userDao; private final UserSpaceDao userSpaceDao; + private final UserSpaceRepository userSpaceRepository; + private final PayRequestRepository payRequestRepository; + private final PayRequestTargetRepository payRequestTargetRepository; + + private final boolean INCOMPLETE_PAY = false; + private final boolean COMPLETE_PAY = true; + + public PayHomeViewResponse getPayHomeInfos(Long userId, Long spaceId) { + // 유저가 스페이스에 속하는 지 검증하고, + UserSpace userSpace = validateUserInSpace(userId, spaceId); + + // 유저가 요청한 정산 중 현재 진행중인 정산 리스트 정보와 + List> payRequests = payRequestRepository.findByUserAndSpace(userSpace.getUser(), userSpace.getSpace(), INCOMPLETE_PAY); + + List payRequestInfoDtos = new ArrayList<>(); + for (Optional payRequest : payRequests) { + payRequest.ifPresent(request -> payRequestInfoDtos.add(request.createPayRequestInfo())); + } + + // 유저가 요청받은 정산 중 현재 진행중인 정산 리스트를 찾아서 + List> payRequestTargets = payRequestTargetRepository.findByUserAndSpace(userSpace.getUser().getUserId(), userSpace.getSpace(), INCOMPLETE_PAY); + + List payReceiveInfoDtos = new ArrayList<>(); + for (Optional payRequestTarget : payRequestTargets) { + payRequestTarget.ifPresent(requestTarget -> payReceiveInfoDtos.add(requestTarget.createPayReceiveInfo())); + } + + // return + return new PayHomeViewResponse(payRequestInfoDtos, payReceiveInfoDtos); + } + + private UserSpace validateUserInSpace(Long userId, Long spaceId) { + return userSpaceRepository.findUserSpaceByUserAndSpace(userId, spaceId).orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE)); + } + + + @Transactional public List getPayRequestInfoForUser(Long userId, Long spaceId, boolean isComplete) { // TODO 1. userId에 해당하는 user find @@ -52,37 +95,13 @@ public List getPayRequestInfoForUser(Long userId, Long spaceI List payRequestInfoDtoList = new ArrayList<>(); for (PayRequest payRequest : payRequestListByUser) { - PayRequestInfoDto payRequestInfoDto = createPayRequestInfoDto(payRequest); + PayRequestInfoDto payRequestInfoDto = payRequest.createPayRequestInfo(); payRequestInfoDtoList.add(payRequestInfoDto); } return payRequestInfoDtoList; } - private PayRequestInfoDto createPayRequestInfoDto(PayRequest payRequest) { - Long payRequestId = payRequest.getPayRequestId(); - int totalAmount = payRequest.getTotalAmount(); - int receiveAmount = 0; - int totalTargetNum = 0; - int receiveTargetNum = 0; - - List payRequestTargetList = payDao.findPayRequestTargetListByPayRequest(payRequest); - - for (PayRequestTarget payRequestTarget : payRequestTargetList) { - if (payRequestTarget.isComplete()) { - // 해당 타겟이 돈을 낸 경우 - receiveAmount += payRequestTarget.getRequestAmount(); - receiveTargetNum++; - } - - totalTargetNum++; - } - - return new PayRequestInfoDto( - payRequestId, totalAmount, receiveAmount, totalTargetNum, receiveTargetNum - ); - } - @Transactional public List getPayReceiveInfoForUser(Long userId, Long spaceId, boolean isComplete) { // TODO 1. userId에 해당하는 유저 find @@ -99,24 +118,13 @@ public List getPayReceiveInfoForUser(Long userId, Long spaceI List payReceiveInfoDtoList = new ArrayList<>(); for (PayRequestTarget payRequestTarget : payRequestTargetListByUser) { - PayReceiveInfoDto payReceiveInfoDto = createPayReceiveInfoDto(payRequestTarget); + PayReceiveInfoDto payReceiveInfoDto = payRequestTarget.createPayReceiveInfo(); payReceiveInfoDtoList.add(payReceiveInfoDto); } return payReceiveInfoDtoList; } - private PayReceiveInfoDto createPayReceiveInfoDto(PayRequestTarget payRequestTarget) { - String payCreatorName = payRequestTarget.getPayRequest().getPayCreateUser().getUserName(); // 리펙토링 필요 - int requestAmount = payRequestTarget.getRequestAmount(); - - // 정산 생성자가 요청한 은행 정보도 response에 추가 - String bankName = payRequestTarget.getPayRequest().getBankName(); - String bankAccountNum = payRequestTarget.getPayRequest().getBankAccountNum(); - - return new PayReceiveInfoDto(payRequestTarget.getPayRequestTargetId(), payCreatorName, requestAmount, bankName, bankAccountNum); - } - @Transactional public GetRecentPayRequestBankInfoResponse getRecentPayRequestBankInfoForUser(Long userId) { // TODO 1. userId에 해당하는 유저 find @@ -162,7 +170,7 @@ public TotalPayInfoDto getTotalPayInfo(Long spaceId, Long payRequestId) { PayRequest payRequestById = payDao.findPayRequestById(payRequestId); // TODO 3. PayRequest로 해당 정산의 정보 get - PayRequestInfoDto payRequestInfoDto = createPayRequestInfoDto(payRequestById); + PayRequestInfoDto payRequestInfoDto = payRequestById.createPayRequestInfo(); // TODO 4. PayRequest의 PayRequestTarget find List payRequestTargetListByPayRequest = payDao.findPayRequestTargetListByPayRequest(payRequestById); diff --git a/src/main/java/space/space_spring/domain/user/repository/UserRepository.java b/src/main/java/space/space_spring/domain/user/repository/UserRepository.java index 58d35588..88269133 100644 --- a/src/main/java/space/space_spring/domain/user/repository/UserRepository.java +++ b/src/main/java/space/space_spring/domain/user/repository/UserRepository.java @@ -1,5 +1,6 @@ package space.space_spring.domain.user.repository; +import org.jetbrains.annotations.NotNull; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @@ -11,5 +12,5 @@ public interface UserRepository extends JpaRepository { @Query("SELECT u FROM User u WHERE u.userId = :userId AND u.status = 'ACTIVE'") - Optional findByUserId(Long userId); + Optional findById(Long userId); } From e72a5f472ddc3ed86aef522d7cc5a6c0caed3699 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Fri, 8 Nov 2024 01:23:55 +0900 Subject: [PATCH 03/20] =?UTF-8?q?refactor=20:=20PayRequest=20entity=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/model/entity/PayRequest.java | 27 +++ .../pay/model/entity/PayRequestTarget.java | 2 + .../domain/pay/repository/PayDao.java | 5 +- .../VoiceRoom/VoiceRoomServiceTest.java | 12 +- .../domain/pay/service/PayServiceTest.java | 56 +++++ .../space_spring/service/PayServiceTest.java | 226 ------------------ 6 files changed, 96 insertions(+), 232 deletions(-) create mode 100644 src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java delete mode 100644 src/test/java/space/space_spring/service/PayServiceTest.java diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index a765b280..bd60c23c 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -1,7 +1,10 @@ package space.space_spring.domain.pay.model.entity; import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.BaseEntity; @@ -13,6 +16,7 @@ @Getter @Entity @Table(name = "Pay_Request") +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class PayRequest extends BaseEntity { @Id @@ -60,6 +64,29 @@ public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } + @Builder + private PayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum, int unRequestedAmount, boolean isComplete) { + this.payCreateUser = payCreateUser; + this.space = space; + this.totalAmount = totalAmount; + this.bankName = bankName; + this.bankAccountNum = bankAccountNum; + this.unRequestedAmount = unRequestedAmount; + this.isComplete = isComplete; + } + + public static PayRequest create(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum, int unRequestedAmount, boolean isComplete) { + return PayRequest.builder() + .payCreateUser(payCreateUser) + .space(space) + .totalAmount(totalAmount) + .bankName(bankName) + .bankAccountNum(bankAccountNum) + .unRequestedAmount(unRequestedAmount) + .isComplete(isComplete) + .build(); + } + public PayRequestInfoDto createPayRequestInfo() { int totalAmount = this.totalAmount; int receiveAmount = 0; diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index 1d583e97..8a1cd311 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -7,6 +7,7 @@ @Entity @Getter +@Table(name = "Pay_Request_Target") public class PayRequestTarget extends BaseEntity { @Id @@ -20,6 +21,7 @@ public class PayRequestTarget extends BaseEntity { @Column(name = "target_user_id") private Long targetUserId; // User 객체를 필드로 가지는 것보다 이게 더 낫나?? + // -> @OneToOne 어노테이션으로 User 엔티티 가지고 있는 방향 생각해볼것 @Column(name = "request_amount") private int requestAmount; diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayDao.java b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java index 30480ff2..a5696ab4 100644 --- a/src/main/java/space/space_spring/domain/pay/repository/PayDao.java +++ b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java @@ -73,8 +73,9 @@ public List findRecentPayRequestBankInfoByUser(User } public PayRequest createPayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum, int unRequestedAmount, boolean isComplete) { - PayRequest payRequest = new PayRequest(); - payRequest.savePayRequest(payCreateUser, space, totalAmount, bankName, bankAccountNum, unRequestedAmount, isComplete); +// PayRequest payRequest = new PayRequest(); +// payRequest.savePayRequest(payCreateUser, space, totalAmount, bankName, bankAccountNum, unRequestedAmount, isComplete); + PayRequest payRequest = PayRequest.create(payCreateUser, space, totalAmount, bankName, bankAccountNum, unRequestedAmount, isComplete); em.persist(payRequest); return payRequest; diff --git a/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java b/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java index 2be67d81..572b96eb 100644 --- a/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java +++ b/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java @@ -85,8 +85,10 @@ public class VoiceRoomServiceTest { testSpace = new Space(); testSpace.saveSpace("testSpace", "test_profile_img_url"); - testPayRequest_user1 = new PayRequest(); - testPayRequest_user1.savePayRequest(user1, testSpace, 30000, "우리은행", "111-111-111", 0, false); +// testPayRequest_user1 = new PayRequest(); +// testPayRequest_user1.savePayRequest(user1, testSpace, 30000, "우리은행", "111-111-111", 0, false); + + testPayRequest_user1 = PayRequest.create(user1, testSpace, 30000, "우리은행", "111-111-111", 0, false); testPayRequestTarget_user2 = new PayRequestTarget(); testPayRequestTarget_user2.savePayRequestTarget(testPayRequest_user1, user2.getUserId(), 10000, false); @@ -97,8 +99,10 @@ public class VoiceRoomServiceTest { testPayRequestTarget_user4 = new PayRequestTarget(); testPayRequestTarget_user4.savePayRequestTarget(testPayRequest_user1, user4.getUserId(), 10000, true); - testPayRequest_user2 = new PayRequest(); - testPayRequest_user2.savePayRequest(user2, testSpace, 10000, "국민은행", "111-111-111", 0, true); +// testPayRequest_user2 = new PayRequest(); +// testPayRequest_user2.savePayRequest(user2, testSpace, 10000, "국민은행", "111-111-111", 0, true); + + testPayRequest_user2 = PayRequest.create(user2, testSpace, 10000, "우리은행", "111-111-111", 0, true); testPayRequestTarget_user1 = new PayRequestTarget(); testPayRequestTarget_user1.savePayRequestTarget(testPayRequest_user2, user1.getUserId(), 10000, true); diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java new file mode 100644 index 00000000..4425db91 --- /dev/null +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -0,0 +1,56 @@ +package space.space_spring.domain.pay.service; + +import ch.qos.logback.core.testUtil.XTeeOutputStream; +import jakarta.persistence.Entity; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.test.context.ActiveProfiles; +import space.space_spring.domain.pay.model.entity.PayRequest; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.pay.repository.PayRequestRepository; +import space.space_spring.domain.pay.repository.PayRequestTargetRepository; +import space.space_spring.domain.user.model.entity.User; +import space.space_spring.domain.user.repository.UserRepository; +import space.space_spring.entity.enumStatus.UserSignupType; + +import static org.junit.jupiter.api.Assertions.*; + +@DataJpaTest +@Import({PayService.class}) +@ActiveProfiles("test") +@EnableJpaRepositories(basePackageClasses = {PayRequestRepository.class, PayRequestTargetRepository.class, UserRepository.class}) +@EntityScan(basePackageClasses = {PayRequest.class, PayRequestTarget.class, User.class}) +class PayServiceTest { + + @Autowired + private PayService payService; + + @Autowired + private PayRequestRepository payRequestRepository; + + @Autowired + private PayRequestTargetRepository payRequestTargetRepository; + + @Autowired + private UserRepository userRepository; + + @Test + @DisplayName("유저가 요청한 정산 중, 현재 진행 중인 정산 정보들과 유저가 요청받은 정산 중, 현재 진행 중인 정산 정보들을 return 한다.") + void getPayHomeInfos() throws Exception { + //given + User user = User.create("email", "password", "name", UserSignupType.LOCAL); + User savedUser = userRepository.save(user); + + + + //when + + //then + } + +} \ No newline at end of file diff --git a/src/test/java/space/space_spring/service/PayServiceTest.java b/src/test/java/space/space_spring/service/PayServiceTest.java deleted file mode 100644 index dd461dfb..00000000 --- a/src/test/java/space/space_spring/service/PayServiceTest.java +++ /dev/null @@ -1,226 +0,0 @@ -package space.space_spring.service; - -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 space.space_spring.domain.pay.repository.PayDao; -import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; -import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; -import space.space_spring.domain.pay.model.request.PostPayCreateRequest; -import space.space_spring.domain.pay.model.entity.PayRequest; -import space.space_spring.domain.pay.model.entity.PayRequestTarget; -import space.space_spring.domain.pay.service.PayService; -import space.space_spring.entity.Space; -import space.space_spring.domain.user.model.entity.User; -import space.space_spring.entity.enumStatus.UserSignupType; -import space.space_spring.util.space.SpaceUtils; -import space.space_spring.util.user.UserUtils; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class PayServiceTest { - - @InjectMocks - private PayService payService; - - @Mock - private PayDao payDao; - - @Mock - private UserUtils userUtils; - - @Mock - private SpaceUtils spaceUtils; - - private User user1; - private User user2; - private User user3; - private User user4; - private User user5; - private User user6; - private User user7; - private Space testSpace; - private PayRequest testPayRequest_user1; - private PayRequest testPayRequest_user2; - private PayRequestTarget testPayRequestTarget_user1; - private PayRequestTarget testPayRequestTarget_user2; - private PayRequestTarget testPayRequestTarget_user3; - private PayRequestTarget testPayRequestTarget_user4; - - @BeforeEach - public void 테스트_셋업() { - /** - * : user2, 3은 정산 완료 X & user4는 정산 완료 - * : user1은 정산 완료 - */ - user1 = new User(); - user1.saveUser("test1@test.com", "abcDEF123!@", "user1", UserSignupType.LOCAL); - - user2 = new User(); - user2.saveUser("test2@test.com", "abcDEF123!@", "user2", UserSignupType.LOCAL); - - user3 = new User(); - user3.saveUser("test3@test.com", "abcDEF123!@", "user3", UserSignupType.LOCAL); - - user4 = new User(); - user4.saveUser("test4@test.com", "abcDEF123!@", "user4", UserSignupType.LOCAL); - - testSpace = new Space(); - testSpace.saveSpace("testSpace", "test_profile_img_url"); - - testPayRequest_user1 = new PayRequest(); - testPayRequest_user1.savePayRequest(user1, testSpace, 30000, "우리은행", "111-111-111", 0, false); - - testPayRequestTarget_user2 = new PayRequestTarget(); - testPayRequestTarget_user2.savePayRequestTarget(testPayRequest_user1, user2.getUserId(), 10000, false); - - testPayRequestTarget_user3 = new PayRequestTarget(); - testPayRequestTarget_user3.savePayRequestTarget(testPayRequest_user1, user3.getUserId(), 10000, false); - - testPayRequestTarget_user4 = new PayRequestTarget(); - testPayRequestTarget_user4.savePayRequestTarget(testPayRequest_user1, user4.getUserId(), 10000, true); - - testPayRequest_user2 = new PayRequest(); - testPayRequest_user2.savePayRequest(user2, testSpace, 10000, "국민은행", "111-111-111", 0, true); - - testPayRequestTarget_user1 = new PayRequestTarget(); - testPayRequestTarget_user1.savePayRequestTarget(testPayRequest_user2, user1.getUserId(), 10000, true); - - /** - * 추가로 user5,6,7 생성 - */ - user5 = new User(); - user6 = new User(); - user7 = new User(); - user5.saveUser("test5@test.com", "abcDEF123!@", "user5", UserSignupType.LOCAL); - user6.saveUser("test6@test.com", "abcDEF123!@", "user6", UserSignupType.LOCAL); - user7.saveUser("test7@test.com", "abcDEF123!@", "user7", UserSignupType.LOCAL); - - } - - @Test - @DisplayName("유저가_요청한_정산중_현재진행중인_정산리스트_찾기") - void 유저가_요청한_정산중_현재진행중인_정산리스트_찾기() throws Exception { - //given - // user1이 user2, 3, 4 에게 요청한 정산 - when(userUtils.findUserByUserId(user1.getUserId())).thenReturn(user1); - when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); - when(payDao.findPayRequestListByUser(user1, testSpace, false)).thenReturn(List.of(testPayRequest_user1)); - when(payDao.findPayRequestTargetListByPayRequest(testPayRequest_user1)).thenReturn(List.of(testPayRequestTarget_user2, testPayRequestTarget_user3, testPayRequestTarget_user4)); - - //when - List payRequestInfoForUser = payService.getPayRequestInfoForUser(user1.getUserId(), testSpace.getSpaceId(), false); - - //then - assertThat(payRequestInfoForUser.size()).isEqualTo(1); - - for (PayRequestInfoDto payRequestInfoDto : payRequestInfoForUser) { - assertThat(payRequestInfoDto.getTotalAmount()).isEqualTo(30000); - assertThat(payRequestInfoDto.getReceiveAmount()).isEqualTo(10000); - assertThat(payRequestInfoDto.getTotalTargetNum()).isEqualTo(3); - assertThat(payRequestInfoDto.getReceiveTargetNum()).isEqualTo(1); - } - } - - @Test - @DisplayName("유저가_요청받은_정산중_현재진행중인_정산리스트_찾기") - void 유저가_요청받은_정산중_현재진행중인_정산리스트_찾기() throws Exception { - //given - // user2가 user1에게 요청받은 정산 - when(userUtils.findUserByUserId(user2.getUserId())).thenReturn(user2); - when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); - when(payDao.findPayRequestTargetListByUser(user2, testSpace, false)).thenReturn(List.of(testPayRequestTarget_user2)); - - //when - List payReceiveInfoForUser = payService.getPayReceiveInfoForUser(user2.getUserId(), testSpace.getSpaceId(), false); - - //then - assertThat(payReceiveInfoForUser.size()).isEqualTo(1); - for (PayReceiveInfoDto payReceiveInfoDto : payReceiveInfoForUser) { - assertThat(payReceiveInfoDto.getPayCreatorName()).isEqualTo(user1.getUserName()); - assertThat(payReceiveInfoDto.getRequestAmount()).isEqualTo(10000); - } - } - - @Test - @DisplayName("유저가_요청한_정산중_완료된_정산리스트_찾기") - void 유저가_요청한_정산중_완료된_정산리스트_찾기() throws Exception { - //given - // user2가 user1에게 요청한 정산 - when(userUtils.findUserByUserId(user2.getUserId())).thenReturn(user2); - when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); - when(payDao.findPayRequestListByUser(user2, testSpace, true)).thenReturn(List.of(testPayRequest_user2)); - when(payDao.findPayRequestTargetListByPayRequest(testPayRequest_user2)).thenReturn(List.of(testPayRequestTarget_user1)); - - //when - List payRequestInfoForUser = payService.getPayRequestInfoForUser(user2.getUserId(), testSpace.getSpaceId(), true); - - //then - assertThat(payRequestInfoForUser.size()).isEqualTo(1); - - for (PayRequestInfoDto payRequestInfoDto : payRequestInfoForUser) { - assertThat(payRequestInfoDto.getTotalAmount()).isEqualTo(10000); - assertThat(payRequestInfoDto.getReceiveAmount()).isEqualTo(10000); - assertThat(payRequestInfoDto.getTotalTargetNum()).isEqualTo(1); - assertThat(payRequestInfoDto.getReceiveTargetNum()).isEqualTo(1); - } - } - - @Test - @DisplayName("정산_생성_테스트") - void 정산_생성_테스트() throws Exception { - //given - // user5가 user6, 7 에게 정산 생성 - PostPayCreateRequest.TargetInfo testTargetInfo1 = new PostPayCreateRequest.TargetInfo(user6.getUserId(), 10000); - PostPayCreateRequest.TargetInfo testTargetInfo2 = new PostPayCreateRequest.TargetInfo(user7.getUserId(), 10000); - - List testTargetInfoList = new ArrayList<>(); - testTargetInfoList.add(testTargetInfo1); - testTargetInfoList.add(testTargetInfo2); - - PostPayCreateRequest testDto = new PostPayCreateRequest( - 20000, - "우리은행", - "111-111-111", - testTargetInfoList - ); - - PayRequest testPayRequest = new PayRequest(); - testPayRequest.savePayRequest(user5, testSpace, testDto.getTotalAmount(), testDto.getBankName(), testDto.getBankAccountNum(), 0, false); - - PayRequestTarget testPayRequestTarget_1 = new PayRequestTarget(); - testPayRequestTarget_1.savePayRequestTarget(testPayRequest, user6.getUserId(), 10000, false); - PayRequestTarget testPayRequestTarget_2 = new PayRequestTarget(); - testPayRequestTarget_2.savePayRequestTarget(testPayRequest, user7.getUserId(), 10000, false); - - when(userUtils.findUserByUserId(user5.getUserId())).thenReturn(user5); - when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); - when(payDao.createPayRequest(user5, testSpace, testDto.getTotalAmount(), testDto.getBankName(), testDto.getBankAccountNum(), 0, false)).thenReturn(testPayRequest); - when(payDao.createPayRequestTarget(testPayRequest, testTargetInfo1.getTargetUserId(), testTargetInfo1.getRequestAmount(), false)).thenReturn(testPayRequestTarget_1); - when(payDao.createPayRequestTarget(testPayRequest, testTargetInfo2.getTargetUserId(), testTargetInfo2.getRequestAmount(), false)).thenReturn(testPayRequestTarget_2); - - //when - List testPayRequestTargetList = payService.createPay(user5.getUserId(), testSpace.getSpaceId(), testDto, 0); - - //then - PayRequestTarget result_1 = testPayRequestTargetList.get(0); - assertThat(result_1.getPayRequest()).isEqualTo(testPayRequest); - assertThat(result_1.getTargetUserId()).isEqualTo(user6.getUserId()); - assertThat(result_1.getRequestAmount()).isEqualTo(10000); - - PayRequestTarget result_2 = testPayRequestTargetList.get(1); - assertThat(result_2.getPayRequest()).isEqualTo(testPayRequest); - assertThat(result_2.getTargetUserId()).isEqualTo(user7.getUserId()); - assertThat(result_2.getRequestAmount()).isEqualTo(10000); - } - -} \ No newline at end of file From 6beb5900180c333a1caa2be6faab57f09ad3a315 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Fri, 8 Nov 2024 15:21:19 +0900 Subject: [PATCH 04/20] =?UTF-8?q?refactor=20:=20User,=20Space,=20Pay=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20entity=20=EC=83=9D=EC=84=B1=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84=20&=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=A0=91=EA=B7=BC=20?= =?UTF-8?q?=EC=A0=9C=ED=95=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/space/space_spring/dao/SpaceDao.java | 3 +- .../pay/model/entity/PayRequestTarget.java | 21 +++ .../domain/pay/repository/PayDao.java | 5 +- .../domain/user/model/entity/User.java | 3 +- .../domain/user/repository/UserDao.java | 3 +- .../java/space/space_spring/entity/Space.java | 17 ++ .../VoiceRoom/VoiceRoomServiceTest.java | 145 ------------------ .../domain/pay/service/PayServiceTest.java | 14 +- 8 files changed, 54 insertions(+), 157 deletions(-) delete mode 100644 src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java diff --git a/src/main/java/space/space_spring/dao/SpaceDao.java b/src/main/java/space/space_spring/dao/SpaceDao.java index 49c8ad1d..dbe95f55 100644 --- a/src/main/java/space/space_spring/dao/SpaceDao.java +++ b/src/main/java/space/space_spring/dao/SpaceDao.java @@ -13,8 +13,7 @@ public class SpaceDao { private EntityManager em; public Space saveSpace(String spaceName, String spaceImgUrl) { - Space space = new Space(); - space.saveSpace(spaceName, spaceImgUrl); + Space space = Space.create(spaceName, spaceImgUrl); em.persist(space); return space; diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index 8a1cd311..ab812e08 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -1,13 +1,17 @@ package space.space_spring.domain.pay.model.entity; import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; import space.space_spring.entity.BaseEntity; @Entity @Getter @Table(name = "Pay_Request_Target") +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class PayRequestTarget extends BaseEntity { @Id @@ -36,6 +40,23 @@ public void savePayRequestTarget(PayRequest payRequest, Long targetUserId, int r this.isComplete = isComplete; } + @Builder + private PayRequestTarget(PayRequest payRequest, Long targetUserId, int requestAmount, boolean isComplete) { + this.payRequest = payRequest; + this.targetUserId = targetUserId; + this.requestAmount = requestAmount; + this.isComplete = isComplete; + } + + public static PayRequestTarget create(PayRequest payRequest, Long targetUserId, int requestAmount, boolean isComplete) { + return PayRequestTarget.builder() + .payRequest(payRequest) + .targetUserId(targetUserId) + .requestAmount(requestAmount) + .isComplete(isComplete) + .build(); + } + public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayDao.java b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java index a5696ab4..c8f5ed9f 100644 --- a/src/main/java/space/space_spring/domain/pay/repository/PayDao.java +++ b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java @@ -73,8 +73,6 @@ public List findRecentPayRequestBankInfoByUser(User } public PayRequest createPayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum, int unRequestedAmount, boolean isComplete) { -// PayRequest payRequest = new PayRequest(); -// payRequest.savePayRequest(payCreateUser, space, totalAmount, bankName, bankAccountNum, unRequestedAmount, isComplete); PayRequest payRequest = PayRequest.create(payCreateUser, space, totalAmount, bankName, bankAccountNum, unRequestedAmount, isComplete); em.persist(payRequest); @@ -82,8 +80,7 @@ public PayRequest createPayRequest(User payCreateUser, Space space, int totalAmo } public PayRequestTarget createPayRequestTarget(PayRequest payRequest, Long targetUserId, int requestAmount, boolean isComplete) { - PayRequestTarget payRequestTarget = new PayRequestTarget(); - payRequestTarget.savePayRequestTarget(payRequest, targetUserId, requestAmount, isComplete); + PayRequestTarget payRequestTarget = PayRequestTarget.create(payRequest, targetUserId, requestAmount, isComplete); em.persist(payRequestTarget); return payRequestTarget; diff --git a/src/main/java/space/space_spring/domain/user/model/entity/User.java b/src/main/java/space/space_spring/domain/user/model/entity/User.java index b58ef710..bee0b88a 100644 --- a/src/main/java/space/space_spring/domain/user/model/entity/User.java +++ b/src/main/java/space/space_spring/domain/user/model/entity/User.java @@ -1,6 +1,7 @@ package space.space_spring.domain.user.model.entity; import jakarta.persistence.*; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -10,7 +11,7 @@ @Entity @Table(name = "Users") @Getter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class User extends BaseEntity { @Id @GeneratedValue diff --git a/src/main/java/space/space_spring/domain/user/repository/UserDao.java b/src/main/java/space/space_spring/domain/user/repository/UserDao.java index d994423f..06b362f2 100644 --- a/src/main/java/space/space_spring/domain/user/repository/UserDao.java +++ b/src/main/java/space/space_spring/domain/user/repository/UserDao.java @@ -17,8 +17,7 @@ public class UserDao { private EntityManager em; public User saveUser(String email, String password, String userName, UserSignupType signupType) { - User user = new User(); - user.saveUser(email, password, userName, signupType); + User user = User.create(email, password, userName, signupType); em.persist(user); return user; diff --git a/src/main/java/space/space_spring/entity/Space.java b/src/main/java/space/space_spring/entity/Space.java index a07a3b6c..8e2eb9b2 100644 --- a/src/main/java/space/space_spring/entity/Space.java +++ b/src/main/java/space/space_spring/entity/Space.java @@ -1,11 +1,15 @@ package space.space_spring.entity; import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; @Entity @Getter @Table(name = "Spaces") +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class Space extends BaseEntity { @Id @GeneratedValue @@ -24,4 +28,17 @@ public void saveSpace(String spaceName, String spaceProfileImg) { initializeBaseEntityFields(); } + @Builder + private Space(String spaceName, String spaceProfileImg) { + this.spaceName = spaceName; + this.spaceProfileImg = spaceProfileImg; + } + + public static Space create(String spaceName, String spaceProfileImg) { + return Space.builder() + .spaceName(spaceName) + .spaceProfileImg(spaceProfileImg) + .build(); + } + } diff --git a/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java b/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java deleted file mode 100644 index 572b96eb..00000000 --- a/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java +++ /dev/null @@ -1,145 +0,0 @@ -package space.space_spring.domain.VoiceRoom; - -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.test.util.ReflectionTestUtils; -import space.space_spring.dao.UserSpaceDao; -import space.space_spring.dao.VoiceRoomDao; -import space.space_spring.dao.VoiceRoomRepository; -import space.space_spring.domain.pay.model.entity.PayRequest; -import space.space_spring.domain.pay.model.entity.PayRequestTarget; -import space.space_spring.domain.user.model.entity.User; -import space.space_spring.dto.VoiceRoom.PostVoiceRoomDto; -import space.space_spring.entity.*; -import space.space_spring.entity.enumStatus.UserSignupType; -import space.space_spring.service.VoiceRoomService; -import space.space_spring.util.LiveKitUtils; -import space.space_spring.util.space.SpaceUtils; - - -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -public class VoiceRoomServiceTest { - @InjectMocks - private VoiceRoomService voiceRoomService; - - @Mock - private VoiceRoomRepository voiceRoomRepository; - - @Mock - private VoiceRoomDao voiceRoomDao; - - @Mock - // 삭제 예정 - private SpaceUtils spaceUtils; - - @Mock - private LiveKitUtils liveKitUtils; - - - - @Mock - private UserSpaceDao userSpaceDao; - - - private User user1; - private User user2; - private User user3; - private User user4; - private User user5; - private User user6; - private User user7; - private Space testSpace; - private PayRequest testPayRequest_user1; - private PayRequest testPayRequest_user2; - private PayRequestTarget testPayRequestTarget_user1; - private PayRequestTarget testPayRequestTarget_user2; - private PayRequestTarget testPayRequestTarget_user3; - private PayRequestTarget testPayRequestTarget_user4; - - @BeforeEach - public void 테스트_셋업() { - /** - * : user2, 3은 정산 완료 X & user4는 정산 완료 - * : user1은 정산 완료 - */ - user1 = new User(); - user1.saveUser("test1@test.com", "abcDEF123!@", "user1", UserSignupType.LOCAL); - - user2 = new User(); - user2.saveUser("test2@test.com", "abcDEF123!@", "user2", UserSignupType.LOCAL); - - user3 = new User(); - user3.saveUser("test3@test.com", "abcDEF123!@", "user3", UserSignupType.LOCAL); - - user4 = new User(); - user4.saveUser("test4@test.com", "abcDEF123!@", "user4", UserSignupType.LOCAL); - - testSpace = new Space(); - testSpace.saveSpace("testSpace", "test_profile_img_url"); - -// testPayRequest_user1 = new PayRequest(); -// testPayRequest_user1.savePayRequest(user1, testSpace, 30000, "우리은행", "111-111-111", 0, false); - - testPayRequest_user1 = PayRequest.create(user1, testSpace, 30000, "우리은행", "111-111-111", 0, false); - - testPayRequestTarget_user2 = new PayRequestTarget(); - testPayRequestTarget_user2.savePayRequestTarget(testPayRequest_user1, user2.getUserId(), 10000, false); - - testPayRequestTarget_user3 = new PayRequestTarget(); - testPayRequestTarget_user3.savePayRequestTarget(testPayRequest_user1, user3.getUserId(), 10000, false); - - testPayRequestTarget_user4 = new PayRequestTarget(); - testPayRequestTarget_user4.savePayRequestTarget(testPayRequest_user1, user4.getUserId(), 10000, true); - -// testPayRequest_user2 = new PayRequest(); -// testPayRequest_user2.savePayRequest(user2, testSpace, 10000, "국민은행", "111-111-111", 0, true); - - testPayRequest_user2 = PayRequest.create(user2, testSpace, 10000, "우리은행", "111-111-111", 0, true); - - testPayRequestTarget_user1 = new PayRequestTarget(); - testPayRequestTarget_user1.savePayRequestTarget(testPayRequest_user2, user1.getUserId(), 10000, true); - - /** - * 추가로 user5,6,7 생성 - */ - user5 = new User(); - user6 = new User(); - user7 = new User(); - user5.saveUser("test5@test.com", "abcDEF123!@", "user5", UserSignupType.LOCAL); - user6.saveUser("test6@test.com", "abcDEF123!@", "user6", UserSignupType.LOCAL); - user7.saveUser("test7@test.com", "abcDEF123!@", "user7", UserSignupType.LOCAL); - - } - - @Test - @DisplayName("create VoiceRoom test") - void voiceRoom_create_test(){ - //given - int spaceOrder =1; - String voiceRoomName = "voiceRoom"; - Long spaceId = 2L; - //when - //when(testSpace.getSpaceId()).thenReturn(1L); - //testSpace. - ReflectionTestUtils.setField(testSpace,"spaceId",spaceId); - when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); - when(voiceRoomRepository.findMaxOrderBySpace(testSpace)).thenReturn(spaceOrder); - when(voiceRoomDao.createVoiceRoom(voiceRoomName,spaceOrder+1,testSpace)).thenReturn(1L); - - - PostVoiceRoomDto.Request request = new PostVoiceRoomDto.Request(voiceRoomName); - Long voiceRoomId = voiceRoomService.createVoiceRoom(testSpace.getSpaceId(),request); - - //then - assertThat(voiceRoomId).isEqualTo(1L); - - } -} diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index 4425db91..44c2ecee 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -10,12 +10,14 @@ import org.springframework.context.annotation.Import; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.test.context.ActiveProfiles; +import space.space_spring.dao.SpaceRepository; import space.space_spring.domain.pay.model.entity.PayRequest; import space.space_spring.domain.pay.model.entity.PayRequestTarget; import space.space_spring.domain.pay.repository.PayRequestRepository; import space.space_spring.domain.pay.repository.PayRequestTargetRepository; import space.space_spring.domain.user.model.entity.User; import space.space_spring.domain.user.repository.UserRepository; +import space.space_spring.entity.Space; import space.space_spring.entity.enumStatus.UserSignupType; import static org.junit.jupiter.api.Assertions.*; @@ -23,8 +25,8 @@ @DataJpaTest @Import({PayService.class}) @ActiveProfiles("test") -@EnableJpaRepositories(basePackageClasses = {PayRequestRepository.class, PayRequestTargetRepository.class, UserRepository.class}) -@EntityScan(basePackageClasses = {PayRequest.class, PayRequestTarget.class, User.class}) +@EnableJpaRepositories(basePackageClasses = {PayRequestRepository.class, PayRequestTargetRepository.class, UserRepository.class, SpaceRepository.class}) +@EntityScan(basePackageClasses = {PayRequest.class, PayRequestTarget.class, User.class, Space.class}) class PayServiceTest { @Autowired @@ -39,12 +41,18 @@ class PayServiceTest { @Autowired private UserRepository userRepository; + @Autowired + private SpaceRepository spaceRepository; + @Test @DisplayName("유저가 요청한 정산 중, 현재 진행 중인 정산 정보들과 유저가 요청받은 정산 중, 현재 진행 중인 정산 정보들을 return 한다.") void getPayHomeInfos() throws Exception { //given User user = User.create("email", "password", "name", UserSignupType.LOCAL); - User savedUser = userRepository.save(user); + Space space = Space.create("space", "profileImg"); + + User testUser = userRepository.save(user); + Space testSpace = spaceRepository.save(space); From 3e68f1f49cecc37effc52f32540879a74cbaa6d4 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sat, 9 Nov 2024 02:21:49 +0900 Subject: [PATCH 05/20] =?UTF-8?q?refactor=20:=20space,=20userSpace=20?= =?UTF-8?q?=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserSpaceAuthHandlerArgumentResolver.java | 3 +- .../controller/PostController.java | 3 +- .../controller/VoiceRoomController.java | 4 +- .../java/space/space_spring/dao/PostDao.java | 2 +- .../space/space_spring/dao/VoiceRoomDao.java | 6 +- .../space_spring/dao/VoiceRoomRepository.java | 2 +- .../chat/custom/ChatRoomRepositoryCustom.java | 2 +- .../chat/custom/ChatRoomRepositoryImpl.java | 2 +- .../domain/pay/controller/PayController.java | 328 +++++++-------- .../domain/pay/model/entity/PayRequest.java | 4 +- .../pay/model/entity/PayRequestTarget.java | 6 - .../domain/pay/repository/PayDao.java | 2 +- .../pay/repository/PayRequestRepository.java | 7 +- .../PayRequestTargetRepository.java | 3 +- .../domain/pay/service/PayService.java | 374 +++++++++--------- .../space}/controller/SpaceController.java | 88 ++--- .../space/model/dto}/GetSpaceHomeDto.java | 2 +- .../space/model/dto}/GetSpaceJoinDto.java | 2 +- .../space/model/dto}/PostSpaceJoinDto.java | 2 +- .../space/model}/entity/Space.java | 8 +- .../model}/request/PostSpaceCreateDto.java | 2 +- .../response/GetUserInfoBySpaceResponse.java | 4 +- .../space/repository}/SpaceDao.java | 5 +- .../space/repository}/SpaceRepository.java | 4 +- .../space}/service/SpaceService.java | 22 +- .../domain/user/service/UserService.java | 4 +- .../model}/GetUserProfileInSpaceDto.java | 3 +- .../model}/PutUserProfileInSpaceDto.java | 2 +- .../userSpace/model}/UserInfoInSpace.java | 2 +- .../userSpace/model}/entity/UserSpace.java | 20 +- .../userSpace/repository}/UserSpaceDao.java | 11 +- .../repository}/UserSpaceRepository.java | 6 +- .../response/ReadChatRoomMemberResponse.java | 2 +- .../response/ReadCommentsResponse.java | 2 +- .../dto/post/request/CreatePostRequest.java | 2 +- .../post/response/ReadPostDetailResponse.java | 2 +- .../dto/post/response/ReadPostsResponse.java | 2 +- .../space/space_spring/entity/ChatRoom.java | 4 +- .../java/space/space_spring/entity/Post.java | 1 + .../space/space_spring/entity/VoiceRoom.java | 5 +- .../UserSpaceValidationInterceptor.java | 8 +- .../space_spring/service/ChatRoomService.java | 6 +- .../space_spring/service/ChattingService.java | 2 +- .../space_spring/service/CommentService.java | 4 +- .../space_spring/service/PostService.java | 6 +- .../service/VoiceRoomService.java | 4 +- .../space_spring/util/space/SpaceUtils.java | 4 +- .../util/userSpace/MemoryUserSpaceUtils.java | 8 +- .../util/userSpace/UserSpaceUtils.java | 2 +- .../concurrency/completableFutureTest.java | 16 +- .../controller/ChatRoomControllerTest.java | 2 +- .../domain/pay/service/PayServiceTest.java | 57 ++- .../repository/ChatRoomRepositoryTest.java | 206 +++++----- .../repository/UserChatRoomDaoTest.java | 2 +- .../service/ChatRoomServiceTest.java | 2 +- 55 files changed, 640 insertions(+), 644 deletions(-) rename src/main/java/space/space_spring/{ => domain/space}/controller/SpaceController.java (76%) rename src/main/java/space/space_spring/{dto/space => domain/space/model/dto}/GetSpaceHomeDto.java (95%) rename src/main/java/space/space_spring/{dto/space => domain/space/model/dto}/GetSpaceJoinDto.java (90%) rename src/main/java/space/space_spring/{dto/space => domain/space/model/dto}/PostSpaceJoinDto.java (95%) rename src/main/java/space/space_spring/{ => domain/space/model}/entity/Space.java (79%) rename src/main/java/space/space_spring/{dto/space => domain/space/model}/request/PostSpaceCreateDto.java (94%) rename src/main/java/space/space_spring/{dto/space => domain/space/model}/response/GetUserInfoBySpaceResponse.java (67%) rename src/main/java/space/space_spring/{dao => domain/space/repository}/SpaceDao.java (80%) rename src/main/java/space/space_spring/{dao => domain/space/repository}/SpaceRepository.java (78%) rename src/main/java/space/space_spring/{ => domain/space}/service/SpaceService.java (89%) rename src/main/java/space/space_spring/{dto/userSpace => domain/userSpace/model}/GetUserProfileInSpaceDto.java (77%) rename src/main/java/space/space_spring/{dto/userSpace => domain/userSpace/model}/PutUserProfileInSpaceDto.java (96%) rename src/main/java/space/space_spring/{dto/userSpace => domain/userSpace/model}/UserInfoInSpace.java (86%) rename src/main/java/space/space_spring/{ => domain/userSpace/model}/entity/UserSpace.java (72%) rename src/main/java/space/space_spring/{dao => domain/userSpace/repository}/UserSpaceDao.java (94%) rename src/main/java/space/space_spring/{dao => domain/userSpace/repository}/UserSpaceRepository.java (78%) diff --git a/src/main/java/space/space_spring/argumentResolver/userSpace/UserSpaceAuthHandlerArgumentResolver.java b/src/main/java/space/space_spring/argumentResolver/userSpace/UserSpaceAuthHandlerArgumentResolver.java index 2f81ca00..9e811960 100644 --- a/src/main/java/space/space_spring/argumentResolver/userSpace/UserSpaceAuthHandlerArgumentResolver.java +++ b/src/main/java/space/space_spring/argumentResolver/userSpace/UserSpaceAuthHandlerArgumentResolver.java @@ -8,8 +8,7 @@ import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; -import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; -import space.space_spring.dao.UserSpaceDao; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; @Component @RequiredArgsConstructor diff --git a/src/main/java/space/space_spring/controller/PostController.java b/src/main/java/space/space_spring/controller/PostController.java index 58674b5e..e1975bdc 100644 --- a/src/main/java/space/space_spring/controller/PostController.java +++ b/src/main/java/space/space_spring/controller/PostController.java @@ -7,14 +7,13 @@ import org.springframework.web.bind.annotation.*; import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; -import org.springframework.web.multipart.MultipartFile; import space.space_spring.argumentResolver.userSpace.CheckUserSpace; import space.space_spring.dto.post.request.CreatePostRequest; import space.space_spring.dto.post.response.ReadPostDetailResponse; import space.space_spring.dto.post.response.ReadPostsResponse; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.exception.CustomException; import space.space_spring.response.BaseResponse; import space.space_spring.service.PostService; diff --git a/src/main/java/space/space_spring/controller/VoiceRoomController.java b/src/main/java/space/space_spring/controller/VoiceRoomController.java index 5b7dd483..bb4aa82b 100644 --- a/src/main/java/space/space_spring/controller/VoiceRoomController.java +++ b/src/main/java/space/space_spring/controller/VoiceRoomController.java @@ -9,7 +9,7 @@ import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; import space.space_spring.argumentResolver.userSpace.UserSpaceAuth; import space.space_spring.argumentResolver.userSpace.UserSpaceId; -import space.space_spring.dao.UserSpaceDao; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; import space.space_spring.dao.VoiceRoomRepository; import space.space_spring.dto.VoiceRoom.*; @@ -21,9 +21,7 @@ import space.space_spring.util.user.UserUtils; import space.space_spring.util.userSpace.UserSpaceUtils; -import javax.print.DocFlavor; import java.util.List; -import java.util.Optional; import static space.space_spring.entity.enumStatus.UserSpaceAuth.MANAGER; import static space.space_spring.response.status.BaseExceptionResponseStatus.*; diff --git a/src/main/java/space/space_spring/dao/PostDao.java b/src/main/java/space/space_spring/dao/PostDao.java index dd616ddf..474a0301 100644 --- a/src/main/java/space/space_spring/dao/PostDao.java +++ b/src/main/java/space/space_spring/dao/PostDao.java @@ -6,7 +6,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import space.space_spring.entity.Post; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import java.util.List; diff --git a/src/main/java/space/space_spring/dao/VoiceRoomDao.java b/src/main/java/space/space_spring/dao/VoiceRoomDao.java index 9530676b..87c2b946 100644 --- a/src/main/java/space/space_spring/dao/VoiceRoomDao.java +++ b/src/main/java/space/space_spring/dao/VoiceRoomDao.java @@ -3,14 +3,10 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import jakarta.transaction.Transactional; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.entity.VoiceRoom; -import java.util.List; -import java.util.Optional; - @Repository public class VoiceRoomDao { @PersistenceContext diff --git a/src/main/java/space/space_spring/dao/VoiceRoomRepository.java b/src/main/java/space/space_spring/dao/VoiceRoomRepository.java index fc169ff7..2d5d0fb7 100644 --- a/src/main/java/space/space_spring/dao/VoiceRoomRepository.java +++ b/src/main/java/space/space_spring/dao/VoiceRoomRepository.java @@ -4,7 +4,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.entity.VoiceRoom; import java.util.List; diff --git a/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryCustom.java b/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryCustom.java index 9407cf21..00ab57cc 100644 --- a/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryCustom.java +++ b/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryCustom.java @@ -1,7 +1,7 @@ package space.space_spring.dao.chat.custom; import space.space_spring.entity.ChatRoom; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; import java.util.List; diff --git a/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryImpl.java b/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryImpl.java index 89a22a36..51e53bea 100644 --- a/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryImpl.java +++ b/src/main/java/space/space_spring/dao/chat/custom/ChatRoomRepositoryImpl.java @@ -3,7 +3,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import space.space_spring.entity.ChatRoom; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; import java.util.List; diff --git a/src/main/java/space/space_spring/domain/pay/controller/PayController.java b/src/main/java/space/space_spring/domain/pay/controller/PayController.java index f86647c3..88627fab 100644 --- a/src/main/java/space/space_spring/domain/pay/controller/PayController.java +++ b/src/main/java/space/space_spring/domain/pay/controller/PayController.java @@ -59,169 +59,169 @@ public BaseResponse showPayHome(@JwtLoginAuth Long userId, // return new BaseResponse<>(new PayHomeViewResponse(payRequestInfoDtoList, payReceiveInfoDtoList)); } - private void validateIsUserInSpace(Long userId, Long spaceId) { - // 유저가 스페이스에 속할 경우 exception이 터지지 않을 것임 - // 그렇지 않을 경우, USER_IS_NOT_IN_SPACE 예외가 터질 것임 -> 추후 exception handling 과정 필요 - userSpaceUtils.isUserInSpace(userId, spaceId); - } - - /** - * 내가 요청한 정산 조회 - */ - @GetMapping("/space/{spaceId}/pay/request") - public BaseResponse showRequestPayListForUser(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { - // TODO 1. 유저가 스페이스에 속하는 지 검증 -> 추후에 인터셉터에서 처리하게끔 리펙토링 필요 - validateIsUserInSpace(userId, spaceId); - - // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get -> 아직 완료되지 않은 정산 : isComplete = false - List payRequestInfoDtoListInComplete = payService.getPayRequestInfoForUser(userId, spaceId, false); - - // TODO 3. 유저가 요청한 정산 중 완료한 정산 리스트 get -> 완료된 정산 : isComplete = true - List payRequestInfoDtoListComplete = payService.getPayRequestInfoForUser(userId, spaceId, true); - - return new BaseResponse<>(new GetRequestPayViewResponse(payRequestInfoDtoListInComplete, payRequestInfoDtoListComplete)); - } - - /** - * 내가 요청받은 정산 조회 - */ - @GetMapping("/space/{spaceId}/pay/receive") - public BaseResponse showReceivePayListForUser(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { - // TODO 1. 유저가 스페이스에 속하는 지 검증 -> 추후에 인터셉터에서 처리하게끔 리펙토링 필요 - validateIsUserInSpace(userId, spaceId); - - // TODO 2. 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 get -> 정산 타겟 유저가 정산 안했을 경우 : isComplete = false - List payReceiveInfoDtoListInComplete = payService.getPayReceiveInfoForUser(userId, spaceId, false); - - // TODO 3. 유저가 요청받은 정산 중 완료한 정산 리스트 get -> 정산 타겟 유저가 정산 했을 경우 : isComplete = true - List payReceiveInfoDtoListComplete = payService.getPayReceiveInfoForUser(userId, spaceId, true); - - return new BaseResponse<>(new GetReceivePayViewResponse(payReceiveInfoDtoListInComplete, payReceiveInfoDtoListComplete)); - } - - - /** - * 유저가 최근 정산받은 은행 계좌 정보 조회 - * 해당 api는 유저가 속한 스페이스의 정보가 필요없다고 판단해서 spaceId 를 request로 받지 않음 - */ - @CheckUserSpace(required = false) - @GetMapping("/space/pay/recent-bank-info") - public BaseResponse showRecentBankInfo(@JwtLoginAuth Long userId) { - - return new BaseResponse<>(payService.getRecentPayRequestBankInfoForUser(userId)); - } - - /** - * 정산 생성 - * response 추가 협의 필요 -> 굳이 PayRequestId를 response 안해도 될꺼같음 - */ - @PostMapping("/space/{spaceId}/pay") - public BaseResponse createPay(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @Validated @RequestBody PostPayCreateRequest postPayCreateRequest, BindingResult bindingResult) { - - // TODO 1. request dto validation - if (bindingResult.hasErrors()) { - throw new CustomException(INVALID_PAY_CREATE, getErrorMessage(bindingResult)); - } - - // TODO 2. 유저가 스페이스에 속하는 지 검증 - validateIsUserInSpace(userId, spaceId); - - // TODO 3. PostPayCreateRequest의 targetInfoList 유저들이 모두 해당 스페이스에 속하는지 검증 - // 현재 검증 시 에러가 발생하면 그냥 "스페이스에 속하는 유저가 아닙니다" 라는 에러메시지만 나오고, - // 어떤 유저가 스페이스에 속하지 않는지에 대한 정보가 없음 - // => 추후 에러메시지의 수정이 필요할듯?? - for (PostPayCreateRequest.TargetInfo targetInfo : postPayCreateRequest.getTargetInfoList()) { - validateIsUserInSpace(targetInfo.getTargetUserId(), spaceId); - } - - // TODO 4. PostPayCreateRequest의 bankName, bankAccountNum 검증 - // => 추후에 은행 이름들의 목록을 enum으로 만들어서 관리 & 유효성 검사 하도록 ?? - - // TODO 5. 정산 요청 금액의 유효성 검사 - // return 값 : 미정산 금액 - int unRequestedAmount = validatePayAmount(postPayCreateRequest); - - // TODO 6. 정산 생성 - payService.createPay(userId, spaceId, postPayCreateRequest, unRequestedAmount); - - return new BaseResponse<>("정산 생성 성공"); - } - - private int validatePayAmount(PostPayCreateRequest postPayCreateRequest) { - - // 1. requestAmount 들의 합이 totalAmount 와 일치하는지 확인 - - // 2-1. 만약 일치한다면 유효성 검사 통과 - // 2-2. 만약 일치하지 않는다면, totalAmount와 requestAmount들의 합의 차이가 n-1보다 작거나 같은지 확인 - - // 3-1, 만약 n-1보다 작거나 같은 경우, 유효성 검사 통과 ('미정산 금액' 확인) - // 3-2, 만약 n-1보다 클 경우, 유효성 검사 통과 X (예외 처리) - - int totalRequestAmount = calculateSumOfRequestAmount(postPayCreateRequest.getTargetInfoList()); - int totalAmount = postPayCreateRequest.getTotalAmount(); - int targetSize = postPayCreateRequest.getTargetInfoList().size(); - int unRequestedAmount = 0; - - if (totalRequestAmount != totalAmount) { - if ((totalAmount - totalRequestAmount) <= (targetSize - 1)) { - unRequestedAmount = totalAmount - totalRequestAmount; - return unRequestedAmount; - } - - throw new CustomException(INVALID_PAY_AMOUNT); - } - - return unRequestedAmount; - } - - private int calculateSumOfRequestAmount(List targetInfoList) { - int totalRequestAmount = 0; - for (PostPayCreateRequest.TargetInfo targetInfo : targetInfoList) { - totalRequestAmount += targetInfo.getRequestAmount(); - } - return totalRequestAmount; - } - - /** - * 하나의 정산에 대한 상세정보 조회 - */ - @GetMapping("/space/{spaceId}/pay/{payRequestId}") - public BaseResponse showTotalPayInfo(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @PathVariable Long payRequestId) { - - // TODO 1. 유저가 스페이스에 속하는 지 검증 - validateIsUserInSpace(userId, spaceId); - - // TODO 2. 정산 상세 정보 조회 - return new BaseResponse<>(payService.getTotalPayInfo(spaceId, payRequestId)); - } - - /** - * 정산 타겟 유저의 정산 완료 처리 - */ - @PostMapping("/space/{spaceId}/pay/complete") - public BaseResponse setPayComplete(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @RequestBody PostPayCompleteRequest postPayCompleteRequest) { - - // TODO 1. 유저가 스페이스에 속하는 지 검증 - validateIsUserInSpace(userId, spaceId); - - // TODO 2. 유저와 정산 타겟 유저가 일치하는지 검증 - checkPayRequestTargetUser(userId, postPayCompleteRequest.getPayRequestTargetId()); - - // TODO 3. 정산 타겟 유저의 정산 완료 처리 - return new BaseResponse<>(payService.setPayRequestTargetToComplete(postPayCompleteRequest.getPayRequestTargetId())); - } - - private void checkPayRequestTargetUser(Long userId, Long payRequestTargetId) { - - User userByUserId = userUtils.findUserByUserId(userId); - PayRequestTarget payRequestTargetById = payUtils.findPayRequestTargetById(payRequestTargetId); - - Long realUserId = userByUserId.getUserId(); - Long targetUserId = payRequestTargetById.getTargetUserId(); - - if (!realUserId.equals(targetUserId)) { - throw new CustomException(INVALID_PAY_REQUEST_TARGET_ID); - } - } +// private void validateIsUserInSpace(Long userId, Long spaceId) { +// // 유저가 스페이스에 속할 경우 exception이 터지지 않을 것임 +// // 그렇지 않을 경우, USER_IS_NOT_IN_SPACE 예외가 터질 것임 -> 추후 exception handling 과정 필요 +// userSpaceUtils.isUserInSpace(userId, spaceId); +// } +// +// /** +// * 내가 요청한 정산 조회 +// */ +// @GetMapping("/space/{spaceId}/pay/request") +// public BaseResponse showRequestPayListForUser(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { +// // TODO 1. 유저가 스페이스에 속하는 지 검증 -> 추후에 인터셉터에서 처리하게끔 리펙토링 필요 +// validateIsUserInSpace(userId, spaceId); +// +// // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get -> 아직 완료되지 않은 정산 : isComplete = false +// List payRequestInfoDtoListInComplete = payService.getPayRequestInfoForUser(userId, spaceId, false); +// +// // TODO 3. 유저가 요청한 정산 중 완료한 정산 리스트 get -> 완료된 정산 : isComplete = true +// List payRequestInfoDtoListComplete = payService.getPayRequestInfoForUser(userId, spaceId, true); +// +// return new BaseResponse<>(new GetRequestPayViewResponse(payRequestInfoDtoListInComplete, payRequestInfoDtoListComplete)); +// } +// +// /** +// * 내가 요청받은 정산 조회 +// */ +// @GetMapping("/space/{spaceId}/pay/receive") +// public BaseResponse showReceivePayListForUser(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { +// // TODO 1. 유저가 스페이스에 속하는 지 검증 -> 추후에 인터셉터에서 처리하게끔 리펙토링 필요 +// validateIsUserInSpace(userId, spaceId); +// +// // TODO 2. 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 get -> 정산 타겟 유저가 정산 안했을 경우 : isComplete = false +// List payReceiveInfoDtoListInComplete = payService.getPayReceiveInfoForUser(userId, spaceId, false); +// +// // TODO 3. 유저가 요청받은 정산 중 완료한 정산 리스트 get -> 정산 타겟 유저가 정산 했을 경우 : isComplete = true +// List payReceiveInfoDtoListComplete = payService.getPayReceiveInfoForUser(userId, spaceId, true); +// +// return new BaseResponse<>(new GetReceivePayViewResponse(payReceiveInfoDtoListInComplete, payReceiveInfoDtoListComplete)); +// } +// +// +// /** +// * 유저가 최근 정산받은 은행 계좌 정보 조회 +// * 해당 api는 유저가 속한 스페이스의 정보가 필요없다고 판단해서 spaceId 를 request로 받지 않음 +// */ +// @CheckUserSpace(required = false) +// @GetMapping("/space/pay/recent-bank-info") +// public BaseResponse showRecentBankInfo(@JwtLoginAuth Long userId) { +// +// return new BaseResponse<>(payService.getRecentPayRequestBankInfoForUser(userId)); +// } +// +// /** +// * 정산 생성 +// * response 추가 협의 필요 -> 굳이 PayRequestId를 response 안해도 될꺼같음 +// */ +// @PostMapping("/space/{spaceId}/pay") +// public BaseResponse createPay(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @Validated @RequestBody PostPayCreateRequest postPayCreateRequest, BindingResult bindingResult) { +// +// // TODO 1. request dto validation +// if (bindingResult.hasErrors()) { +// throw new CustomException(INVALID_PAY_CREATE, getErrorMessage(bindingResult)); +// } +// +// // TODO 2. 유저가 스페이스에 속하는 지 검증 +// validateIsUserInSpace(userId, spaceId); +// +// // TODO 3. PostPayCreateRequest의 targetInfoList 유저들이 모두 해당 스페이스에 속하는지 검증 +// // 현재 검증 시 에러가 발생하면 그냥 "스페이스에 속하는 유저가 아닙니다" 라는 에러메시지만 나오고, +// // 어떤 유저가 스페이스에 속하지 않는지에 대한 정보가 없음 +// // => 추후 에러메시지의 수정이 필요할듯?? +// for (PostPayCreateRequest.TargetInfo targetInfo : postPayCreateRequest.getTargetInfoList()) { +// validateIsUserInSpace(targetInfo.getTargetUserId(), spaceId); +// } +// +// // TODO 4. PostPayCreateRequest의 bankName, bankAccountNum 검증 +// // => 추후에 은행 이름들의 목록을 enum으로 만들어서 관리 & 유효성 검사 하도록 ?? +// +// // TODO 5. 정산 요청 금액의 유효성 검사 +// // return 값 : 미정산 금액 +// int unRequestedAmount = validatePayAmount(postPayCreateRequest); +// +// // TODO 6. 정산 생성 +// payService.createPay(userId, spaceId, postPayCreateRequest, unRequestedAmount); +// +// return new BaseResponse<>("정산 생성 성공"); +// } +// +// private int validatePayAmount(PostPayCreateRequest postPayCreateRequest) { +// +// // 1. requestAmount 들의 합이 totalAmount 와 일치하는지 확인 +// +// // 2-1. 만약 일치한다면 유효성 검사 통과 +// // 2-2. 만약 일치하지 않는다면, totalAmount와 requestAmount들의 합의 차이가 n-1보다 작거나 같은지 확인 +// +// // 3-1, 만약 n-1보다 작거나 같은 경우, 유효성 검사 통과 ('미정산 금액' 확인) +// // 3-2, 만약 n-1보다 클 경우, 유효성 검사 통과 X (예외 처리) +// +// int totalRequestAmount = calculateSumOfRequestAmount(postPayCreateRequest.getTargetInfoList()); +// int totalAmount = postPayCreateRequest.getTotalAmount(); +// int targetSize = postPayCreateRequest.getTargetInfoList().size(); +// int unRequestedAmount = 0; +// +// if (totalRequestAmount != totalAmount) { +// if ((totalAmount - totalRequestAmount) <= (targetSize - 1)) { +// unRequestedAmount = totalAmount - totalRequestAmount; +// return unRequestedAmount; +// } +// +// throw new CustomException(INVALID_PAY_AMOUNT); +// } +// +// return unRequestedAmount; +// } +// +// private int calculateSumOfRequestAmount(List targetInfoList) { +// int totalRequestAmount = 0; +// for (PostPayCreateRequest.TargetInfo targetInfo : targetInfoList) { +// totalRequestAmount += targetInfo.getRequestAmount(); +// } +// return totalRequestAmount; +// } +// +// /** +// * 하나의 정산에 대한 상세정보 조회 +// */ +// @GetMapping("/space/{spaceId}/pay/{payRequestId}") +// public BaseResponse showTotalPayInfo(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @PathVariable Long payRequestId) { +// +// // TODO 1. 유저가 스페이스에 속하는 지 검증 +// validateIsUserInSpace(userId, spaceId); +// +// // TODO 2. 정산 상세 정보 조회 +// return new BaseResponse<>(payService.getTotalPayInfo(spaceId, payRequestId)); +// } +// +// /** +// * 정산 타겟 유저의 정산 완료 처리 +// */ +// @PostMapping("/space/{spaceId}/pay/complete") +// public BaseResponse setPayComplete(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @RequestBody PostPayCompleteRequest postPayCompleteRequest) { +// +// // TODO 1. 유저가 스페이스에 속하는 지 검증 +// validateIsUserInSpace(userId, spaceId); +// +// // TODO 2. 유저와 정산 타겟 유저가 일치하는지 검증 +// checkPayRequestTargetUser(userId, postPayCompleteRequest.getPayRequestTargetId()); +// +// // TODO 3. 정산 타겟 유저의 정산 완료 처리 +// return new BaseResponse<>(payService.setPayRequestTargetToComplete(postPayCompleteRequest.getPayRequestTargetId())); +// } +// +// private void checkPayRequestTargetUser(Long userId, Long payRequestTargetId) { +// +// User userByUserId = userUtils.findUserByUserId(userId); +// PayRequestTarget payRequestTargetById = payUtils.findPayRequestTargetById(payRequestTargetId); +// +// Long realUserId = userByUserId.getUserId(); +// Long targetUserId = payRequestTargetById.getTargetUserId(); +// +// if (!realUserId.equals(targetUserId)) { +// throw new CustomException(INVALID_PAY_REQUEST_TARGET_ID); +// } +// } } diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index bd60c23c..647e42bf 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -8,7 +8,7 @@ import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.BaseEntity; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import java.util.ArrayList; import java.util.List; @@ -33,7 +33,7 @@ public class PayRequest extends BaseEntity { private Space space; // 정산이 이루어지는 스페이스 @Column(name = "total_amount") - private int totalAmount; // 정산의 총 금액 + private int totalAmount; // 정산의 총 금액 @Column(name = "pay_request_bank") private String bankName; // 정산 받을 은행 이름 diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index ab812e08..aa18e064 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -33,12 +33,6 @@ public class PayRequestTarget extends BaseEntity { @Column(name = "is_complete") private boolean isComplete; - public void savePayRequestTarget(PayRequest payRequest, Long targetUserId, int requestAmount, boolean isComplete) { - this.payRequest = payRequest; - this.targetUserId = targetUserId; - this.requestAmount = requestAmount; - this.isComplete = isComplete; - } @Builder private PayRequestTarget(PayRequest payRequest, Long targetUserId, int requestAmount, boolean isComplete) { diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayDao.java b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java index c8f5ed9f..bc7287e7 100644 --- a/src/main/java/space/space_spring/domain/pay/repository/PayDao.java +++ b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java @@ -7,7 +7,7 @@ import space.space_spring.domain.pay.model.dto.RecentPayRequestBankInfoDto; import space.space_spring.domain.pay.model.entity.PayRequest; import space.space_spring.domain.pay.model.entity.PayRequestTarget; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; import java.util.List; diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java b/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java index 8b93fec7..da5c2074 100644 --- a/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java +++ b/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java @@ -1,23 +1,18 @@ package space.space_spring.domain.pay.repository; -import com.querydsl.jpa.impl.JPAQueryFactory; -import lombok.RequiredArgsConstructor; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import space.space_spring.domain.pay.model.entity.PayRequest; import space.space_spring.domain.user.model.entity.User; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import java.util.List; import java.util.Optional; @Repository -//@RequiredArgsConstructor public interface PayRequestRepository extends JpaRepository { -// private final JPAQueryFactory jpaQueryFactory; - @Query("select pr from PayRequest pr where pr.payCreateUser = :user and pr.space = :space and pr.isComplete = :isComplete and pr.status = 'ACTIVE'") List> findByUserAndSpace(User user, Space space, boolean isComplete); diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java b/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java index 6bb3f214..5af17058 100644 --- a/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java +++ b/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java @@ -4,8 +4,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import space.space_spring.domain.pay.model.entity.PayRequestTarget; -import space.space_spring.domain.user.model.entity.User; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import java.util.List; import java.util.Optional; diff --git a/src/main/java/space/space_spring/domain/pay/service/PayService.java b/src/main/java/space/space_spring/domain/pay/service/PayService.java index 784693c7..b8d7349e 100644 --- a/src/main/java/space/space_spring/domain/pay/service/PayService.java +++ b/src/main/java/space/space_spring/domain/pay/service/PayService.java @@ -3,26 +3,16 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import space.space_spring.dao.UserSpaceRepository; +import space.space_spring.domain.userSpace.model.entity.UserSpace; +import space.space_spring.domain.userSpace.repository.UserSpaceRepository; import space.space_spring.domain.pay.model.entity.PayRequest; import space.space_spring.domain.pay.model.dto.*; import space.space_spring.domain.pay.model.entity.PayRequestTarget; import space.space_spring.domain.pay.model.response.PayHomeViewResponse; -import space.space_spring.domain.pay.repository.PayDao; import space.space_spring.domain.pay.repository.PayRequestRepository; import space.space_spring.domain.pay.repository.PayRequestTargetRepository; -import space.space_spring.domain.user.model.entity.User; -import space.space_spring.domain.user.repository.UserDao; -import space.space_spring.dao.UserSpaceDao; -import space.space_spring.domain.pay.model.request.PostPayCreateRequest; -import space.space_spring.domain.pay.model.response.GetRecentPayRequestBankInfoResponse; -import space.space_spring.domain.pay.model.response.PostPayCompleteResponse; -import space.space_spring.entity.*; import space.space_spring.exception.CustomException; -import space.space_spring.util.space.SpaceUtils; -import space.space_spring.util.user.UserUtils; -import java.time.ZoneId; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -34,11 +24,11 @@ @Transactional(readOnly = true) public class PayService { - private final PayDao payDao; - private final UserUtils userUtils; - private final SpaceUtils spaceUtils; - private final UserDao userDao; - private final UserSpaceDao userSpaceDao; +// private final PayDao payDao; +// private final UserUtils userUtils; +// private final SpaceUtils spaceUtils; +// private final UserDao userDao; +// private final UserSpaceDao userSpaceDao; private final UserSpaceRepository userSpaceRepository; private final PayRequestRepository payRequestRepository; @@ -77,179 +67,179 @@ private UserSpace validateUserInSpace(Long userId, Long spaceId) { - @Transactional - public List getPayRequestInfoForUser(Long userId, Long spaceId, boolean isComplete) { - // TODO 1. userId에 해당하는 user find - User userByUserId = userUtils.findUserByUserId(userId); - - // TODO 2. spaceId에 해당하는 space find - Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); - - // TODO 3. 유저가 요청한 정산 리스트 select - List payRequestListByUser = payDao.findPayRequestListByUser(userByUserId, spaceBySpaceId, isComplete); - - // TODO 4. return 타입 구성 - // - - // 3-1. 각 payRequest 에 해당하는 모든 payRequestTarget 을 loop로 돌면서 데이터 수집 - List payRequestInfoDtoList = new ArrayList<>(); - - for (PayRequest payRequest : payRequestListByUser) { - PayRequestInfoDto payRequestInfoDto = payRequest.createPayRequestInfo(); - payRequestInfoDtoList.add(payRequestInfoDto); - } - - return payRequestInfoDtoList; - } - - @Transactional - public List getPayReceiveInfoForUser(Long userId, Long spaceId, boolean isComplete) { - // TODO 1. userId에 해당하는 유저 find - User userByUserId = userUtils.findUserByUserId(userId); - - // TODO 2. spaceId에 해당하는 space find - Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); - - // TODO 3. 유저가 요청받은 정산 리스트 select - List payRequestTargetListByUser = payDao.findPayRequestTargetListByUser(userByUserId, spaceBySpaceId, isComplete); - - // TODO 4. return 타입 구성 - // 3-1. 각 payRequestTarget 에 해당하는 정산 요청자, 정산 요청 금액 을 loop를 돌면서 데이터 수집 - List payReceiveInfoDtoList = new ArrayList<>(); - - for (PayRequestTarget payRequestTarget : payRequestTargetListByUser) { - PayReceiveInfoDto payReceiveInfoDto = payRequestTarget.createPayReceiveInfo(); - payReceiveInfoDtoList.add(payReceiveInfoDto); - } - - return payReceiveInfoDtoList; - } - - @Transactional - public GetRecentPayRequestBankInfoResponse getRecentPayRequestBankInfoForUser(Long userId) { - // TODO 1. userId에 해당하는 유저 find - User userByUserId = userUtils.findUserByUserId(userId); - - // TODO 2. 유저의 최근 정산받은 은행 계좌 목록 fine - List recentPayRequestBankInfoByUser = payDao.findRecentPayRequestBankInfoByUser(userByUserId); - - return new GetRecentPayRequestBankInfoResponse(recentPayRequestBankInfoByUser); - } - - @Transactional - public List createPay(Long userId, Long spaceId, PostPayCreateRequest postPayCreateRequest, int unRequestedAmount) { - // TODO 1. userId로 User find (user : 정산 생성한 유저) - User payCreateUser = userUtils.findUserByUserId(userId); - - // TODO 2. spaceId로 Space find - Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); - - // TODO 3. PayRequest 엔티티 생성 - boolean isComplete = false; - PayRequest payRequest = payDao.createPayRequest(payCreateUser, spaceBySpaceId, postPayCreateRequest.getTotalAmount(), postPayCreateRequest.getBankName(), postPayCreateRequest.getBankAccountNum(), unRequestedAmount, isComplete); - - // TODO 4. PayRequestTarget 엔티티 생성 - List resultList = new ArrayList<>(); - for (PostPayCreateRequest.TargetInfo targetInfo : postPayCreateRequest.getTargetInfoList()) { - PayRequestTarget payRequestTarget = payDao.createPayRequestTarget(payRequest, targetInfo.getTargetUserId(), targetInfo.getRequestAmount(), isComplete); - resultList.add(payRequestTarget); - } - - return resultList; - } - - /** - * 하나의 정산에 대한 상세정보 조회 - */ - @Transactional - public TotalPayInfoDto getTotalPayInfo(Long spaceId, Long payRequestId) { - // TODO 1. spaceId로 Space 엔티티 find - Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); - - // TODO 2. payRequestId 로 PayRequest 엔티티 find - PayRequest payRequestById = payDao.findPayRequestById(payRequestId); - - // TODO 3. PayRequest로 해당 정산의 정보 get - PayRequestInfoDto payRequestInfoDto = payRequestById.createPayRequestInfo(); - - // TODO 4. PayRequest의 PayRequestTarget find - List payRequestTargetListByPayRequest = payDao.findPayRequestTargetListByPayRequest(payRequestById); - - // TODO 5. 정산 타겟 유저 정보 get - List payTargetInfoDtoList = new ArrayList<>(); - for (PayRequestTarget payRequestTarget : payRequestTargetListByPayRequest) { - PayTargetInfoDto payTargetInfoDto = createPayTargetInfoDto(payRequestTarget, spaceBySpaceId); - payTargetInfoDtoList.add(payTargetInfoDto); - } - - // TODO 6. return 타입 구성 - return new TotalPayInfoDto( - payRequestId, - payRequestById.getBankName(), - payRequestById.getBankAccountNum(), - payRequestById.getTotalAmount(), - payRequestInfoDto.getReceiveAmount(), - payRequestInfoDto.getTotalTargetNum(), - payRequestInfoDto.getReceiveTargetNum(), - payTargetInfoDtoList, - payRequestById.isComplete(), - payRequestById.getCreatedAt().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime() - ); - } - - private PayTargetInfoDto createPayTargetInfoDto(PayRequestTarget payRequestTarget, Space space) { - Long targetUserId = payRequestTarget.getTargetUserId(); - User userByUserId = userDao.findUserByUserId(targetUserId); - - UserSpace userSpace = userSpaceDao.findUserSpaceByUserAndSpace(userByUserId, space) - .orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE)); - - String userName = userSpace.getUserName(); - String userProfileImg = userSpace.getUserProfileImg(); - - return new PayTargetInfoDto( - payRequestTarget.getTargetUserId(), - userName, - userProfileImg, - payRequestTarget.getRequestAmount(), - payRequestTarget.isComplete() - ); - } - - /** - * 정산 타겟 유저의 정산 완료 처리 - */ - @Transactional - public PostPayCompleteResponse setPayRequestTargetToComplete(Long payRequestTargetId) { - - // TODO 1. payRequestTargetId로 PayRequestTarget find - PayRequestTarget payRequestTargetById = payDao.findPayRequestTargetById(payRequestTargetId); - - // TODO 2. 해당 PayRequestTarget 정산 완료 처리 - payRequestTargetById.changeCompleteStatus(true); - - // TODO 3. PayRequest의 완료 여부 파악 - PayRequest payRequest = payRequestTargetById.getPayRequest(); - boolean payRequestCompleteStatus = isPayRequestComplete(payRequest); - if (payRequestCompleteStatus) { - payRequest.changeCompleteStatus(true); - } - - // TODO 4. return 타입 구성 - return new PostPayCompleteResponse( - payRequest.getPayRequestId(), - payRequestCompleteStatus - ); - } - - private boolean isPayRequestComplete(PayRequest payRequest) { - List payRequestTargetListByPayRequest = payDao.findPayRequestTargetListByPayRequest(payRequest); - for (PayRequestTarget payRequestTarget : payRequestTargetListByPayRequest) { - if (!payRequestTarget.isComplete()) { - return false; - } - } - - return true; - } +// @Transactional +// public List getPayRequestInfoForUser(Long userId, Long spaceId, boolean isComplete) { +// // TODO 1. userId에 해당하는 user find +// User userByUserId = userUtils.findUserByUserId(userId); +// +// // TODO 2. spaceId에 해당하는 space find +// Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); +// +// // TODO 3. 유저가 요청한 정산 리스트 select +// List payRequestListByUser = payDao.findPayRequestListByUser(userByUserId, spaceBySpaceId, isComplete); +// +// // TODO 4. return 타입 구성 +// // +// +// // 3-1. 각 payRequest 에 해당하는 모든 payRequestTarget 을 loop로 돌면서 데이터 수집 +// List payRequestInfoDtoList = new ArrayList<>(); +// +// for (PayRequest payRequest : payRequestListByUser) { +// PayRequestInfoDto payRequestInfoDto = payRequest.createPayRequestInfo(); +// payRequestInfoDtoList.add(payRequestInfoDto); +// } +// +// return payRequestInfoDtoList; +// } +// +// @Transactional +// public List getPayReceiveInfoForUser(Long userId, Long spaceId, boolean isComplete) { +// // TODO 1. userId에 해당하는 유저 find +// User userByUserId = userUtils.findUserByUserId(userId); +// +// // TODO 2. spaceId에 해당하는 space find +// Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); +// +// // TODO 3. 유저가 요청받은 정산 리스트 select +// List payRequestTargetListByUser = payDao.findPayRequestTargetListByUser(userByUserId, spaceBySpaceId, isComplete); +// +// // TODO 4. return 타입 구성 +// // 3-1. 각 payRequestTarget 에 해당하는 정산 요청자, 정산 요청 금액 을 loop를 돌면서 데이터 수집 +// List payReceiveInfoDtoList = new ArrayList<>(); +// +// for (PayRequestTarget payRequestTarget : payRequestTargetListByUser) { +// PayReceiveInfoDto payReceiveInfoDto = payRequestTarget.createPayReceiveInfo(); +// payReceiveInfoDtoList.add(payReceiveInfoDto); +// } +// +// return payReceiveInfoDtoList; +// } +// +// @Transactional +// public GetRecentPayRequestBankInfoResponse getRecentPayRequestBankInfoForUser(Long userId) { +// // TODO 1. userId에 해당하는 유저 find +// User userByUserId = userUtils.findUserByUserId(userId); +// +// // TODO 2. 유저의 최근 정산받은 은행 계좌 목록 fine +// List recentPayRequestBankInfoByUser = payDao.findRecentPayRequestBankInfoByUser(userByUserId); +// +// return new GetRecentPayRequestBankInfoResponse(recentPayRequestBankInfoByUser); +// } +// +// @Transactional +// public List createPay(Long userId, Long spaceId, PostPayCreateRequest postPayCreateRequest, int unRequestedAmount) { +// // TODO 1. userId로 User find (user : 정산 생성한 유저) +// User payCreateUser = userUtils.findUserByUserId(userId); +// +// // TODO 2. spaceId로 Space find +// Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); +// +// // TODO 3. PayRequest 엔티티 생성 +// boolean isComplete = false; +// PayRequest payRequest = payDao.createPayRequest(payCreateUser, spaceBySpaceId, postPayCreateRequest.getTotalAmount(), postPayCreateRequest.getBankName(), postPayCreateRequest.getBankAccountNum(), unRequestedAmount, isComplete); +// +// // TODO 4. PayRequestTarget 엔티티 생성 +// List resultList = new ArrayList<>(); +// for (PostPayCreateRequest.TargetInfo targetInfo : postPayCreateRequest.getTargetInfoList()) { +// PayRequestTarget payRequestTarget = payDao.createPayRequestTarget(payRequest, targetInfo.getTargetUserId(), targetInfo.getRequestAmount(), isComplete); +// resultList.add(payRequestTarget); +// } +// +// return resultList; +// } +// +// /** +// * 하나의 정산에 대한 상세정보 조회 +// */ +// @Transactional +// public TotalPayInfoDto getTotalPayInfo(Long spaceId, Long payRequestId) { +// // TODO 1. spaceId로 Space 엔티티 find +// Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); +// +// // TODO 2. payRequestId 로 PayRequest 엔티티 find +// PayRequest payRequestById = payDao.findPayRequestById(payRequestId); +// +// // TODO 3. PayRequest로 해당 정산의 정보 get +// PayRequestInfoDto payRequestInfoDto = payRequestById.createPayRequestInfo(); +// +// // TODO 4. PayRequest의 PayRequestTarget find +// List payRequestTargetListByPayRequest = payDao.findPayRequestTargetListByPayRequest(payRequestById); +// +// // TODO 5. 정산 타겟 유저 정보 get +// List payTargetInfoDtoList = new ArrayList<>(); +// for (PayRequestTarget payRequestTarget : payRequestTargetListByPayRequest) { +// PayTargetInfoDto payTargetInfoDto = createPayTargetInfoDto(payRequestTarget, spaceBySpaceId); +// payTargetInfoDtoList.add(payTargetInfoDto); +// } +// +// // TODO 6. return 타입 구성 +// return new TotalPayInfoDto( +// payRequestId, +// payRequestById.getBankName(), +// payRequestById.getBankAccountNum(), +// payRequestById.getTotalAmount(), +// payRequestInfoDto.getReceiveAmount(), +// payRequestInfoDto.getTotalTargetNum(), +// payRequestInfoDto.getReceiveTargetNum(), +// payTargetInfoDtoList, +// payRequestById.isComplete(), +// payRequestById.getCreatedAt().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime() +// ); +// } +// +// private PayTargetInfoDto createPayTargetInfoDto(PayRequestTarget payRequestTarget, Space space) { +// Long targetUserId = payRequestTarget.getTargetUserId(); +// User userByUserId = userDao.findUserByUserId(targetUserId); +// +// UserSpace userSpace = userSpaceDao.findUserSpaceByUserAndSpace(userByUserId, space) +// .orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE)); +// +// String userName = userSpace.getUserName(); +// String userProfileImg = userSpace.getUserProfileImg(); +// +// return new PayTargetInfoDto( +// payRequestTarget.getTargetUserId(), +// userName, +// userProfileImg, +// payRequestTarget.getRequestAmount(), +// payRequestTarget.isComplete() +// ); +// } +// +// /** +// * 정산 타겟 유저의 정산 완료 처리 +// */ +// @Transactional +// public PostPayCompleteResponse setPayRequestTargetToComplete(Long payRequestTargetId) { +// +// // TODO 1. payRequestTargetId로 PayRequestTarget find +// PayRequestTarget payRequestTargetById = payDao.findPayRequestTargetById(payRequestTargetId); +// +// // TODO 2. 해당 PayRequestTarget 정산 완료 처리 +// payRequestTargetById.changeCompleteStatus(true); +// +// // TODO 3. PayRequest의 완료 여부 파악 +// PayRequest payRequest = payRequestTargetById.getPayRequest(); +// boolean payRequestCompleteStatus = isPayRequestComplete(payRequest); +// if (payRequestCompleteStatus) { +// payRequest.changeCompleteStatus(true); +// } +// +// // TODO 4. return 타입 구성 +// return new PostPayCompleteResponse( +// payRequest.getPayRequestId(), +// payRequestCompleteStatus +// ); +// } +// +// private boolean isPayRequestComplete(PayRequest payRequest) { +// List payRequestTargetListByPayRequest = payDao.findPayRequestTargetListByPayRequest(payRequest); +// for (PayRequestTarget payRequestTarget : payRequestTargetListByPayRequest) { +// if (!payRequestTarget.isComplete()) { +// return false; +// } +// } +// +// return true; +// } } diff --git a/src/main/java/space/space_spring/controller/SpaceController.java b/src/main/java/space/space_spring/domain/space/controller/SpaceController.java similarity index 76% rename from src/main/java/space/space_spring/controller/SpaceController.java rename to src/main/java/space/space_spring/domain/space/controller/SpaceController.java index 95b4df6a..e9a5b90f 100644 --- a/src/main/java/space/space_spring/controller/SpaceController.java +++ b/src/main/java/space/space_spring/domain/space/controller/SpaceController.java @@ -1,4 +1,4 @@ -package space.space_spring.controller; +package space.space_spring.domain.space.controller; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -8,29 +8,23 @@ import org.springframework.web.multipart.MultipartFile; import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; import space.space_spring.argumentResolver.userSpace.CheckUserSpace; -import space.space_spring.argumentResolver.userSpace.UserSpaceAuth; -import space.space_spring.argumentResolver.userSpace.UserSpaceId; -import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; -import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; -import space.space_spring.dto.space.GetSpaceHomeDto; -import space.space_spring.dto.space.GetSpaceJoinDto; -import space.space_spring.dto.space.PostSpaceJoinDto; -import space.space_spring.dto.space.request.PostSpaceCreateDto; -import space.space_spring.dto.space.response.GetUserInfoBySpaceResponse; - -import space.space_spring.dto.userSpace.GetUserProfileInSpaceDto; -import space.space_spring.dto.userSpace.PutUserProfileInSpaceDto; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.dto.GetSpaceJoinDto; +import space.space_spring.domain.space.model.dto.PostSpaceJoinDto; +import space.space_spring.domain.space.model.request.PostSpaceCreateDto; +import space.space_spring.domain.space.model.response.GetUserInfoBySpaceResponse; + +import space.space_spring.domain.userSpace.model.GetUserProfileInSpaceDto; +import space.space_spring.domain.userSpace.model.PutUserProfileInSpaceDto; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.exception.CustomException; import space.space_spring.response.BaseResponse; import space.space_spring.domain.pay.service.PayService; import space.space_spring.service.PostService; import space.space_spring.service.S3Uploader; -import space.space_spring.service.SpaceService; +import space.space_spring.domain.space.service.SpaceService; import space.space_spring.util.userSpace.UserSpaceUtils; import java.io.IOException; -import java.util.List; import static space.space_spring.response.status.BaseExceptionResponseStatus.*; import static space.space_spring.util.bindingResult.BindingResultUtils.getErrorMessage; @@ -197,35 +191,35 @@ public BaseResponse joinUserToSpace(@JwtLoginAuth Long userId, @PathVari return new BaseResponse<>("유저의 스페이스 가입 처리 성공"); } - /** - * 스페이스 홈 화면 - */ - @GetMapping("/{spaceId}") - public BaseResponse showSpaceHome(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @UserSpaceId Long userSpaceId, @UserSpaceAuth String userAuth) { - log.info("userId = {}, spaceId = {}, userSpaceID = {}, userAuth = {}", userId, spaceId, userSpaceId, userAuth); - - // TODO 1. 스페이스 정보 get - GetSpaceHomeDto.SpaceInfoForHome spaceInfoForHome = spaceService.getSpaceInfoForHome(spaceId); - - // TODO 2. 해당 스페이스에서의 유저 정산 정보 get - // 유저가 요청한 정산 중 현재 진행중인 정산 리스트 - // AND - // 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 - List payRequestInfoForUser = payService.getPayRequestInfoForUser(userId, spaceId, false); - List payReceiveInfoForUser = payService.getPayReceiveInfoForUser(userId, spaceId, false); - - // TODO 3. 해당 스페이스의 공지사항 get - List noticeInfoForHome = postService.getNoticeInfoForHome(spaceId); - - // TODO 4. return - return new BaseResponse<>(new GetSpaceHomeDto.Response( - spaceInfoForHome.getSpaceName(), - spaceInfoForHome.getSpaceProfileImg(), - payRequestInfoForUser, - payReceiveInfoForUser, - noticeInfoForHome, - spaceInfoForHome.getMemberNum(), - userAuth - )); - } +// /** +// * 스페이스 홈 화면 +// */ +// @GetMapping("/{spaceId}") +// public BaseResponse showSpaceHome(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @UserSpaceId Long userSpaceId, @UserSpaceAuth String userAuth) { +// log.info("userId = {}, spaceId = {}, userSpaceID = {}, userAuth = {}", userId, spaceId, userSpaceId, userAuth); +// +// // TODO 1. 스페이스 정보 get +// GetSpaceHomeDto.SpaceInfoForHome spaceInfoForHome = spaceService.getSpaceInfoForHome(spaceId); +// +// // TODO 2. 해당 스페이스에서의 유저 정산 정보 get +// // 유저가 요청한 정산 중 현재 진행중인 정산 리스트 +// // AND +// // 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 +// List payRequestInfoForUser = payService.getPayRequestInfoForUser(userId, spaceId, false); +// List payReceiveInfoForUser = payService.getPayReceiveInfoForUser(userId, spaceId, false); +// +// // TODO 3. 해당 스페이스의 공지사항 get +// List noticeInfoForHome = postService.getNoticeInfoForHome(spaceId); +// +// // TODO 4. return +// return new BaseResponse<>(new GetSpaceHomeDto.Response( +// spaceInfoForHome.getSpaceName(), +// spaceInfoForHome.getSpaceProfileImg(), +// payRequestInfoForUser, +// payReceiveInfoForUser, +// noticeInfoForHome, +// spaceInfoForHome.getMemberNum(), +// userAuth +// )); +// } } diff --git a/src/main/java/space/space_spring/dto/space/GetSpaceHomeDto.java b/src/main/java/space/space_spring/domain/space/model/dto/GetSpaceHomeDto.java similarity index 95% rename from src/main/java/space/space_spring/dto/space/GetSpaceHomeDto.java rename to src/main/java/space/space_spring/domain/space/model/dto/GetSpaceHomeDto.java index 8d656790..6ca34c31 100644 --- a/src/main/java/space/space_spring/dto/space/GetSpaceHomeDto.java +++ b/src/main/java/space/space_spring/domain/space/model/dto/GetSpaceHomeDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.space; +package space.space_spring.domain.space.model.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/dto/space/GetSpaceJoinDto.java b/src/main/java/space/space_spring/domain/space/model/dto/GetSpaceJoinDto.java similarity index 90% rename from src/main/java/space/space_spring/dto/space/GetSpaceJoinDto.java rename to src/main/java/space/space_spring/domain/space/model/dto/GetSpaceJoinDto.java index 0e335fa6..8a87a6f2 100644 --- a/src/main/java/space/space_spring/dto/space/GetSpaceJoinDto.java +++ b/src/main/java/space/space_spring/domain/space/model/dto/GetSpaceJoinDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.space; +package space.space_spring.domain.space.model.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/dto/space/PostSpaceJoinDto.java b/src/main/java/space/space_spring/domain/space/model/dto/PostSpaceJoinDto.java similarity index 95% rename from src/main/java/space/space_spring/dto/space/PostSpaceJoinDto.java rename to src/main/java/space/space_spring/domain/space/model/dto/PostSpaceJoinDto.java index 8a45f70b..e661c524 100644 --- a/src/main/java/space/space_spring/dto/space/PostSpaceJoinDto.java +++ b/src/main/java/space/space_spring/domain/space/model/dto/PostSpaceJoinDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.space; +package space.space_spring.domain.space.model.dto; import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotBlank; diff --git a/src/main/java/space/space_spring/entity/Space.java b/src/main/java/space/space_spring/domain/space/model/entity/Space.java similarity index 79% rename from src/main/java/space/space_spring/entity/Space.java rename to src/main/java/space/space_spring/domain/space/model/entity/Space.java index 8e2eb9b2..55769e7a 100644 --- a/src/main/java/space/space_spring/entity/Space.java +++ b/src/main/java/space/space_spring/domain/space/model/entity/Space.java @@ -1,10 +1,11 @@ -package space.space_spring.entity; +package space.space_spring.domain.space.model.entity; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import space.space_spring.entity.BaseEntity; @Entity @Getter @@ -22,11 +23,6 @@ public class Space extends BaseEntity { @Column(name = "space_profile_img") private String spaceProfileImg; - public void saveSpace(String spaceName, String spaceProfileImg) { - this.spaceName = spaceName; - this.spaceProfileImg = spaceProfileImg; - initializeBaseEntityFields(); - } @Builder private Space(String spaceName, String spaceProfileImg) { diff --git a/src/main/java/space/space_spring/dto/space/request/PostSpaceCreateDto.java b/src/main/java/space/space_spring/domain/space/model/request/PostSpaceCreateDto.java similarity index 94% rename from src/main/java/space/space_spring/dto/space/request/PostSpaceCreateDto.java rename to src/main/java/space/space_spring/domain/space/model/request/PostSpaceCreateDto.java index de71436d..2698bcda 100644 --- a/src/main/java/space/space_spring/dto/space/request/PostSpaceCreateDto.java +++ b/src/main/java/space/space_spring/domain/space/model/request/PostSpaceCreateDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.space.request; +package space.space_spring.domain.space.model.request; import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotBlank; diff --git a/src/main/java/space/space_spring/dto/space/response/GetUserInfoBySpaceResponse.java b/src/main/java/space/space_spring/domain/space/model/response/GetUserInfoBySpaceResponse.java similarity index 67% rename from src/main/java/space/space_spring/dto/space/response/GetUserInfoBySpaceResponse.java rename to src/main/java/space/space_spring/domain/space/model/response/GetUserInfoBySpaceResponse.java index 726d158e..53941f84 100644 --- a/src/main/java/space/space_spring/dto/space/response/GetUserInfoBySpaceResponse.java +++ b/src/main/java/space/space_spring/domain/space/model/response/GetUserInfoBySpaceResponse.java @@ -1,8 +1,8 @@ -package space.space_spring.dto.space.response; +package space.space_spring.domain.space.model.response; import lombok.AllArgsConstructor; import lombok.Getter; -import space.space_spring.dto.userSpace.UserInfoInSpace; +import space.space_spring.domain.userSpace.model.UserInfoInSpace; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/space/space_spring/dao/SpaceDao.java b/src/main/java/space/space_spring/domain/space/repository/SpaceDao.java similarity index 80% rename from src/main/java/space/space_spring/dao/SpaceDao.java rename to src/main/java/space/space_spring/domain/space/repository/SpaceDao.java index dbe95f55..65fc3d29 100644 --- a/src/main/java/space/space_spring/dao/SpaceDao.java +++ b/src/main/java/space/space_spring/domain/space/repository/SpaceDao.java @@ -1,10 +1,9 @@ -package space.space_spring.dao; +package space.space_spring.domain.space.repository; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import org.springframework.stereotype.Repository; -import space.space_spring.dto.space.GetSpaceJoinDto; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; @Repository public class SpaceDao { diff --git a/src/main/java/space/space_spring/dao/SpaceRepository.java b/src/main/java/space/space_spring/domain/space/repository/SpaceRepository.java similarity index 78% rename from src/main/java/space/space_spring/dao/SpaceRepository.java rename to src/main/java/space/space_spring/domain/space/repository/SpaceRepository.java index 3eee1c63..a5eec095 100644 --- a/src/main/java/space/space_spring/dao/SpaceRepository.java +++ b/src/main/java/space/space_spring/domain/space/repository/SpaceRepository.java @@ -1,9 +1,9 @@ -package space.space_spring.dao; +package space.space_spring.domain.space.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import java.util.Optional; diff --git a/src/main/java/space/space_spring/service/SpaceService.java b/src/main/java/space/space_spring/domain/space/service/SpaceService.java similarity index 89% rename from src/main/java/space/space_spring/service/SpaceService.java rename to src/main/java/space/space_spring/domain/space/service/SpaceService.java index 48138291..0a037d6b 100644 --- a/src/main/java/space/space_spring/service/SpaceService.java +++ b/src/main/java/space/space_spring/domain/space/service/SpaceService.java @@ -1,20 +1,20 @@ -package space.space_spring.service; +package space.space_spring.domain.space.service; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import space.space_spring.dao.SpaceDao; +import space.space_spring.domain.space.repository.SpaceDao; import space.space_spring.domain.user.repository.UserDao; -import space.space_spring.dao.UserSpaceDao; -import space.space_spring.dto.space.GetSpaceHomeDto; -import space.space_spring.dto.space.GetSpaceJoinDto; -import space.space_spring.dto.space.PostSpaceJoinDto; -import space.space_spring.dto.space.response.GetUserInfoBySpaceResponse; -import space.space_spring.dto.userSpace.GetUserProfileInSpaceDto; -import space.space_spring.dto.userSpace.PutUserProfileInSpaceDto; -import space.space_spring.entity.Space; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; +import space.space_spring.domain.space.model.dto.GetSpaceHomeDto; +import space.space_spring.domain.space.model.dto.GetSpaceJoinDto; +import space.space_spring.domain.space.model.dto.PostSpaceJoinDto; +import space.space_spring.domain.space.model.response.GetUserInfoBySpaceResponse; +import space.space_spring.domain.userSpace.model.GetUserProfileInSpaceDto; +import space.space_spring.domain.userSpace.model.PutUserProfileInSpaceDto; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSpaceAuth; import space.space_spring.exception.CustomException; import space.space_spring.util.space.SpaceUtils; diff --git a/src/main/java/space/space_spring/domain/user/service/UserService.java b/src/main/java/space/space_spring/domain/user/service/UserService.java index 76ee0d76..2052d00c 100644 --- a/src/main/java/space/space_spring/domain/user/service/UserService.java +++ b/src/main/java/space/space_spring/domain/user/service/UserService.java @@ -5,12 +5,12 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import space.space_spring.dao.UserSpaceDao; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; import space.space_spring.domain.user.model.GetUserProfileListDto; import space.space_spring.domain.user.model.dto.SpaceChoiceViewDto; import space.space_spring.domain.user.model.request.PostUserSignupRequest; import space.space_spring.domain.user.model.response.GetSpaceInfoForUserResponse; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSignupType; import space.space_spring.exception.CustomException; import space.space_spring.domain.user.repository.UserDao; diff --git a/src/main/java/space/space_spring/dto/userSpace/GetUserProfileInSpaceDto.java b/src/main/java/space/space_spring/domain/userSpace/model/GetUserProfileInSpaceDto.java similarity index 77% rename from src/main/java/space/space_spring/dto/userSpace/GetUserProfileInSpaceDto.java rename to src/main/java/space/space_spring/domain/userSpace/model/GetUserProfileInSpaceDto.java index fc9673fd..beb74e8c 100644 --- a/src/main/java/space/space_spring/dto/userSpace/GetUserProfileInSpaceDto.java +++ b/src/main/java/space/space_spring/domain/userSpace/model/GetUserProfileInSpaceDto.java @@ -1,6 +1,5 @@ -package space.space_spring.dto.userSpace; +package space.space_spring.domain.userSpace.model; -import com.amazonaws.services.ec2.model.CpuOptionsRequest; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/dto/userSpace/PutUserProfileInSpaceDto.java b/src/main/java/space/space_spring/domain/userSpace/model/PutUserProfileInSpaceDto.java similarity index 96% rename from src/main/java/space/space_spring/dto/userSpace/PutUserProfileInSpaceDto.java rename to src/main/java/space/space_spring/domain/userSpace/model/PutUserProfileInSpaceDto.java index 6e50c459..9123043d 100644 --- a/src/main/java/space/space_spring/dto/userSpace/PutUserProfileInSpaceDto.java +++ b/src/main/java/space/space_spring/domain/userSpace/model/PutUserProfileInSpaceDto.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.userSpace; +package space.space_spring.domain.userSpace.model; import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotBlank; diff --git a/src/main/java/space/space_spring/dto/userSpace/UserInfoInSpace.java b/src/main/java/space/space_spring/domain/userSpace/model/UserInfoInSpace.java similarity index 86% rename from src/main/java/space/space_spring/dto/userSpace/UserInfoInSpace.java rename to src/main/java/space/space_spring/domain/userSpace/model/UserInfoInSpace.java index 865007d2..a94719fb 100644 --- a/src/main/java/space/space_spring/dto/userSpace/UserInfoInSpace.java +++ b/src/main/java/space/space_spring/domain/userSpace/model/UserInfoInSpace.java @@ -1,4 +1,4 @@ -package space.space_spring.dto.userSpace; +package space.space_spring.domain.userSpace.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/space/space_spring/entity/UserSpace.java b/src/main/java/space/space_spring/domain/userSpace/model/entity/UserSpace.java similarity index 72% rename from src/main/java/space/space_spring/entity/UserSpace.java rename to src/main/java/space/space_spring/domain/userSpace/model/entity/UserSpace.java index e2e04105..5b34ed7c 100644 --- a/src/main/java/space/space_spring/entity/UserSpace.java +++ b/src/main/java/space/space_spring/domain/userSpace/model/entity/UserSpace.java @@ -1,14 +1,20 @@ -package space.space_spring.entity; +package space.space_spring.domain.userSpace.model.entity; import jakarta.annotation.Nullable; import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; +import space.space_spring.entity.BaseEntity; import space.space_spring.entity.enumStatus.UserSpaceAuth; @Entity @Getter @Table(name = "User_Space") +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class UserSpace extends BaseEntity { @Id @GeneratedValue @@ -42,13 +48,23 @@ public class UserSpace extends BaseEntity { @Column(name = "space_order") private int spaceOrder; - public void createUserSpace(User user, Space space, UserSpaceAuth userSpaceAuth) { + + @Builder + private UserSpace(User user, Space space, UserSpaceAuth userSpaceAuth) { this.user = user; this.space = space; this.userName = user.getUserName(); this.userSpaceAuth = userSpaceAuth.getAuth(); } + public static UserSpace create(User user, Space space, UserSpaceAuth userSpaceAuth) { + return UserSpace.builder() + .user(user) + .space(space) + .userSpaceAuth(userSpaceAuth) + .build(); + } + public void changeUserName(String userName) { this.userName = userName; } diff --git a/src/main/java/space/space_spring/dao/UserSpaceDao.java b/src/main/java/space/space_spring/domain/userSpace/repository/UserSpaceDao.java similarity index 94% rename from src/main/java/space/space_spring/dao/UserSpaceDao.java rename to src/main/java/space/space_spring/domain/userSpace/repository/UserSpaceDao.java index 90092d77..80ac48ed 100644 --- a/src/main/java/space/space_spring/dao/UserSpaceDao.java +++ b/src/main/java/space/space_spring/domain/userSpace/repository/UserSpaceDao.java @@ -1,4 +1,4 @@ -package space.space_spring.dao; +package space.space_spring.domain.userSpace.repository; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; @@ -7,10 +7,10 @@ import org.springframework.transaction.annotation.Transactional; import space.space_spring.domain.user.model.dto.SpaceChoiceInfo; import space.space_spring.domain.user.model.dto.SpaceChoiceViewDto; -import space.space_spring.dto.userSpace.UserInfoInSpace; -import space.space_spring.entity.Space; +import space.space_spring.domain.userSpace.model.UserInfoInSpace; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSpaceAuth; import java.util.*; @@ -22,8 +22,7 @@ public class UserSpaceDao { private EntityManager em; public UserSpace createUserSpace(User manager, Space saveSpace, UserSpaceAuth userSpaceAuth) { - UserSpace userSpace = new UserSpace(); - userSpace.createUserSpace(manager, saveSpace, userSpaceAuth); + UserSpace userSpace = UserSpace.create(manager, saveSpace, userSpaceAuth); em.persist(userSpace); return userSpace; diff --git a/src/main/java/space/space_spring/dao/UserSpaceRepository.java b/src/main/java/space/space_spring/domain/userSpace/repository/UserSpaceRepository.java similarity index 78% rename from src/main/java/space/space_spring/dao/UserSpaceRepository.java rename to src/main/java/space/space_spring/domain/userSpace/repository/UserSpaceRepository.java index e6e64b68..d4eb79d1 100644 --- a/src/main/java/space/space_spring/dao/UserSpaceRepository.java +++ b/src/main/java/space/space_spring/domain/userSpace/repository/UserSpaceRepository.java @@ -1,12 +1,10 @@ -package space.space_spring.dao; +package space.space_spring.domain.userSpace.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import space.space_spring.entity.UserSpace; -import space.space_spring.entity.VoiceRoom; +import space.space_spring.domain.userSpace.model.entity.UserSpace; -import java.util.List; import java.util.Optional; public interface UserSpaceRepository extends JpaRepository { diff --git a/src/main/java/space/space_spring/dto/chat/response/ReadChatRoomMemberResponse.java b/src/main/java/space/space_spring/dto/chat/response/ReadChatRoomMemberResponse.java index 926af0dd..6f0f7c06 100644 --- a/src/main/java/space/space_spring/dto/chat/response/ReadChatRoomMemberResponse.java +++ b/src/main/java/space/space_spring/dto/chat/response/ReadChatRoomMemberResponse.java @@ -2,7 +2,7 @@ import lombok.Builder; import lombok.Getter; -import space.space_spring.dto.userSpace.UserInfoInSpace; +import space.space_spring.domain.userSpace.model.UserInfoInSpace; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/space/space_spring/dto/comment/response/ReadCommentsResponse.java b/src/main/java/space/space_spring/dto/comment/response/ReadCommentsResponse.java index 0ada6021..21de9916 100644 --- a/src/main/java/space/space_spring/dto/comment/response/ReadCommentsResponse.java +++ b/src/main/java/space/space_spring/dto/comment/response/ReadCommentsResponse.java @@ -2,7 +2,7 @@ import lombok.*; import space.space_spring.entity.Comment; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.util.post.ConvertCreatedDate; @Builder diff --git a/src/main/java/space/space_spring/dto/post/request/CreatePostRequest.java b/src/main/java/space/space_spring/dto/post/request/CreatePostRequest.java index 17b1ae07..aa08c3ab 100644 --- a/src/main/java/space/space_spring/dto/post/request/CreatePostRequest.java +++ b/src/main/java/space/space_spring/dto/post/request/CreatePostRequest.java @@ -4,7 +4,7 @@ import org.springframework.web.multipart.MultipartFile; import space.space_spring.entity.Post; import space.space_spring.entity.PostImage; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; import java.util.List; diff --git a/src/main/java/space/space_spring/dto/post/response/ReadPostDetailResponse.java b/src/main/java/space/space_spring/dto/post/response/ReadPostDetailResponse.java index 49540c3c..c37462e8 100644 --- a/src/main/java/space/space_spring/dto/post/response/ReadPostDetailResponse.java +++ b/src/main/java/space/space_spring/dto/post/response/ReadPostDetailResponse.java @@ -4,7 +4,7 @@ import space.space_spring.dto.comment.response.ReadCommentsResponse; import space.space_spring.entity.Post; import space.space_spring.entity.PostImage; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.util.post.ConvertCreatedDate; import java.util.List; diff --git a/src/main/java/space/space_spring/dto/post/response/ReadPostsResponse.java b/src/main/java/space/space_spring/dto/post/response/ReadPostsResponse.java index 4641ca86..0ff1bf76 100644 --- a/src/main/java/space/space_spring/dto/post/response/ReadPostsResponse.java +++ b/src/main/java/space/space_spring/dto/post/response/ReadPostsResponse.java @@ -3,7 +3,7 @@ import lombok.*; import space.space_spring.entity.Post; import space.space_spring.entity.PostImage; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.util.post.ConvertCreatedDate; import java.util.List; diff --git a/src/main/java/space/space_spring/entity/ChatRoom.java b/src/main/java/space/space_spring/entity/ChatRoom.java index 87107e81..aca0fa99 100644 --- a/src/main/java/space/space_spring/entity/ChatRoom.java +++ b/src/main/java/space/space_spring/entity/ChatRoom.java @@ -7,9 +7,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.Comment; - -import java.time.LocalDateTime; -import java.time.ZoneId; +import space.space_spring.domain.space.model.entity.Space; @Entity @Getter diff --git a/src/main/java/space/space_spring/entity/Post.java b/src/main/java/space/space_spring/entity/Post.java index fc23b1c1..43db56cf 100644 --- a/src/main/java/space/space_spring/entity/Post.java +++ b/src/main/java/space/space_spring/entity/Post.java @@ -4,6 +4,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; import java.util.List; diff --git a/src/main/java/space/space_spring/entity/VoiceRoom.java b/src/main/java/space/space_spring/entity/VoiceRoom.java index 2472dd92..df707c1f 100644 --- a/src/main/java/space/space_spring/entity/VoiceRoom.java +++ b/src/main/java/space/space_spring/entity/VoiceRoom.java @@ -1,11 +1,10 @@ package space.space_spring.entity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import space.space_spring.dto.VoiceRoom.GetVoiceRoomList; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.dto.VoiceRoom.RoomDto; @Entity @@ -35,7 +34,7 @@ public VoiceRoom(String name,int order,Space space){ this.order = order; this.space = space; } - public static VoiceRoom createVoiceRoom(String name,int order,Space space){ + public static VoiceRoom createVoiceRoom(String name, int order, Space space){ VoiceRoom voiceRoom= VoiceRoom.builder() .name(name) .order(order) diff --git a/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java b/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java index 9fe94cd2..2eea716d 100644 --- a/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java +++ b/src/main/java/space/space_spring/interceptor/UserSpaceValidationInterceptor.java @@ -8,12 +8,12 @@ import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerMapping; import space.space_spring.argumentResolver.userSpace.CheckUserSpace; -import space.space_spring.dao.SpaceDao; +import space.space_spring.domain.space.repository.SpaceDao; import space.space_spring.domain.user.repository.UserDao; -import space.space_spring.dao.UserSpaceDao; -import space.space_spring.entity.Space; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.exception.CustomException; import java.util.Map; diff --git a/src/main/java/space/space_spring/service/ChatRoomService.java b/src/main/java/space/space_spring/service/ChatRoomService.java index fc4a8271..ce59d85f 100644 --- a/src/main/java/space/space_spring/service/ChatRoomService.java +++ b/src/main/java/space/space_spring/service/ChatRoomService.java @@ -4,16 +4,18 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import space.space_spring.dao.UserSpaceDao; +import space.space_spring.domain.userSpace.model.entity.UserSpace; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; import space.space_spring.dao.chat.ChatRoomRepository; import space.space_spring.dao.chat.ChattingRepository; import space.space_spring.dao.chat.UserChatRoomRepository; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; import space.space_spring.dto.chat.dto.LastMessageInfoDto; import space.space_spring.dto.chat.request.JoinChatRoomRequest; import space.space_spring.dto.chat.response.*; import space.space_spring.dto.chat.request.CreateChatRoomRequest; -import space.space_spring.dto.userSpace.UserInfoInSpace; +import space.space_spring.domain.userSpace.model.UserInfoInSpace; import space.space_spring.entity.*; import space.space_spring.entity.document.ChatMessage; diff --git a/src/main/java/space/space_spring/service/ChattingService.java b/src/main/java/space/space_spring/service/ChattingService.java index 25d4b81f..2a83d4ad 100644 --- a/src/main/java/space/space_spring/service/ChattingService.java +++ b/src/main/java/space/space_spring/service/ChattingService.java @@ -7,7 +7,7 @@ import space.space_spring.dto.chat.request.ChatMessageRequest; import space.space_spring.dto.chat.response.ChatMessageLogResponse; import space.space_spring.dto.chat.response.ChatMessageResponse; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.entity.document.ChatMessage; import space.space_spring.entity.enumStatus.ChatMessageType; import space.space_spring.exception.CustomException; diff --git a/src/main/java/space/space_spring/service/CommentService.java b/src/main/java/space/space_spring/service/CommentService.java index b1701a2f..eba3b079 100644 --- a/src/main/java/space/space_spring/service/CommentService.java +++ b/src/main/java/space/space_spring/service/CommentService.java @@ -6,13 +6,13 @@ import org.springframework.stereotype.Service; import space.space_spring.dao.CommentDao; import space.space_spring.dao.PostDao; -import space.space_spring.dao.UserSpaceDao; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; import space.space_spring.dto.comment.request.CreateCommentRequest; import space.space_spring.dto.comment.response.ReadCommentsResponse; import space.space_spring.entity.Post; import space.space_spring.entity.Comment; import space.space_spring.domain.user.model.entity.User; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.exception.CustomException; import space.space_spring.util.user.UserUtils; import space.space_spring.util.userSpace.UserSpaceUtils; diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java index 47953599..f2921a2f 100644 --- a/src/main/java/space/space_spring/service/PostService.java +++ b/src/main/java/space/space_spring/service/PostService.java @@ -7,13 +7,15 @@ import org.springframework.stereotype.Service; import space.space_spring.dao.CommentDao; import space.space_spring.dao.PostDao; -import space.space_spring.dao.UserSpaceDao; +import space.space_spring.domain.userSpace.model.entity.UserSpace; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; import space.space_spring.dto.comment.response.ReadCommentsResponse; import space.space_spring.dto.post.request.CreatePostRequest; import space.space_spring.dto.post.response.ReadPostDetailResponse; import space.space_spring.dto.post.response.ReadPostsResponse; -import space.space_spring.dto.space.GetSpaceHomeDto; +import space.space_spring.domain.space.model.dto.GetSpaceHomeDto; import space.space_spring.entity.*; import space.space_spring.exception.CustomException; import space.space_spring.util.space.SpaceUtils; diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index 133fe6a6..92158e63 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -6,11 +6,11 @@ import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; import space.space_spring.domain.user.repository.UserDao; -import space.space_spring.dao.UserSpaceDao; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; import space.space_spring.dao.VoiceRoomDao; import space.space_spring.dao.VoiceRoomRepository; import space.space_spring.dto.VoiceRoom.*; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.VoiceRoom; import space.space_spring.util.LiveKitUtils; diff --git a/src/main/java/space/space_spring/util/space/SpaceUtils.java b/src/main/java/space/space_spring/util/space/SpaceUtils.java index d050e09b..06749902 100644 --- a/src/main/java/space/space_spring/util/space/SpaceUtils.java +++ b/src/main/java/space/space_spring/util/space/SpaceUtils.java @@ -3,8 +3,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import space.space_spring.dao.SpaceDao; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.repository.SpaceDao; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.exception.CustomException; import static space.space_spring.response.status.BaseExceptionResponseStatus.SPACE_NOT_FOUND; diff --git a/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java b/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java index 1ec0b953..bc44ed72 100644 --- a/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java +++ b/src/main/java/space/space_spring/util/userSpace/MemoryUserSpaceUtils.java @@ -3,12 +3,12 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import space.space_spring.dao.SpaceDao; +import space.space_spring.domain.space.repository.SpaceDao; import space.space_spring.domain.user.repository.UserDao; -import space.space_spring.dao.UserSpaceDao; -import space.space_spring.entity.Space; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.model.entity.User; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSpaceAuth; import space.space_spring.exception.CustomException; diff --git a/src/main/java/space/space_spring/util/userSpace/UserSpaceUtils.java b/src/main/java/space/space_spring/util/userSpace/UserSpaceUtils.java index 28dfef47..9187cc01 100644 --- a/src/main/java/space/space_spring/util/userSpace/UserSpaceUtils.java +++ b/src/main/java/space/space_spring/util/userSpace/UserSpaceUtils.java @@ -1,6 +1,6 @@ package space.space_spring.util.userSpace; -import space.space_spring.entity.UserSpace; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import java.util.Optional; diff --git a/src/test/java/space/space_spring/concurrency/completableFutureTest.java b/src/test/java/space/space_spring/concurrency/completableFutureTest.java index db951e46..27319e9c 100644 --- a/src/test/java/space/space_spring/concurrency/completableFutureTest.java +++ b/src/test/java/space/space_spring/concurrency/completableFutureTest.java @@ -1,26 +1,12 @@ package space.space_spring.concurrency; -import livekit.LivekitModels; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import space.space_spring.dao.VoiceRoomRepository; -import space.space_spring.dto.VoiceRoom.RoomDto; -import space.space_spring.entity.Space; -import space.space_spring.entity.VoiceRoom; -import org.mockito.Mock; -import org.mockito.InjectMocks; -import space.space_spring.util.LiveKitUtils; -import space.space_spring.util.space.SpaceUtils; - -import java.util.ArrayList; + import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; -import static org.mockito.Mockito.when; - public class completableFutureTest { @Test diff --git a/src/test/java/space/space_spring/controller/ChatRoomControllerTest.java b/src/test/java/space/space_spring/controller/ChatRoomControllerTest.java index 6d1c244b..91e631d1 100644 --- a/src/test/java/space/space_spring/controller/ChatRoomControllerTest.java +++ b/src/test/java/space/space_spring/controller/ChatRoomControllerTest.java @@ -20,7 +20,7 @@ import space.space_spring.dto.chat.request.CreateChatRoomRequest; import space.space_spring.dto.chat.request.JoinChatRoomRequest; import space.space_spring.dto.chat.response.*; -import space.space_spring.dto.userSpace.UserInfoInSpace; +import space.space_spring.domain.userSpace.model.UserInfoInSpace; import space.space_spring.interceptor.UserSpaceValidationInterceptor; import space.space_spring.interceptor.jwtLogin.JwtLoginAuthInterceptor; import space.space_spring.service.ChatRoomService; diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index 44c2ecee..45551f69 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -1,7 +1,5 @@ package space.space_spring.domain.pay.service; -import ch.qos.logback.core.testUtil.XTeeOutputStream; -import jakarta.persistence.Entity; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -10,23 +8,31 @@ import org.springframework.context.annotation.Import; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.test.context.ActiveProfiles; -import space.space_spring.dao.SpaceRepository; +import space.space_spring.domain.space.repository.SpaceRepository; +import space.space_spring.domain.userSpace.repository.UserSpaceRepository; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import space.space_spring.domain.pay.model.entity.PayRequest; import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.pay.model.response.PayHomeViewResponse; import space.space_spring.domain.pay.repository.PayRequestRepository; import space.space_spring.domain.pay.repository.PayRequestTargetRepository; import space.space_spring.domain.user.model.entity.User; import space.space_spring.domain.user.repository.UserRepository; -import space.space_spring.entity.Space; +import space.space_spring.domain.space.model.entity.Space; +import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSignupType; +import space.space_spring.entity.enumStatus.UserSpaceAuth; -import static org.junit.jupiter.api.Assertions.*; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; @DataJpaTest @Import({PayService.class}) @ActiveProfiles("test") -@EnableJpaRepositories(basePackageClasses = {PayRequestRepository.class, PayRequestTargetRepository.class, UserRepository.class, SpaceRepository.class}) -@EntityScan(basePackageClasses = {PayRequest.class, PayRequestTarget.class, User.class, Space.class}) +@EnableJpaRepositories(basePackageClasses = {PayRequestRepository.class, PayRequestTargetRepository.class, UserRepository.class, SpaceRepository.class, UserSpaceRepository.class}) +@EntityScan(basePackageClasses = {PayRequest.class, PayRequestTarget.class, User.class, Space.class, UserSpace.class}) class PayServiceTest { @Autowired @@ -44,21 +50,52 @@ class PayServiceTest { @Autowired private SpaceRepository spaceRepository; + @Autowired + private UserSpaceRepository userSpaceRepository; + @Test - @DisplayName("유저가 요청한 정산 중, 현재 진행 중인 정산 정보들과 유저가 요청받은 정산 중, 현재 진행 중인 정산 정보들을 return 한다.") + @DisplayName("유저가 요청한 정산 중, 현재 진행 중인 정산 정보들을 return 한다.") void getPayHomeInfos() throws Exception { //given - User user = User.create("email", "password", "name", UserSignupType.LOCAL); + User user1 = User.create("email", "password", "name", UserSignupType.LOCAL); + User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); + User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); Space space = Space.create("space", "profileImg"); - User testUser = userRepository.save(user); + User testUser1 = userRepository.save(user1); + User testUser2 = userRepository.save(user2); + User testUser3 = userRepository.save(user3); Space testSpace = spaceRepository.save(space); + UserSpace userSpace = UserSpace.create(testUser1, testSpace, UserSpaceAuth.NORMAL); + userSpaceRepository.save(userSpace); + + PayRequest inCompletePay = PayRequest.create(testUser1, testSpace, 20000, "bank", "accountNum", 20000, false); + PayRequest completePay = PayRequest.create(testUser1, testSpace, 20000, "bank", "accountNum", 20000, true); + + PayRequestTarget inCompleteTarget1 = PayRequestTarget.create(inCompletePay, testUser2.getUserId(), 10000, false); + PayRequestTarget inCompleteTarget2 = PayRequestTarget.create(inCompletePay, testUser3.getUserId(), 10000, false); + PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, testUser2.getUserId(), 10000, true); + PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, testUser3.getUserId(), 10000, true); + + payRequestRepository.save(inCompletePay); + payRequestRepository.save(completePay); + payRequestTargetRepository.save(inCompleteTarget1); + payRequestTargetRepository.save(inCompleteTarget2); + payRequestTargetRepository.save(completeTarget1); + payRequestTargetRepository.save(completeTarget2); //when + PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(testUser1.getUserId(), testSpace.getSpaceId()); + List payRequestInfos = payHomeInfos.getPayRequestInfoDtoList(); //then + assertThat(payRequestInfos).hasSize(1) + .extracting("totalAmount", "receiveAmount", "totalTargetNum", "receiveTargetNum") + .containsExactlyInAnyOrder( + tuple(20000, 0, 2, 0) + ); } } \ No newline at end of file diff --git a/src/test/java/space/space_spring/repository/ChatRoomRepositoryTest.java b/src/test/java/space/space_spring/repository/ChatRoomRepositoryTest.java index 4f8fdceb..1903647a 100644 --- a/src/test/java/space/space_spring/repository/ChatRoomRepositoryTest.java +++ b/src/test/java/space/space_spring/repository/ChatRoomRepositoryTest.java @@ -1,103 +1,103 @@ -package space.space_spring.repository; - -import org.junit.jupiter.api.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.context.annotation.Import; -import space.space_spring.config.QueryDslConfig; -import space.space_spring.dao.chat.ChatRoomRepository; -import space.space_spring.dao.chat.UserChatRoomRepository; -import space.space_spring.entity.ChatRoom; -import space.space_spring.entity.Space; -import space.space_spring.domain.user.model.entity.User; -import space.space_spring.entity.UserChatRoom; -import space.space_spring.entity.enumStatus.BaseStatusType; -import space.space_spring.entity.enumStatus.UserSignupType; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.*; - -@DataJpaTest -@Import({QueryDslConfig.class, QueryDslConfig.class}) -public class ChatRoomRepositoryTest { - - @Autowired - private ChatRoomRepository chatRoomRepository; - - @Autowired - private UserChatRoomRepository userChatRoomRepository; - - private Space testSpace; - - private ChatRoom testChatRoom1; - - private ChatRoom testChatRoom2; - - private User testUser; - - @BeforeEach - void 테스트_셋업() { - testUser = new User(); - - testUser.saveUser("testUser@test.com", "Asdf1234!", "testUser", UserSignupType.LOCAL); - - testSpace = new Space(); - - // testSpace에 속한 chatRoom 엔티티 생성 - testChatRoom1 = ChatRoom.of(testSpace, "testChatRoom1", ""); - testChatRoom2 = ChatRoom.of(testSpace, "testChatRoom2", ""); - } - - @Test - @DisplayName("채팅방_저장_테스트") - void 채팅방_저장_테스트() { - // given - - // when - ChatRoom savedTestChatRoom1 = chatRoomRepository.save(testChatRoom1); - ChatRoom savedTestChatRoom2 = chatRoomRepository.save(testChatRoom2); - - // then - assertThat(savedTestChatRoom1.getId()).isEqualTo(testChatRoom1.getId()); - assertThat(savedTestChatRoom2.getId()).isEqualTo(testChatRoom2.getId()); - } - - @Test - @DisplayName("id로_채팅방_조회_테스트") - void id로_채팅방_조회_테스트() { - // given - ChatRoom savedTestChatRoom1 = chatRoomRepository.save(testChatRoom1); - ChatRoom savedTestChatRoom2 = chatRoomRepository.save(testChatRoom2); - - // when - Optional chatRoom1byId = Optional.ofNullable( - chatRoomRepository.findByIdAndStatus(savedTestChatRoom1.getId(), BaseStatusType.ACTIVE)); - Optional chatRoom2byId = Optional.ofNullable( - chatRoomRepository.findByIdAndStatus(savedTestChatRoom2.getId(), BaseStatusType.ACTIVE)); - - // then - chatRoom1byId.ifPresent(chatRoom -> assertThat(chatRoom.getId()).isEqualTo(savedTestChatRoom1.getId())); - chatRoom2byId.ifPresent(chatRoom -> assertThat(chatRoom.getId()).isEqualTo(savedTestChatRoom2.getId())); - } - - @Test - @DisplayName("유저와_스페이스로_채팅방_조회_테스트") - void 유저와_스페이스로_채팅방_조회_테스트() { - // given - ChatRoom savedTestChatRoom1 = chatRoomRepository.save(testChatRoom1); - ChatRoom savedTestChatRoom2 = chatRoomRepository.save(testChatRoom2); - UserChatRoom userChatRoom1 = UserChatRoom.of(savedTestChatRoom1, testUser, LocalDateTime.now()); - UserChatRoom userChatRoom2 = UserChatRoom.of(savedTestChatRoom2, testUser, LocalDateTime.now()); - userChatRoomRepository.save(userChatRoom1); - userChatRoomRepository.save(userChatRoom2); - - // when - List chatRoomListByUser = chatRoomRepository.findByUserAndSpace(testUser, testSpace); - - // then - assertThat(chatRoomListByUser.size()).isEqualTo(2); - } -} +//package space.space_spring.repository; +// +//import org.junit.jupiter.api.*; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +//import org.springframework.context.annotation.Import; +//import space.space_spring.config.QueryDslConfig; +//import space.space_spring.dao.chat.ChatRoomRepository; +//import space.space_spring.dao.chat.UserChatRoomRepository; +//import space.space_spring.entity.ChatRoom; +//import space.space_spring.domain.space.model.entity.Space; +//import space.space_spring.domain.user.model.entity.User; +//import space.space_spring.entity.UserChatRoom; +//import space.space_spring.entity.enumStatus.BaseStatusType; +//import space.space_spring.entity.enumStatus.UserSignupType; +// +//import java.time.LocalDateTime; +//import java.util.List; +//import java.util.Optional; +// +//import static org.assertj.core.api.Assertions.*; +// +//@DataJpaTest +//@Import({QueryDslConfig.class, QueryDslConfig.class}) +//public class ChatRoomRepositoryTest { +// +// @Autowired +// private ChatRoomRepository chatRoomRepository; +// +// @Autowired +// private UserChatRoomRepository userChatRoomRepository; +// +// private Space testSpace; +// +// private ChatRoom testChatRoom1; +// +// private ChatRoom testChatRoom2; +// +// private User testUser; +// +// @BeforeEach +// void 테스트_셋업() { +// testUser = new User(); +// +// testUser.saveUser("testUser@test.com", "Asdf1234!", "testUser", UserSignupType.LOCAL); +// +// testSpace = new Space(); +// +// // testSpace에 속한 chatRoom 엔티티 생성 +// testChatRoom1 = ChatRoom.of(testSpace, "testChatRoom1", ""); +// testChatRoom2 = ChatRoom.of(testSpace, "testChatRoom2", ""); +// } +// +// @Test +// @DisplayName("채팅방_저장_테스트") +// void 채팅방_저장_테스트() { +// // given +// +// // when +// ChatRoom savedTestChatRoom1 = chatRoomRepository.save(testChatRoom1); +// ChatRoom savedTestChatRoom2 = chatRoomRepository.save(testChatRoom2); +// +// // then +// assertThat(savedTestChatRoom1.getId()).isEqualTo(testChatRoom1.getId()); +// assertThat(savedTestChatRoom2.getId()).isEqualTo(testChatRoom2.getId()); +// } +// +// @Test +// @DisplayName("id로_채팅방_조회_테스트") +// void id로_채팅방_조회_테스트() { +// // given +// ChatRoom savedTestChatRoom1 = chatRoomRepository.save(testChatRoom1); +// ChatRoom savedTestChatRoom2 = chatRoomRepository.save(testChatRoom2); +// +// // when +// Optional chatRoom1byId = Optional.ofNullable( +// chatRoomRepository.findByIdAndStatus(savedTestChatRoom1.getId(), BaseStatusType.ACTIVE)); +// Optional chatRoom2byId = Optional.ofNullable( +// chatRoomRepository.findByIdAndStatus(savedTestChatRoom2.getId(), BaseStatusType.ACTIVE)); +// +// // then +// chatRoom1byId.ifPresent(chatRoom -> assertThat(chatRoom.getId()).isEqualTo(savedTestChatRoom1.getId())); +// chatRoom2byId.ifPresent(chatRoom -> assertThat(chatRoom.getId()).isEqualTo(savedTestChatRoom2.getId())); +// } +// +// @Test +// @DisplayName("유저와_스페이스로_채팅방_조회_테스트") +// void 유저와_스페이스로_채팅방_조회_테스트() { +// // given +// ChatRoom savedTestChatRoom1 = chatRoomRepository.save(testChatRoom1); +// ChatRoom savedTestChatRoom2 = chatRoomRepository.save(testChatRoom2); +// UserChatRoom userChatRoom1 = UserChatRoom.of(savedTestChatRoom1, testUser, LocalDateTime.now()); +// UserChatRoom userChatRoom2 = UserChatRoom.of(savedTestChatRoom2, testUser, LocalDateTime.now()); +// userChatRoomRepository.save(userChatRoom1); +// userChatRoomRepository.save(userChatRoom2); +// +// // when +// List chatRoomListByUser = chatRoomRepository.findByUserAndSpace(testUser, testSpace); +// +// // then +// assertThat(chatRoomListByUser.size()).isEqualTo(2); +// } +//} diff --git a/src/test/java/space/space_spring/repository/UserChatRoomDaoTest.java b/src/test/java/space/space_spring/repository/UserChatRoomDaoTest.java index 686c391d..81f0472a 100644 --- a/src/test/java/space/space_spring/repository/UserChatRoomDaoTest.java +++ b/src/test/java/space/space_spring/repository/UserChatRoomDaoTest.java @@ -8,7 +8,7 @@ //import space.space_spring.dao.chat.ChatRoomDao; //import space.space_spring.dao.chat.UserChatRoomDao; //import space.space_spring.entity.ChatRoom; -//import space.space_spring.entity.Space; +//import space.space_spring.domain.space.model.entity.Space; //import space.space_spring.domain.user.model.entity.User; //import space.space_spring.entity.UserChatRoom; //import space.space_spring.entity.enumStatus.UserSignupType; diff --git a/src/test/java/space/space_spring/service/ChatRoomServiceTest.java b/src/test/java/space/space_spring/service/ChatRoomServiceTest.java index 3d6b18ce..0f2fda26 100644 --- a/src/test/java/space/space_spring/service/ChatRoomServiceTest.java +++ b/src/test/java/space/space_spring/service/ChatRoomServiceTest.java @@ -7,7 +7,7 @@ //import org.mockito.junit.jupiter.MockitoExtension; //import org.springframework.mock.web.MockMultipartFile; //import org.springframework.test.util.ReflectionTestUtils; -//import space.space_spring.dao.UserSpaceDao; +//import space.space_spring.domain.userSpace.repository.UserSpaceDao; //import space.space_spring.dao.chat.ChatRoomDao; //import space.space_spring.dao.chat.ChattingDao; //import space.space_spring.dao.chat.UserChatRoomDao; From 180222ade0cddb84993b26abc70364ee91b949a0 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sun, 10 Nov 2024 01:14:03 +0900 Subject: [PATCH 06/20] =?UTF-8?q?test=20:=20PayService.getPayHomeInfos()?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/controller/PayController.java | 4 +- .../pay/model/dto/PayReceiveInfoDto.java | 2 +- .../pay/model/dto/PayRequestInfoDto.java | 2 +- .../pay/model/dto/PayTargetInfoDto.java | 2 +- .../domain/pay/model/dto/TotalPayInfoDto.java | 2 +- .../domain/pay/model/entity/PayRequest.java | 40 ++----- .../pay/model/entity/PayRequestTarget.java | 20 ++-- .../model/request/PostPayCreateRequest.java | 4 +- .../domain/pay/repository/PayDao.java | 8 +- .../pay/repository/PayRequestRepository.java | 2 +- .../PayRequestTargetRepository.java | 7 +- .../domain/pay/service/PayService.java | 19 +-- .../domain/pay/service/PayServiceTest.java | 109 +++++++++++++++--- 13 files changed, 143 insertions(+), 78 deletions(-) diff --git a/src/main/java/space/space_spring/domain/pay/controller/PayController.java b/src/main/java/space/space_spring/domain/pay/controller/PayController.java index 88627fab..b057897e 100644 --- a/src/main/java/space/space_spring/domain/pay/controller/PayController.java +++ b/src/main/java/space/space_spring/domain/pay/controller/PayController.java @@ -149,10 +149,10 @@ public BaseResponse showPayHome(@JwtLoginAuth Long userId, // // private int validatePayAmount(PostPayCreateRequest postPayCreateRequest) { // -// // 1. requestAmount 들의 합이 totalAmount 와 일치하는지 확인 +// // 1. requestedAmount 들의 합이 totalAmount 와 일치하는지 확인 // // // 2-1. 만약 일치한다면 유효성 검사 통과 -// // 2-2. 만약 일치하지 않는다면, totalAmount와 requestAmount들의 합의 차이가 n-1보다 작거나 같은지 확인 +// // 2-2. 만약 일치하지 않는다면, totalAmount와 requestedAmount들의 합의 차이가 n-1보다 작거나 같은지 확인 // // // 3-1, 만약 n-1보다 작거나 같은 경우, 유효성 검사 통과 ('미정산 금액' 확인) // // 3-2, 만약 n-1보다 클 경우, 유효성 검사 통과 X (예외 처리) diff --git a/src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java index f0b45533..84408ce6 100644 --- a/src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java @@ -11,7 +11,7 @@ public class PayReceiveInfoDto { private String payCreatorName; - private int requestAmount; + private int requestedAmount; private String bankName; diff --git a/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java index 3b421060..b4fde2d0 100644 --- a/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java @@ -15,5 +15,5 @@ public class PayRequestInfoDto { private int totalTargetNum; // 정산 요청한 사람 수 - private int receiveTargetNum; // 그 중, 돈 보낸 사람 수 + private int paySendTargetNum; // 그 중, 돈 보낸 사람 수 } diff --git a/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java index a6408735..286f2949 100644 --- a/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java @@ -13,7 +13,7 @@ public class PayTargetInfoDto { private String targetUserProfileImg; - private int requestAmount; + private int requestedAmount; private boolean isComplete; } diff --git a/src/main/java/space/space_spring/domain/pay/model/dto/TotalPayInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/TotalPayInfoDto.java index fc7e0eef..e9618a7a 100644 --- a/src/main/java/space/space_spring/domain/pay/model/dto/TotalPayInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/TotalPayInfoDto.java @@ -23,7 +23,7 @@ public class TotalPayInfoDto { private int totalTargetNum; - private int receiveTargetNum; + private int paySendTargetNum; private List payTargetInfoDtoList = new ArrayList<>(); diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index 647e42bf..8a923648 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -41,70 +41,54 @@ public class PayRequest extends BaseEntity { @Column(name = "bank_account_num") private String bankAccountNum; // 정산 받을 은행 계좌번호 - @Column(name = "un_requested_amount") - private int unRequestedAmount; // 미정산 금액 + @Column(name = "received_amount") + private int receivedAmount; // 정산 받은 금액 @Column(name = "is_complete") private boolean isComplete; - @OneToMany(mappedBy = "payRequest") - private List payRequestTargets = new ArrayList<>(); - - public void savePayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum, int unRequestedAmount, boolean isComplete) { - this.payCreateUser = payCreateUser; - this.space = space; - this.totalAmount = totalAmount; - this.bankName = bankName; - this.bankAccountNum = bankAccountNum; - this.unRequestedAmount = unRequestedAmount; - this.isComplete = isComplete; - } public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } @Builder - private PayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum, int unRequestedAmount, boolean isComplete) { + private PayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum) { this.payCreateUser = payCreateUser; this.space = space; this.totalAmount = totalAmount; this.bankName = bankName; this.bankAccountNum = bankAccountNum; - this.unRequestedAmount = unRequestedAmount; - this.isComplete = isComplete; + this.receivedAmount = 0; + this.isComplete = false; } - public static PayRequest create(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum, int unRequestedAmount, boolean isComplete) { + public static PayRequest create(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum) { return PayRequest.builder() .payCreateUser(payCreateUser) .space(space) .totalAmount(totalAmount) .bankName(bankName) .bankAccountNum(bankAccountNum) - .unRequestedAmount(unRequestedAmount) - .isComplete(isComplete) .build(); } - public PayRequestInfoDto createPayRequestInfo() { - int totalAmount = this.totalAmount; - int receiveAmount = 0; + public PayRequestInfoDto createPayRequestInfo(List payRequestTargets) { int totalTargetNum = 0; - int receiveTargetNum = 0; + int paySendTargetNum = 0; - for (PayRequestTarget payRequestTarget : this.payRequestTargets) { + for (PayRequestTarget payRequestTarget : payRequestTargets) { if (payRequestTarget.isComplete()) { // 해당 타겟이 돈을 낸 경우 - receiveAmount += payRequestTarget.getRequestAmount(); - receiveTargetNum++; + paySendTargetNum++; } totalTargetNum++; } + // 빌더 패턴으로 변경 return new PayRequestInfoDto( - this.payRequestId, totalAmount, receiveAmount, totalTargetNum, receiveTargetNum + payRequestId, totalAmount, receivedAmount, totalTargetNum, paySendTargetNum ); } } diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index aa18e064..142f5dca 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -28,26 +28,25 @@ public class PayRequestTarget extends BaseEntity { // -> @OneToOne 어노테이션으로 User 엔티티 가지고 있는 방향 생각해볼것 @Column(name = "request_amount") - private int requestAmount; + private int requestedAmount; // 정산 요청받은 금액 @Column(name = "is_complete") private boolean isComplete; @Builder - private PayRequestTarget(PayRequest payRequest, Long targetUserId, int requestAmount, boolean isComplete) { + private PayRequestTarget(PayRequest payRequest, Long targetUserId, int requestedAmount) { this.payRequest = payRequest; this.targetUserId = targetUserId; - this.requestAmount = requestAmount; - this.isComplete = isComplete; + this.requestedAmount = requestedAmount; + this.isComplete = false; } - public static PayRequestTarget create(PayRequest payRequest, Long targetUserId, int requestAmount, boolean isComplete) { + public static PayRequestTarget create(PayRequest payRequest, Long targetUserId, int requestedAmount) { return PayRequestTarget.builder() .payRequest(payRequest) .targetUserId(targetUserId) - .requestAmount(requestAmount) - .isComplete(isComplete) + .requestedAmount(requestedAmount) .build(); } @@ -56,13 +55,14 @@ public void changeCompleteStatus(boolean isComplete) { } public PayReceiveInfoDto createPayReceiveInfo() { - String payCreatorName = payRequest.getPayCreateUser().getUserName(); // 리펙토링 필요 - int requestAmount = this.requestAmount; + String payCreatorName = payRequest.getPayCreateUser().getUserName(); // 이정도는 괜찮지 않나? + int requestedAmount = this.requestedAmount; // 정산 생성자가 요청한 은행 정보도 response에 추가 String bankName = payRequest.getBankName(); String bankAccountNum = payRequest.getBankAccountNum(); - return new PayReceiveInfoDto(this.payRequestTargetId, payCreatorName, requestAmount, bankName, bankAccountNum); + // 빌더패턴으로 변경 + return new PayReceiveInfoDto(payRequestTargetId, payCreatorName, requestedAmount, bankName, bankAccountNum); } } diff --git a/src/main/java/space/space_spring/domain/pay/model/request/PostPayCreateRequest.java b/src/main/java/space/space_spring/domain/pay/model/request/PostPayCreateRequest.java index d117385a..b6ae0411 100644 --- a/src/main/java/space/space_spring/domain/pay/model/request/PostPayCreateRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/request/PostPayCreateRequest.java @@ -28,7 +28,7 @@ public class PostPayCreateRequest { /** * PayRequestTarget 엔티티 생성 시 필요한 정보 - * 쌍 + * 쌍 */ private List targetInfoList = new ArrayList<>(); @@ -41,6 +41,6 @@ public static class TargetInfo { private Long targetUserId; @NotBlank(message = "정산 요청 금액은 공백일 수 없습니다.") - private int requestAmount; + private int requestedAmount; } } diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayDao.java b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java index bc7287e7..e31b0bd9 100644 --- a/src/main/java/space/space_spring/domain/pay/repository/PayDao.java +++ b/src/main/java/space/space_spring/domain/pay/repository/PayDao.java @@ -72,15 +72,15 @@ public List findRecentPayRequestBankInfoByUser(User .collect(Collectors.toList()); } - public PayRequest createPayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum, int unRequestedAmount, boolean isComplete) { - PayRequest payRequest = PayRequest.create(payCreateUser, space, totalAmount, bankName, bankAccountNum, unRequestedAmount, isComplete); + public PayRequest createPayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum) { + PayRequest payRequest = PayRequest.create(payCreateUser, space, totalAmount, bankName, bankAccountNum); em.persist(payRequest); return payRequest; } - public PayRequestTarget createPayRequestTarget(PayRequest payRequest, Long targetUserId, int requestAmount, boolean isComplete) { - PayRequestTarget payRequestTarget = PayRequestTarget.create(payRequest, targetUserId, requestAmount, isComplete); + public PayRequestTarget createPayRequestTarget(PayRequest payRequest, Long targetUserId, int requestedAmount) { + PayRequestTarget payRequestTarget = PayRequestTarget.create(payRequest, targetUserId, requestedAmount); em.persist(payRequestTarget); return payRequestTarget; diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java b/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java index da5c2074..d5ae2025 100644 --- a/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java +++ b/src/main/java/space/space_spring/domain/pay/repository/PayRequestRepository.java @@ -14,6 +14,6 @@ public interface PayRequestRepository extends JpaRepository { @Query("select pr from PayRequest pr where pr.payCreateUser = :user and pr.space = :space and pr.isComplete = :isComplete and pr.status = 'ACTIVE'") - List> findByUserAndSpace(User user, Space space, boolean isComplete); + List findAllByUserAndSpace(User user, Space space, boolean isComplete); } diff --git a/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java b/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java index 5af17058..830f9967 100644 --- a/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java +++ b/src/main/java/space/space_spring/domain/pay/repository/PayRequestTargetRepository.java @@ -3,6 +3,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import space.space_spring.domain.pay.model.entity.PayRequest; import space.space_spring.domain.pay.model.entity.PayRequestTarget; import space.space_spring.domain.space.model.entity.Space; @@ -12,8 +13,10 @@ @Repository public interface PayRequestTargetRepository extends JpaRepository { - @Query("select prt from PayRequestTarget prt where prt.targetUserId = :userId and prt.payRequest.space = :space and prt.payRequest.isComplete = :isComplete and prt.status = 'ACTIVE'") - List> findByUserAndSpace(Long userId, Space space, boolean isComplete); + @Query("select prt from PayRequestTarget prt where prt.targetUserId = :userId and prt.payRequest.space = :space and prt.isComplete = :isComplete and prt.status = 'ACTIVE'") + List findAllByUserAndSpace(Long userId, Space space, boolean isComplete); + @Query("select prt from PayRequestTarget prt where prt.payRequest = :payRequest and prt.status = 'ACTIVE'") + List findAllByPayRequest(PayRequest payRequest); } diff --git a/src/main/java/space/space_spring/domain/pay/service/PayService.java b/src/main/java/space/space_spring/domain/pay/service/PayService.java index b8d7349e..80c9abd0 100644 --- a/src/main/java/space/space_spring/domain/pay/service/PayService.java +++ b/src/main/java/space/space_spring/domain/pay/service/PayService.java @@ -41,20 +41,23 @@ public PayHomeViewResponse getPayHomeInfos(Long userId, Long spaceId) { // 유저가 스페이스에 속하는 지 검증하고, UserSpace userSpace = validateUserInSpace(userId, spaceId); - // 유저가 요청한 정산 중 현재 진행중인 정산 리스트 정보와 - List> payRequests = payRequestRepository.findByUserAndSpace(userSpace.getUser(), userSpace.getSpace(), INCOMPLETE_PAY); + // 유저가 요청한 정산들 중, 완료되지 않은 정산 리스트 정보와 + List payRequests = payRequestRepository.findAllByUserAndSpace(userSpace.getUser(), userSpace.getSpace(), INCOMPLETE_PAY); List payRequestInfoDtos = new ArrayList<>(); - for (Optional payRequest : payRequests) { - payRequest.ifPresent(request -> payRequestInfoDtos.add(request.createPayRequestInfo())); + for (PayRequest payRequest : payRequests) { + List findTargets = payRequestTargetRepository.findAllByPayRequest(payRequest); + PayRequestInfoDto payRequestInfo = payRequest.createPayRequestInfo(findTargets); + payRequestInfoDtos.add(payRequestInfo); } - // 유저가 요청받은 정산 중 현재 진행중인 정산 리스트를 찾아서 - List> payRequestTargets = payRequestTargetRepository.findByUserAndSpace(userSpace.getUser().getUserId(), userSpace.getSpace(), INCOMPLETE_PAY); + // 유저가 요청받은 정산들 중, 완료되지 않은 정산 리스트를 찾아서 + List payRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(userSpace.getUser().getUserId(), userSpace.getSpace(), INCOMPLETE_PAY); List payReceiveInfoDtos = new ArrayList<>(); - for (Optional payRequestTarget : payRequestTargets) { - payRequestTarget.ifPresent(requestTarget -> payReceiveInfoDtos.add(requestTarget.createPayReceiveInfo())); + for (PayRequestTarget payRequestTarget : payRequestTargets) { + PayReceiveInfoDto payReceiveInfo = payRequestTarget.createPayReceiveInfo(); + payReceiveInfoDtos.add(payReceiveInfo); } // return diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index 45551f69..2a079ca0 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -8,6 +8,7 @@ import org.springframework.context.annotation.Import; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.test.context.ActiveProfiles; +import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; import space.space_spring.domain.space.repository.SpaceRepository; import space.space_spring.domain.userSpace.repository.UserSpaceRepository; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; @@ -54,48 +55,122 @@ class PayServiceTest { private UserSpaceRepository userSpaceRepository; @Test - @DisplayName("유저가 요청한 정산 중, 현재 진행 중인 정산 정보들을 return 한다.") - void getPayHomeInfos() throws Exception { + @DisplayName("유저가 요청한 정산 중, 완료되지 않은 정산 정보들을 return 한다.") + void getPayHomeInfos1() throws Exception { //given User user1 = User.create("email", "password", "name", UserSignupType.LOCAL); User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); + User user4 = User.create("email", "password", "name", UserSignupType.LOCAL); Space space = Space.create("space", "profileImg"); - User testUser1 = userRepository.save(user1); - User testUser2 = userRepository.save(user2); - User testUser3 = userRepository.save(user3); + User payCreator = userRepository.save(user1); + User payTarget1 = userRepository.save(user2); + User payTarget2 = userRepository.save(user3); + User payTarget3 = userRepository.save(user4); Space testSpace = spaceRepository.save(space); - UserSpace userSpace = UserSpace.create(testUser1, testSpace, UserSpaceAuth.NORMAL); + UserSpace userSpace = UserSpace.create(payCreator, testSpace, UserSpaceAuth.NORMAL); userSpaceRepository.save(userSpace); - PayRequest inCompletePay = PayRequest.create(testUser1, testSpace, 20000, "bank", "accountNum", 20000, false); - PayRequest completePay = PayRequest.create(testUser1, testSpace, 20000, "bank", "accountNum", 20000, true); + PayRequest inCompletePay1 = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); + PayRequest inCompletePay2 = PayRequest.create(payCreator, testSpace, 40000, "bank", "accountNum"); + PayRequest completePay = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); + completePay.changeCompleteStatus(true); - PayRequestTarget inCompleteTarget1 = PayRequestTarget.create(inCompletePay, testUser2.getUserId(), 10000, false); - PayRequestTarget inCompleteTarget2 = PayRequestTarget.create(inCompletePay, testUser3.getUserId(), 10000, false); - PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, testUser2.getUserId(), 10000, true); - PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, testUser3.getUserId(), 10000, true); + PayRequestTarget inCompleteTarget1 = PayRequestTarget.create(inCompletePay1, payTarget1.getUserId(), 10000); + PayRequestTarget inCompleteTarget2 = PayRequestTarget.create(inCompletePay1, payTarget2.getUserId(), 10000); - payRequestRepository.save(inCompletePay); + PayRequestTarget inCompleteTarget3 = PayRequestTarget.create(inCompletePay2, payTarget2.getUserId(), 20000); + PayRequestTarget inCompleteTarget4 = PayRequestTarget.create(inCompletePay2, payTarget3.getUserId(), 20000); + + PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, payTarget1.getUserId(), 10000); + PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, payTarget2.getUserId(), 10000); + completeTarget1.changeCompleteStatus(true); + completeTarget2.changeCompleteStatus(true); + + payRequestRepository.save(inCompletePay1); + payRequestRepository.save(inCompletePay2); payRequestRepository.save(completePay); payRequestTargetRepository.save(inCompleteTarget1); payRequestTargetRepository.save(inCompleteTarget2); + payRequestTargetRepository.save(inCompleteTarget3); + payRequestTargetRepository.save(inCompleteTarget4); payRequestTargetRepository.save(completeTarget1); payRequestTargetRepository.save(completeTarget2); //when - PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(testUser1.getUserId(), testSpace.getSpaceId()); + PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payCreator.getUserId(), testSpace.getSpaceId()); List payRequestInfos = payHomeInfos.getPayRequestInfoDtoList(); //then - assertThat(payRequestInfos).hasSize(1) - .extracting("totalAmount", "receiveAmount", "totalTargetNum", "receiveTargetNum") + assertThat(payRequestInfos).hasSize(2) + .extracting("totalAmount", "receiveAmount", "totalTargetNum", "paySendTargetNum") .containsExactlyInAnyOrder( - tuple(20000, 0, 2, 0) + tuple(20000, 0, 2, 0), + tuple(40000, 0, 2, 0) ); } + @Test + @DisplayName("유저가 요청받은 정산 중, 완료되지 않은 정산 정보들을 return 한다.") + void getPayHomeInfos2() throws Exception { + //given + User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); + User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); + User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); + User user4 = User.create("email", "password", "name", UserSignupType.LOCAL); + Space space = Space.create("space", "profileImg"); + + User payCreator = userRepository.save(user1); + User payTarget1 = userRepository.save(user2); + User payTarget2 = userRepository.save(user3); + User payTarget3 = userRepository.save(user4); + Space testSpace = spaceRepository.save(space); + + UserSpace userSpace = UserSpace.create(payTarget2, testSpace, UserSpaceAuth.NORMAL); + userSpaceRepository.save(userSpace); + + PayRequest inCompletePay1 = PayRequest.create(payCreator, testSpace, 20000, "우리은행", "111-111"); + PayRequest inCompletePay2 = PayRequest.create(payCreator, testSpace, 40000, "국민은행", "222-222"); + PayRequest completePay = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); + completePay.changeCompleteStatus(true); + + PayRequestTarget inCompleteTarget1 = PayRequestTarget.create(inCompletePay1, payTarget1.getUserId(), 10000); + PayRequestTarget inCompleteTarget2 = PayRequestTarget.create(inCompletePay1, payTarget2.getUserId(), 10000); + + PayRequestTarget inCompleteTarget3 = PayRequestTarget.create(inCompletePay2, payTarget2.getUserId(), 20000); + PayRequestTarget inCompleteTarget4 = PayRequestTarget.create(inCompletePay2, payTarget3.getUserId(), 20000); + + PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, payTarget1.getUserId(), 10000); + PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, payTarget2.getUserId(), 10000); + completeTarget1.changeCompleteStatus(true); + completeTarget2.changeCompleteStatus(true); + + payRequestRepository.save(inCompletePay1); + payRequestRepository.save(inCompletePay2); + payRequestRepository.save(completePay); + + payRequestTargetRepository.save(inCompleteTarget1); + payRequestTargetRepository.save(inCompleteTarget2); + payRequestTargetRepository.save(inCompleteTarget3); + payRequestTargetRepository.save(inCompleteTarget4); + payRequestTargetRepository.save(completeTarget1); + payRequestTargetRepository.save(completeTarget2); + + //when + PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payTarget2.getUserId(), testSpace.getSpaceId()); + List payReceiveInfoDtoList = payHomeInfos.getPayReceiveInfoDtoList(); + + //then + assertThat(payReceiveInfoDtoList).hasSize(2) + .extracting("payCreatorName", "requestedAmount", "bankName", "bankAccountNum") + .containsExactlyInAnyOrder( + tuple("노성준", 10000, "우리은행", "111-111"), + tuple("노성준", 20000, "국민은행", "222-222") + ); + } + + } \ No newline at end of file From 76eab7f7788fa246fba9de879a200f212975202d Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sun, 10 Nov 2024 01:53:02 +0900 Subject: [PATCH 07/20] =?UTF-8?q?test=20:=20getPayHomeInfos=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/controller/PayController.java | 19 +--- .../pay/model/dto/PayReceiveInfoDto.java | 19 ---- .../pay/model/dto/PayTargetInfoDto.java | 10 +- .../pay/model/entity/PayRequestTarget.java | 6 +- .../response/GetReceivePayViewResponse.java | 6 +- .../model/response/PayHomeViewResponse.java | 6 +- .../domain/pay/service/PayService.java | 41 +++++--- .../space/controller/SpaceController.java | 2 +- .../space/model/dto/GetSpaceHomeDto.java | 4 +- .../domain/pay/service/PayServiceTest.java | 99 ++++++++++++++++--- 10 files changed, 134 insertions(+), 78 deletions(-) delete mode 100644 src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java diff --git a/src/main/java/space/space_spring/domain/pay/controller/PayController.java b/src/main/java/space/space_spring/domain/pay/controller/PayController.java index b057897e..0a11280f 100644 --- a/src/main/java/space/space_spring/domain/pay/controller/PayController.java +++ b/src/main/java/space/space_spring/domain/pay/controller/PayController.java @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.*; import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; import space.space_spring.argumentResolver.userSpace.CheckUserSpace; -import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import space.space_spring.domain.pay.model.dto.TotalPayInfoDto; import space.space_spring.domain.pay.model.request.PostPayCompleteRequest; @@ -44,19 +44,6 @@ public class PayController { public BaseResponse showPayHome(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { return new BaseResponse<>(payService.getPayHomeInfos(userId, spaceId)); - -// // TODO 1. 유저가 스페이스에 속하는 지 검증 -// validateIsUserInSpace(userId, spaceId); -// -// // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get -// // 현재 진행중인 정산 -> isComplete = false -// List payRequestInfoDtoList = payService.getPayRequestInfoForUser(userId, spaceId, false); -// -// // TODO 3. 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 get -// // 현재 진행중인 정산 -> isComplete = false -// List payReceiveInfoDtoList = payService.getPayReceiveInfoForUser(userId, spaceId, false); -// -// return new BaseResponse<>(new PayHomeViewResponse(payRequestInfoDtoList, payReceiveInfoDtoList)); } // private void validateIsUserInSpace(Long userId, Long spaceId) { @@ -91,10 +78,10 @@ public BaseResponse showPayHome(@JwtLoginAuth Long userId, // validateIsUserInSpace(userId, spaceId); // // // TODO 2. 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 get -> 정산 타겟 유저가 정산 안했을 경우 : isComplete = false -// List payReceiveInfoDtoListInComplete = payService.getPayReceiveInfoForUser(userId, spaceId, false); +// List payReceiveInfoDtoListInComplete = payService.getPayReceiveInfoForUser(userId, spaceId, false); // // // TODO 3. 유저가 요청받은 정산 중 완료한 정산 리스트 get -> 정산 타겟 유저가 정산 했을 경우 : isComplete = true -// List payReceiveInfoDtoListComplete = payService.getPayReceiveInfoForUser(userId, spaceId, true); +// List payReceiveInfoDtoListComplete = payService.getPayReceiveInfoForUser(userId, spaceId, true); // // return new BaseResponse<>(new GetReceivePayViewResponse(payReceiveInfoDtoListInComplete, payReceiveInfoDtoListComplete)); // } diff --git a/src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java deleted file mode 100644 index 84408ce6..00000000 --- a/src/main/java/space/space_spring/domain/pay/model/dto/PayReceiveInfoDto.java +++ /dev/null @@ -1,19 +0,0 @@ -package space.space_spring.domain.pay.model.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class PayReceiveInfoDto { - - private Long payRequestTargetId; - - private String payCreatorName; - - private int requestedAmount; - - private String bankName; - - private String bankAccountNum; -} diff --git a/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java index 286f2949..721c8925 100644 --- a/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java @@ -7,13 +7,13 @@ @AllArgsConstructor public class PayTargetInfoDto { - private Long targetUserId; + private Long payRequestTargetId; - private String targetUserName; - - private String targetUserProfileImg; + private String payCreatorName; private int requestedAmount; - private boolean isComplete; + private String bankName; + + private String bankAccountNum; } diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index 142f5dca..ff97ee7f 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -5,7 +5,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import space.space_spring.entity.BaseEntity; @Entity @@ -54,7 +54,7 @@ public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } - public PayReceiveInfoDto createPayReceiveInfo() { + public PayTargetInfoDto createPayReceiveInfo() { String payCreatorName = payRequest.getPayCreateUser().getUserName(); // 이정도는 괜찮지 않나? int requestedAmount = this.requestedAmount; @@ -63,6 +63,6 @@ public PayReceiveInfoDto createPayReceiveInfo() { String bankAccountNum = payRequest.getBankAccountNum(); // 빌더패턴으로 변경 - return new PayReceiveInfoDto(payRequestTargetId, payCreatorName, requestedAmount, bankName, bankAccountNum); + return new PayTargetInfoDto(payRequestTargetId, payCreatorName, requestedAmount, bankName, bankAccountNum); } } diff --git a/src/main/java/space/space_spring/domain/pay/model/response/GetReceivePayViewResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/GetReceivePayViewResponse.java index 9f2abcb6..c184c95f 100644 --- a/src/main/java/space/space_spring/domain/pay/model/response/GetReceivePayViewResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/GetReceivePayViewResponse.java @@ -2,7 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import java.util.ArrayList; import java.util.List; @@ -11,7 +11,7 @@ @AllArgsConstructor public class GetReceivePayViewResponse { - private List payReceiveInfoDtoListIncomplete = new ArrayList<>(); + private List payReceiveInfoDtoListIncomplete = new ArrayList<>(); - private List payReceiveInfoDtoListComplete = new ArrayList<>(); + private List payReceiveInfoDtoListComplete = new ArrayList<>(); } diff --git a/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java index 75095db4..5dc5a43f 100644 --- a/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java @@ -2,7 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import java.util.ArrayList; @@ -12,7 +12,7 @@ @AllArgsConstructor public class PayHomeViewResponse { - private List payRequestInfoDtoList = new ArrayList<>(); + private List payRequestInfoDtos; - private List payReceiveInfoDtoList = new ArrayList<>(); + private List payTargetInfoDtos; } diff --git a/src/main/java/space/space_spring/domain/pay/service/PayService.java b/src/main/java/space/space_spring/domain/pay/service/PayService.java index 80c9abd0..f9879f00 100644 --- a/src/main/java/space/space_spring/domain/pay/service/PayService.java +++ b/src/main/java/space/space_spring/domain/pay/service/PayService.java @@ -1,6 +1,7 @@ package space.space_spring.domain.pay.service; import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import space.space_spring.domain.userSpace.model.entity.UserSpace; @@ -42,6 +43,27 @@ public PayHomeViewResponse getPayHomeInfos(Long userId, Long spaceId) { UserSpace userSpace = validateUserInSpace(userId, spaceId); // 유저가 요청한 정산들 중, 완료되지 않은 정산 리스트 정보와 + List payRequestInfoDtos = getPayRequestInfos(userSpace); + + // 유저가 요청받은 정산들 중, 완료되지 않은 정산 리스트를 찾아서 + List payTargetInfoDtos = getPayTargetInfos(userSpace); + + // return + return new PayHomeViewResponse(payRequestInfoDtos, payTargetInfoDtos); + } + + private List getPayTargetInfos(UserSpace userSpace) { + List payRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(userSpace.getUser().getUserId(), userSpace.getSpace(), INCOMPLETE_PAY); + + List payTargetInfoDtos = new ArrayList<>(); + for (PayRequestTarget payRequestTarget : payRequestTargets) { + PayTargetInfoDto payReceiveInfo = payRequestTarget.createPayReceiveInfo(); + payTargetInfoDtos.add(payReceiveInfo); + } + return payTargetInfoDtos; + } + + private List getPayRequestInfos(UserSpace userSpace) { List payRequests = payRequestRepository.findAllByUserAndSpace(userSpace.getUser(), userSpace.getSpace(), INCOMPLETE_PAY); List payRequestInfoDtos = new ArrayList<>(); @@ -50,18 +72,7 @@ public PayHomeViewResponse getPayHomeInfos(Long userId, Long spaceId) { PayRequestInfoDto payRequestInfo = payRequest.createPayRequestInfo(findTargets); payRequestInfoDtos.add(payRequestInfo); } - - // 유저가 요청받은 정산들 중, 완료되지 않은 정산 리스트를 찾아서 - List payRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(userSpace.getUser().getUserId(), userSpace.getSpace(), INCOMPLETE_PAY); - - List payReceiveInfoDtos = new ArrayList<>(); - for (PayRequestTarget payRequestTarget : payRequestTargets) { - PayReceiveInfoDto payReceiveInfo = payRequestTarget.createPayReceiveInfo(); - payReceiveInfoDtos.add(payReceiveInfo); - } - - // return - return new PayHomeViewResponse(payRequestInfoDtos, payReceiveInfoDtos); + return payRequestInfoDtos; } private UserSpace validateUserInSpace(Long userId, Long spaceId) { @@ -96,7 +107,7 @@ private UserSpace validateUserInSpace(Long userId, Long spaceId) { // } // // @Transactional -// public List getPayReceiveInfoForUser(Long userId, Long spaceId, boolean isComplete) { +// public List getPayReceiveInfoForUser(Long userId, Long spaceId, boolean isComplete) { // // TODO 1. userId에 해당하는 유저 find // User userByUserId = userUtils.findUserByUserId(userId); // @@ -108,10 +119,10 @@ private UserSpace validateUserInSpace(Long userId, Long spaceId) { // // // TODO 4. return 타입 구성 // // 3-1. 각 payRequestTarget 에 해당하는 정산 요청자, 정산 요청 금액 을 loop를 돌면서 데이터 수집 -// List payReceiveInfoDtoList = new ArrayList<>(); +// List payReceiveInfoDtoList = new ArrayList<>(); // // for (PayRequestTarget payRequestTarget : payRequestTargetListByUser) { -// PayReceiveInfoDto payReceiveInfoDto = payRequestTarget.createPayReceiveInfo(); +// PayTargetInfoDto payReceiveInfoDto = payRequestTarget.createPayReceiveInfo(); // payReceiveInfoDtoList.add(payReceiveInfoDto); // } // diff --git a/src/main/java/space/space_spring/domain/space/controller/SpaceController.java b/src/main/java/space/space_spring/domain/space/controller/SpaceController.java index e9a5b90f..52ba46fe 100644 --- a/src/main/java/space/space_spring/domain/space/controller/SpaceController.java +++ b/src/main/java/space/space_spring/domain/space/controller/SpaceController.java @@ -206,7 +206,7 @@ public BaseResponse joinUserToSpace(@JwtLoginAuth Long userId, @PathVari // // AND // // 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 // List payRequestInfoForUser = payService.getPayRequestInfoForUser(userId, spaceId, false); -// List payReceiveInfoForUser = payService.getPayReceiveInfoForUser(userId, spaceId, false); +// List payReceiveInfoForUser = payService.getPayReceiveInfoForUser(userId, spaceId, false); // // // TODO 3. 해당 스페이스의 공지사항 get // List noticeInfoForHome = postService.getNoticeInfoForHome(spaceId); diff --git a/src/main/java/space/space_spring/domain/space/model/dto/GetSpaceHomeDto.java b/src/main/java/space/space_spring/domain/space/model/dto/GetSpaceHomeDto.java index 6ca34c31..89e7d715 100644 --- a/src/main/java/space/space_spring/domain/space/model/dto/GetSpaceHomeDto.java +++ b/src/main/java/space/space_spring/domain/space/model/dto/GetSpaceHomeDto.java @@ -2,7 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import java.util.List; @@ -18,7 +18,7 @@ public static class Response { private List payRequestInfoDtoList; - private List payReceiveInfoDtoList; + private List payReceiveInfoDtoList; private List noticeList; diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index 2a079ca0..37272b5b 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -8,7 +8,7 @@ import org.springframework.context.annotation.Import; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.test.context.ActiveProfiles; -import space.space_spring.domain.pay.model.dto.PayReceiveInfoDto; +import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import space.space_spring.domain.space.repository.SpaceRepository; import space.space_spring.domain.userSpace.repository.UserSpaceRepository; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; @@ -55,7 +55,7 @@ class PayServiceTest { private UserSpaceRepository userSpaceRepository; @Test - @DisplayName("유저가 요청한 정산 중, 완료되지 않은 정산 정보들을 return 한다.") + @DisplayName("유저가 요청한 정산들 중, 완료되지 않은 정산 정보들을 return 한다.") void getPayHomeInfos1() throws Exception { //given User user1 = User.create("email", "password", "name", UserSignupType.LOCAL); @@ -102,19 +102,19 @@ void getPayHomeInfos1() throws Exception { //when PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payCreator.getUserId(), testSpace.getSpaceId()); - List payRequestInfos = payHomeInfos.getPayRequestInfoDtoList(); + List payRequestInfos = payHomeInfos.getPayRequestInfoDtos(); //then assertThat(payRequestInfos).hasSize(2) - .extracting("totalAmount", "receiveAmount", "totalTargetNum", "paySendTargetNum") + .extracting("payRequestId", "totalAmount", "receiveAmount", "totalTargetNum", "paySendTargetNum") .containsExactlyInAnyOrder( - tuple(20000, 0, 2, 0), - tuple(40000, 0, 2, 0) + tuple(inCompletePay1.getPayRequestId(), 20000, 0, 2, 0), + tuple(inCompletePay2.getPayRequestId(), 40000, 0, 2, 0) ); } @Test - @DisplayName("유저가 요청받은 정산 중, 완료되지 않은 정산 정보들을 return 한다.") + @DisplayName("유저가 요청받은 정산들 중, 완료되지 않은 정산 정보들을 return 한다.") void getPayHomeInfos2() throws Exception { //given User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); @@ -161,16 +161,93 @@ void getPayHomeInfos2() throws Exception { //when PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payTarget2.getUserId(), testSpace.getSpaceId()); - List payReceiveInfoDtoList = payHomeInfos.getPayReceiveInfoDtoList(); + List payReceiveInfoDtoList = payHomeInfos.getPayTargetInfoDtos(); //then assertThat(payReceiveInfoDtoList).hasSize(2) - .extracting("payCreatorName", "requestedAmount", "bankName", "bankAccountNum") + .extracting("payRequestTargetId", "payCreatorName", "requestedAmount", "bankName", "bankAccountNum") .containsExactlyInAnyOrder( - tuple("노성준", 10000, "우리은행", "111-111"), - tuple("노성준", 20000, "국민은행", "222-222") + tuple(inCompleteTarget2.getPayRequestTargetId(), "노성준", 10000, "우리은행", "111-111"), + tuple(inCompleteTarget3.getPayRequestTargetId(), "노성준", 20000, "국민은행", "222-222") ); } + @Test + @DisplayName("유저가 요청한 정산들 중, 완료되지 않은 정산이 없으면 빈 ArrayList 를 return 한다.") + void getPayHomeInfos3() throws Exception { + //given + User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); + User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); + User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); + Space space = Space.create("space", "profileImg"); + + User payCreator = userRepository.save(user1); + User payTarget1 = userRepository.save(user2); + User payTarget2 = userRepository.save(user3); + Space testSpace = spaceRepository.save(space); + + UserSpace userSpace = UserSpace.create(payCreator, testSpace, UserSpaceAuth.NORMAL); + userSpaceRepository.save(userSpace); + + PayRequest completePay = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); + completePay.changeCompleteStatus(true); + + PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, payTarget1.getUserId(), 10000); + PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, payTarget2.getUserId(), 10000); + completeTarget1.changeCompleteStatus(true); + completeTarget2.changeCompleteStatus(true); + + payRequestRepository.save(completePay); + + payRequestTargetRepository.save(completeTarget1); + payRequestTargetRepository.save(completeTarget2); + + //when + PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payCreator.getUserId(), testSpace.getSpaceId()); + List payRequestInfoDtoList = payHomeInfos.getPayRequestInfoDtos(); + + //then + assertThat(payRequestInfoDtoList).hasSize(0); + } + + @Test + @DisplayName("유저가 요청받은 정산들 중, 완료되지 않은 정산이 없으면 빈 ArrayList를 return 한다.") + void test() throws Exception { + //given + User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); + User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); + User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); + Space space = Space.create("space", "profileImg"); + + User payCreator = userRepository.save(user1); + User payTarget1 = userRepository.save(user2); + User payTarget2 = userRepository.save(user3); + Space testSpace = spaceRepository.save(space); + + UserSpace userSpace = UserSpace.create(payTarget2, testSpace, UserSpaceAuth.NORMAL); + userSpaceRepository.save(userSpace); + + PayRequest completePay = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); + completePay.changeCompleteStatus(true); + + PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, payTarget1.getUserId(), 10000); + PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, payTarget2.getUserId(), 10000); + completeTarget1.changeCompleteStatus(true); + completeTarget2.changeCompleteStatus(true); + + payRequestRepository.save(completePay); + + payRequestTargetRepository.save(completeTarget1); + payRequestTargetRepository.save(completeTarget2); + + //when + PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payTarget2.getUserId(), testSpace.getSpaceId()); + List payTargetInfoDtos = payHomeInfos.getPayTargetInfoDtos(); + + //then + assertThat(payTargetInfoDtos).hasSize(0); + } + + } \ No newline at end of file From 87ea6b31d6001e88664031d1342215f29f53791d Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sun, 10 Nov 2024 03:18:25 +0900 Subject: [PATCH 08/20] =?UTF-8?q?test=20:=20PayRequest=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20&=20PayService=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/model/dto/PayRequestInfoDto.java | 3 +- .../pay/model/dto/PayTargetInfoDto.java | 3 +- .../domain/pay/model/entity/PayRequest.java | 22 +-- .../pay/model/entity/PayRequestTarget.java | 18 ++- .../model/response/PayHomeViewResponse.java | 3 +- .../domain/pay/service/PayService.java | 27 ++-- .../pay/model/entity/PayRequestTest.java | 47 +++++++ .../domain/pay/service/PayServiceTest.java | 126 ++++++------------ 8 files changed, 133 insertions(+), 116 deletions(-) create mode 100644 src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java diff --git a/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java index b4fde2d0..69ff011b 100644 --- a/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/PayRequestInfoDto.java @@ -1,10 +1,11 @@ package space.space_spring.domain.pay.model.dto; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; @Getter -@AllArgsConstructor +@Builder public class PayRequestInfoDto { private Long payRequestId; diff --git a/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java b/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java index 721c8925..dec8e710 100644 --- a/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java +++ b/src/main/java/space/space_spring/domain/pay/model/dto/PayTargetInfoDto.java @@ -1,10 +1,11 @@ package space.space_spring.domain.pay.model.dto; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; @Getter -@AllArgsConstructor +@Builder public class PayTargetInfoDto { private Long payRequestTargetId; diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index 8a923648..0a45f899 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -41,8 +41,8 @@ public class PayRequest extends BaseEntity { @Column(name = "bank_account_num") private String bankAccountNum; // 정산 받을 은행 계좌번호 - @Column(name = "received_amount") - private int receivedAmount; // 정산 받은 금액 + @Column(name = "receive_amount") + private int receiveAmount; // 정산 받은 금액 @Column(name = "is_complete") private boolean isComplete; @@ -52,6 +52,10 @@ public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } + public void changeReceiveAmount(int receiveAmount) { + this.receiveAmount = receiveAmount; + } + @Builder private PayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum) { this.payCreateUser = payCreateUser; @@ -59,7 +63,7 @@ private PayRequest(User payCreateUser, Space space, int totalAmount, String bank this.totalAmount = totalAmount; this.bankName = bankName; this.bankAccountNum = bankAccountNum; - this.receivedAmount = 0; + this.receiveAmount = 0; this.isComplete = false; } @@ -82,13 +86,15 @@ public PayRequestInfoDto createPayRequestInfo(List payRequestT // 해당 타겟이 돈을 낸 경우 paySendTargetNum++; } - totalTargetNum++; } - // 빌더 패턴으로 변경 - return new PayRequestInfoDto( - payRequestId, totalAmount, receivedAmount, totalTargetNum, paySendTargetNum - ); + return PayRequestInfoDto.builder() + .payRequestId(payRequestId) + .totalAmount(totalAmount) + .receiveAmount(receiveAmount) + .totalTargetNum(totalTargetNum) + .paySendTargetNum(paySendTargetNum) + .build(); } } diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index ff97ee7f..a7ead29b 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -54,15 +54,13 @@ public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } - public PayTargetInfoDto createPayReceiveInfo() { - String payCreatorName = payRequest.getPayCreateUser().getUserName(); // 이정도는 괜찮지 않나? - int requestedAmount = this.requestedAmount; - - // 정산 생성자가 요청한 은행 정보도 response에 추가 - String bankName = payRequest.getBankName(); - String bankAccountNum = payRequest.getBankAccountNum(); - - // 빌더패턴으로 변경 - return new PayTargetInfoDto(payRequestTargetId, payCreatorName, requestedAmount, bankName, bankAccountNum); + public PayTargetInfoDto createPayTargetInfo() { + return PayTargetInfoDto.builder() + .payRequestTargetId(payRequestTargetId) + .payCreatorName(payRequest.getPayCreateUser().getUserName()) + .requestedAmount(requestedAmount) + .bankName(payRequest.getBankName()) + .bankAccountNum(payRequest.getBankAccountNum()) + .build(); } } diff --git a/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java index 5dc5a43f..978805ef 100644 --- a/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java @@ -1,6 +1,7 @@ package space.space_spring.domain.pay.model.response; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; @@ -9,7 +10,7 @@ import java.util.List; @Getter -@AllArgsConstructor +@Builder public class PayHomeViewResponse { private List payRequestInfoDtos; diff --git a/src/main/java/space/space_spring/domain/pay/service/PayService.java b/src/main/java/space/space_spring/domain/pay/service/PayService.java index f9879f00..6b2a8cd3 100644 --- a/src/main/java/space/space_spring/domain/pay/service/PayService.java +++ b/src/main/java/space/space_spring/domain/pay/service/PayService.java @@ -49,18 +49,10 @@ public PayHomeViewResponse getPayHomeInfos(Long userId, Long spaceId) { List payTargetInfoDtos = getPayTargetInfos(userSpace); // return - return new PayHomeViewResponse(payRequestInfoDtos, payTargetInfoDtos); - } - - private List getPayTargetInfos(UserSpace userSpace) { - List payRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(userSpace.getUser().getUserId(), userSpace.getSpace(), INCOMPLETE_PAY); - - List payTargetInfoDtos = new ArrayList<>(); - for (PayRequestTarget payRequestTarget : payRequestTargets) { - PayTargetInfoDto payReceiveInfo = payRequestTarget.createPayReceiveInfo(); - payTargetInfoDtos.add(payReceiveInfo); - } - return payTargetInfoDtos; + return PayHomeViewResponse.builder() + .payRequestInfoDtos(payRequestInfoDtos) + .payTargetInfoDtos(payTargetInfoDtos) + .build(); } private List getPayRequestInfos(UserSpace userSpace) { @@ -75,6 +67,17 @@ private List getPayRequestInfos(UserSpace userSpace) { return payRequestInfoDtos; } + private List getPayTargetInfos(UserSpace userSpace) { + List payRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(userSpace.getUser().getUserId(), userSpace.getSpace(), INCOMPLETE_PAY); + + List payTargetInfoDtos = new ArrayList<>(); + for (PayRequestTarget payRequestTarget : payRequestTargets) { + PayTargetInfoDto payReceiveInfo = payRequestTarget.createPayTargetInfo(); + payTargetInfoDtos.add(payReceiveInfo); + } + return payTargetInfoDtos; + } + private UserSpace validateUserInSpace(Long userId, Long spaceId) { return userSpaceRepository.findUserSpaceByUserAndSpace(userId, spaceId).orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE)); } diff --git a/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java b/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java new file mode 100644 index 00000000..26fa10bc --- /dev/null +++ b/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java @@ -0,0 +1,47 @@ +package space.space_spring.domain.pay.model.entity; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; +import space.space_spring.domain.space.model.entity.Space; +import space.space_spring.domain.user.model.entity.User; +import space.space_spring.entity.enumStatus.UserSignupType; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +class PayRequestTest { + + @Test + @DisplayName("해당 PayRequest의 target list를 인자로 받으면, PayRequestInfoDto를 return 한다.") + void createPayRequestInfo() throws Exception { + //given + User payCreator = User.create("email", "password", "노성준", UserSignupType.LOCAL); + + Space space = Space.create("space", "img"); + + PayRequest payRequest = PayRequest.create(payCreator, space, 30000, "우리은행", "111-111"); + + PayRequestTarget target1 = PayRequestTarget.create(payRequest, 1L, 10000); + PayRequestTarget target2 = PayRequestTarget.create(payRequest, 2L, 10000); + PayRequestTarget target3 = PayRequestTarget.create(payRequest, 3L, 10000); + + // target1 : 미정산, target2, target3 : 정산 완료 + target2.changeCompleteStatus(true); + target3.changeCompleteStatus(true); + payRequest.changeReceiveAmount(20000); + + List targets = List.of(target1, target2, target3); + + //when + PayRequestInfoDto payRequestInfo = payRequest.createPayRequestInfo(targets); + + //then + assertThat(payRequestInfo) + .extracting("totalAmount", "receiveAmount", "totalTargetNum", "paySendTargetNum") + .contains(30000, 20000, 3, 2); + } + +} \ No newline at end of file diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index 37272b5b..ff90d60f 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -55,43 +55,52 @@ class PayServiceTest { private UserSpaceRepository userSpaceRepository; @Test - @DisplayName("유저가 요청한 정산들 중, 완료되지 않은 정산 정보들을 return 한다.") + @DisplayName("유저가 요청한 정산들 중 완료되지 않은 정산 정보들과, 요청받은 정산들 중 완료되지 않은 정산 정보들을 return 한다.") void getPayHomeInfos1() throws Exception { //given - User user1 = User.create("email", "password", "name", UserSignupType.LOCAL); - User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); - User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); - User user4 = User.create("email", "password", "name", UserSignupType.LOCAL); + User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); + User user2 = User.create("email", "password", "김상준", UserSignupType.LOCAL); + User user3 = User.create("email", "password", "정서현", UserSignupType.LOCAL); + User user4 = User.create("email", "password", "김경민", UserSignupType.LOCAL); Space space = Space.create("space", "profileImg"); - User payCreator = userRepository.save(user1); - User payTarget1 = userRepository.save(user2); - User payTarget2 = userRepository.save(user3); - User payTarget3 = userRepository.save(user4); + User seongjun = userRepository.save(user1); + User sangjun = userRepository.save(user2); + User seohyun = userRepository.save(user3); + User kyeongmin = userRepository.save(user4); Space testSpace = spaceRepository.save(space); - UserSpace userSpace = UserSpace.create(payCreator, testSpace, UserSpaceAuth.NORMAL); + UserSpace userSpace = UserSpace.create(seongjun, testSpace, UserSpaceAuth.NORMAL); userSpaceRepository.save(userSpace); - PayRequest inCompletePay1 = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); - PayRequest inCompletePay2 = PayRequest.create(payCreator, testSpace, 40000, "bank", "accountNum"); - PayRequest completePay = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); - completePay.changeCompleteStatus(true); + // seongjun 이 testSpace 에서 생성한 3개의 정산 요청 + PayRequest inCompletePay1_seongjun = PayRequest.create(seongjun, testSpace, 20000, "bank", "accountNum"); + PayRequest inCompletePay2_seongjun = PayRequest.create(seongjun, testSpace, 40000, "bank", "accountNum"); + PayRequest completePay_seongjun = PayRequest.create(seongjun, testSpace, 20000, "bank", "accountNum"); + completePay_seongjun.changeCompleteStatus(true); - PayRequestTarget inCompleteTarget1 = PayRequestTarget.create(inCompletePay1, payTarget1.getUserId(), 10000); - PayRequestTarget inCompleteTarget2 = PayRequestTarget.create(inCompletePay1, payTarget2.getUserId(), 10000); + // seohyun 이 testSpace 에서 생성한 1개의 정산 요청 + PayRequest inCompletePay_seohyun = PayRequest.create(seohyun, testSpace, 40000, "국민은행", "111-111"); - PayRequestTarget inCompleteTarget3 = PayRequestTarget.create(inCompletePay2, payTarget2.getUserId(), 20000); - PayRequestTarget inCompleteTarget4 = PayRequestTarget.create(inCompletePay2, payTarget3.getUserId(), 20000); + // 각 정산 요청의 타겟들 + PayRequestTarget inCompleteTarget1 = PayRequestTarget.create(inCompletePay1_seongjun, sangjun.getUserId(), 10000); + PayRequestTarget inCompleteTarget2 = PayRequestTarget.create(inCompletePay1_seongjun, kyeongmin.getUserId(), 10000); - PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, payTarget1.getUserId(), 10000); - PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, payTarget2.getUserId(), 10000); + PayRequestTarget inCompleteTarget3 = PayRequestTarget.create(inCompletePay2_seongjun, seohyun.getUserId(), 20000); + PayRequestTarget inCompleteTarget4 = PayRequestTarget.create(inCompletePay2_seongjun, kyeongmin.getUserId(), 20000); + + PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay_seongjun, sangjun.getUserId(), 10000); + PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay_seongjun, seohyun.getUserId(), 10000); completeTarget1.changeCompleteStatus(true); completeTarget2.changeCompleteStatus(true); - payRequestRepository.save(inCompletePay1); - payRequestRepository.save(inCompletePay2); - payRequestRepository.save(completePay); + PayRequestTarget inCompleteTarget5 = PayRequestTarget.create(inCompletePay_seohyun, seongjun.getUserId(), 20000); + PayRequestTarget inCompleteTarget6 = PayRequestTarget.create(inCompletePay_seohyun, sangjun.getUserId(), 20000); + + payRequestRepository.save(inCompletePay1_seongjun); + payRequestRepository.save(inCompletePay2_seongjun); + payRequestRepository.save(completePay_seongjun); + payRequestRepository.save(inCompletePay_seohyun); payRequestTargetRepository.save(inCompleteTarget1); payRequestTargetRepository.save(inCompleteTarget2); @@ -99,82 +108,33 @@ void getPayHomeInfos1() throws Exception { payRequestTargetRepository.save(inCompleteTarget4); payRequestTargetRepository.save(completeTarget1); payRequestTargetRepository.save(completeTarget2); + payRequestTargetRepository.save(inCompleteTarget5); + payRequestTargetRepository.save(inCompleteTarget6); //when - PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payCreator.getUserId(), testSpace.getSpaceId()); + PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(seongjun.getUserId(), testSpace.getSpaceId()); List payRequestInfos = payHomeInfos.getPayRequestInfoDtos(); + List payTargetInfoDtos = payHomeInfos.getPayTargetInfoDtos(); //then assertThat(payRequestInfos).hasSize(2) .extracting("payRequestId", "totalAmount", "receiveAmount", "totalTargetNum", "paySendTargetNum") .containsExactlyInAnyOrder( - tuple(inCompletePay1.getPayRequestId(), 20000, 0, 2, 0), - tuple(inCompletePay2.getPayRequestId(), 40000, 0, 2, 0) + tuple(inCompletePay1_seongjun.getPayRequestId(), 20000, 0, 2, 0), + tuple(inCompletePay2_seongjun.getPayRequestId(), 40000, 0, 2, 0) ); - } - - @Test - @DisplayName("유저가 요청받은 정산들 중, 완료되지 않은 정산 정보들을 return 한다.") - void getPayHomeInfos2() throws Exception { - //given - User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); - User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); - User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); - User user4 = User.create("email", "password", "name", UserSignupType.LOCAL); - Space space = Space.create("space", "profileImg"); - - User payCreator = userRepository.save(user1); - User payTarget1 = userRepository.save(user2); - User payTarget2 = userRepository.save(user3); - User payTarget3 = userRepository.save(user4); - Space testSpace = spaceRepository.save(space); - UserSpace userSpace = UserSpace.create(payTarget2, testSpace, UserSpaceAuth.NORMAL); - userSpaceRepository.save(userSpace); - - PayRequest inCompletePay1 = PayRequest.create(payCreator, testSpace, 20000, "우리은행", "111-111"); - PayRequest inCompletePay2 = PayRequest.create(payCreator, testSpace, 40000, "국민은행", "222-222"); - PayRequest completePay = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); - completePay.changeCompleteStatus(true); - - PayRequestTarget inCompleteTarget1 = PayRequestTarget.create(inCompletePay1, payTarget1.getUserId(), 10000); - PayRequestTarget inCompleteTarget2 = PayRequestTarget.create(inCompletePay1, payTarget2.getUserId(), 10000); - - PayRequestTarget inCompleteTarget3 = PayRequestTarget.create(inCompletePay2, payTarget2.getUserId(), 20000); - PayRequestTarget inCompleteTarget4 = PayRequestTarget.create(inCompletePay2, payTarget3.getUserId(), 20000); - - PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, payTarget1.getUserId(), 10000); - PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, payTarget2.getUserId(), 10000); - completeTarget1.changeCompleteStatus(true); - completeTarget2.changeCompleteStatus(true); - - payRequestRepository.save(inCompletePay1); - payRequestRepository.save(inCompletePay2); - payRequestRepository.save(completePay); - - payRequestTargetRepository.save(inCompleteTarget1); - payRequestTargetRepository.save(inCompleteTarget2); - payRequestTargetRepository.save(inCompleteTarget3); - payRequestTargetRepository.save(inCompleteTarget4); - payRequestTargetRepository.save(completeTarget1); - payRequestTargetRepository.save(completeTarget2); - - //when - PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payTarget2.getUserId(), testSpace.getSpaceId()); - List payReceiveInfoDtoList = payHomeInfos.getPayTargetInfoDtos(); - - //then - assertThat(payReceiveInfoDtoList).hasSize(2) + assertThat(payTargetInfoDtos).hasSize(1) .extracting("payRequestTargetId", "payCreatorName", "requestedAmount", "bankName", "bankAccountNum") .containsExactlyInAnyOrder( - tuple(inCompleteTarget2.getPayRequestTargetId(), "노성준", 10000, "우리은행", "111-111"), - tuple(inCompleteTarget3.getPayRequestTargetId(), "노성준", 20000, "국민은행", "222-222") + tuple(inCompleteTarget5.getPayRequestTargetId(), "정서현", 20000, "국민은행", "111-111") ); } + @Test @DisplayName("유저가 요청한 정산들 중, 완료되지 않은 정산이 없으면 빈 ArrayList 를 return 한다.") - void getPayHomeInfos3() throws Exception { + void getPayHomeInfos2() throws Exception { //given User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); @@ -212,7 +172,7 @@ void getPayHomeInfos3() throws Exception { @Test @DisplayName("유저가 요청받은 정산들 중, 완료되지 않은 정산이 없으면 빈 ArrayList를 return 한다.") - void test() throws Exception { + void getPayHomeInfos3() throws Exception { //given User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); From e23312a3666e87b1e77c4e122e5aa27c0b9c203d Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sun, 10 Nov 2024 10:54:15 +0900 Subject: [PATCH 09/20] =?UTF-8?q?test=20:=20PayServiceTest=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/domain/pay/service/PayServiceTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index ff90d60f..b3439dae 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -82,6 +82,10 @@ void getPayHomeInfos1() throws Exception { // seohyun 이 testSpace 에서 생성한 1개의 정산 요청 PayRequest inCompletePay_seohyun = PayRequest.create(seohyun, testSpace, 40000, "국민은행", "111-111"); + // Kyeongmin 이 testSpace에서 생성한 1개의 정산 요청 + PayRequest completePay_kyeongmin = PayRequest.create(kyeongmin, testSpace, 20000, "우리은행", "222-222"); + completePay_kyeongmin.changeCompleteStatus(true); + // 각 정산 요청의 타겟들 PayRequestTarget inCompleteTarget1 = PayRequestTarget.create(inCompletePay1_seongjun, sangjun.getUserId(), 10000); PayRequestTarget inCompleteTarget2 = PayRequestTarget.create(inCompletePay1_seongjun, kyeongmin.getUserId(), 10000); @@ -97,10 +101,14 @@ void getPayHomeInfos1() throws Exception { PayRequestTarget inCompleteTarget5 = PayRequestTarget.create(inCompletePay_seohyun, seongjun.getUserId(), 20000); PayRequestTarget inCompleteTarget6 = PayRequestTarget.create(inCompletePay_seohyun, sangjun.getUserId(), 20000); + PayRequestTarget completeTarget3 = PayRequestTarget.create(completePay_kyeongmin, seongjun.getUserId(), 20000); + completeTarget3.changeCompleteStatus(true); + payRequestRepository.save(inCompletePay1_seongjun); payRequestRepository.save(inCompletePay2_seongjun); payRequestRepository.save(completePay_seongjun); payRequestRepository.save(inCompletePay_seohyun); + payRequestRepository.save(completePay_kyeongmin); payRequestTargetRepository.save(inCompleteTarget1); payRequestTargetRepository.save(inCompleteTarget2); @@ -110,6 +118,7 @@ void getPayHomeInfos1() throws Exception { payRequestTargetRepository.save(completeTarget2); payRequestTargetRepository.save(inCompleteTarget5); payRequestTargetRepository.save(inCompleteTarget6); + payRequestTargetRepository.save(completeTarget3); //when PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(seongjun.getUserId(), testSpace.getSpaceId()); From 4e8486b39b762d2d2bf52144edd6571000251cb8 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Wed, 13 Nov 2024 00:00:37 +0900 Subject: [PATCH 10/20] =?UTF-8?q?test=20:=20=EC=9C=A0=EC=A0=80=EA=B0=80=20?= =?UTF-8?q?=EC=8A=A4=ED=8E=98=EC=9D=B4=EC=8A=A4=EC=97=90=20=EC=86=8D?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/service/PayServiceTest.java | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index b3439dae..d2e37da8 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -23,11 +23,12 @@ import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.entity.enumStatus.UserSignupType; import space.space_spring.entity.enumStatus.UserSpaceAuth; +import space.space_spring.exception.CustomException; import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; +import static org.assertj.core.api.Assertions.*; +import static space.space_spring.response.status.BaseExceptionResponseStatus.USER_IS_NOT_IN_SPACE; @DataJpaTest @Import({PayService.class}) @@ -217,6 +218,42 @@ void getPayHomeInfos3() throws Exception { assertThat(payTargetInfoDtos).hasSize(0); } + @Test + @DisplayName("user는 자신이 속한 space의 정산 홈 view만을 볼 수 있다.") + void getPayHomeInfos4() throws Exception { + //given + User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); + User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); + User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); + Space space1 = Space.create("space", "profileImg"); + Space space2 = Space.create("space", "profileImg"); + + User payCreator = userRepository.save(user1); + User payTarget1 = userRepository.save(user2); + User payTarget2 = userRepository.save(user3); + Space KUIT = spaceRepository.save(space1); + Space ALKON = spaceRepository.save(space2); + + UserSpace userSpace = UserSpace.create(payCreator, KUIT, UserSpaceAuth.NORMAL); + userSpaceRepository.save(userSpace); + + PayRequest payRequest = PayRequest.create(payCreator, KUIT, 20000, "bank", "accountNum"); + + PayRequestTarget target1 = PayRequestTarget.create(payRequest, payTarget1.getUserId(), 10000); + PayRequestTarget target2 = PayRequestTarget.create(payRequest, payTarget2.getUserId(), 10000); + + payRequestRepository.save(payRequest); + + payRequestTargetRepository.save(target1); + payRequestTargetRepository.save(target2); + + //when // then + assertThatThrownBy(() -> payService.getPayHomeInfos(payCreator.getUserId(), ALKON.getSpaceId())) + .isInstanceOf(CustomException.class) + .hasMessage(USER_IS_NOT_IN_SPACE.getMessage()); + } + + } \ No newline at end of file From c08d85c799c75960ff18e564d6c9497d8d0ae0f3 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Fri, 15 Nov 2024 16:22:55 +0900 Subject: [PATCH 11/20] =?UTF-8?q?refactor=20:=20=EC=9D=BC=EA=B8=89=20?= =?UTF-8?q?=EC=BB=AC=EB=A0=89=EC=85=98=20=EC=A0=81=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=97=AC=20PayService=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8E=99=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/model/entity/PayRequest.java | 19 +++++++-- .../firstCollection/PayRequestInfos.java | 19 +++++++++ .../firstCollection/PayRequestTargets.java | 40 +++++++++++++++++++ .../model/firstCollection/PayRequests.java | 39 ++++++++++++++++++ .../model/firstCollection/PayTargetInfos.java | 19 +++++++++ .../domain/pay/model/mapper/PayMapper.java | 23 +++++++++++ .../domain/pay/service/PayService.java | 34 ++++++++++------ .../pay/model/entity/PayRequestTest.java | 8 ++-- .../domain/pay/service/PayServiceTest.java | 20 ++++++---- 9 files changed, 195 insertions(+), 26 deletions(-) create mode 100644 src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestInfos.java create mode 100644 src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargets.java create mode 100644 src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequests.java create mode 100644 src/main/java/space/space_spring/domain/pay/model/firstCollection/PayTargetInfos.java create mode 100644 src/main/java/space/space_spring/domain/pay/model/mapper/PayMapper.java diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index 0a45f899..dae8df8e 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -6,11 +6,11 @@ import lombok.Getter; import lombok.NoArgsConstructor; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; +import space.space_spring.domain.pay.model.firstCollection.PayRequestTargets; import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.BaseEntity; import space.space_spring.domain.space.model.entity.Space; -import java.util.ArrayList; import java.util.List; @Getter @@ -42,11 +42,20 @@ public class PayRequest extends BaseEntity { private String bankAccountNum; // 정산 받을 은행 계좌번호 @Column(name = "receive_amount") - private int receiveAmount; // 정산 받은 금액 + private int receiveAmount; // 정산 받은 금액 @Column(name = "is_complete") private boolean isComplete; + @OneToMany(mappedBy = "payRequest") + private List payRequestTargets; + // PayRequestTarget list를 양방향 매핑으로 참조하는것이 더 좋을까? + + + public PayRequestTargets toPayRequestTargets() { + return PayRequestTargets.create(payRequestTargets); + } + public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; @@ -56,6 +65,10 @@ public void changeReceiveAmount(int receiveAmount) { this.receiveAmount = receiveAmount; } + public void setPayRequestTargets(List payRequestTargets) { + this.payRequestTargets = payRequestTargets; + } + @Builder private PayRequest(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum) { this.payCreateUser = payCreateUser; @@ -77,7 +90,7 @@ public static PayRequest create(User payCreateUser, Space space, int totalAmount .build(); } - public PayRequestInfoDto createPayRequestInfo(List payRequestTargets) { + public PayRequestInfoDto getPayRequestInfo() { int totalTargetNum = 0; int paySendTargetNum = 0; diff --git a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestInfos.java b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestInfos.java new file mode 100644 index 00000000..461c4021 --- /dev/null +++ b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestInfos.java @@ -0,0 +1,19 @@ +package space.space_spring.domain.pay.model.firstCollection; + +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; + +import java.util.ArrayList; +import java.util.List; + +public class PayRequestInfos { + + private final List payRequestInfos = new ArrayList<>(); + + public void add(PayRequestInfoDto payRequestInfoDto) { + payRequestInfos.add(payRequestInfoDto); + } + + public List getAll() { + return payRequestInfos; + } +} diff --git a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargets.java b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargets.java new file mode 100644 index 00000000..ad7d1d53 --- /dev/null +++ b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargets.java @@ -0,0 +1,40 @@ +package space.space_spring.domain.pay.model.firstCollection; + +import jakarta.persistence.Embeddable; +import jakarta.persistence.Embedded; +import lombok.Builder; +import lombok.Getter; +import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; + +import java.util.List; + +@Getter +public class PayRequestTargets { + + private final List payRequestTargets; + + @Builder + private PayRequestTargets(List payRequestTargets) { + this.payRequestTargets = payRequestTargets; + } + + public static PayRequestTargets create(List payRequestTargets) { + return PayRequestTargets.builder() + .payRequestTargets(payRequestTargets) + .build(); + } + + public PayTargetInfos getPayTargetInfos() { + PayTargetInfos payTargetInfos = new PayTargetInfos(); + + for (PayRequestTarget payRequestTarget : payRequestTargets) { + PayTargetInfoDto payTargetInfo = payRequestTarget.createPayTargetInfo(); + payTargetInfos.add(payTargetInfo); + } + + return payTargetInfos; + } + + +} diff --git a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequests.java b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequests.java new file mode 100644 index 00000000..64d67682 --- /dev/null +++ b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequests.java @@ -0,0 +1,39 @@ +package space.space_spring.domain.pay.model.firstCollection; + +import lombok.Builder; +import lombok.Getter; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; +import space.space_spring.domain.pay.model.entity.PayRequest; + +import java.util.List; + +@Getter +public class PayRequests { + + private final List payRequests; + + @Builder + private PayRequests(List payRequests) { + this.payRequests = payRequests; + } + + public static PayRequests create(List payRequests) { + return PayRequests.builder() + .payRequests(payRequests) + .build(); + } + + public PayRequestInfos getPayRequestInfos() { + PayRequestInfos payRequestInfos = new PayRequestInfos(); + + for (PayRequest payRequest : payRequests) { + PayRequestInfoDto payRequestInfo = payRequest.getPayRequestInfo(); + payRequestInfos.add(payRequestInfo); + } + + return payRequestInfos; + } + + + +} diff --git a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayTargetInfos.java b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayTargetInfos.java new file mode 100644 index 00000000..3f0e9237 --- /dev/null +++ b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayTargetInfos.java @@ -0,0 +1,19 @@ +package space.space_spring.domain.pay.model.firstCollection; + +import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; + +import java.util.ArrayList; +import java.util.List; + +public class PayTargetInfos { + + private final List payTargetInfoDtos = new ArrayList<>(); + + public void add(PayTargetInfoDto payTargetInfoDto) { + payTargetInfoDtos.add(payTargetInfoDto); + } + + public List getAll() { + return payTargetInfoDtos; + } +} diff --git a/src/main/java/space/space_spring/domain/pay/model/mapper/PayMapper.java b/src/main/java/space/space_spring/domain/pay/model/mapper/PayMapper.java new file mode 100644 index 00000000..906db48f --- /dev/null +++ b/src/main/java/space/space_spring/domain/pay/model/mapper/PayMapper.java @@ -0,0 +1,23 @@ +package space.space_spring.domain.pay.model.mapper; + +import org.springframework.stereotype.Component; +import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; +import space.space_spring.domain.pay.model.firstCollection.PayRequestInfos; +import space.space_spring.domain.pay.model.firstCollection.PayRequests; +import space.space_spring.domain.pay.model.firstCollection.PayTargetInfos; +import space.space_spring.domain.pay.model.response.PayHomeViewResponse; + +import java.util.List; + +@Component +public class PayMapper { + + + public PayHomeViewResponse createPayHomeViewResponse(PayRequestInfos payRequestInfos, PayTargetInfos payTargetInfos) { + return PayHomeViewResponse.builder() + .payRequestInfoDtos(payRequestInfos.getAll()) + .payTargetInfoDtos(payTargetInfos.getAll()) + .build(); + } + +} diff --git a/src/main/java/space/space_spring/domain/pay/service/PayService.java b/src/main/java/space/space_spring/domain/pay/service/PayService.java index 6b2a8cd3..fb7d6b51 100644 --- a/src/main/java/space/space_spring/domain/pay/service/PayService.java +++ b/src/main/java/space/space_spring/domain/pay/service/PayService.java @@ -1,9 +1,13 @@ package space.space_spring.domain.pay.service; import lombok.RequiredArgsConstructor; -import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import space.space_spring.domain.pay.model.firstCollection.PayRequestInfos; +import space.space_spring.domain.pay.model.firstCollection.PayRequestTargets; +import space.space_spring.domain.pay.model.firstCollection.PayRequests; +import space.space_spring.domain.pay.model.firstCollection.PayTargetInfos; +import space.space_spring.domain.pay.model.mapper.PayMapper; import space.space_spring.domain.userSpace.model.entity.UserSpace; import space.space_spring.domain.userSpace.repository.UserSpaceRepository; import space.space_spring.domain.pay.model.entity.PayRequest; @@ -16,7 +20,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Optional; import static space.space_spring.response.status.BaseExceptionResponseStatus.*; @@ -34,25 +37,33 @@ public class PayService { private final UserSpaceRepository userSpaceRepository; private final PayRequestRepository payRequestRepository; private final PayRequestTargetRepository payRequestTargetRepository; + private final PayMapper payMapper; private final boolean INCOMPLETE_PAY = false; private final boolean COMPLETE_PAY = true; + @Transactional // 지연로딩을 이용하기 위한 Transaction 설정 + // 이래도 test 에서 PayRequest의 PayRequestTarget list 못 찾아 오는데 ?? public PayHomeViewResponse getPayHomeInfos(Long userId, Long spaceId) { // 유저가 스페이스에 속하는 지 검증하고, UserSpace userSpace = validateUserInSpace(userId, spaceId); - // 유저가 요청한 정산들 중, 완료되지 않은 정산 리스트 정보와 - List payRequestInfoDtos = getPayRequestInfos(userSpace); + List allPayRequests = payRequestRepository.findAllByUserAndSpace(userSpace.getUser(), userSpace.getSpace(), INCOMPLETE_PAY); + PayRequests payRequests = PayRequests.create(allPayRequests); + PayRequestInfos payRequestInfos = payRequests.getPayRequestInfos(); - // 유저가 요청받은 정산들 중, 완료되지 않은 정산 리스트를 찾아서 - List payTargetInfoDtos = getPayTargetInfos(userSpace); + List allPayRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(userId, userSpace.getSpace(), INCOMPLETE_PAY); + PayRequestTargets payRequestTargets = PayRequestTargets.create(allPayRequestTargets); + PayTargetInfos payTargetInfos = payRequestTargets.getPayTargetInfos(); + +// // 유저가 요청한 정산들 중, 완료되지 않은 정산 리스트 정보와 +// List payRequestInfoDtos = getPayRequestInfos(userSpace); +// +// // 유저가 요청받은 정산들 중, 완료되지 않은 정산 리스트를 찾아서 +// List payTargetInfoDtos = getPayTargetInfos(userSpace); // return - return PayHomeViewResponse.builder() - .payRequestInfoDtos(payRequestInfoDtos) - .payTargetInfoDtos(payTargetInfoDtos) - .build(); + return payMapper.createPayHomeViewResponse(payRequestInfos, payTargetInfos); } private List getPayRequestInfos(UserSpace userSpace) { @@ -60,8 +71,7 @@ private List getPayRequestInfos(UserSpace userSpace) { List payRequestInfoDtos = new ArrayList<>(); for (PayRequest payRequest : payRequests) { - List findTargets = payRequestTargetRepository.findAllByPayRequest(payRequest); - PayRequestInfoDto payRequestInfo = payRequest.createPayRequestInfo(findTargets); + PayRequestInfoDto payRequestInfo = payRequest.getPayRequestInfo(); payRequestInfoDtos.add(payRequestInfo); } return payRequestInfoDtos; diff --git a/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java b/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java index 26fa10bc..0e14c7fb 100644 --- a/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java +++ b/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java @@ -10,7 +10,6 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; class PayRequestTest { @@ -31,12 +30,13 @@ void createPayRequestInfo() throws Exception { // target1 : 미정산, target2, target3 : 정산 완료 target2.changeCompleteStatus(true); target3.changeCompleteStatus(true); + payRequest.setPayRequestTargets(List.of(target1, target2, target3)); payRequest.changeReceiveAmount(20000); - List targets = List.of(target1, target2, target3); - //when - PayRequestInfoDto payRequestInfo = payRequest.createPayRequestInfo(targets); + PayRequestInfoDto payRequestInfo = payRequest.getPayRequestInfo(); + // -> 테스트 어떻게 ?? + //then assertThat(payRequestInfo) diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index d2e37da8..191123fb 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.test.context.ActiveProfiles; import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; +import space.space_spring.domain.pay.model.mapper.PayMapper; import space.space_spring.domain.space.repository.SpaceRepository; import space.space_spring.domain.userSpace.repository.UserSpaceRepository; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; @@ -31,7 +32,7 @@ import static space.space_spring.response.status.BaseExceptionResponseStatus.USER_IS_NOT_IN_SPACE; @DataJpaTest -@Import({PayService.class}) +@Import({PayService.class, PayMapper.class}) @ActiveProfiles("test") @EnableJpaRepositories(basePackageClasses = {PayRequestRepository.class, PayRequestTargetRepository.class, UserRepository.class, SpaceRepository.class, UserSpaceRepository.class}) @EntityScan(basePackageClasses = {PayRequest.class, PayRequestTarget.class, User.class, Space.class, UserSpace.class}) @@ -55,6 +56,9 @@ class PayServiceTest { @Autowired private UserSpaceRepository userSpaceRepository; + @Autowired + private PayMapper payMapper; + @Test @DisplayName("유저가 요청한 정산들 중 완료되지 않은 정산 정보들과, 요청받은 정산들 중 완료되지 않은 정산 정보들을 return 한다.") void getPayHomeInfos1() throws Exception { @@ -105,12 +109,6 @@ void getPayHomeInfos1() throws Exception { PayRequestTarget completeTarget3 = PayRequestTarget.create(completePay_kyeongmin, seongjun.getUserId(), 20000); completeTarget3.changeCompleteStatus(true); - payRequestRepository.save(inCompletePay1_seongjun); - payRequestRepository.save(inCompletePay2_seongjun); - payRequestRepository.save(completePay_seongjun); - payRequestRepository.save(inCompletePay_seohyun); - payRequestRepository.save(completePay_kyeongmin); - payRequestTargetRepository.save(inCompleteTarget1); payRequestTargetRepository.save(inCompleteTarget2); payRequestTargetRepository.save(inCompleteTarget3); @@ -121,6 +119,14 @@ void getPayHomeInfos1() throws Exception { payRequestTargetRepository.save(inCompleteTarget6); payRequestTargetRepository.save(completeTarget3); + + payRequestRepository.save(inCompletePay1_seongjun); + payRequestRepository.save(inCompletePay2_seongjun); + payRequestRepository.save(completePay_seongjun); + payRequestRepository.save(inCompletePay_seohyun); + payRequestRepository.save(completePay_kyeongmin); + + //when PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(seongjun.getUserId(), testSpace.getSpaceId()); List payRequestInfos = payHomeInfos.getPayRequestInfoDtos(); From 8a04697882a870d4a7ee690623e4ecff79aca01a Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sat, 16 Nov 2024 22:34:45 +0900 Subject: [PATCH 12/20] =?UTF-8?q?test=20:=20PayService=20@SpringBootTest?= =?UTF-8?q?=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- .../domain/pay/model/entity/PayRequest.java | 5 +- .../pay/model/entity/PayRequestTarget.java | 6 +- .../domain/pay/service/PayServiceTest.java | 15 +-- src/test/resources/application-test.yml | 94 ++++++++++++++----- 5 files changed, 89 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 190eaf0c..4848c5e5 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,7 @@ out/ src/main/resource/application-local.yml /**/application-local.yml src/main/resource/application-dev.yml -/**/application-dev.yml \ No newline at end of file +/**/application-dev.yml + +### test yml file ### +src/test/resources/application-test.yml \ No newline at end of file diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index dae8df8e..201463f5 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -11,6 +11,7 @@ import space.space_spring.entity.BaseEntity; import space.space_spring.domain.space.model.entity.Space; +import java.util.ArrayList; import java.util.List; @Getter @@ -47,8 +48,8 @@ public class PayRequest extends BaseEntity { @Column(name = "is_complete") private boolean isComplete; - @OneToMany(mappedBy = "payRequest") - private List payRequestTargets; + @OneToMany(mappedBy = "payRequest", cascade = CascadeType.ALL, orphanRemoval = true) + private List payRequestTargets = new ArrayList<>(); // PayRequestTarget list를 양방향 매핑으로 참조하는것이 더 좋을까? diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index a7ead29b..902e9658 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -43,11 +43,15 @@ private PayRequestTarget(PayRequest payRequest, Long targetUserId, int requested } public static PayRequestTarget create(PayRequest payRequest, Long targetUserId, int requestedAmount) { - return PayRequestTarget.builder() + PayRequestTarget build = PayRequestTarget.builder() .payRequest(payRequest) .targetUserId(targetUserId) .requestedAmount(requestedAmount) .build(); + + payRequest.getPayRequestTargets().add(build); + + return build; } public void changeCompleteStatus(boolean isComplete) { diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index 191123fb..6bf808ac 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -3,11 +3,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.context.annotation.Import; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; +import org.springframework.transaction.annotation.Transactional; import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import space.space_spring.domain.pay.model.mapper.PayMapper; import space.space_spring.domain.space.repository.SpaceRepository; @@ -31,11 +29,9 @@ import static org.assertj.core.api.Assertions.*; import static space.space_spring.response.status.BaseExceptionResponseStatus.USER_IS_NOT_IN_SPACE; -@DataJpaTest -@Import({PayService.class, PayMapper.class}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@Transactional @ActiveProfiles("test") -@EnableJpaRepositories(basePackageClasses = {PayRequestRepository.class, PayRequestTargetRepository.class, UserRepository.class, SpaceRepository.class, UserSpaceRepository.class}) -@EntityScan(basePackageClasses = {PayRequest.class, PayRequestTarget.class, User.class, Space.class, UserSpace.class}) class PayServiceTest { @Autowired @@ -56,9 +52,6 @@ class PayServiceTest { @Autowired private UserSpaceRepository userSpaceRepository; - @Autowired - private PayMapper payMapper; - @Test @DisplayName("유저가 요청한 정산들 중 완료되지 않은 정산 정보들과, 요청받은 정산들 중 완료되지 않은 정산 정보들을 return 한다.") void getPayHomeInfos1() throws Exception { diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index 42c9af63..d0a5914c 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -1,25 +1,77 @@ -spring: - h2: - console: - enabled: true - path: /h2-console - datasource: - url: jdbc:h2:mem:~/space_spring - driver-class-name: org.h2.Driver - username: sa - password: - jpa: +# 서버 포트 설정 +server: + port: 8080 + +# H2 인메모리 데이터베이스 설정 +datasource: + url: jdbc:h2:mem:space_testdb + driver-class-name: org.h2.Driver + username: sa + password: + +# JPA 설정 +jpa: + hibernate: + ddl-auto: create-drop # 테스트 시작 시 테이블 생성, 종료 시 삭제 + show-sql: true + properties: hibernate: - ddl-auto: create - show-sql: true - properties: - hibernate: - format_sql: true + format_sql: true + use_sql_comments: true - sql: - init: - mode: never # sql initialization 을 사용하지 않겠다 +# MongoDB 설정 (embedded MongoDB 사용 또는 목 처리) +data: + mongodb: + uri: mongodb://localhost:27017/test_db # 테스트용 로컬 MongoDB +# AWS S3 설정 (로컬 스토리지로 대체하거나 목 처리) +cloud: + aws: + credentials: + access-key: test-access-key + secret-key: test-secret-key + s3: + bucket: test-bucket + region: + static: us-east-1 + stack: + auto: false -server: - port: 8080 \ No newline at end of file +# JWT 시크릿 키 설정 +secret: + jwt: + access-secret-key: test-access-secret-key + refresh-secret-key: test-refresh-secret-key + access-expired-in: 30000 + refresh-expired-in: 60000 + +# OAuth 설정 (테스트용으로 대체) +oauth: + kakao: + client: + id: test-client-id + secret: test-client-secret + redirect: + uri: http://localhost:8080/oauth/callback/kakao + +# LiveKit 설정 (테스트용으로 대체) +livekit: + project: + host: https://test-livekit-host + id: test-project-id + api: + key: test-api-key + secretKey: test-api-secret + +# 멀티파트 설정 +spring: + servlet: + multipart: + max-file-size: 5MB + max-request-size: 5MB + +# 기타 설정 +logging: + level: + org.hibernate.SQL: debug + org.hibernate.type.descriptor.sql.BasicBinder: trace \ No newline at end of file From 930e755c8b6a0828743fab6a979fcb80fe10ae75 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sat, 16 Nov 2024 23:10:52 +0900 Subject: [PATCH 13/20] =?UTF-8?q?test=20:=20PayServiceTest=20@BeforeEach?= =?UTF-8?q?=20=EB=A1=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/service/PayServiceTest.java | 130 +++++++----------- 1 file changed, 49 insertions(+), 81 deletions(-) diff --git a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java index 6bf808ac..c3abe89a 100644 --- a/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/domain/pay/service/PayServiceTest.java @@ -1,5 +1,6 @@ package space.space_spring.domain.pay.service; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -7,7 +8,6 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; -import space.space_spring.domain.pay.model.mapper.PayMapper; import space.space_spring.domain.space.repository.SpaceRepository; import space.space_spring.domain.userSpace.repository.UserSpaceRepository; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; @@ -52,36 +52,43 @@ class PayServiceTest { @Autowired private UserSpaceRepository userSpaceRepository; + private User seongjun; + private User sangjun; + private User seohyun; + private User kyeongmin; + private Space kuit; + + @BeforeEach + void setUp() { + // kuit 에 성준, 상준, 서현, 경민 이 가입되어 있음 + seongjun = userRepository.save(User.create("email1", "password", "노성준", UserSignupType.LOCAL)); + sangjun = userRepository.save(User.create("email2", "password", "김상준", UserSignupType.LOCAL)); + seohyun = userRepository.save(User.create("email3", "password", "정서현", UserSignupType.LOCAL)); + kyeongmin = userRepository.save(User.create("email4", "password", "김경민", UserSignupType.LOCAL)); + + kuit = spaceRepository.save(Space.create("space", "profileImg")); + + userSpaceRepository.save(UserSpace.create(seongjun, kuit, UserSpaceAuth.NORMAL)); + userSpaceRepository.save(UserSpace.create(sangjun, kuit, UserSpaceAuth.NORMAL)); + userSpaceRepository.save(UserSpace.create(seohyun, kuit, UserSpaceAuth.NORMAL)); + userSpaceRepository.save(UserSpace.create(kyeongmin, kuit, UserSpaceAuth.NORMAL)); + } + @Test @DisplayName("유저가 요청한 정산들 중 완료되지 않은 정산 정보들과, 요청받은 정산들 중 완료되지 않은 정산 정보들을 return 한다.") void getPayHomeInfos1() throws Exception { //given - User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); - User user2 = User.create("email", "password", "김상준", UserSignupType.LOCAL); - User user3 = User.create("email", "password", "정서현", UserSignupType.LOCAL); - User user4 = User.create("email", "password", "김경민", UserSignupType.LOCAL); - Space space = Space.create("space", "profileImg"); - - User seongjun = userRepository.save(user1); - User sangjun = userRepository.save(user2); - User seohyun = userRepository.save(user3); - User kyeongmin = userRepository.save(user4); - Space testSpace = spaceRepository.save(space); - - UserSpace userSpace = UserSpace.create(seongjun, testSpace, UserSpaceAuth.NORMAL); - userSpaceRepository.save(userSpace); - - // seongjun 이 testSpace 에서 생성한 3개의 정산 요청 - PayRequest inCompletePay1_seongjun = PayRequest.create(seongjun, testSpace, 20000, "bank", "accountNum"); - PayRequest inCompletePay2_seongjun = PayRequest.create(seongjun, testSpace, 40000, "bank", "accountNum"); - PayRequest completePay_seongjun = PayRequest.create(seongjun, testSpace, 20000, "bank", "accountNum"); + // seongjun 이 kuit 에서 생성한 3개의 정산 요청 + PayRequest inCompletePay1_seongjun = PayRequest.create(seongjun, kuit, 20000, "bank", "accountNum"); + PayRequest inCompletePay2_seongjun = PayRequest.create(seongjun, kuit, 40000, "bank", "accountNum"); + PayRequest completePay_seongjun = PayRequest.create(seongjun, kuit, 20000, "bank", "accountNum"); completePay_seongjun.changeCompleteStatus(true); - // seohyun 이 testSpace 에서 생성한 1개의 정산 요청 - PayRequest inCompletePay_seohyun = PayRequest.create(seohyun, testSpace, 40000, "국민은행", "111-111"); + // seohyun 이 kuit 에서 생성한 1개의 정산 요청 + PayRequest inCompletePay_seohyun = PayRequest.create(seohyun, kuit, 40000, "국민은행", "111-111"); - // Kyeongmin 이 testSpace에서 생성한 1개의 정산 요청 - PayRequest completePay_kyeongmin = PayRequest.create(kyeongmin, testSpace, 20000, "우리은행", "222-222"); + // Kyeongmin 이 kuit 에서 생성한 1개의 정산 요청 + PayRequest completePay_kyeongmin = PayRequest.create(kyeongmin, kuit, 20000, "우리은행", "222-222"); completePay_kyeongmin.changeCompleteStatus(true); // 각 정산 요청의 타겟들 @@ -112,16 +119,14 @@ void getPayHomeInfos1() throws Exception { payRequestTargetRepository.save(inCompleteTarget6); payRequestTargetRepository.save(completeTarget3); - payRequestRepository.save(inCompletePay1_seongjun); payRequestRepository.save(inCompletePay2_seongjun); payRequestRepository.save(completePay_seongjun); payRequestRepository.save(inCompletePay_seohyun); payRequestRepository.save(completePay_kyeongmin); - //when - PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(seongjun.getUserId(), testSpace.getSpaceId()); + PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(seongjun.getUserId(), kuit.getSpaceId()); List payRequestInfos = payHomeInfos.getPayRequestInfoDtos(); List payTargetInfoDtos = payHomeInfos.getPayTargetInfoDtos(); @@ -145,24 +150,11 @@ void getPayHomeInfos1() throws Exception { @DisplayName("유저가 요청한 정산들 중, 완료되지 않은 정산이 없으면 빈 ArrayList 를 return 한다.") void getPayHomeInfos2() throws Exception { //given - User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); - User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); - User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); - Space space = Space.create("space", "profileImg"); - - User payCreator = userRepository.save(user1); - User payTarget1 = userRepository.save(user2); - User payTarget2 = userRepository.save(user3); - Space testSpace = spaceRepository.save(space); - - UserSpace userSpace = UserSpace.create(payCreator, testSpace, UserSpaceAuth.NORMAL); - userSpaceRepository.save(userSpace); - - PayRequest completePay = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); + PayRequest completePay = PayRequest.create(seongjun, kuit, 20000, "bank", "accountNum"); completePay.changeCompleteStatus(true); - PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, payTarget1.getUserId(), 10000); - PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, payTarget2.getUserId(), 10000); + PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, sangjun.getUserId(), 10000); + PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, seohyun.getUserId(), 10000); completeTarget1.changeCompleteStatus(true); completeTarget2.changeCompleteStatus(true); @@ -172,35 +164,23 @@ void getPayHomeInfos2() throws Exception { payRequestTargetRepository.save(completeTarget2); //when - PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payCreator.getUserId(), testSpace.getSpaceId()); + PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(seongjun.getUserId(), kuit.getSpaceId()); List payRequestInfoDtoList = payHomeInfos.getPayRequestInfoDtos(); //then - assertThat(payRequestInfoDtoList).hasSize(0); + assertThat(payRequestInfoDtoList).isNotNull() + .hasSize(0); } @Test @DisplayName("유저가 요청받은 정산들 중, 완료되지 않은 정산이 없으면 빈 ArrayList를 return 한다.") void getPayHomeInfos3() throws Exception { //given - User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); - User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); - User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); - Space space = Space.create("space", "profileImg"); - - User payCreator = userRepository.save(user1); - User payTarget1 = userRepository.save(user2); - User payTarget2 = userRepository.save(user3); - Space testSpace = spaceRepository.save(space); - - UserSpace userSpace = UserSpace.create(payTarget2, testSpace, UserSpaceAuth.NORMAL); - userSpaceRepository.save(userSpace); - - PayRequest completePay = PayRequest.create(payCreator, testSpace, 20000, "bank", "accountNum"); + PayRequest completePay = PayRequest.create(seongjun, kuit, 20000, "bank", "accountNum"); completePay.changeCompleteStatus(true); - PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, payTarget1.getUserId(), 10000); - PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, payTarget2.getUserId(), 10000); + PayRequestTarget completeTarget1 = PayRequestTarget.create(completePay, seohyun.getUserId(), 10000); + PayRequestTarget completeTarget2 = PayRequestTarget.create(completePay, kyeongmin.getUserId(), 10000); completeTarget1.changeCompleteStatus(true); completeTarget2.changeCompleteStatus(true); @@ -210,36 +190,24 @@ void getPayHomeInfos3() throws Exception { payRequestTargetRepository.save(completeTarget2); //when - PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(payTarget2.getUserId(), testSpace.getSpaceId()); + PayHomeViewResponse payHomeInfos = payService.getPayHomeInfos(kyeongmin.getUserId(), kuit.getSpaceId()); List payTargetInfoDtos = payHomeInfos.getPayTargetInfoDtos(); //then - assertThat(payTargetInfoDtos).hasSize(0); + assertThat(payTargetInfoDtos).isNotNull() + .hasSize(0); } @Test @DisplayName("user는 자신이 속한 space의 정산 홈 view만을 볼 수 있다.") void getPayHomeInfos4() throws Exception { //given - User user1 = User.create("email", "password", "노성준", UserSignupType.LOCAL); - User user2 = User.create("email", "password", "name", UserSignupType.LOCAL); - User user3 = User.create("email", "password", "name", UserSignupType.LOCAL); - Space space1 = Space.create("space", "profileImg"); - Space space2 = Space.create("space", "profileImg"); - - User payCreator = userRepository.save(user1); - User payTarget1 = userRepository.save(user2); - User payTarget2 = userRepository.save(user3); - Space KUIT = spaceRepository.save(space1); - Space ALKON = spaceRepository.save(space2); - - UserSpace userSpace = UserSpace.create(payCreator, KUIT, UserSpaceAuth.NORMAL); - userSpaceRepository.save(userSpace); + Space alcon = spaceRepository.save(Space.create("space", "profileImg")); - PayRequest payRequest = PayRequest.create(payCreator, KUIT, 20000, "bank", "accountNum"); + PayRequest payRequest = PayRequest.create(seongjun, kuit, 20000, "bank", "accountNum"); - PayRequestTarget target1 = PayRequestTarget.create(payRequest, payTarget1.getUserId(), 10000); - PayRequestTarget target2 = PayRequestTarget.create(payRequest, payTarget2.getUserId(), 10000); + PayRequestTarget target1 = PayRequestTarget.create(payRequest, sangjun.getUserId(), 10000); + PayRequestTarget target2 = PayRequestTarget.create(payRequest, seohyun.getUserId(), 10000); payRequestRepository.save(payRequest); @@ -247,7 +215,7 @@ void getPayHomeInfos4() throws Exception { payRequestTargetRepository.save(target2); //when // then - assertThatThrownBy(() -> payService.getPayHomeInfos(payCreator.getUserId(), ALKON.getSpaceId())) + assertThatThrownBy(() -> payService.getPayHomeInfos(seongjun.getUserId(), alcon.getSpaceId())) .isInstanceOf(CustomException.class) .hasMessage(USER_IS_NOT_IN_SPACE.getMessage()); } From a7cb985cc3fb7c857fd8d9ddd3f227b371f1336e Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sat, 16 Nov 2024 23:37:56 +0900 Subject: [PATCH 14/20] =?UTF-8?q?refactor=20:=20PayRequestTarget=20<->=20P?= =?UTF-8?q?ayRequest=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=ED=8E=B8?= =?UTF-8?q?=EC=9D=98=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=95=EC=9D=98=20?= =?UTF-8?q?&=20PayRequestTest=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/model/entity/PayRequest.java | 10 ++---- .../pay/model/entity/PayRequestTarget.java | 2 +- .../domain/pay/service/PayService.java | 33 ++----------------- .../pay/model/entity/PayRequestTest.java | 7 ++-- 4 files changed, 8 insertions(+), 44 deletions(-) diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index 201463f5..c2e4a1b6 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -50,12 +50,6 @@ public class PayRequest extends BaseEntity { @OneToMany(mappedBy = "payRequest", cascade = CascadeType.ALL, orphanRemoval = true) private List payRequestTargets = new ArrayList<>(); - // PayRequestTarget list를 양방향 매핑으로 참조하는것이 더 좋을까? - - - public PayRequestTargets toPayRequestTargets() { - return PayRequestTargets.create(payRequestTargets); - } public void changeCompleteStatus(boolean isComplete) { @@ -66,8 +60,8 @@ public void changeReceiveAmount(int receiveAmount) { this.receiveAmount = receiveAmount; } - public void setPayRequestTargets(List payRequestTargets) { - this.payRequestTargets = payRequestTargets; + public void addPayRequestTarget(PayRequestTarget payRequestTarget) { + payRequestTargets.add(payRequestTarget); } @Builder diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index 902e9658..cbea5a4e 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -49,7 +49,7 @@ public static PayRequestTarget create(PayRequest payRequest, Long targetUserId, .requestedAmount(requestedAmount) .build(); - payRequest.getPayRequestTargets().add(build); + payRequest.addPayRequestTarget(build); // 연관관계 편의 메서드 return build; } diff --git a/src/main/java/space/space_spring/domain/pay/service/PayService.java b/src/main/java/space/space_spring/domain/pay/service/PayService.java index fb7d6b51..a49fbf4e 100644 --- a/src/main/java/space/space_spring/domain/pay/service/PayService.java +++ b/src/main/java/space/space_spring/domain/pay/service/PayService.java @@ -42,52 +42,25 @@ public class PayService { private final boolean INCOMPLETE_PAY = false; private final boolean COMPLETE_PAY = true; - @Transactional // 지연로딩을 이용하기 위한 Transaction 설정 - // 이래도 test 에서 PayRequest의 PayRequestTarget list 못 찾아 오는데 ?? + @Transactional // 지연로딩을 이용하기 위한 Transaction 설정 public PayHomeViewResponse getPayHomeInfos(Long userId, Long spaceId) { // 유저가 스페이스에 속하는 지 검증하고, UserSpace userSpace = validateUserInSpace(userId, spaceId); + // 유저가 요청한 정산들 중, 현재 진행중인 정산 찾고 List allPayRequests = payRequestRepository.findAllByUserAndSpace(userSpace.getUser(), userSpace.getSpace(), INCOMPLETE_PAY); PayRequests payRequests = PayRequests.create(allPayRequests); PayRequestInfos payRequestInfos = payRequests.getPayRequestInfos(); + // 유저가 요청받은 정산들 중, 현재 진행중인 정산 찾아서 List allPayRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(userId, userSpace.getSpace(), INCOMPLETE_PAY); PayRequestTargets payRequestTargets = PayRequestTargets.create(allPayRequestTargets); PayTargetInfos payTargetInfos = payRequestTargets.getPayTargetInfos(); -// // 유저가 요청한 정산들 중, 완료되지 않은 정산 리스트 정보와 -// List payRequestInfoDtos = getPayRequestInfos(userSpace); -// -// // 유저가 요청받은 정산들 중, 완료되지 않은 정산 리스트를 찾아서 -// List payTargetInfoDtos = getPayTargetInfos(userSpace); - // return return payMapper.createPayHomeViewResponse(payRequestInfos, payTargetInfos); } - private List getPayRequestInfos(UserSpace userSpace) { - List payRequests = payRequestRepository.findAllByUserAndSpace(userSpace.getUser(), userSpace.getSpace(), INCOMPLETE_PAY); - - List payRequestInfoDtos = new ArrayList<>(); - for (PayRequest payRequest : payRequests) { - PayRequestInfoDto payRequestInfo = payRequest.getPayRequestInfo(); - payRequestInfoDtos.add(payRequestInfo); - } - return payRequestInfoDtos; - } - - private List getPayTargetInfos(UserSpace userSpace) { - List payRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(userSpace.getUser().getUserId(), userSpace.getSpace(), INCOMPLETE_PAY); - - List payTargetInfoDtos = new ArrayList<>(); - for (PayRequestTarget payRequestTarget : payRequestTargets) { - PayTargetInfoDto payReceiveInfo = payRequestTarget.createPayTargetInfo(); - payTargetInfoDtos.add(payReceiveInfo); - } - return payTargetInfoDtos; - } - private UserSpace validateUserInSpace(Long userId, Long spaceId) { return userSpaceRepository.findUserSpaceByUserAndSpace(userId, spaceId).orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE)); } diff --git a/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java b/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java index 0e14c7fb..976ade14 100644 --- a/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java +++ b/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java @@ -14,8 +14,8 @@ class PayRequestTest { @Test - @DisplayName("해당 PayRequest의 target list를 인자로 받으면, PayRequestInfoDto를 return 한다.") - void createPayRequestInfo() throws Exception { + @DisplayName("해당 정산 요청에 대해 [총 정산 요청 사람 수, 그 중 돈을 낸 사람 수, 총 정산 요청 금액, 그 중 받은 금액] 의 정보를 알려준다.") + void getPayRequestInfo() throws Exception { //given User payCreator = User.create("email", "password", "노성준", UserSignupType.LOCAL); @@ -30,13 +30,10 @@ void createPayRequestInfo() throws Exception { // target1 : 미정산, target2, target3 : 정산 완료 target2.changeCompleteStatus(true); target3.changeCompleteStatus(true); - payRequest.setPayRequestTargets(List.of(target1, target2, target3)); payRequest.changeReceiveAmount(20000); //when PayRequestInfoDto payRequestInfo = payRequest.getPayRequestInfo(); - // -> 테스트 어떻게 ?? - //then assertThat(payRequestInfo) From d35a942f90817c49d8ba6efe0d93344af25c166c Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sun, 17 Nov 2024 00:03:08 +0900 Subject: [PATCH 15/20] =?UTF-8?q?refactor=20:=20=EC=A0=95=EC=82=B0=20?= =?UTF-8?q?=ED=99=88=20view=20api=20=EC=9D=98=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=EB=8B=A8=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8E=99?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/model/mapper/PayMapper.java | 1 - .../model/response/PayHomeViewResponse.java | 2 -- .../domain/pay/service/PayService.java | 26 +++++++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/space/space_spring/domain/pay/model/mapper/PayMapper.java b/src/main/java/space/space_spring/domain/pay/model/mapper/PayMapper.java index 906db48f..73167202 100644 --- a/src/main/java/space/space_spring/domain/pay/model/mapper/PayMapper.java +++ b/src/main/java/space/space_spring/domain/pay/model/mapper/PayMapper.java @@ -12,7 +12,6 @@ @Component public class PayMapper { - public PayHomeViewResponse createPayHomeViewResponse(PayRequestInfos payRequestInfos, PayTargetInfos payTargetInfos) { return PayHomeViewResponse.builder() .payRequestInfoDtos(payRequestInfos.getAll()) diff --git a/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java b/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java index 978805ef..033e8519 100644 --- a/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java +++ b/src/main/java/space/space_spring/domain/pay/model/response/PayHomeViewResponse.java @@ -1,12 +1,10 @@ package space.space_spring.domain.pay.model.response; -import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; -import java.util.ArrayList; import java.util.List; @Getter diff --git a/src/main/java/space/space_spring/domain/pay/service/PayService.java b/src/main/java/space/space_spring/domain/pay/service/PayService.java index a49fbf4e..a3510111 100644 --- a/src/main/java/space/space_spring/domain/pay/service/PayService.java +++ b/src/main/java/space/space_spring/domain/pay/service/PayService.java @@ -47,15 +47,11 @@ public PayHomeViewResponse getPayHomeInfos(Long userId, Long spaceId) { // 유저가 스페이스에 속하는 지 검증하고, UserSpace userSpace = validateUserInSpace(userId, spaceId); - // 유저가 요청한 정산들 중, 현재 진행중인 정산 찾고 - List allPayRequests = payRequestRepository.findAllByUserAndSpace(userSpace.getUser(), userSpace.getSpace(), INCOMPLETE_PAY); - PayRequests payRequests = PayRequests.create(allPayRequests); - PayRequestInfos payRequestInfos = payRequests.getPayRequestInfos(); + // 유저가 요청한 정산들 중, 완료되지 않은 정산 찾고 + PayRequestInfos payRequestInfos = getPayRequestInfos(userSpace, INCOMPLETE_PAY); - // 유저가 요청받은 정산들 중, 현재 진행중인 정산 찾아서 - List allPayRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(userId, userSpace.getSpace(), INCOMPLETE_PAY); - PayRequestTargets payRequestTargets = PayRequestTargets.create(allPayRequestTargets); - PayTargetInfos payTargetInfos = payRequestTargets.getPayTargetInfos(); + // 유저가 요청받은 정산들 중, 완료되지 않은 정산 찾아서 + PayTargetInfos payTargetInfos = getPayTargetInfos(userSpace, INCOMPLETE_PAY); // return return payMapper.createPayHomeViewResponse(payRequestInfos, payTargetInfos); @@ -65,6 +61,20 @@ private UserSpace validateUserInSpace(Long userId, Long spaceId) { return userSpaceRepository.findUserSpaceByUserAndSpace(userId, spaceId).orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE)); } + private PayRequestInfos getPayRequestInfos(UserSpace userSpace, boolean payRequestStatus) { + List allPayRequests = payRequestRepository.findAllByUserAndSpace(userSpace.getUser(), userSpace.getSpace(), payRequestStatus); + PayRequests payRequests = PayRequests.create(allPayRequests); + + return payRequests.getPayRequestInfos(); + } + + private PayTargetInfos getPayTargetInfos(UserSpace userSpace, boolean payRequestTargetStatus) { + Long targetUserId = userSpace.getUser().getUserId(); + List allPayRequestTargets = payRequestTargetRepository.findAllByUserAndSpace(targetUserId, userSpace.getSpace(), payRequestTargetStatus); + PayRequestTargets payRequestTargets = PayRequestTargets.create(allPayRequestTargets); + + return payRequestTargets.getPayTargetInfos(); + } // @Transactional From 3cf9abcc85f0eeebe12c5baf54bd90b91306ed59 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Tue, 19 Nov 2024 15:17:51 +0900 Subject: [PATCH 16/20] =?UTF-8?q?refactor=20:=20Dto=20list=EC=9D=98=20?= =?UTF-8?q?=EC=9D=BC=EA=B8=89=20=EC=BB=AC=EB=A0=89=EC=85=98.getAll()=20?= =?UTF-8?q?=EC=9D=B4=20=EB=B6=88=EB=B3=80=EC=84=B1=20=EB=B3=B4=EC=9E=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/model/firstCollection/PayRequestInfos.java | 4 +++- .../domain/pay/model/firstCollection/PayTargetInfos.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestInfos.java b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestInfos.java index 461c4021..74df6777 100644 --- a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestInfos.java +++ b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestInfos.java @@ -3,6 +3,7 @@ import space.space_spring.domain.pay.model.dto.PayRequestInfoDto; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class PayRequestInfos { @@ -14,6 +15,7 @@ public void add(PayRequestInfoDto payRequestInfoDto) { } public List getAll() { - return payRequestInfos; + // getAll 메서드가 반환하는 리스트는 '읽기 전용' + return Collections.unmodifiableList(payRequestInfos); } } diff --git a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayTargetInfos.java b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayTargetInfos.java index 3f0e9237..e1addb6e 100644 --- a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayTargetInfos.java +++ b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayTargetInfos.java @@ -3,6 +3,7 @@ import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class PayTargetInfos { @@ -14,6 +15,7 @@ public void add(PayTargetInfoDto payTargetInfoDto) { } public List getAll() { - return payTargetInfoDtos; + // getAll 메서드가 반환하는 리스트는 '읽기 전용' + return Collections.unmodifiableList(payTargetInfoDtos); } } From 210e97fbc92d9aaad71df86a79d61164f16f2ff7 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Wed, 20 Nov 2024 00:55:09 +0900 Subject: [PATCH 17/20] =?UTF-8?q?refactor=20:=20PayRequest=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=97=90=20=EC=9D=BC=EA=B8=89=20=EC=BB=AC?= =?UTF-8?q?=EB=A0=89=EC=85=98=20=ED=95=84=EB=93=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/pay/model/entity/PayRequest.java | 25 ++++++++----------- .../pay/model/entity/PayRequestTarget.java | 2 +- .../firstCollection/PayRequestTargets.java | 23 ++++++++++++++--- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index c2e4a1b6..35b8fd00 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -12,7 +12,6 @@ import space.space_spring.domain.space.model.entity.Space; import java.util.ArrayList; -import java.util.List; @Getter @Entity @@ -48,8 +47,8 @@ public class PayRequest extends BaseEntity { @Column(name = "is_complete") private boolean isComplete; - @OneToMany(mappedBy = "payRequest", cascade = CascadeType.ALL, orphanRemoval = true) - private List payRequestTargets = new ArrayList<>(); + @Embedded + private PayRequestTargets payRequestTargets; // PayRequest의 target 들 public void changeCompleteStatus(boolean isComplete) { @@ -61,7 +60,7 @@ public void changeReceiveAmount(int receiveAmount) { } public void addPayRequestTarget(PayRequestTarget payRequestTarget) { - payRequestTargets.add(payRequestTarget); + payRequestTargets.addPayRequestTarget(payRequestTarget); } @Builder @@ -76,26 +75,22 @@ private PayRequest(User payCreateUser, Space space, int totalAmount, String bank } public static PayRequest create(User payCreateUser, Space space, int totalAmount, String bankName, String bankAccountNum) { - return PayRequest.builder() + PayRequest build = PayRequest.builder() .payCreateUser(payCreateUser) .space(space) .totalAmount(totalAmount) .bankName(bankName) .bankAccountNum(bankAccountNum) .build(); + + build.payRequestTargets = PayRequestTargets.create(new ArrayList<>()); // + + return build; } public PayRequestInfoDto getPayRequestInfo() { - int totalTargetNum = 0; - int paySendTargetNum = 0; - - for (PayRequestTarget payRequestTarget : payRequestTargets) { - if (payRequestTarget.isComplete()) { - // 해당 타겟이 돈을 낸 경우 - paySendTargetNum++; - } - totalTargetNum++; - } + int totalTargetNum = payRequestTargets.countTotalTargets(); + int paySendTargetNum = payRequestTargets.countCompleteTargets(); return PayRequestInfoDto.builder() .payRequestId(payRequestId) diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java index cbea5a4e..fbefb308 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequestTarget.java @@ -58,7 +58,7 @@ public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } - public PayTargetInfoDto createPayTargetInfo() { + public PayTargetInfoDto getPayTargetInfo() { return PayTargetInfoDto.builder() .payRequestTargetId(payRequestTargetId) .payCreatorName(payRequest.getPayCreateUser().getUserName()) diff --git a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargets.java b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargets.java index ad7d1d53..4f1d3c7e 100644 --- a/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargets.java +++ b/src/main/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargets.java @@ -1,18 +1,23 @@ package space.space_spring.domain.pay.model.firstCollection; import jakarta.persistence.Embeddable; -import jakarta.persistence.Embedded; +import jakarta.persistence.OneToMany; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import space.space_spring.domain.pay.model.dto.PayTargetInfoDto; import space.space_spring.domain.pay.model.entity.PayRequestTarget; import java.util.List; @Getter +@Embeddable +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class PayRequestTargets { - private final List payRequestTargets; + @OneToMany(mappedBy = "payRequest") + private List payRequestTargets; @Builder private PayRequestTargets(List payRequestTargets) { @@ -29,12 +34,24 @@ public PayTargetInfos getPayTargetInfos() { PayTargetInfos payTargetInfos = new PayTargetInfos(); for (PayRequestTarget payRequestTarget : payRequestTargets) { - PayTargetInfoDto payTargetInfo = payRequestTarget.createPayTargetInfo(); + PayTargetInfoDto payTargetInfo = payRequestTarget.getPayTargetInfo(); payTargetInfos.add(payTargetInfo); } return payTargetInfos; } + public void addPayRequestTarget(PayRequestTarget payRequestTarget) { + payRequestTargets.add(payRequestTarget); + } + + public int countTotalTargets() { + return payRequestTargets.size(); + } + public int countCompleteTargets() { + return (int) payRequestTargets.stream() + .filter(PayRequestTarget::isComplete) + .count(); + } } From 6e67e809369b4416995cf6c96de186910cca2b16 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Wed, 20 Nov 2024 13:50:30 +0900 Subject: [PATCH 18/20] =?UTF-8?q?test=20:=20PayRequestTargets=20=EC=9D=BC?= =?UTF-8?q?=EA=B8=89=20=EC=BB=AC=EB=A0=89=EC=85=98=EC=9D=98=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=ED=85=8C=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 --- .../domain/pay/model/entity/PayRequest.java | 2 +- .../PayRequestTargetsTest.java | 108 ++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargetsTest.java diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index 35b8fd00..10d24627 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -83,7 +83,7 @@ public static PayRequest create(User payCreateUser, Space space, int totalAmount .bankAccountNum(bankAccountNum) .build(); - build.payRequestTargets = PayRequestTargets.create(new ArrayList<>()); // + build.payRequestTargets = PayRequestTargets.create(new ArrayList<>()); return build; } diff --git a/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargetsTest.java b/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargetsTest.java new file mode 100644 index 00000000..6a4250ac --- /dev/null +++ b/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestTargetsTest.java @@ -0,0 +1,108 @@ +package space.space_spring.domain.pay.model.firstCollection; + +import org.assertj.core.groups.Tuple; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import space.space_spring.domain.pay.model.entity.PayRequest; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.space.model.entity.Space; +import space.space_spring.domain.user.model.entity.User; +import space.space_spring.entity.enumStatus.UserSignupType; + +import java.util.List; + +import static org.assertj.core.api.Assertions.*; + +class PayRequestTargetsTest { + + private User seongjun; + private User sangjun; + private User seohyun; + private User kyeongmin; + private Space kuit; + + @BeforeEach + void setUp() { + // 1L : seongjun, 2L : sangjun, 3L : seohyun, 4L : kyeongmin + seongjun = User.create("email", "password", "노성준", UserSignupType.LOCAL); + sangjun = User.create("email", "password", "김상준", UserSignupType.LOCAL); + seohyun = User.create("email", "password", "정서현", UserSignupType.LOCAL); + kyeongmin = User.create("email", "password", "김경민", UserSignupType.LOCAL); + kuit = Space.create("space", "profileImg"); + } + + @Test + @DisplayName("멤버 변수인 PayRequestTarget list 로부터 [payRequestTargetId, 정산 생성자 이름, 요청받은 정산 금액, 송금해야할 은행 이름, 계좌번호] 정보를 찾아준다.") + void getPayTargetInfos() throws Exception { + //given + PayRequest payRequest1 = PayRequest.create(sangjun, kuit, 40000, "우리은행", "111-111"); + PayRequestTarget target1 = PayRequestTarget.create(payRequest1, 1L, 20000); + PayRequestTarget target2 = PayRequestTarget.create(payRequest1, 2L, 20000); + + PayRequest payRequest2 = PayRequest.create(seohyun, kuit, 40000, "신한은행", "222-222"); + PayRequestTarget target3 = PayRequestTarget.create(payRequest2, 1L, 10000); + PayRequestTarget target4 = PayRequestTarget.create(payRequest2, 4L, 30000); + + PayRequestTargets targetIsSeongjun = PayRequestTargets.create(List.of(target1, target3)); + + //when + PayTargetInfos payTargetInfos = targetIsSeongjun.getPayTargetInfos(); + + //then + assertThat(payTargetInfos.getAll()).hasSize(2) + .extracting("payCreatorName", "requestedAmount", "bankName", "bankAccountNum") + .containsExactlyInAnyOrder( + tuple("김상준", 20000, "우리은행", "111-111"), + tuple("정서현", 10000, "신한은행", "222-222") + ); + } + + @Test + @DisplayName("멤버 변수인 PayRequestTarget list 의 전체 크기를 알려준다.") + void countTotalTargets() throws Exception { + //given + PayRequest payRequest1 = PayRequest.create(sangjun, kuit, 40000, "우리은행", "111-111"); + PayRequestTarget target1 = PayRequestTarget.create(payRequest1, 1L, 20000); + PayRequestTarget target2 = PayRequestTarget.create(payRequest1, 2L, 20000); + + PayRequest payRequest2 = PayRequest.create(seohyun, kuit, 40000, "신한은행", "222-222"); + PayRequestTarget target3 = PayRequestTarget.create(payRequest2, 1L, 10000); + PayRequestTarget target4 = PayRequestTarget.create(payRequest2, 4L, 30000); + + PayRequestTargets targetIsSeongjun = PayRequestTargets.create(List.of(target1, target3)); + + //when + int totalCount = targetIsSeongjun.countTotalTargets(); + + //then + assertThat(totalCount).isEqualTo(2); + } + + @Test + @DisplayName("멤버 변수인 PayRequestTarget list 중 정산을 완료한 타겟이 몇 명인지 알려준다.") + void countCompleteTargets() throws Exception { + //given + PayRequest payRequest1 = PayRequest.create(sangjun, kuit, 40000, "우리은행", "111-111"); + PayRequestTarget target1 = PayRequestTarget.create(payRequest1, 1L, 20000); + PayRequestTarget target2 = PayRequestTarget.create(payRequest1, 2L, 20000); + + PayRequest payRequest2 = PayRequest.create(seohyun, kuit, 40000, "신한은행", "222-222"); + PayRequestTarget target3 = PayRequestTarget.create(payRequest2, 1L, 10000); + PayRequestTarget target4 = PayRequestTarget.create(payRequest2, 4L, 30000); + + PayRequestTargets targetIsSeongjun = PayRequestTargets.create(List.of(target1, target3)); + + // sangjun이 요청한 정산은 정산 완료 & seohyun이 요청한 정산은 정산 완료 X + target1.changeCompleteStatus(true); + + //when + int completeCount = targetIsSeongjun.countCompleteTargets(); + + //then + assertThat(completeCount).isEqualTo(1); + } + + + +} \ No newline at end of file From b93b6a7c7a8b9d68a7e2e34812ef8d10b371d3c1 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Wed, 20 Nov 2024 14:03:23 +0900 Subject: [PATCH 19/20] =?UTF-8?q?test=20:=20PayRequests=20=EC=9D=BC?= =?UTF-8?q?=EA=B8=89=20=EC=BB=AC=EB=A0=89=EC=85=98=EC=9D=98=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=ED=85=8C=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 --- .../firstCollection/PayRequestsTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestsTest.java diff --git a/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestsTest.java b/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestsTest.java new file mode 100644 index 00000000..19f609d8 --- /dev/null +++ b/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestsTest.java @@ -0,0 +1,69 @@ +package space.space_spring.domain.pay.model.firstCollection; + +import org.assertj.core.groups.Tuple; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import space.space_spring.domain.pay.model.entity.PayRequest; +import space.space_spring.domain.pay.model.entity.PayRequestTarget; +import space.space_spring.domain.space.model.entity.Space; +import space.space_spring.domain.user.model.entity.User; +import space.space_spring.entity.enumStatus.UserSignupType; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; +import static org.junit.jupiter.api.Assertions.*; + +class PayRequestsTest { + + private User seongjun; + private User sangjun; + private User seohyun; + private User kyeongmin; + private Space kuit; + + @BeforeEach + void setUp() { + // 1L : seongjun, 2L : sangjun, 3L : seohyun, 4L : kyeongmin + seongjun = User.create("email", "password", "노성준", UserSignupType.LOCAL); + sangjun = User.create("email", "password", "김상준", UserSignupType.LOCAL); + seohyun = User.create("email", "password", "정서현", UserSignupType.LOCAL); + kyeongmin = User.create("email", "password", "김경민", UserSignupType.LOCAL); + kuit = Space.create("space", "profileImg"); + } + + @Test + @DisplayName("멤버 변수인 PayRequest list 로부터 [payRequestId, 정산 총 금액, 현재까지 받은 금액, 정산 요청한 총 사람 수, 그 중 돈을 보낸 사람 수] 정보를 찾아준다.") + void getPayRequestInfos() throws Exception { + //given + PayRequest payRequest1 = PayRequest.create(seongjun, kuit, 40000, "우리은행", "111-111"); + PayRequestTarget target1 = PayRequestTarget.create(payRequest1, 2L, 20000); + PayRequestTarget target2 = PayRequestTarget.create(payRequest1, 3L, 20000); + + PayRequest payRequest2 = PayRequest.create(seongjun, kuit, 40000, "신한은행", "222-222"); + PayRequestTarget target3 = PayRequestTarget.create(payRequest2, 3L, 10000); + PayRequestTarget target4 = PayRequestTarget.create(payRequest2, 4L, 30000); + + target1.changeCompleteStatus(true); // payRequest1 에 대해서 target1은 정산 완료 + payRequest1.changeReceiveAmount(20000); + + target3.changeCompleteStatus(true); // payRequest2 에 대해서 target3은 정산 완료 + payRequest2.changeReceiveAmount(10000); + + PayRequests payCreatorIsSeongjun = PayRequests.create(List.of(payRequest1, payRequest2)); + + //when + PayRequestInfos payRequestInfos = payCreatorIsSeongjun.getPayRequestInfos(); + + //then + assertThat(payRequestInfos.getAll()).hasSize(2) + .extracting("totalAmount", "receiveAmount", "totalTargetNum", "paySendTargetNum") + .containsExactlyInAnyOrder( + tuple(40000, 20000, 2, 1), + tuple(40000, 10000, 2, 1) + ); + } + +} \ No newline at end of file From 844c2c257afbb8691206ec10a835cb94ff599218 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Wed, 20 Nov 2024 14:07:22 +0900 Subject: [PATCH 20/20] =?UTF-8?q?refactor=20:=20PayRequest=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EA=B0=80=20target=EC=9C=BC=EB=A1=9C=EB=B6=80?= =?UTF-8?q?=ED=84=B0=20=EB=8F=88=EC=9D=84=20=EB=B0=9B=EB=8A=94=20=ED=96=89?= =?UTF-8?q?=EB=8F=99=EC=9D=84=20=EA=B0=80=EC=A7=80=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/domain/pay/model/entity/PayRequest.java | 4 ++-- .../domain/pay/model/entity/PayRequestTest.java | 4 +--- .../domain/pay/model/firstCollection/PayRequestsTest.java | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java index 10d24627..d0cdd8a9 100644 --- a/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java +++ b/src/main/java/space/space_spring/domain/pay/model/entity/PayRequest.java @@ -55,8 +55,8 @@ public void changeCompleteStatus(boolean isComplete) { this.isComplete = isComplete; } - public void changeReceiveAmount(int receiveAmount) { - this.receiveAmount = receiveAmount; + public void receiveMoneyFromTarget(int money) { + receiveAmount += money; } public void addPayRequestTarget(PayRequestTarget payRequestTarget) { diff --git a/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java b/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java index 976ade14..a18576e6 100644 --- a/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java +++ b/src/test/java/space/space_spring/domain/pay/model/entity/PayRequestTest.java @@ -7,8 +7,6 @@ import space.space_spring.domain.user.model.entity.User; import space.space_spring.entity.enumStatus.UserSignupType; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; class PayRequestTest { @@ -30,7 +28,7 @@ void getPayRequestInfo() throws Exception { // target1 : 미정산, target2, target3 : 정산 완료 target2.changeCompleteStatus(true); target3.changeCompleteStatus(true); - payRequest.changeReceiveAmount(20000); + payRequest.receiveMoneyFromTarget(20000); //when PayRequestInfoDto payRequestInfo = payRequest.getPayRequestInfo(); diff --git a/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestsTest.java b/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestsTest.java index 19f609d8..bd509276 100644 --- a/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestsTest.java +++ b/src/test/java/space/space_spring/domain/pay/model/firstCollection/PayRequestsTest.java @@ -1,6 +1,5 @@ package space.space_spring.domain.pay.model.firstCollection; -import org.assertj.core.groups.Tuple; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -14,7 +13,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; -import static org.junit.jupiter.api.Assertions.*; class PayRequestsTest { @@ -47,10 +45,10 @@ void getPayRequestInfos() throws Exception { PayRequestTarget target4 = PayRequestTarget.create(payRequest2, 4L, 30000); target1.changeCompleteStatus(true); // payRequest1 에 대해서 target1은 정산 완료 - payRequest1.changeReceiveAmount(20000); + payRequest1.receiveMoneyFromTarget(20000); target3.changeCompleteStatus(true); // payRequest2 에 대해서 target3은 정산 완료 - payRequest2.changeReceiveAmount(10000); + payRequest2.receiveMoneyFromTarget(10000); PayRequests payCreatorIsSeongjun = PayRequests.create(List.of(payRequest1, payRequest2));