From 497711d8a69ec4ef42d985cbcaa194e54f19bb2e Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 17:23:49 +0900 Subject: [PATCH 01/20] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20service=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/application/UserGetService.java | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 src/main/java/com/gloddy/server/user/application/UserGetService.java diff --git a/src/main/java/com/gloddy/server/user/application/UserGetService.java b/src/main/java/com/gloddy/server/user/application/UserGetService.java deleted file mode 100644 index 191f564c..00000000 --- a/src/main/java/com/gloddy/server/user/application/UserGetService.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.gloddy.server.user.application; - -import com.gloddy.server.auth.domain.User; -import com.gloddy.server.praise.domain.Praise; -import com.gloddy.server.mate.infra.repository.MateJpaRepository; -import com.gloddy.server.praise.domain.handler.PraiseQueryHandler; -import com.gloddy.server.reliability.domain.Reliability; -import com.gloddy.server.reliability.domain.handler.ReliabilityQueryHandler; -import com.gloddy.server.user.domain.dto.UserGetResponse; -import com.gloddy.server.user.domain.handler.UserQueryHandler; -import com.gloddy.server.user.domain.service.UserDtoMapper; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -public class UserGetService { - private final UserQueryHandler userQueryHandler; - private final PraiseQueryHandler praiseQueryHandler; - private final MateJpaRepository mateJpaRepository; - private final ReliabilityQueryHandler reliabilityQueryHandler; - - @Transactional(readOnly = true) - public UserGetResponse getUserPage(Long userId) { - User user = userQueryHandler.findById(userId); - Praise praise = praiseQueryHandler.findByUserId(userId); - Reliability reliability = reliabilityQueryHandler.findByUserId(userId); - - return UserDtoMapper.toUserGet(user, reliability, praise, getReviewCount(userId)); - } - - private int getReviewCount(Long userId) { - return mateJpaRepository.countByMateId(userId).intValue(); - } -} From 84d10711ee96e4ad2f5251eaf72410f30445f2af Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:48:51 +0900 Subject: [PATCH 02/20] =?UTF-8?q?refactor:=20user=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20queryHandler=EB=A1=9C?= =?UTF-8?q?=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mate/application/MateSaveService.java | 6 +++--- .../gloddy/server/user/api/UserGetApi.java | 1 - .../user/application/UserFindService.java | 21 ------------------- .../user/application/UserUpdateService.java | 6 ++++-- .../application/facade/UserGetFacade.java | 6 ++---- 5 files changed, 9 insertions(+), 31 deletions(-) delete mode 100644 src/main/java/com/gloddy/server/user/application/UserFindService.java diff --git a/src/main/java/com/gloddy/server/mate/application/MateSaveService.java b/src/main/java/com/gloddy/server/mate/application/MateSaveService.java index 2dbb5a5f..bd5a0db1 100644 --- a/src/main/java/com/gloddy/server/mate/application/MateSaveService.java +++ b/src/main/java/com/gloddy/server/mate/application/MateSaveService.java @@ -3,9 +3,9 @@ import com.gloddy.server.auth.domain.User; import com.gloddy.server.mate.event.MateCreateEvent; import com.gloddy.server.mate.event.producer.MateEventProducer; -import com.gloddy.server.user.application.UserFindService; import com.gloddy.server.mate.domain.Mate; import com.gloddy.server.mate.infra.repository.MateJpaRepository; +import com.gloddy.server.user.domain.handler.UserQueryHandler; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +16,12 @@ @RequiredArgsConstructor public class MateSaveService { private final MateJpaRepository mateJpaRepository; - private final UserFindService userFindService; + private final UserQueryHandler userQueryHandler private final MateEventProducer mateEventProducer; @Transactional public Mate save(MateInfo mateInfo, Long mateId) { - User user = userFindService.findById(mateInfo.getUserId()); + User user = userQueryHandler.findById(mateInfo.getUserId()); mateEventProducer.produceEvent(new MateCreateEvent(mateInfo.getUserId())); return mateJpaRepository.save( Mate.builder() diff --git a/src/main/java/com/gloddy/server/user/api/UserGetApi.java b/src/main/java/com/gloddy/server/user/api/UserGetApi.java index 79094e0c..7f7bff5c 100644 --- a/src/main/java/com/gloddy/server/user/api/UserGetApi.java +++ b/src/main/java/com/gloddy/server/user/api/UserGetApi.java @@ -6,7 +6,6 @@ import com.gloddy.server.user.api.dto.UserResponse; import com.gloddy.server.user.application.UserService; import com.gloddy.server.user.application.facade.UserGetFacade; -import com.gloddy.server.user.application.UserGetService; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/com/gloddy/server/user/application/UserFindService.java b/src/main/java/com/gloddy/server/user/application/UserFindService.java deleted file mode 100644 index b6b6f594..00000000 --- a/src/main/java/com/gloddy/server/user/application/UserFindService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.gloddy.server.user.application; - -import com.gloddy.server.auth.domain.User; -import com.gloddy.server.user.infra.repository.UserJpaRepository; -import com.gloddy.server.core.error.handler.exception.UserBusinessException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import static com.gloddy.server.core.error.handler.errorCode.ErrorCode.USER_NOT_FOUND; - -@Service -@RequiredArgsConstructor -public class UserFindService { - - private final UserJpaRepository userJpaRepository; - - public User findById(Long id) { - return userJpaRepository.findById(id) - .orElseThrow(() -> new UserBusinessException(USER_NOT_FOUND)); - } -} diff --git a/src/main/java/com/gloddy/server/user/application/UserUpdateService.java b/src/main/java/com/gloddy/server/user/application/UserUpdateService.java index 275e052c..8d6561c8 100644 --- a/src/main/java/com/gloddy/server/user/application/UserUpdateService.java +++ b/src/main/java/com/gloddy/server/user/application/UserUpdateService.java @@ -1,7 +1,9 @@ package com.gloddy.server.user.application; import com.gloddy.server.auth.domain.User; +import com.gloddy.server.auth.domain.vo.kind.Status; import com.gloddy.server.user.domain.dto.UserUpdateResponse; +import com.gloddy.server.user.domain.handler.UserQueryHandler; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -11,11 +13,11 @@ @Service @RequiredArgsConstructor public class UserUpdateService { - private final UserFindService userFindService; + private final UserQueryHandler userQueryHandler; @Transactional public UserUpdateResponse update(Long userId, Info request) { - User user = userFindService.findById(userId); + User user = userQueryHandler.findByIdAndStatus(userId, Status.ACTIVE); user.updateProfile( request.getImageUrl(), request.getName(), diff --git a/src/main/java/com/gloddy/server/user/application/facade/UserGetFacade.java b/src/main/java/com/gloddy/server/user/application/facade/UserGetFacade.java index d3869d5f..a026590b 100644 --- a/src/main/java/com/gloddy/server/user/application/facade/UserGetFacade.java +++ b/src/main/java/com/gloddy/server/user/application/facade/UserGetFacade.java @@ -1,12 +1,10 @@ package com.gloddy.server.user.application.facade; import com.gloddy.server.auth.domain.User; -import com.gloddy.server.group_member.api.dto.GroupMemberResponse; +import com.gloddy.server.auth.domain.vo.kind.Status; import com.gloddy.server.group_member.domain.handler.GroupMemberQueryHandler; -import com.gloddy.server.mate.domain.dto.MateResponse; import com.gloddy.server.mate.domain.handler.MateQueryHandler; import com.gloddy.server.praise.domain.Praise; -import com.gloddy.server.praise.domain.dto.PraiseResponse; import com.gloddy.server.praise.domain.handler.PraiseQueryHandler; import com.gloddy.server.reliability.domain.Reliability; import com.gloddy.server.reliability.domain.handler.ReliabilityQueryHandler; @@ -29,7 +27,7 @@ public class UserGetFacade { @Transactional(readOnly = true) public UserResponse.FacadeGet getUserFacade(Long userId) { - User user = userQueryHandler.findById(userId); + User user = userQueryHandler.findByIdAndStatus(userId, Status.ACTIVE); Praise praise = praiseQueryHandler.findByUserId(userId); Reliability reliability = reliabilityQueryHandler.findByUserId(userId); Long countParticipatedGroup = groupMemberQueryHandler.countParticipatedGroup(userId); From 11bd64797de98524ff22bd6e54fbf346a061154f Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:50:02 +0900 Subject: [PATCH 03/20] =?UTF-8?q?feat:=20user=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=EC=97=90=20status=20=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/infra/repository/UserJpaRepository.java | 3 +++ .../infra/repository/impl/UserJpaRepositoryImpl.java | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gloddy/server/user/infra/repository/UserJpaRepository.java b/src/main/java/com/gloddy/server/user/infra/repository/UserJpaRepository.java index 7d88be5f..1459c91c 100644 --- a/src/main/java/com/gloddy/server/user/infra/repository/UserJpaRepository.java +++ b/src/main/java/com/gloddy/server/user/infra/repository/UserJpaRepository.java @@ -1,6 +1,7 @@ package com.gloddy.server.user.infra.repository; import com.gloddy.server.auth.domain.User; +import com.gloddy.server.auth.domain.vo.kind.Status; import com.gloddy.server.user.infra.repository.custom.UserJpaRepositoryCustom; import org.springframework.data.jpa.repository.JpaRepository; @@ -10,4 +11,6 @@ public interface UserJpaRepository extends JpaRepository, UserJpaRep User findFirstByOrderByIdDesc(); boolean existsByProfile_Nickname(String nickName); + + Optional findByIdAndStatus(Long userId, Status status); } diff --git a/src/main/java/com/gloddy/server/user/infra/repository/impl/UserJpaRepositoryImpl.java b/src/main/java/com/gloddy/server/user/infra/repository/impl/UserJpaRepositoryImpl.java index 71c5a61a..1d9a72f1 100644 --- a/src/main/java/com/gloddy/server/user/infra/repository/impl/UserJpaRepositoryImpl.java +++ b/src/main/java/com/gloddy/server/user/infra/repository/impl/UserJpaRepositoryImpl.java @@ -1,8 +1,8 @@ package com.gloddy.server.user.infra.repository.impl; -import com.gloddy.server.auth.domain.QUser; import com.gloddy.server.auth.domain.User; import com.gloddy.server.auth.domain.vo.Phone; +import com.gloddy.server.auth.domain.vo.kind.Status; import com.gloddy.server.user.infra.repository.custom.UserJpaRepositoryCustom; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -21,14 +21,14 @@ public class UserJpaRepositoryImpl implements UserJpaRepositoryCustom { @Override public Optional findByPhone(Phone phone) { return Optional.ofNullable(query.selectFrom(user) - .where(eqPhone(phone)) + .where(eqPhone(phone), isActive()) .fetchOne()); } @Override public Optional findByEmail(String email) { return Optional.ofNullable(query.selectFrom(user) - .where(eqEmail(email)) + .where(eqEmail(email), isActive()) .fetchOne()); } @@ -39,4 +39,8 @@ private BooleanExpression eqPhone(Phone phone) { private BooleanExpression eqEmail(String email) { return user.school.email.eq(email); } + + private BooleanExpression isActive() { + return user.status.eq(Status.ACTIVE); + } } From 9d1ea3ae7b2368b791ca52a392d06143fa6ddbfe Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:50:36 +0900 Subject: [PATCH 04/20] =?UTF-8?q?feat:=20user=20status=20enum=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 --- .../java/com/gloddy/server/auth/domain/vo/kind/Status.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/gloddy/server/auth/domain/vo/kind/Status.java diff --git a/src/main/java/com/gloddy/server/auth/domain/vo/kind/Status.java b/src/main/java/com/gloddy/server/auth/domain/vo/kind/Status.java new file mode 100644 index 00000000..aced5cca --- /dev/null +++ b/src/main/java/com/gloddy/server/auth/domain/vo/kind/Status.java @@ -0,0 +1,7 @@ +package com.gloddy.server.auth.domain.vo.kind; + +public enum Status { + ACTIVE, + WITHDRAW, + ; +} From 5755e09428a9cbadb1c00cdcbbae44b35c60427c Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:50:52 +0900 Subject: [PATCH 05/20] =?UTF-8?q?feat:=20user=20entity=EC=97=90=20status?= =?UTF-8?q?=20=EC=BB=AC=EB=9F=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/gloddy/server/auth/domain/User.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/gloddy/server/auth/domain/User.java b/src/main/java/com/gloddy/server/auth/domain/User.java index 6c627454..b8e6aab4 100644 --- a/src/main/java/com/gloddy/server/auth/domain/User.java +++ b/src/main/java/com/gloddy/server/auth/domain/User.java @@ -6,6 +6,7 @@ import com.gloddy.server.auth.domain.vo.kind.Authority; import com.gloddy.server.auth.domain.vo.kind.Gender; import com.gloddy.server.auth.domain.vo.kind.Personality; +import com.gloddy.server.auth.domain.vo.kind.Status; import com.gloddy.server.core.entity.common.BaseTimeEntity; import com.gloddy.server.core.event.GroupParticipateEvent; import com.gloddy.server.group.event.GroupCreateEvent; @@ -39,6 +40,10 @@ public class User extends BaseTimeEntity { @Column(name = "authority") private Authority authority; + @Enumerated(EnumType.STRING) + @Column(name = "status") + private Status status; + @Embedded private Phone phone; @@ -59,6 +64,7 @@ public User(Phone phone, School school, Profile profile) { this.phone = phone; this.school = school; this.profile = profile; + this.status = Status.ACTIVE; authorityDefault(); } @@ -131,4 +137,8 @@ public LocalDate getBirth() { public LocalDate getJoinAt() { return this.getCreatedAt().toLocalDate(); } + + public void withDraw() { + this.status = Status.WITHDRAW; + } } From b1a354c445c2b699f2274ea7337d254a4bff910d Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:51:16 +0900 Subject: [PATCH 06/20] =?UTF-8?q?feat:=20active=20user=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20handler=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/domain/handler/UserQueryHandler.java | 10 +++++++++- .../handler/impl/UserQueryHandlerImpl.java | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gloddy/server/user/domain/handler/UserQueryHandler.java b/src/main/java/com/gloddy/server/user/domain/handler/UserQueryHandler.java index 119269ad..336d6391 100644 --- a/src/main/java/com/gloddy/server/user/domain/handler/UserQueryHandler.java +++ b/src/main/java/com/gloddy/server/user/domain/handler/UserQueryHandler.java @@ -1,10 +1,18 @@ package com.gloddy.server.user.domain.handler; import com.gloddy.server.auth.domain.User; +import com.gloddy.server.auth.domain.vo.Phone; +import com.gloddy.server.auth.domain.vo.kind.Status; + +import java.util.Optional; public interface UserQueryHandler { User findById(Long id); - User findByEmail(String email); + + User findByIdAndStatus(Long id, Status status); + Optional findByEmail(String email); boolean existsByNickname(String nickname); + + Optional findByPhone(Phone phone); } diff --git a/src/main/java/com/gloddy/server/user/domain/handler/impl/UserQueryHandlerImpl.java b/src/main/java/com/gloddy/server/user/domain/handler/impl/UserQueryHandlerImpl.java index 22f00904..a556a68f 100644 --- a/src/main/java/com/gloddy/server/user/domain/handler/impl/UserQueryHandlerImpl.java +++ b/src/main/java/com/gloddy/server/user/domain/handler/impl/UserQueryHandlerImpl.java @@ -1,6 +1,8 @@ package com.gloddy.server.user.domain.handler.impl; import com.gloddy.server.auth.domain.User; +import com.gloddy.server.auth.domain.vo.Phone; +import com.gloddy.server.auth.domain.vo.kind.Status; import com.gloddy.server.user.domain.handler.UserQueryHandler; import com.gloddy.server.user.infra.repository.UserJpaRepository; import com.gloddy.server.core.error.handler.errorCode.ErrorCode; @@ -8,6 +10,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository @RequiredArgsConstructor public class UserQueryHandlerImpl implements UserQueryHandler { @@ -21,13 +25,23 @@ public User findById(Long id) { } @Override - public User findByEmail(String email) { - return userJpaRepository.findByEmail(email) + public User findByIdAndStatus(Long id, Status status) { + return userJpaRepository.findByIdAndStatus(id, status) .orElseThrow(() -> new UserBusinessException(ErrorCode.USER_NOT_FOUND)); } + @Override + public Optional findByEmail(String email) { + return userJpaRepository.findByEmail(email); + } + @Override public boolean existsByNickname(String nickname) { return userJpaRepository.existsByProfile_Nickname(nickname); } + + @Override + public Optional findByPhone(Phone phone) { + return userJpaRepository.findByPhone(phone); + } } From 7383cf56a2b85a520aabc348ed23f8765aa8324a Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:51:40 +0900 Subject: [PATCH 07/20] =?UTF-8?q?fix:=20comment=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20userId=20=ED=95=84=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gloddy/server/comment/domain/service/CommentDtoMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gloddy/server/comment/domain/service/CommentDtoMapper.java b/src/main/java/com/gloddy/server/comment/domain/service/CommentDtoMapper.java index a7ef755b..57fb8ea3 100644 --- a/src/main/java/com/gloddy/server/comment/domain/service/CommentDtoMapper.java +++ b/src/main/java/com/gloddy/server/comment/domain/service/CommentDtoMapper.java @@ -20,7 +20,7 @@ public static List mapToGetCommentListFrom(List comments, U private static GetComment getComment(Comment comment, User user) { return new GetComment( - user.getId(), + comment.getUser().getId(), comment.getId(), comment.getWriterImageUrl(), comment.getWriterNickName(), From 2ab3b2191443eab06826151e1c19d79c7307e569 Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:51:57 +0900 Subject: [PATCH 08/20] =?UTF-8?q?fix:=20article=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20userId=20=ED=95=84=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gloddy/server/article/domain/service/ArticleDtoMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gloddy/server/article/domain/service/ArticleDtoMapper.java b/src/main/java/com/gloddy/server/article/domain/service/ArticleDtoMapper.java index c2e28c61..bd9fb9c6 100644 --- a/src/main/java/com/gloddy/server/article/domain/service/ArticleDtoMapper.java +++ b/src/main/java/com/gloddy/server/article/domain/service/ArticleDtoMapper.java @@ -25,7 +25,7 @@ public static GetArticle getArticleDto(Article article, User currentUser) { Profile profile = user.getProfile(); return new GetArticle( - currentUser.getId(), + user.getId(), article.getId(), profile.getImageUrl(), profile.getNickname(), From 335d23dea988b66a726e1bbb53a3f22afe70649b Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:53:47 +0900 Subject: [PATCH 09/20] =?UTF-8?q?fix:=20user=20=EC=A1=B0=ED=9A=8C=20->=20a?= =?UTF-8?q?ctive=20user=20=EC=A1=B0=ED=9A=8C=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group_member/application/GroupMemberService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gloddy/server/group_member/application/GroupMemberService.java b/src/main/java/com/gloddy/server/group_member/application/GroupMemberService.java index 8f129ff0..8874e8a8 100644 --- a/src/main/java/com/gloddy/server/group_member/application/GroupMemberService.java +++ b/src/main/java/com/gloddy/server/group_member/application/GroupMemberService.java @@ -1,6 +1,7 @@ package com.gloddy.server.group_member.application; import com.gloddy.server.auth.domain.User; +import com.gloddy.server.auth.domain.vo.kind.Status; import com.gloddy.server.core.response.PageResponse; import com.gloddy.server.group.domain.dto.GroupResponse; import com.gloddy.server.group.domain.Group; @@ -13,7 +14,7 @@ import com.gloddy.server.group_member.domain.service.GroupMemberPraiser; import com.gloddy.server.group_member.event.producer.GroupMemberEventProducer; import com.gloddy.server.group_member.infra.repository.GroupMemberJpaRepository; -import com.gloddy.server.user.application.UserFindService; +import com.gloddy.server.user.domain.handler.UserQueryHandler; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -26,7 +27,7 @@ @RequiredArgsConstructor public class GroupMemberService { - private final UserFindService userFindService; + private final UserQueryHandler userQueryHandler; private final GroupMemberQueryHandler groupMemberQueryHandler; private final GroupMemberEventProducer groupMemberEventProducer; private final GroupMemberPraisePolicy groupMemberPraisePolicy; @@ -34,7 +35,7 @@ public class GroupMemberService { private final GroupMemberJpaRepository userGroupJpaRepository; public GroupResponse.GetGroups getExpectedMyGroup(Long userId) { - User findUser = userFindService.findById(userId); + User findUser = userQueryHandler.findByIdAndStatus(userId, Status.ACTIVE); List expectedMyGroups = userGroupJpaRepository.findExpectedGroupsByUser(findUser); return expectedMyGroups.stream() .map(GroupResponse.GetGroup::from) @@ -42,7 +43,7 @@ public GroupResponse.GetGroups getExpectedMyGroup(Long userId) { } public PageResponse getParticipatedMyGroup(Long userId, int page, int size) { - User findUser = userFindService.findById(userId); + User findUser = userQueryHandler.findByIdAndStatus(userId, Status.ACTIVE); return PageResponse.from( userGroupJpaRepository.findParticipatedGroupsByUser(findUser, PageRequest.of(page, size)) .map(GroupResponse.GetParticipatedGroup::from) From ac8b0b78362c124daaddd9a900f93da850d92a2d Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:54:27 +0900 Subject: [PATCH 10/20] =?UTF-8?q?feat:=20=EC=A7=84=ED=96=89=20=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=EA=B7=B8=EB=A3=B9=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EB=B0=98=ED=99=98=20=EC=BF=BC=EB=A6=AC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GroupMemberJpaRepositoryCustom.java | 2 ++ .../impl/GroupMemberJpaRepositoryImpl.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/com/gloddy/server/group_member/infra/repository/custom/GroupMemberJpaRepositoryCustom.java b/src/main/java/com/gloddy/server/group_member/infra/repository/custom/GroupMemberJpaRepositoryCustom.java index 904dd71f..9ed0e5f1 100644 --- a/src/main/java/com/gloddy/server/group_member/infra/repository/custom/GroupMemberJpaRepositoryCustom.java +++ b/src/main/java/com/gloddy/server/group_member/infra/repository/custom/GroupMemberJpaRepositoryCustom.java @@ -22,4 +22,6 @@ public interface GroupMemberJpaRepositoryCustom { List findByUserIdFetchGroupAndUser(Long userId); Long countByUserIdAndIsAbsenceAndEndDateTimeBeforeJoinGroup(Long userId, boolean isAbsence, LocalDateTime time); + + boolean existsByUserAndGroupEndTimeBefore(User user); } diff --git a/src/main/java/com/gloddy/server/group_member/infra/repository/impl/GroupMemberJpaRepositoryImpl.java b/src/main/java/com/gloddy/server/group_member/infra/repository/impl/GroupMemberJpaRepositoryImpl.java index a4a6e4e5..6fa8611f 100644 --- a/src/main/java/com/gloddy/server/group_member/infra/repository/impl/GroupMemberJpaRepositoryImpl.java +++ b/src/main/java/com/gloddy/server/group_member/infra/repository/impl/GroupMemberJpaRepositoryImpl.java @@ -1,5 +1,6 @@ package com.gloddy.server.group_member.infra.repository.impl; +import com.gloddy.server.auth.domain.QUser; import com.gloddy.server.auth.domain.User; import com.gloddy.server.group.domain.Group; import com.gloddy.server.group_member.domain.GroupMember; @@ -97,6 +98,20 @@ public Long countByUserIdAndIsAbsenceAndEndDateTimeBeforeJoinGroup(Long userId, .fetchOne(); } + @Override + public boolean existsByUserAndGroupEndTimeBefore(User user) { + Long fetchFirst = query.select(group.id) + .from(groupMember) + .innerJoin(groupMember.group, group) + .innerJoin(groupMember.user, QUser.user) + .where( + userEq(user), + endTimeAfter(LocalDateTime.now()) + ).fetchFirst(); + + return fetchFirst != null; + } + private BooleanExpression userEq(User user) { return groupMember.user.eq(user); } @@ -125,6 +140,10 @@ private BooleanExpression endTimeBefore(LocalDateTime time) { return groupMember.group.dateTime.endDateTime.before(time); } + private BooleanExpression endTimeAfter(LocalDateTime time) { + return groupMember.group.dateTime.endDateTime.after(time); + } + private BooleanExpression isAbsenceEq(boolean isAbsence) { return groupMember.isAbsence.eq(isAbsence); } From 10911be54f256747f2b92c942326d1c3932e4d5c Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:54:51 +0900 Subject: [PATCH 11/20] =?UTF-8?q?feat:=20=EC=A7=84=ED=96=89=20=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=EA=B7=B8=EB=A3=B9=20=EC=97=AC=EB=B6=80=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=EC=BF=BC=EB=A6=AC=20handler=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=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/handler/GroupMemberQueryHandler.java | 3 +++ .../domain/handler/impl/GroupMemberQueryHandlerImpl.java | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/com/gloddy/server/group_member/domain/handler/GroupMemberQueryHandler.java b/src/main/java/com/gloddy/server/group_member/domain/handler/GroupMemberQueryHandler.java index 81d2f27a..0ffa6ac5 100644 --- a/src/main/java/com/gloddy/server/group_member/domain/handler/GroupMemberQueryHandler.java +++ b/src/main/java/com/gloddy/server/group_member/domain/handler/GroupMemberQueryHandler.java @@ -1,5 +1,6 @@ package com.gloddy.server.group_member.domain.handler; +import com.gloddy.server.auth.domain.User; import com.gloddy.server.group_member.domain.GroupMember; import java.util.List; @@ -14,4 +15,6 @@ public interface GroupMemberQueryHandler { List findAllByUserId(Long userId); Long countParticipatedGroup(Long userId); + + boolean existsByUserAndGroupEndTimeBefore(User user); } diff --git a/src/main/java/com/gloddy/server/group_member/domain/handler/impl/GroupMemberQueryHandlerImpl.java b/src/main/java/com/gloddy/server/group_member/domain/handler/impl/GroupMemberQueryHandlerImpl.java index d53f6c46..ace3d807 100644 --- a/src/main/java/com/gloddy/server/group_member/domain/handler/impl/GroupMemberQueryHandlerImpl.java +++ b/src/main/java/com/gloddy/server/group_member/domain/handler/impl/GroupMemberQueryHandlerImpl.java @@ -1,5 +1,6 @@ package com.gloddy.server.group_member.domain.handler.impl; +import com.gloddy.server.auth.domain.User; import com.gloddy.server.group_member.domain.GroupMember; import com.gloddy.server.group_member.domain.handler.GroupMemberQueryHandler; import com.gloddy.server.group_member.infra.repository.GroupMemberJpaRepository; @@ -45,4 +46,9 @@ public Long countParticipatedGroup(Long userId) { ); } + @Override + public boolean existsByUserAndGroupEndTimeBefore(User user) { + return groupMemberJpaRepository.existsByUserAndGroupEndTimeBefore(user); + } + } From cb63da0840c5c3b343eda43ff522de0f1b6931b2 Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:56:39 +0900 Subject: [PATCH 12/20] =?UTF-8?q?feat:=20wait=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=A7=80=EC=9B=90=EC=84=9C=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EB=B0=98=ED=99=98=20jpa=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=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 --- .../server/apply/infra/repository/ApplyJpaRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/gloddy/server/apply/infra/repository/ApplyJpaRepository.java b/src/main/java/com/gloddy/server/apply/infra/repository/ApplyJpaRepository.java index 2b4c4567..9fb87ebe 100644 --- a/src/main/java/com/gloddy/server/apply/infra/repository/ApplyJpaRepository.java +++ b/src/main/java/com/gloddy/server/apply/infra/repository/ApplyJpaRepository.java @@ -3,6 +3,7 @@ import com.gloddy.server.apply.domain.Apply; import com.gloddy.server.apply.domain.vo.Status; import com.gloddy.server.apply.infra.repository.custom.ApplyJpaRepositoryCustom; +import com.gloddy.server.auth.domain.User; import com.gloddy.server.group.domain.Group; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -25,4 +26,6 @@ public interface ApplyJpaRepository extends JpaRepository, ApplyJpa Apply findFirstByOrderByIdDesc(); Boolean existsByUserIdAndGroupIdAndStatus(Long userId, Long groupId, Status status); + + Boolean existsByUserAndStatus(User user, Status status); } From 212a910fab5ac8ebcb60930deb6c90759076e7f8 Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:57:01 +0900 Subject: [PATCH 13/20] =?UTF-8?q?feat:=20wait=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=A7=80=EC=9B=90=EC=84=9C=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EB=B0=98=ED=99=98=20=EC=BF=BC=EB=A6=AC=20handler?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/apply/domain/handler/ApplyQueryHandler.java | 3 +++ .../apply/domain/handler/impl/ApplyQueryHandlerImpl.java | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/com/gloddy/server/apply/domain/handler/ApplyQueryHandler.java b/src/main/java/com/gloddy/server/apply/domain/handler/ApplyQueryHandler.java index 3c7e6dd7..57186dad 100644 --- a/src/main/java/com/gloddy/server/apply/domain/handler/ApplyQueryHandler.java +++ b/src/main/java/com/gloddy/server/apply/domain/handler/ApplyQueryHandler.java @@ -2,6 +2,7 @@ import com.gloddy.server.apply.domain.Apply; import com.gloddy.server.apply.domain.vo.Status; +import com.gloddy.server.auth.domain.User; import com.gloddy.server.group.domain.Group; import java.util.List; @@ -25,4 +26,6 @@ public interface ApplyQueryHandler { Apply findById(Long applyId); Boolean existsByUserIdAndGroupIdAndStatus(Long userId, Long groupId, Status status); + + Boolean existsByUserAndStatus(User user, Status status); } diff --git a/src/main/java/com/gloddy/server/apply/domain/handler/impl/ApplyQueryHandlerImpl.java b/src/main/java/com/gloddy/server/apply/domain/handler/impl/ApplyQueryHandlerImpl.java index fa0deda2..2df78700 100644 --- a/src/main/java/com/gloddy/server/apply/domain/handler/impl/ApplyQueryHandlerImpl.java +++ b/src/main/java/com/gloddy/server/apply/domain/handler/impl/ApplyQueryHandlerImpl.java @@ -5,6 +5,7 @@ import com.gloddy.server.apply.domain.handler.ApplyQueryHandler; import com.gloddy.server.apply.exception.NotFoundApplyException; import com.gloddy.server.apply.infra.repository.ApplyJpaRepository; +import com.gloddy.server.auth.domain.User; import com.gloddy.server.group.domain.Group; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -59,4 +60,9 @@ public Apply findById(Long applyId) { public Boolean existsByUserIdAndGroupIdAndStatus(Long userId, Long groupId, Status status) { return applyJpaRepository.existsByUserIdAndGroupIdAndStatus(userId, groupId, status); } + + @Override + public Boolean existsByUserAndStatus(User user, Status status) { + return applyJpaRepository.existsByUserAndStatus(user, status); + } } From 513450f3c351b62eebbb4c646e7e453ce9c7c2d9 Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:57:15 +0900 Subject: [PATCH 14/20] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gloddy/server/auth/api/AuthApi.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gloddy/server/auth/api/AuthApi.java b/src/main/java/com/gloddy/server/auth/api/AuthApi.java index 1ace1d51..6c66788f 100644 --- a/src/main/java/com/gloddy/server/auth/api/AuthApi.java +++ b/src/main/java/com/gloddy/server/auth/api/AuthApi.java @@ -8,20 +8,17 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1") +@RequestMapping("/api/v1/auth") public class AuthApi { private final AuthService authService; @Operation(security = {}) - @PostMapping("/auth/email/check") + @PostMapping("/email/check") public ResponseEntity emailCheck(@RequestBody AuthRequest.EmailCheck req) { AuthResponse.Whether response = authService.emailCheck(req.getEmail()); @@ -29,7 +26,7 @@ public ResponseEntity emailCheck(@RequestBody AuthRequest. } @Operation(security = {}) - @PostMapping("/auth/sign-up") + @PostMapping("/sign-up") public ResponseEntity signUp(@RequestBody AuthRequest.SignUp req) { AuthResponse.SignUp response = authService.signUp(req); @@ -37,7 +34,7 @@ public ResponseEntity signUp(@RequestBody AuthRequest.SignU } @Operation(security = {}) - @PostMapping("/auth/login") + @PostMapping("/login") public ResponseEntity login(@RequestBody AuthRequest.Login req) { AuthResponse.Login response = authService.login(req); @@ -45,10 +42,17 @@ public ResponseEntity login(@RequestBody AuthRequest.Login r } @Operation(security = {}) - @PostMapping("/auth/token-reissue") + @PostMapping("/token-reissue") public ResponseEntity tokenReissue(@RequestBody AuthRequest.ReIssueToken req) { AuthResponse.Token response = authService.reissueToken(req.getAccessToken(), req.getRefreshToken()); return ApiResponse.ok(response); } + @PatchMapping("/sign-out") + public ResponseEntity signOut( + @AuthenticationPrincipal Long userId + ) { + authService.signOut(userId); + return ApiResponse.noContent(); + } } From 65ccdab8660fc4b369c4fcaccd3cff74532a8e51 Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:58:01 +0900 Subject: [PATCH 15/20] =?UTF-8?q?feat:=20signout=20validator=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/UserSignOutPolicy.java | 42 +++++++++++++++++++ .../auth/domain/service/UserSignUpPolicy.java | 14 ++----- 2 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/gloddy/server/auth/domain/service/UserSignOutPolicy.java diff --git a/src/main/java/com/gloddy/server/auth/domain/service/UserSignOutPolicy.java b/src/main/java/com/gloddy/server/auth/domain/service/UserSignOutPolicy.java new file mode 100644 index 00000000..25501ab4 --- /dev/null +++ b/src/main/java/com/gloddy/server/auth/domain/service/UserSignOutPolicy.java @@ -0,0 +1,42 @@ +package com.gloddy.server.auth.domain.service; + +import com.gloddy.server.apply.domain.handler.ApplyQueryHandler; +import com.gloddy.server.auth.domain.User; +import com.gloddy.server.auth.exception.WithdrawRequirementsNotMetException; +import com.gloddy.server.core.error.handler.errorCode.ErrorCode; +import com.gloddy.server.group_member.domain.handler.GroupMemberQueryHandler; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class UserSignOutPolicy { + + private final GroupMemberQueryHandler groupMemberQueryHandler; + private final ApplyQueryHandler applyQueryHandler; + + public void validate(User user) { + validateGroup(user); + validateApply(user); + } + + private void validateGroup(User user) { + if (existsParticipationGroup(user)) { + throw new WithdrawRequirementsNotMetException(ErrorCode.EXISTS_PARTICIPATING_GROUP); + } + } + + private void validateApply(User user) { + if (existsWaitApply(user)) { + throw new WithdrawRequirementsNotMetException(ErrorCode.EXISTS_WAIT_APPLY); + } + } + + private boolean existsParticipationGroup(User user) { + return groupMemberQueryHandler.existsByUserAndGroupEndTimeBefore(user); + } + + private boolean existsWaitApply(User user) { + return applyQueryHandler.existsByUserAndStatus(user, com.gloddy.server.apply.domain.vo.Status.WAIT); + } +} diff --git a/src/main/java/com/gloddy/server/auth/domain/service/UserSignUpPolicy.java b/src/main/java/com/gloddy/server/auth/domain/service/UserSignUpPolicy.java index 9b35677b..ba512fb9 100644 --- a/src/main/java/com/gloddy/server/auth/domain/service/UserSignUpPolicy.java +++ b/src/main/java/com/gloddy/server/auth/domain/service/UserSignUpPolicy.java @@ -1,27 +1,21 @@ package com.gloddy.server.auth.domain.service; -import com.gloddy.server.auth.domain.User; import com.gloddy.server.auth.domain.vo.Phone; import com.gloddy.server.auth.exception.AlreadyUserSignUpException; -import com.gloddy.server.user.infra.repository.UserJpaRepository; +import com.gloddy.server.user.domain.handler.UserQueryHandler; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import java.util.Optional; - @Component @RequiredArgsConstructor public class UserSignUpPolicy { - private final UserJpaRepository userJpaRepository; + private final UserQueryHandler userQueryHandler; public void validate(String phoneNumber) { Phone phone = new Phone(phoneNumber); - Optional user = userJpaRepository.findByPhone(phone); - - if (user.isPresent()) { - throw new AlreadyUserSignUpException(); - } + userQueryHandler.findByPhone(phone) + .ifPresent(user -> {throw new AlreadyUserSignUpException();}); } } From 0ae734a435fe19438eb75f93de4b7ff57b1867c8 Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:59:20 +0900 Subject: [PATCH 16/20] =?UTF-8?q?refactor:=20findByPhone=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20handler=20=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=EB=A1=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gloddy/server/auth/security/UserDetailsServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gloddy/server/auth/security/UserDetailsServiceImpl.java b/src/main/java/com/gloddy/server/auth/security/UserDetailsServiceImpl.java index 7a50eed7..6f1866e7 100644 --- a/src/main/java/com/gloddy/server/auth/security/UserDetailsServiceImpl.java +++ b/src/main/java/com/gloddy/server/auth/security/UserDetailsServiceImpl.java @@ -4,7 +4,7 @@ import com.gloddy.server.auth.domain.User; import com.gloddy.server.auth.domain.vo.Phone; import com.gloddy.server.auth.jwt.JwtUserAdapter; -import com.gloddy.server.user.infra.repository.UserJpaRepository; +import com.gloddy.server.user.domain.handler.UserQueryHandler; import com.gloddy.server.core.error.handler.errorCode.ErrorCode; import com.gloddy.server.core.error.handler.exception.UserBusinessException; import lombok.RequiredArgsConstructor; @@ -17,12 +17,12 @@ @Component public class UserDetailsServiceImpl implements UserDetailsService { - private final UserJpaRepository userJpaRepository; + private final UserQueryHandler userQueryHandler; @Override public UserDetails loadUserByUsername(String phoneNumber) throws UsernameNotFoundException { - User user = userJpaRepository.findByPhone(new Phone(phoneNumber)) + User user = userQueryHandler.findByPhone(new Phone(phoneNumber)) .orElseThrow(() -> new UserBusinessException(ErrorCode.USER_NOT_FOUND)); return JwtUserAdapter.from(user); From 0b73c33d778077ee8219ab1530416f52f5b588b9 Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:59:35 +0900 Subject: [PATCH 17/20] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/auth/application/AuthService.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gloddy/server/auth/application/AuthService.java b/src/main/java/com/gloddy/server/auth/application/AuthService.java index a5014952..503597e1 100644 --- a/src/main/java/com/gloddy/server/auth/application/AuthService.java +++ b/src/main/java/com/gloddy/server/auth/application/AuthService.java @@ -1,15 +1,19 @@ package com.gloddy.server.auth.application; +import com.gloddy.server.apply.domain.handler.ApplyQueryHandler; import com.gloddy.server.auth.domain.User; import com.gloddy.server.auth.domain.service.UserFactory; +import com.gloddy.server.auth.domain.service.UserSignOutPolicy; import com.gloddy.server.auth.domain.vo.Phone; +import com.gloddy.server.auth.domain.vo.kind.Status; +import com.gloddy.server.auth.exception.WithdrawRequirementsNotMetException; import com.gloddy.server.auth.jwt.JwtToken; -import com.gloddy.server.auth.jwt.JwtTokenBuilder; import com.gloddy.server.auth.jwt.JwtTokenIssuer; +import com.gloddy.server.core.error.handler.errorCode.ErrorCode; +import com.gloddy.server.group_member.domain.handler.GroupMemberQueryHandler; import com.gloddy.server.user.domain.handler.UserCommandHandler; import com.gloddy.server.user.domain.handler.UserQueryHandler; import com.gloddy.server.user.event.producer.UserEventProducer; -import com.gloddy.server.user.infra.repository.UserJpaRepository; import com.gloddy.server.auth.domain.dto.AuthRequest; import com.gloddy.server.auth.domain.dto.AuthResponse; import com.gloddy.server.user.event.UserCreateEvent; @@ -23,10 +27,11 @@ @RequiredArgsConstructor public class AuthService { - private final UserJpaRepository userJpaRepository; private final UserCommandHandler userCommandHandler; + private final UserQueryHandler userQueryHandler; private final JwtTokenIssuer jwtTokenIssuer; private final UserEventProducer userEventProducer; + private final UserSignOutPolicy userSignOutPolicy; private final UserFactory userFactory; @Transactional @@ -41,15 +46,15 @@ public AuthResponse.SignUp signUp(AuthRequest.SignUp req) { @Transactional(readOnly = true) public AuthResponse.Login login(AuthRequest.Login req) { - Optional findUser = userJpaRepository.findByPhone(new Phone(req.getPhoneNumber())); + Phone phone = new Phone(req.getPhoneNumber()); + Optional findUser = userQueryHandler.findByPhone(phone); return findUser.map(user -> AuthResponse.Login.from(user, jwtTokenIssuer)) .orElseGet(AuthResponse.Login::fail); } @Transactional(readOnly = true) public AuthResponse.Whether emailCheck(String email) { - - Optional findUser = userJpaRepository.findByEmail(email); + Optional findUser = userQueryHandler.findByEmail(email); if (findUser.isEmpty()) { return new AuthResponse.Whether(false); @@ -63,4 +68,11 @@ public AuthResponse.Token reissueToken(String accessToken, String refreshToken) JwtToken token = jwtTokenIssuer.reIssueToken(accessToken, refreshToken); return new AuthResponse.Token(token); } + + @Transactional + public void signOut(Long userId) { + User user = userQueryHandler.findByIdAndStatus(userId, Status.ACTIVE); + userSignOutPolicy.validate(user); + user.withDraw(); + } } From 387114f8eb532bb90e55b7d95c07ae9f20755df2 Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 19:59:52 +0900 Subject: [PATCH 18/20] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EA=B4=80=EB=A0=A8=20errorCode=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gloddy/server/core/error/handler/errorCode/ErrorCode.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/gloddy/server/core/error/handler/errorCode/ErrorCode.java b/src/main/java/com/gloddy/server/core/error/handler/errorCode/ErrorCode.java index 2a20adcd..f91620ef 100644 --- a/src/main/java/com/gloddy/server/core/error/handler/errorCode/ErrorCode.java +++ b/src/main/java/com/gloddy/server/core/error/handler/errorCode/ErrorCode.java @@ -26,6 +26,7 @@ public enum ErrorCode { NOT_EXIST_RELIABILITY_LEVEL(404, "존재하지 않는 신뢰도 레벨입니다."), GROUP_TIME_INVALID(400, "올바르지 않은 그룹 시작 시간입니다."), + EXISTS_PARTICIPATING_GROUP(400, "참여 중인 모임이 존재합니다."), EMAIL_INVALID(404, "유효하지 않은 이메일 형식입니다."), PHONE_NUMBER_INVALID(400, "유효하지 않은 휴대폰 번호입니다."), @@ -45,6 +46,7 @@ public enum ErrorCode { GROUP_NOT_FOUND(404, "존재하지 않는 그룹입니다."), GROUP_NOT_CAPTAIN(403, "권한이 없습니다."), APPLY_NOT_FOUND(404, "존재하지 않는 지원서입니다."), + EXISTS_WAIT_APPLY(400, "대기 상태인 지원서가 존재합니다."), NO_TOTAL_GROUP_MEMBER_PRAISE(400, "모든 그룹 참여자에 대해 칭찬 하지 않았습니다"), SMS_BAD_REQUEST(400, "잘못된 형식의 SMS 요청입니다."), From fae21d08e9186fff1fd7c9f17d52309449ad1ce4 Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 20:00:05 +0900 Subject: [PATCH 19/20] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EA=B4=80=EB=A0=A8=20exception=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/WithdrawRequirementsNotMetException.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/com/gloddy/server/auth/exception/WithdrawRequirementsNotMetException.java diff --git a/src/main/java/com/gloddy/server/auth/exception/WithdrawRequirementsNotMetException.java b/src/main/java/com/gloddy/server/auth/exception/WithdrawRequirementsNotMetException.java new file mode 100644 index 00000000..b6840416 --- /dev/null +++ b/src/main/java/com/gloddy/server/auth/exception/WithdrawRequirementsNotMetException.java @@ -0,0 +1,10 @@ +package com.gloddy.server.auth.exception; + +import com.gloddy.server.core.error.handler.errorCode.ErrorCode; +import com.gloddy.server.core.error.handler.exception.BaseBusinessException; + +public class WithdrawRequirementsNotMetException extends BaseBusinessException { + public WithdrawRequirementsNotMetException(ErrorCode errorCode) { + super(errorCode); + } +} From 19a75a8f324d2b85e53fd30803a3a00fbdd3d7cc Mon Sep 17 00:00:00 2001 From: twoosky Date: Wed, 6 Sep 2023 20:11:16 +0900 Subject: [PATCH 20/20] =?UTF-8?q?fix:=20=EA=B5=AC=EB=AC=B8=20error=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gloddy/server/mate/application/MateSaveService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gloddy/server/mate/application/MateSaveService.java b/src/main/java/com/gloddy/server/mate/application/MateSaveService.java index bd5a0db1..9d6c3e30 100644 --- a/src/main/java/com/gloddy/server/mate/application/MateSaveService.java +++ b/src/main/java/com/gloddy/server/mate/application/MateSaveService.java @@ -16,7 +16,7 @@ @RequiredArgsConstructor public class MateSaveService { private final MateJpaRepository mateJpaRepository; - private final UserQueryHandler userQueryHandler + private final UserQueryHandler userQueryHandler; private final MateEventProducer mateEventProducer; @Transactional