From dd2545f4315eb21ca0dfe4e9d4a4c9b47976a35f Mon Sep 17 00:00:00 2001 From: JuHongseok Date: Sun, 3 Dec 2023 14:20:24 +0900 Subject: [PATCH 1/5] =?UTF-8?q?chore:=20=ED=8C=A8=ED=82=A4=EC=A7=80=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 --- .../event/service/EventScheduler.java | 29 +++++++++++++++++++ .../event/service/MenteeToEventService.java | 1 + .../service/{ => listener}/EventCreation.java | 2 +- .../{ => listener}/EventCreationListener.java | 2 +- .../EventCreationPublisher.java | 4 +-- .../mail/service/EmailInfoGenerator.java | 7 +++-- .../user/controller/FollowController.java | 2 +- .../MentorApplicationController.java | 2 +- .../user/controller/UserController.java | 2 +- .../UserRepository.java | 3 +- .../user/{entity => service}/UserService.java | 4 ++- .../auth/filter/JwtAuthorizationFilter.java | 2 +- .../filter/RoleConsistencyCheckFilter.java | 2 +- .../filter/handler/CustomLogoutHandler.java | 2 +- .../filter/handler/OAuth2SuccessHandler.java | 2 +- .../authorization/AuthorizationResolver.java | 2 +- .../login/OAuth2CustomUserService.java | 2 +- .../security/SecurityServiceConfig.java | 2 +- .../security/properties/ManagerInjector.java | 2 +- .../event/service/EventServiceTest.java | 5 ++-- .../resumeme/common/ControllerUnitTest.java | 2 +- 21 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 src/main/java/org/devcourse/resumeme/business/event/service/EventScheduler.java rename src/main/java/org/devcourse/resumeme/business/event/service/{ => listener}/EventCreation.java (91%) rename src/main/java/org/devcourse/resumeme/business/event/service/{ => listener}/EventCreationListener.java (95%) rename src/main/java/org/devcourse/resumeme/business/event/service/{ => listener}/EventCreationPublisher.java (77%) rename src/main/java/org/devcourse/resumeme/business/user/{entity => repository}/UserRepository.java (86%) rename src/main/java/org/devcourse/resumeme/business/user/{entity => service}/UserService.java (94%) diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/EventScheduler.java b/src/main/java/org/devcourse/resumeme/business/event/service/EventScheduler.java new file mode 100644 index 000000000..771dca486 --- /dev/null +++ b/src/main/java/org/devcourse/resumeme/business/event/service/EventScheduler.java @@ -0,0 +1,29 @@ +package org.devcourse.resumeme.business.event.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.devcourse.resumeme.business.event.domain.EventStatus; +import org.devcourse.resumeme.business.event.repository.EventRepository; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; + +@Slf4j +@Service +@Transactional +@RequiredArgsConstructor +public class EventScheduler { + + private final EventRepository eventRepository; + + @Scheduled(cron = "0 0/1 * * * *") + public void openBookedEvents() { + log.info("scheduler 실행 됨"); + eventRepository.openBookedEvent(EventStatus.OPEN, LocalDateTime.now()); + eventRepository.closeApplyToEvent(EventStatus.CLOSE, LocalDateTime.now()); + eventRepository.finishEvent(EventStatus.FINISH, LocalDateTime.now()); + } + +} diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/MenteeToEventService.java b/src/main/java/org/devcourse/resumeme/business/event/service/MenteeToEventService.java index 7e4efb0a3..d8eca5157 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/service/MenteeToEventService.java +++ b/src/main/java/org/devcourse/resumeme/business/event/service/MenteeToEventService.java @@ -39,6 +39,7 @@ public Long update(Long eventId, ApplyUpdateVo applyUpdateVo) { .orElseThrow(() -> new EventException(EVENT_NOT_FOUND)); ApplimentUpdate model = applyUpdateVo.toModel(); + return model.update(event); } diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/EventCreation.java b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreation.java similarity index 91% rename from src/main/java/org/devcourse/resumeme/business/event/service/EventCreation.java rename to src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreation.java index 80fab8367..e2057f6a6 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/service/EventCreation.java +++ b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreation.java @@ -1,4 +1,4 @@ -package org.devcourse.resumeme.business.event.service; +package org.devcourse.resumeme.business.event.service.listener; import lombok.Getter; import org.devcourse.resumeme.business.event.domain.Event; diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/EventCreationListener.java b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationListener.java similarity index 95% rename from src/main/java/org/devcourse/resumeme/business/event/service/EventCreationListener.java rename to src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationListener.java index 3449fdafe..37854d72b 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/service/EventCreationListener.java +++ b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationListener.java @@ -1,4 +1,4 @@ -package org.devcourse.resumeme.business.event.service; +package org.devcourse.resumeme.business.event.service.listener; import lombok.RequiredArgsConstructor; import org.devcourse.resumeme.business.mail.service.EmailService; diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/EventCreationPublisher.java b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationPublisher.java similarity index 77% rename from src/main/java/org/devcourse/resumeme/business/event/service/EventCreationPublisher.java rename to src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationPublisher.java index 397f1ba36..c3271caca 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/service/EventCreationPublisher.java +++ b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationPublisher.java @@ -1,10 +1,10 @@ -package org.devcourse.resumeme.business.event.service; +package org.devcourse.resumeme.business.event.service.listener; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Component; -import static org.devcourse.resumeme.business.event.service.EventCreation.*; +import static org.devcourse.resumeme.business.event.service.listener.EventCreation.*; @Component @RequiredArgsConstructor diff --git a/src/main/java/org/devcourse/resumeme/business/mail/service/EmailInfoGenerator.java b/src/main/java/org/devcourse/resumeme/business/mail/service/EmailInfoGenerator.java index 021f68187..f1cf3397b 100644 --- a/src/main/java/org/devcourse/resumeme/business/mail/service/EmailInfoGenerator.java +++ b/src/main/java/org/devcourse/resumeme/business/mail/service/EmailInfoGenerator.java @@ -1,17 +1,18 @@ package org.devcourse.resumeme.business.mail.service; +import lombok.NoArgsConstructor; import org.devcourse.resumeme.business.mail.EmailInfo; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; -import org.springframework.stereotype.Component; import java.util.List; import java.util.Map; -import static org.devcourse.resumeme.business.event.service.EventCreation.EventNoticeInfo; +import static lombok.AccessLevel.PRIVATE; +import static org.devcourse.resumeme.business.event.service.listener.EventCreation.EventNoticeInfo; import static org.devcourse.resumeme.business.mail.EmailType.EVENT_CREATED; import static org.devcourse.resumeme.business.mail.EmailType.MENTOR_APPROVED; -@Component +@NoArgsConstructor(access = PRIVATE) public class EmailInfoGenerator { private static final String BASE_URL = "https://resumeme.vercel.app"; diff --git a/src/main/java/org/devcourse/resumeme/business/user/controller/FollowController.java b/src/main/java/org/devcourse/resumeme/business/user/controller/FollowController.java index 16be0d6b4..b5c770a63 100644 --- a/src/main/java/org/devcourse/resumeme/business/user/controller/FollowController.java +++ b/src/main/java/org/devcourse/resumeme/business/user/controller/FollowController.java @@ -5,7 +5,7 @@ import org.devcourse.resumeme.business.user.controller.dto.FollowResponse; import org.devcourse.resumeme.business.user.domain.mentee.Follow; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.business.user.service.mentee.FollowService; import org.devcourse.resumeme.common.response.IdResponse; import org.devcourse.resumeme.global.auth.model.jwt.JwtUser; diff --git a/src/main/java/org/devcourse/resumeme/business/user/controller/MentorApplicationController.java b/src/main/java/org/devcourse/resumeme/business/user/controller/MentorApplicationController.java index ea1e3979f..e4456de11 100644 --- a/src/main/java/org/devcourse/resumeme/business/user/controller/MentorApplicationController.java +++ b/src/main/java/org/devcourse/resumeme/business/user/controller/MentorApplicationController.java @@ -7,7 +7,7 @@ import org.devcourse.resumeme.business.user.domain.admin.MentorApplication; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; import org.devcourse.resumeme.business.user.entity.User; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.business.user.service.admin.MentorApplicationService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/src/main/java/org/devcourse/resumeme/business/user/controller/UserController.java b/src/main/java/org/devcourse/resumeme/business/user/controller/UserController.java index 79c648886..5b7a41957 100644 --- a/src/main/java/org/devcourse/resumeme/business/user/controller/UserController.java +++ b/src/main/java/org/devcourse/resumeme/business/user/controller/UserController.java @@ -6,7 +6,7 @@ import org.devcourse.resumeme.business.user.controller.dto.UserInfoUpdateRequest; import org.devcourse.resumeme.business.user.controller.dto.UserRegisterInfoRequest; import org.devcourse.resumeme.business.user.domain.Role; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.business.user.service.AccountService; import org.devcourse.resumeme.business.user.service.vo.CreatedUserVo; import org.devcourse.resumeme.business.user.service.vo.RegisterAccountVo; diff --git a/src/main/java/org/devcourse/resumeme/business/user/entity/UserRepository.java b/src/main/java/org/devcourse/resumeme/business/user/repository/UserRepository.java similarity index 86% rename from src/main/java/org/devcourse/resumeme/business/user/entity/UserRepository.java rename to src/main/java/org/devcourse/resumeme/business/user/repository/UserRepository.java index f4c396675..7175b2a3f 100644 --- a/src/main/java/org/devcourse/resumeme/business/user/entity/UserRepository.java +++ b/src/main/java/org/devcourse/resumeme/business/user/repository/UserRepository.java @@ -1,5 +1,6 @@ -package org.devcourse.resumeme.business.user.entity; +package org.devcourse.resumeme.business.user.repository; +import org.devcourse.resumeme.business.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/org/devcourse/resumeme/business/user/entity/UserService.java b/src/main/java/org/devcourse/resumeme/business/user/service/UserService.java similarity index 94% rename from src/main/java/org/devcourse/resumeme/business/user/entity/UserService.java rename to src/main/java/org/devcourse/resumeme/business/user/service/UserService.java index 4dd61644e..4b590fc82 100644 --- a/src/main/java/org/devcourse/resumeme/business/user/entity/UserService.java +++ b/src/main/java/org/devcourse/resumeme/business/user/service/UserService.java @@ -1,10 +1,12 @@ -package org.devcourse.resumeme.business.user.entity; +package org.devcourse.resumeme.business.user.service; import lombok.RequiredArgsConstructor; import org.devcourse.resumeme.business.user.controller.dto.admin.ApplicationProcessType; import org.devcourse.resumeme.business.user.domain.Role; import org.devcourse.resumeme.business.user.domain.mentee.Mentee; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; +import org.devcourse.resumeme.business.user.entity.User; +import org.devcourse.resumeme.business.user.repository.UserRepository; import org.devcourse.resumeme.business.user.service.admin.MentorApplicationEventPublisher; import org.devcourse.resumeme.business.user.service.vo.CreatedUserVo; import org.devcourse.resumeme.business.user.service.vo.UpdateUserVo; diff --git a/src/main/java/org/devcourse/resumeme/global/auth/filter/JwtAuthorizationFilter.java b/src/main/java/org/devcourse/resumeme/global/auth/filter/JwtAuthorizationFilter.java index bffe8f165..3add2b1fc 100644 --- a/src/main/java/org/devcourse/resumeme/global/auth/filter/JwtAuthorizationFilter.java +++ b/src/main/java/org/devcourse/resumeme/global/auth/filter/JwtAuthorizationFilter.java @@ -6,7 +6,7 @@ import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.global.auth.model.jwt.Claims; import org.devcourse.resumeme.global.auth.model.jwt.JwtUser; import org.devcourse.resumeme.global.auth.service.jwt.JwtService; diff --git a/src/main/java/org/devcourse/resumeme/global/auth/filter/RoleConsistencyCheckFilter.java b/src/main/java/org/devcourse/resumeme/global/auth/filter/RoleConsistencyCheckFilter.java index cb4f29c4a..c4d624654 100644 --- a/src/main/java/org/devcourse/resumeme/global/auth/filter/RoleConsistencyCheckFilter.java +++ b/src/main/java/org/devcourse/resumeme/global/auth/filter/RoleConsistencyCheckFilter.java @@ -7,7 +7,7 @@ import lombok.RequiredArgsConstructor; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; import org.devcourse.resumeme.business.user.entity.User; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.global.auth.model.jwt.JwtUser; import org.devcourse.resumeme.global.exception.ChangeMentorRoleException; import org.springframework.security.core.Authentication; diff --git a/src/main/java/org/devcourse/resumeme/global/auth/filter/handler/CustomLogoutHandler.java b/src/main/java/org/devcourse/resumeme/global/auth/filter/handler/CustomLogoutHandler.java index cef2e8069..b486c1597 100644 --- a/src/main/java/org/devcourse/resumeme/global/auth/filter/handler/CustomLogoutHandler.java +++ b/src/main/java/org/devcourse/resumeme/global/auth/filter/handler/CustomLogoutHandler.java @@ -3,7 +3,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.global.auth.model.jwt.JwtUser; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.logout.LogoutHandler; diff --git a/src/main/java/org/devcourse/resumeme/global/auth/filter/handler/OAuth2SuccessHandler.java b/src/main/java/org/devcourse/resumeme/global/auth/filter/handler/OAuth2SuccessHandler.java index b9e0d9187..44b229f8a 100644 --- a/src/main/java/org/devcourse/resumeme/global/auth/filter/handler/OAuth2SuccessHandler.java +++ b/src/main/java/org/devcourse/resumeme/global/auth/filter/handler/OAuth2SuccessHandler.java @@ -3,7 +3,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.global.auth.model.UserCommonInfo; import org.devcourse.resumeme.global.auth.model.jwt.Claims; import org.devcourse.resumeme.global.auth.model.login.OAuth2CustomUser; diff --git a/src/main/java/org/devcourse/resumeme/global/auth/service/authorization/AuthorizationResolver.java b/src/main/java/org/devcourse/resumeme/global/auth/service/authorization/AuthorizationResolver.java index 3f94df260..20692ba38 100644 --- a/src/main/java/org/devcourse/resumeme/global/auth/service/authorization/AuthorizationResolver.java +++ b/src/main/java/org/devcourse/resumeme/global/auth/service/authorization/AuthorizationResolver.java @@ -3,7 +3,7 @@ import lombok.RequiredArgsConstructor; import org.devcourse.resumeme.business.event.repository.EventRepository; import org.devcourse.resumeme.business.resume.repository.ResumeRepository; -import org.devcourse.resumeme.business.user.entity.UserRepository; +import org.devcourse.resumeme.business.user.repository.UserRepository; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; diff --git a/src/main/java/org/devcourse/resumeme/global/auth/service/login/OAuth2CustomUserService.java b/src/main/java/org/devcourse/resumeme/global/auth/service/login/OAuth2CustomUserService.java index 887e13142..98a94e108 100644 --- a/src/main/java/org/devcourse/resumeme/global/auth/service/login/OAuth2CustomUserService.java +++ b/src/main/java/org/devcourse/resumeme/global/auth/service/login/OAuth2CustomUserService.java @@ -4,7 +4,7 @@ import lombok.extern.slf4j.Slf4j; import org.devcourse.resumeme.business.user.domain.Provider; import org.devcourse.resumeme.business.user.entity.User; -import org.devcourse.resumeme.business.user.entity.UserRepository; +import org.devcourse.resumeme.business.user.repository.UserRepository; import org.devcourse.resumeme.global.auth.model.UserCommonInfo; import org.devcourse.resumeme.global.auth.model.login.OAuth2CustomUser; import org.devcourse.resumeme.global.auth.model.login.info.OAuth2UserInfo; diff --git a/src/main/java/org/devcourse/resumeme/global/config/security/SecurityServiceConfig.java b/src/main/java/org/devcourse/resumeme/global/config/security/SecurityServiceConfig.java index 40e0ccaef..ec317682b 100644 --- a/src/main/java/org/devcourse/resumeme/global/config/security/SecurityServiceConfig.java +++ b/src/main/java/org/devcourse/resumeme/global/config/security/SecurityServiceConfig.java @@ -1,7 +1,7 @@ package org.devcourse.resumeme.global.config.security; import com.fasterxml.jackson.databind.ObjectMapper; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.global.auth.filter.ExceptionHandlerFilter; import org.devcourse.resumeme.global.auth.filter.JwtAuthorizationFilter; import org.devcourse.resumeme.global.auth.filter.OAuthTokenResponseFilter; diff --git a/src/main/java/org/devcourse/resumeme/global/config/security/properties/ManagerInjector.java b/src/main/java/org/devcourse/resumeme/global/config/security/properties/ManagerInjector.java index c2fc4ca95..3259f0a2d 100644 --- a/src/main/java/org/devcourse/resumeme/global/config/security/properties/ManagerInjector.java +++ b/src/main/java/org/devcourse/resumeme/global/config/security/properties/ManagerInjector.java @@ -3,7 +3,7 @@ import jakarta.annotation.PostConstruct; import org.devcourse.resumeme.business.event.repository.EventRepository; import org.devcourse.resumeme.business.resume.repository.ResumeRepository; -import org.devcourse.resumeme.business.user.entity.UserRepository; +import org.devcourse.resumeme.business.user.repository.UserRepository; import org.devcourse.resumeme.global.auth.service.authorization.AuthorizationResolver; import org.devcourse.resumeme.global.auth.service.authorization.OnlyOwn; import org.springframework.stereotype.Component; diff --git a/src/test/java/org/devcourse/resumeme/business/event/service/EventServiceTest.java b/src/test/java/org/devcourse/resumeme/business/event/service/EventServiceTest.java index 23ddcac6a..4f6f5b4ed 100644 --- a/src/test/java/org/devcourse/resumeme/business/event/service/EventServiceTest.java +++ b/src/test/java/org/devcourse/resumeme/business/event/service/EventServiceTest.java @@ -5,11 +5,12 @@ import org.devcourse.resumeme.business.event.domain.EventTimeInfo; import org.devcourse.resumeme.business.event.exception.EventException; import org.devcourse.resumeme.business.event.repository.EventRepository; +import org.devcourse.resumeme.business.event.service.listener.EventCreationPublisher; import org.devcourse.resumeme.business.user.domain.Provider; import org.devcourse.resumeme.business.user.domain.Role; import org.devcourse.resumeme.business.user.domain.mentee.RequiredInfo; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -28,7 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.devcourse.resumeme.business.event.service.EventCreation.EventNoticeInfo; +import static org.devcourse.resumeme.business.event.service.listener.EventCreation.EventNoticeInfo; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; diff --git a/src/test/java/org/devcourse/resumeme/common/ControllerUnitTest.java b/src/test/java/org/devcourse/resumeme/common/ControllerUnitTest.java index 570e36208..6924ba4ee 100644 --- a/src/test/java/org/devcourse/resumeme/common/ControllerUnitTest.java +++ b/src/test/java/org/devcourse/resumeme/common/ControllerUnitTest.java @@ -23,7 +23,7 @@ import org.devcourse.resumeme.business.user.controller.FollowController; import org.devcourse.resumeme.business.user.controller.UserController; import org.devcourse.resumeme.business.user.controller.MentorApplicationController; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.business.user.service.AccountService; import org.devcourse.resumeme.business.user.service.admin.MentorApplicationService; import org.devcourse.resumeme.business.user.service.mentee.FollowService; From da94b7e33d1272bc4a735d5a3bb9e33683e731dd Mon Sep 17 00:00:00 2001 From: JuHongseok Date: Sun, 3 Dec 2023 14:22:36 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=A0=84=EC=9A=A9=20role=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/EventController.java | 4 +-- .../business/event/service/EventService.java | 32 ++++++------------- .../event/service/vo/AllEventFilter.java | 5 --- .../event/service/vo/AuthorizationRole.java | 17 ++++++++++ .../service/vo/EventsFoundCondition.java | 5 +++ .../controller/UserEventController.java | 11 ++++--- .../event/controller/EventControllerTest.java | 5 ++- .../controller/UserEventControllerTest.java | 6 ++-- 8 files changed, 45 insertions(+), 40 deletions(-) delete mode 100644 src/main/java/org/devcourse/resumeme/business/event/service/vo/AllEventFilter.java create mode 100644 src/main/java/org/devcourse/resumeme/business/event/service/vo/AuthorizationRole.java create mode 100644 src/main/java/org/devcourse/resumeme/business/event/service/vo/EventsFoundCondition.java diff --git a/src/main/java/org/devcourse/resumeme/business/event/controller/EventController.java b/src/main/java/org/devcourse/resumeme/business/event/controller/EventController.java index eeef8f542..977170210 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/controller/EventController.java +++ b/src/main/java/org/devcourse/resumeme/business/event/controller/EventController.java @@ -9,7 +9,7 @@ import org.devcourse.resumeme.business.event.domain.EventPosition; import org.devcourse.resumeme.business.event.service.EventPositionService; import org.devcourse.resumeme.business.event.service.EventService; -import org.devcourse.resumeme.business.event.service.vo.AllEventFilter; +import org.devcourse.resumeme.business.event.service.vo.EventsFoundCondition; import org.devcourse.resumeme.business.event.service.vo.EventUpdateVo; import org.devcourse.resumeme.business.user.entity.User; import org.devcourse.resumeme.business.user.entity.UserService; @@ -66,7 +66,7 @@ public EventInfoResponse getOne(@PathVariable Long eventId) { @GetMapping public EventPageResponse getAll(Pageable pageable) { - Page pageAbleEvent = eventService.getAllWithPage(new AllEventFilter(null, null), pageable); + Page pageAbleEvent = eventService.getAllWithPage(new EventsFoundCondition(null, null), pageable); List events = getEvents(pageAbleEvent); List positions = getPositions(events); diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/EventService.java b/src/main/java/org/devcourse/resumeme/business/event/service/EventService.java index e5bfe5ad9..ebe3de758 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/service/EventService.java +++ b/src/main/java/org/devcourse/resumeme/business/event/service/EventService.java @@ -3,10 +3,10 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.devcourse.resumeme.business.event.domain.Event; -import org.devcourse.resumeme.business.event.domain.EventStatus; import org.devcourse.resumeme.business.event.exception.EventException; import org.devcourse.resumeme.business.event.repository.EventRepository; -import org.devcourse.resumeme.business.event.service.vo.AllEventFilter; +import org.devcourse.resumeme.business.event.service.listener.EventCreationPublisher; +import org.devcourse.resumeme.business.event.service.vo.EventsFoundCondition; import org.devcourse.resumeme.business.event.service.vo.EventUpdateVo; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; import org.devcourse.resumeme.business.user.entity.User; @@ -14,13 +14,10 @@ import org.devcourse.resumeme.global.exception.CustomException; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDateTime; - -import static org.devcourse.resumeme.business.event.service.EventCreation.*; +import static org.devcourse.resumeme.business.event.service.listener.EventCreation.*; import static org.devcourse.resumeme.global.exception.ExceptionCode.EVENT_NOT_FOUND; import static org.devcourse.resumeme.global.exception.ExceptionCode.RESUME_NOT_FOUND; @@ -55,16 +52,12 @@ public Event getOne(Long eventId) { } @Transactional(readOnly = true) - public Page getAllWithPage(AllEventFilter filter, Pageable pageable) { - if (filter.mentorId() != null) { - return eventRepository.findAllByMentorIdOrderByCreatedDateDesc(filter.mentorId(), pageable); - } - - if (filter.menteeId() != null) { - return eventRepository.findAllByApplicantsMenteeIdOrderByCreatedDateDesc(filter.menteeId(), pageable); - } - - return eventRepository.findAllByOrderByCreatedDateDesc(pageable); + public Page getAllWithPage(EventsFoundCondition condition, Pageable pageable) { + return switch (condition.role()) { + case MENTEE -> eventRepository.findAllByApplicantsMenteeIdOrderByCreatedDateDesc(condition.userId(), pageable); + case MENTOR -> eventRepository.findAllByMentorIdOrderByCreatedDateDesc(condition.userId(), pageable); + case ALL -> eventRepository.findAllByOrderByCreatedDateDesc(pageable); + }; } public String getOverallReview(Event event, Long resumeId) { @@ -85,11 +78,4 @@ public void checkCommentAvailableDate(Long eventId) { event.checkDate(); } - @Scheduled(cron = "0 0/1 * * * *") - public void openBookedEvents() { - log.info("scheduler 실행 됨"); - eventRepository.openBookedEvent(EventStatus.OPEN, LocalDateTime.now()); - eventRepository.closeApplyToEvent(EventStatus.CLOSE, LocalDateTime.now()); - eventRepository.finishEvent(EventStatus.FINISH, LocalDateTime.now()); - } } diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/vo/AllEventFilter.java b/src/main/java/org/devcourse/resumeme/business/event/service/vo/AllEventFilter.java deleted file mode 100644 index 0e297c928..000000000 --- a/src/main/java/org/devcourse/resumeme/business/event/service/vo/AllEventFilter.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.devcourse.resumeme.business.event.service.vo; - -public record AllEventFilter(Long mentorId, Long menteeId) { - -} diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/vo/AuthorizationRole.java b/src/main/java/org/devcourse/resumeme/business/event/service/vo/AuthorizationRole.java new file mode 100644 index 000000000..62b178b27 --- /dev/null +++ b/src/main/java/org/devcourse/resumeme/business/event/service/vo/AuthorizationRole.java @@ -0,0 +1,17 @@ +package org.devcourse.resumeme.business.event.service.vo; + +import org.devcourse.resumeme.business.user.domain.Role; + +public enum AuthorizationRole { + MENTOR, + MENTEE, + ALL; + + public static AuthorizationRole of(Role role) { + return switch (role) { + case ROLE_MENTEE -> MENTEE; + case ROLE_PENDING, ROLE_MENTOR -> MENTOR; + case ROLE_ADMIN -> ALL; + }; + } +} diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/vo/EventsFoundCondition.java b/src/main/java/org/devcourse/resumeme/business/event/service/vo/EventsFoundCondition.java new file mode 100644 index 000000000..c0f20bafa --- /dev/null +++ b/src/main/java/org/devcourse/resumeme/business/event/service/vo/EventsFoundCondition.java @@ -0,0 +1,5 @@ +package org.devcourse.resumeme.business.event.service.vo; + +public record EventsFoundCondition(Long userId, AuthorizationRole role) { + +} diff --git a/src/main/java/org/devcourse/resumeme/business/userevent/controller/UserEventController.java b/src/main/java/org/devcourse/resumeme/business/userevent/controller/UserEventController.java index b9ec9f66c..63a26a328 100644 --- a/src/main/java/org/devcourse/resumeme/business/userevent/controller/UserEventController.java +++ b/src/main/java/org/devcourse/resumeme/business/userevent/controller/UserEventController.java @@ -5,9 +5,11 @@ import org.devcourse.resumeme.business.event.domain.MenteeToEvent; import org.devcourse.resumeme.business.event.service.EventService; import org.devcourse.resumeme.business.event.service.MenteeToEventService; -import org.devcourse.resumeme.business.event.service.vo.AllEventFilter; +import org.devcourse.resumeme.business.event.service.vo.AuthorizationRole; +import org.devcourse.resumeme.business.event.service.vo.EventsFoundCondition; import org.devcourse.resumeme.business.resume.entity.Resume; import org.devcourse.resumeme.business.resume.service.ResumeService; +import org.devcourse.resumeme.business.user.domain.Role; import org.devcourse.resumeme.business.user.domain.mentee.Mentee; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; import org.devcourse.resumeme.business.user.entity.UserService; @@ -36,9 +38,10 @@ public class UserEventController { private final MenteeToEventService menteeToEventService; - @GetMapping("/mentors/{mentorId}/events") - public List all(@PathVariable Long mentorId) { - Page events = eventService.getAllWithPage(new AllEventFilter(mentorId, null), Pageable.unpaged()); + @GetMapping("/{role}/{mentorId}/events") + public List all(@PathVariable Role role, @PathVariable Long mentorId) { + AuthorizationRole authorizationRole = AuthorizationRole.of(role); + Page events = eventService.getAllWithPage(new EventsFoundCondition(mentorId, authorizationRole), Pageable.unpaged()); List resumes = getResumes(events.getContent()); List mentees = getMentees(resumes); diff --git a/src/test/java/org/devcourse/resumeme/business/event/controller/EventControllerTest.java b/src/test/java/org/devcourse/resumeme/business/event/controller/EventControllerTest.java index 7f0544216..4259071e5 100644 --- a/src/test/java/org/devcourse/resumeme/business/event/controller/EventControllerTest.java +++ b/src/test/java/org/devcourse/resumeme/business/event/controller/EventControllerTest.java @@ -8,14 +8,13 @@ import org.devcourse.resumeme.business.event.domain.EventInfo; import org.devcourse.resumeme.business.event.domain.EventPosition; import org.devcourse.resumeme.business.event.domain.EventTimeInfo; -import org.devcourse.resumeme.business.event.service.vo.AllEventFilter; +import org.devcourse.resumeme.business.event.service.vo.EventsFoundCondition; import org.devcourse.resumeme.business.event.service.vo.EventUpdateVo; import org.devcourse.resumeme.business.resume.entity.Resume; import org.devcourse.resumeme.business.user.domain.Provider; import org.devcourse.resumeme.business.user.domain.Role; import org.devcourse.resumeme.business.user.domain.mentee.RequiredInfo; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; -import org.devcourse.resumeme.business.user.entity.User; import org.devcourse.resumeme.common.ControllerUnitTest; import org.devcourse.resumeme.common.support.WithMockCustomUser; import org.junit.jupiter.api.BeforeEach; @@ -272,7 +271,7 @@ void setUp() { setId(event, 1L); given(userService.getByIds(List.of(1L))).willReturn(List.of(mentor.from())); - given(eventService.getAllWithPage(new AllEventFilter(null, null), PageRequest.of(0, 10))).willReturn(new PageImpl<>(List.of(event))); + given(eventService.getAllWithPage(new EventsFoundCondition(null, null), PageRequest.of(0, 10))).willReturn(new PageImpl<>(List.of(event))); given(eventPositionService.getAll(List.of(1L))).willReturn(List.of(new EventPosition(BACK, event, 1))); // when diff --git a/src/test/java/org/devcourse/resumeme/business/userevent/controller/UserEventControllerTest.java b/src/test/java/org/devcourse/resumeme/business/userevent/controller/UserEventControllerTest.java index 59d45cb10..5e05c4e70 100644 --- a/src/test/java/org/devcourse/resumeme/business/userevent/controller/UserEventControllerTest.java +++ b/src/test/java/org/devcourse/resumeme/business/userevent/controller/UserEventControllerTest.java @@ -4,14 +4,13 @@ import org.devcourse.resumeme.business.event.domain.EventInfo; import org.devcourse.resumeme.business.event.domain.EventTimeInfo; import org.devcourse.resumeme.business.event.domain.MenteeToEvent; -import org.devcourse.resumeme.business.event.service.vo.AllEventFilter; +import org.devcourse.resumeme.business.event.service.vo.EventsFoundCondition; import org.devcourse.resumeme.business.resume.entity.Resume; import org.devcourse.resumeme.business.user.domain.Provider; import org.devcourse.resumeme.business.user.domain.Role; import org.devcourse.resumeme.business.user.domain.mentee.Mentee; import org.devcourse.resumeme.business.user.domain.mentee.RequiredInfo; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; -import org.devcourse.resumeme.business.user.entity.User; import org.devcourse.resumeme.common.ControllerUnitTest; import org.devcourse.resumeme.common.support.WithMockCustomUser; import org.junit.jupiter.api.BeforeEach; @@ -24,6 +23,7 @@ import java.util.List; import java.util.Set; +import static org.devcourse.resumeme.business.event.service.vo.AuthorizationRole.MENTOR; import static org.devcourse.resumeme.common.util.ApiDocumentUtils.getDocumentRequest; import static org.devcourse.resumeme.common.util.ApiDocumentUtils.getDocumentResponse; import static org.devcourse.resumeme.common.util.DocumentLinkGenerator.DocUrl.EVENT_STATUS; @@ -95,7 +95,7 @@ void init() throws NoSuchFieldException, IllegalAccessException { // given Long mentorId = 1L; - given(eventService.getAllWithPage(new AllEventFilter(mentorId, null), Pageable.unpaged())).willReturn(new PageImpl<>(List.of(event))); + given(eventService.getAllWithPage(new EventsFoundCondition(mentorId, MENTOR), Pageable.unpaged())).willReturn(new PageImpl<>(List.of(event))); given(resumeService.getAll(List.of(1L))).willReturn(List.of(resume)); given(userService.getByIds(List.of(1L))).willReturn(List.of(mentee.from())); From 5519227d4c38fe0b17c6c65b3724823650198874 Mon Sep 17 00:00:00 2001 From: JuHongseok Date: Sun, 3 Dec 2023 15:50:51 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=EC=9C=A0=EC=A0=80=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/EventController.java | 14 ++++---- .../controller/dto/EventPageResponse.java | 10 +++--- .../event/controller/dto/EventResponse.java | 8 ++--- .../business/event/service/EventService.java | 16 ++++----- .../event/service/listener/EventCreation.java | 6 ++-- .../listener/EventCreationListener.java | 10 +++--- .../resume/controller/ResumeController.java | 12 +++---- .../dto/resume/BasicResumeInfo.java | 8 ++--- .../user/service/UserInfoProvider.java | 35 +++++++++++++++++++ .../business/user/service/UserProvider.java | 13 +++++++ .../user/service/vo/UserResponse.java | 11 ++++++ .../controller/UserEventController.java | 23 +++++------- .../controller/dto/MentorEventResponse.java | 12 +++---- .../userevent/controller/dto/Response.java | 15 ++++---- .../global/exception/ExceptionCode.java | 4 +-- 15 files changed, 122 insertions(+), 75 deletions(-) create mode 100644 src/main/java/org/devcourse/resumeme/business/user/service/UserInfoProvider.java create mode 100644 src/main/java/org/devcourse/resumeme/business/user/service/UserProvider.java create mode 100644 src/main/java/org/devcourse/resumeme/business/user/service/vo/UserResponse.java diff --git a/src/main/java/org/devcourse/resumeme/business/event/controller/EventController.java b/src/main/java/org/devcourse/resumeme/business/event/controller/EventController.java index 977170210..15b40e292 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/controller/EventController.java +++ b/src/main/java/org/devcourse/resumeme/business/event/controller/EventController.java @@ -9,10 +9,10 @@ import org.devcourse.resumeme.business.event.domain.EventPosition; import org.devcourse.resumeme.business.event.service.EventPositionService; import org.devcourse.resumeme.business.event.service.EventService; -import org.devcourse.resumeme.business.event.service.vo.EventsFoundCondition; import org.devcourse.resumeme.business.event.service.vo.EventUpdateVo; -import org.devcourse.resumeme.business.user.entity.User; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.event.service.vo.EventsFoundCondition; +import org.devcourse.resumeme.business.user.service.UserProvider; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.devcourse.resumeme.common.response.IdResponse; import org.devcourse.resumeme.global.auth.model.jwt.JwtUser; import org.springframework.data.domain.Page; @@ -37,7 +37,7 @@ public class EventController { private final EventService eventService; - private final UserService userService; + private final UserProvider userProvider; private final EventPositionService eventPositionService; @@ -70,7 +70,7 @@ public EventPageResponse getAll(Pageable pageable) { List events = getEvents(pageAbleEvent); List positions = getPositions(events); - List mentors = getMentors(events); + List mentors = getMentors(events); return EventPageResponse.of(positions, mentors, pageAbleEvent); } @@ -90,12 +90,12 @@ private List getPositions(List content) { return eventPositionService.getAll(eventIds); } - private List getMentors(List events) { + private List getMentors(List events) { List mentorIds = events.stream() .map(Event::getMentorId) .toList(); - return userService.getByIds(mentorIds); + return userProvider.getByIds(mentorIds); } } diff --git a/src/main/java/org/devcourse/resumeme/business/event/controller/dto/EventPageResponse.java b/src/main/java/org/devcourse/resumeme/business/event/controller/dto/EventPageResponse.java index d043bf43e..3e5ec6fbb 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/controller/dto/EventPageResponse.java +++ b/src/main/java/org/devcourse/resumeme/business/event/controller/dto/EventPageResponse.java @@ -2,8 +2,7 @@ import org.devcourse.resumeme.business.event.domain.Event; import org.devcourse.resumeme.business.event.domain.EventPosition; -import org.devcourse.resumeme.business.user.domain.mentor.Mentor; -import org.devcourse.resumeme.business.user.entity.User; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; @@ -19,12 +18,11 @@ public record EventPageResponse(List events, PageableResponse pageData) { - public static EventPageResponse of(List positions, List mentors, Page pageAbleEvent) { + public static EventPageResponse of(List positions, List mentors, Page pageAbleEvent) { Map> positionsMap = positions.stream() .collect(groupingBy(position -> position.getEvent().getId(), toList())); - Map mentorsMap = mentors.stream() - .map(Mentor::of) - .collect(Collectors.toMap(Mentor::getId, Function.identity())); + Map mentorsMap = mentors.stream() + .collect(Collectors.toMap(UserResponse::userId, Function.identity())); List responses = getEvents(pageAbleEvent).stream() .map(event -> new EventResponse(event, positionsMap.get(event.getId()), mentorsMap.get(event.getMentorId()))) diff --git a/src/main/java/org/devcourse/resumeme/business/event/controller/dto/EventResponse.java b/src/main/java/org/devcourse/resumeme/business/event/controller/dto/EventResponse.java index ede4af12c..021c49214 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/controller/dto/EventResponse.java +++ b/src/main/java/org/devcourse/resumeme/business/event/controller/dto/EventResponse.java @@ -2,20 +2,20 @@ import org.devcourse.resumeme.business.event.domain.Event; import org.devcourse.resumeme.business.event.domain.EventPosition; -import org.devcourse.resumeme.business.user.domain.mentor.Mentor; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import java.util.List; public record EventResponse(EventInfoResponse info, MentorInfo mentorInfo) { - public EventResponse(Event event, List positions, Mentor mentor) { + public EventResponse(Event event, List positions, UserResponse mentor) { this(new EventInfoResponse(event, positions), new MentorInfo(mentor)); } record MentorInfo(Long mentorId, String nickname, String imageUrl) { - MentorInfo(Mentor mentor) { - this(mentor.getId(), mentor.getRequiredInfo().getNickname(), mentor.getImageUrl()); + MentorInfo(UserResponse mentor) { + this(mentor.userId(), mentor.nickname(), mentor.imageUrl()); } } diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/EventService.java b/src/main/java/org/devcourse/resumeme/business/event/service/EventService.java index ebe3de758..2939b4b1d 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/service/EventService.java +++ b/src/main/java/org/devcourse/resumeme/business/event/service/EventService.java @@ -6,18 +6,17 @@ import org.devcourse.resumeme.business.event.exception.EventException; import org.devcourse.resumeme.business.event.repository.EventRepository; import org.devcourse.resumeme.business.event.service.listener.EventCreationPublisher; -import org.devcourse.resumeme.business.event.service.vo.EventsFoundCondition; import org.devcourse.resumeme.business.event.service.vo.EventUpdateVo; -import org.devcourse.resumeme.business.user.domain.mentor.Mentor; -import org.devcourse.resumeme.business.user.entity.User; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.event.service.vo.EventsFoundCondition; +import org.devcourse.resumeme.business.user.service.UserProvider; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.devcourse.resumeme.global.exception.CustomException; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static org.devcourse.resumeme.business.event.service.listener.EventCreation.*; +import static org.devcourse.resumeme.business.event.service.listener.EventCreation.EventNoticeInfo; import static org.devcourse.resumeme.global.exception.ExceptionCode.EVENT_NOT_FOUND; import static org.devcourse.resumeme.global.exception.ExceptionCode.RESUME_NOT_FOUND; @@ -31,15 +30,14 @@ public class EventService { private final EventRepository eventRepository; - private final UserService userService; + private final UserProvider userProvider; public Long create(Event event) { eventRepository.findAllByMentorId(event.getMentorId()) .forEach(Event::checkOpen); Event savedEvent = eventRepository.save(event); - User user = userService.getOne(savedEvent.getMentorId()); - Mentor mentor = Mentor.of(user); - EventNoticeInfo eventNoticeInfo = new EventNoticeInfo(savedEvent, mentor); + UserResponse user = userProvider.getOne(savedEvent.getMentorId()); + EventNoticeInfo eventNoticeInfo = new EventNoticeInfo(savedEvent, user); eventCreationPublisher.publishEventCreation(eventNoticeInfo); return savedEvent.getId(); diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreation.java b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreation.java index e2057f6a6..afab76974 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreation.java +++ b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreation.java @@ -2,7 +2,7 @@ import lombok.Getter; import org.devcourse.resumeme.business.event.domain.Event; -import org.devcourse.resumeme.business.user.domain.mentor.Mentor; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.springframework.context.ApplicationEvent; public class EventCreation extends ApplicationEvent { @@ -17,8 +17,8 @@ public EventCreation(Object source, EventNoticeInfo eventNoticeInfo) { public record EventNoticeInfo(Long eventId, Long mentorId, String mentorNickname) { - public EventNoticeInfo(Event event, Mentor mentor) { - this(event.getId(), mentor.getId(), mentor.getNickname()); + public EventNoticeInfo(Event event, UserResponse mentor) { + this(event.getId(), mentor.userId(), mentor.nickname()); } } diff --git a/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationListener.java b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationListener.java index 37854d72b..f3e16e034 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationListener.java +++ b/src/main/java/org/devcourse/resumeme/business/event/service/listener/EventCreationListener.java @@ -3,9 +3,9 @@ import lombok.RequiredArgsConstructor; import org.devcourse.resumeme.business.mail.service.EmailService; import org.devcourse.resumeme.business.user.domain.mentee.Follow; -import org.devcourse.resumeme.business.user.entity.User; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserProvider; import org.devcourse.resumeme.business.user.service.mentee.FollowService; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; @@ -21,7 +21,7 @@ public class EventCreationListener implements ApplicationListener private final FollowService followService; - private final UserService userService; + private final UserProvider userProvider; @Override public void onApplicationEvent(EventCreation eventCreation) { @@ -31,8 +31,8 @@ public void onApplicationEvent(EventCreation eventCreation) { .map(Follow::getMenteeId) .toList(); - List emails = userService.getByIds(followerIds).stream() - .map(User::getEmail) + List emails = userProvider.getByIds(followerIds).stream() + .map(UserResponse::email) .toList(); emailService.sendEmail(createEventCreationMail(emails, eventCreation.getEventNoticeInfo())); diff --git a/src/main/java/org/devcourse/resumeme/business/resume/controller/ResumeController.java b/src/main/java/org/devcourse/resumeme/business/resume/controller/ResumeController.java index 3b55eb54a..daac86596 100644 --- a/src/main/java/org/devcourse/resumeme/business/resume/controller/ResumeController.java +++ b/src/main/java/org/devcourse/resumeme/business/resume/controller/ResumeController.java @@ -6,9 +6,8 @@ import org.devcourse.resumeme.business.resume.controller.dto.resume.ResumeResponse; import org.devcourse.resumeme.business.resume.entity.Resume; import org.devcourse.resumeme.business.resume.service.ResumeService; -import org.devcourse.resumeme.business.user.domain.mentee.Mentee; -import org.devcourse.resumeme.business.user.entity.User; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserProvider; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.devcourse.resumeme.common.response.IdResponse; import org.devcourse.resumeme.global.auth.model.jwt.JwtUser; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -29,7 +28,7 @@ public class ResumeController { private final ResumeService resumeService; - private final UserService userService; + private final UserProvider userProvider; @PostMapping public IdResponse createResume(@AuthenticationPrincipal JwtUser user, @RequestBody ResumeRequest request) { @@ -42,10 +41,9 @@ public IdResponse createResume(@AuthenticationPrincipal JwtUser user, @RequestBo @GetMapping("/{resumeId}/basic") public BasicResumeInfo getBasicInformation(@PathVariable Long resumeId) { Resume resume = resumeService.getOne(resumeId); - User user = userService.getOne(resume.getMenteeId()); - Mentee mentee = Mentee.of(user); + UserResponse user = userProvider.getOne(resume.getMenteeId()); - return new BasicResumeInfo(resume, mentee); + return new BasicResumeInfo(resume, user); } @GetMapping diff --git a/src/main/java/org/devcourse/resumeme/business/resume/controller/dto/resume/BasicResumeInfo.java b/src/main/java/org/devcourse/resumeme/business/resume/controller/dto/resume/BasicResumeInfo.java index 39357c353..5673d18f6 100644 --- a/src/main/java/org/devcourse/resumeme/business/resume/controller/dto/resume/BasicResumeInfo.java +++ b/src/main/java/org/devcourse/resumeme/business/resume/controller/dto/resume/BasicResumeInfo.java @@ -1,22 +1,22 @@ package org.devcourse.resumeme.business.resume.controller.dto.resume; import org.devcourse.resumeme.business.resume.entity.Resume; -import org.devcourse.resumeme.business.user.domain.mentee.Mentee; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import java.util.Set; public record BasicResumeInfo(String title, String position, Set skills, String introduce, Long originResumeId, OwnerInfo ownerInfo) { - public BasicResumeInfo(Resume resume, Mentee mentee) { + public BasicResumeInfo(Resume resume, UserResponse mentee) { this(resume.getTitle(), resume.getResumeInfo().getPosition(), resume.getResumeInfo().getSkillSet(), resume.getResumeInfo().getIntroduce(), resume.getOriginResumeId(), new OwnerInfo(mentee)); } record OwnerInfo(Long id, String name, String phoneNumber) { - public OwnerInfo(Mentee mentee) { - this(mentee.getId(), mentee.getRequiredInfo().getRealName(), mentee.getRequiredInfo().getPhoneNumber()); + public OwnerInfo(UserResponse mentee) { + this(mentee.userId(), mentee.name(), mentee.phoneNumber()); } } diff --git a/src/main/java/org/devcourse/resumeme/business/user/service/UserInfoProvider.java b/src/main/java/org/devcourse/resumeme/business/user/service/UserInfoProvider.java new file mode 100644 index 000000000..dcf088750 --- /dev/null +++ b/src/main/java/org/devcourse/resumeme/business/user/service/UserInfoProvider.java @@ -0,0 +1,35 @@ +package org.devcourse.resumeme.business.user.service; + +import lombok.RequiredArgsConstructor; +import org.devcourse.resumeme.business.user.entity.User; +import org.devcourse.resumeme.business.user.repository.UserRepository; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; +import org.devcourse.resumeme.global.exception.CustomException; +import org.springframework.stereotype.Service; + +import java.util.List; + +import static org.devcourse.resumeme.global.exception.ExceptionCode.USER_NOT_FOUND; + +@Service +@RequiredArgsConstructor +public class UserInfoProvider implements UserProvider { + + private final UserRepository userRepository; + + @Override + public UserResponse getOne(Long userId) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); + + return new UserResponse(user); + } + + @Override + public List getByIds(List userIds) { + return userRepository.findAllByIds(userIds).stream() + .map(UserResponse::new) + .toList(); + } + +} diff --git a/src/main/java/org/devcourse/resumeme/business/user/service/UserProvider.java b/src/main/java/org/devcourse/resumeme/business/user/service/UserProvider.java new file mode 100644 index 000000000..25a1473a6 --- /dev/null +++ b/src/main/java/org/devcourse/resumeme/business/user/service/UserProvider.java @@ -0,0 +1,13 @@ +package org.devcourse.resumeme.business.user.service; + +import org.devcourse.resumeme.business.user.service.vo.UserResponse; + +import java.util.List; + +public interface UserProvider { + + UserResponse getOne(Long userId); + + List getByIds(List userIds); + +} diff --git a/src/main/java/org/devcourse/resumeme/business/user/service/vo/UserResponse.java b/src/main/java/org/devcourse/resumeme/business/user/service/vo/UserResponse.java new file mode 100644 index 000000000..d75937187 --- /dev/null +++ b/src/main/java/org/devcourse/resumeme/business/user/service/vo/UserResponse.java @@ -0,0 +1,11 @@ +package org.devcourse.resumeme.business.user.service.vo; + +import org.devcourse.resumeme.business.user.entity.User; + +public record UserResponse(Long userId, String nickname, String name, String email, String phoneNumber, String imageUrl) { + + public UserResponse(User user) { + this(user.getId(), user.getRequiredInfo().getNickname(), user.getRequiredInfo().getRealName(), user.getEmail(), user.getRequiredInfo().getPhoneNumber(), user.getImageUrl()); + } + +} diff --git a/src/main/java/org/devcourse/resumeme/business/userevent/controller/UserEventController.java b/src/main/java/org/devcourse/resumeme/business/userevent/controller/UserEventController.java index 63a26a328..11b96a7df 100644 --- a/src/main/java/org/devcourse/resumeme/business/userevent/controller/UserEventController.java +++ b/src/main/java/org/devcourse/resumeme/business/userevent/controller/UserEventController.java @@ -10,9 +10,8 @@ import org.devcourse.resumeme.business.resume.entity.Resume; import org.devcourse.resumeme.business.resume.service.ResumeService; import org.devcourse.resumeme.business.user.domain.Role; -import org.devcourse.resumeme.business.user.domain.mentee.Mentee; -import org.devcourse.resumeme.business.user.domain.mentor.Mentor; -import org.devcourse.resumeme.business.user.entity.UserService; +import org.devcourse.resumeme.business.user.service.UserProvider; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.devcourse.resumeme.business.userevent.controller.dto.MenteeEventResponse; import org.devcourse.resumeme.business.userevent.controller.dto.MentorEventResponse; import org.devcourse.resumeme.business.userevent.controller.dto.Response; @@ -34,7 +33,7 @@ public class UserEventController { private final ResumeService resumeService; - private final UserService userService; + private final UserProvider userProvider; private final MenteeToEventService menteeToEventService; @@ -43,7 +42,7 @@ public List all(@PathVariable Role role, @PathVariable Long AuthorizationRole authorizationRole = AuthorizationRole.of(role); Page events = eventService.getAllWithPage(new EventsFoundCondition(mentorId, authorizationRole), Pageable.unpaged()); List resumes = getResumes(events.getContent()); - List mentees = getMentees(resumes); + List mentees = getMentees(resumes); return events.stream() .map(event -> new MentorEventResponse(event, resumes, mentees)) @@ -53,7 +52,7 @@ public List all(@PathVariable Role role, @PathVariable Long @GetMapping("/mentees/{menteeId}/events") public List getOwnEvents(@PathVariable Long menteeId) { List menteeToEvents = menteeToEventService.getByMenteeId(menteeId); - List mentors = getMentors(menteeToEvents); + List mentors = getMentors(menteeToEvents); List events = getEvents(menteeToEvents); List resumes = getResumes(events); @@ -69,24 +68,20 @@ private List getResumes(List events) { return resumeService.getAll(resumeIds); } - private List getMentees(List resumes) { + private List getMentees(List resumes) { List menteeIds = resumes.stream() .map(Resume::getMenteeId) .toList(); - return userService.getByIds(menteeIds).stream() - .map(Mentee::of) - .toList(); + return userProvider.getByIds(menteeIds); } - private List getMentors(List byMenteeId) { + private List getMentors(List byMenteeId) { List mentorIds = byMenteeId.stream() .map(m -> m.getEvent().getMentorId()) .toList(); - return userService.getByIds(mentorIds).stream() - .map(Mentor::of) - .toList(); + return userProvider.getByIds(mentorIds); } private List getEvents(List menteeToEvents) { diff --git a/src/main/java/org/devcourse/resumeme/business/userevent/controller/dto/MentorEventResponse.java b/src/main/java/org/devcourse/resumeme/business/userevent/controller/dto/MentorEventResponse.java index b5358d995..f5d342758 100644 --- a/src/main/java/org/devcourse/resumeme/business/userevent/controller/dto/MentorEventResponse.java +++ b/src/main/java/org/devcourse/resumeme/business/userevent/controller/dto/MentorEventResponse.java @@ -4,7 +4,7 @@ import org.devcourse.resumeme.business.event.domain.Event; import org.devcourse.resumeme.business.event.domain.MenteeToEvent; import org.devcourse.resumeme.business.resume.entity.Resume; -import org.devcourse.resumeme.business.user.domain.mentee.Mentee; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import java.util.ArrayList; import java.util.List; @@ -14,22 +14,22 @@ public record MentorEventResponse(EventInfoResponse info, List resumes) { - public MentorEventResponse(Event event, List resumes, List mentees) { + public MentorEventResponse(Event event, List resumes, List mentees) { this(new EventInfoResponse(event, new ArrayList<>()), toResponse(event, resumes, mentees)); } - public static List toResponse(Event event, List resumes, List mentees) { + public static List toResponse(Event event, List resumes, List mentees) { if (resumes.isEmpty()) { return List.of(); } Map resumesMap = resumes.stream() .collect(Collectors.toMap(Resume::getId, Function.identity())); - Map menteeMap = mentees.stream() - .collect(Collectors.toMap(Mentee::getId, Function.identity())); + Map menteeMap = mentees.stream() + .collect(Collectors.toMap(UserResponse::userId, UserResponse::name)); Map menteeNames = resumes.stream() - .map(resume -> new MenteeEvent(resume.getId(), menteeMap.get(resume.getMenteeId()).getRequiredInfo().getRealName())) + .map(resume -> new MenteeEvent(resume.getId(), menteeMap.get(resume.getMenteeId()))) .collect(Collectors.toMap(MenteeEvent::resumeId, MenteeEvent::menteeName)); diff --git a/src/main/java/org/devcourse/resumeme/business/userevent/controller/dto/Response.java b/src/main/java/org/devcourse/resumeme/business/userevent/controller/dto/Response.java index 824af063f..eaa74de8c 100644 --- a/src/main/java/org/devcourse/resumeme/business/userevent/controller/dto/Response.java +++ b/src/main/java/org/devcourse/resumeme/business/userevent/controller/dto/Response.java @@ -2,23 +2,22 @@ import org.devcourse.resumeme.business.event.domain.MenteeToEvent; import org.devcourse.resumeme.business.resume.entity.Resume; -import org.devcourse.resumeme.business.user.domain.mentor.Mentor; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import java.util.List; import java.util.Map; -import java.util.function.Function; import java.util.stream.Collectors; public record Response(List responses) { - public Response(List menteeToEvents, List mentors, List resumes) { + public Response(List menteeToEvents, List mentors, List resumes) { this(getResponses(menteeToEvents, mentors, resumes)); } - private static List getResponses(List menteeToEvents, List mentors, List resumes) { - Map mentorsMap = mentors.stream() - .collect(Collectors.toMap(Mentor::getId, Function.identity())); - Map mentorEventMap = menteeToEvents.stream() + private static List getResponses(List menteeToEvents, List mentors, List resumes) { + Map mentorsMap = mentors.stream() + .collect(Collectors.toMap(UserResponse::userId, UserResponse::nickname)); + Map mentorEventMap = menteeToEvents.stream() .collect(Collectors.toMap(e -> e.getEvent().getId(), e -> mentorsMap.get(e.getEvent().getMentorId()))); Map resumeTitles = resumes.stream() .collect(Collectors.toMap(Resume::getId, Resume::getTitle)); @@ -26,7 +25,7 @@ private static List getResponses(List mentee return menteeToEvents.stream() .map(menteeToEvent -> { Long eventId = menteeToEvent.getEvent().getId(); - String nickname = mentorEventMap.get(eventId).getNickname(); + String nickname = mentorEventMap.get(eventId); String resumeTitle = resumeTitles.get(menteeToEvent.getResumeId()); return new MenteeEventResponse(menteeToEvent, nickname, resumeTitle); diff --git a/src/main/java/org/devcourse/resumeme/global/exception/ExceptionCode.java b/src/main/java/org/devcourse/resumeme/global/exception/ExceptionCode.java index cffe4a5e6..77e4adcc4 100644 --- a/src/main/java/org/devcourse/resumeme/global/exception/ExceptionCode.java +++ b/src/main/java/org/devcourse/resumeme/global/exception/ExceptionCode.java @@ -43,8 +43,8 @@ public enum ExceptionCode implements DocsEnumType { ALREADY_FOLLOWING("이미 팔로우 중인 멘토입니다"), NOT_FOLLOWING_NOW("현재 팔로우 하고있지 않은 멘토입니다"), NOT_AVAILABLE_COMMENT_TIME("첨삭 가능한 시간이 아닙니다"), - NOT_UPDATE_EVENT("이벤트를 수정 할 수 없습니다") - ; + NOT_UPDATE_EVENT("이벤트를 수정 할 수 없습니다"), + USER_NOT_FOUND("사용자를 찾을 수 없습니다"); private final String message; From 8eecd24765739f426e0346a12b41c97605daf9e3 Mon Sep 17 00:00:00 2001 From: JuHongseok Date: Sun, 3 Dec 2023 16:04:05 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=A0=A5=EC=84=9C?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MenteeToEventController.java | 10 +++------ .../business/resume/service/ResumeCopier.java | 22 +++++++++++++++++++ .../resume/service/ResumeProvider.java | 7 ++++++ 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/devcourse/resumeme/business/resume/service/ResumeCopier.java create mode 100644 src/main/java/org/devcourse/resumeme/business/resume/service/ResumeProvider.java diff --git a/src/main/java/org/devcourse/resumeme/business/event/controller/MenteeToEventController.java b/src/main/java/org/devcourse/resumeme/business/event/controller/MenteeToEventController.java index 180717974..93d5ac5d6 100644 --- a/src/main/java/org/devcourse/resumeme/business/event/controller/MenteeToEventController.java +++ b/src/main/java/org/devcourse/resumeme/business/event/controller/MenteeToEventController.java @@ -6,8 +6,7 @@ import org.devcourse.resumeme.business.event.service.MenteeToEventService; import org.devcourse.resumeme.business.event.service.vo.AcceptMenteeToEvent; import org.devcourse.resumeme.business.event.service.vo.ApplyUpdateVo; -import org.devcourse.resumeme.business.resume.service.ComponentService; -import org.devcourse.resumeme.business.resume.service.ResumeService; +import org.devcourse.resumeme.business.resume.service.ResumeProvider; import org.devcourse.resumeme.business.snapshot.service.SnapshotCapture; import org.devcourse.resumeme.common.response.IdResponse; import org.devcourse.resumeme.global.auth.model.jwt.JwtUser; @@ -25,9 +24,7 @@ @RequestMapping("/api/v1/appliments/events") public class MenteeToEventController { - private final ResumeService resumeService; - - private final ComponentService componentService; + private final ResumeProvider resumeProvider; private final MenteeToEventService applyService; @@ -42,8 +39,7 @@ public IdResponse getParticipantRecord(@PathVariable Long eventId, @Authenticati @PostMapping("/{eventId}") public void applyEvent(@PathVariable Long eventId, @RequestBody ApplyToEventRequest request, @AuthenticationPrincipal JwtUser user) { - Long copyResumeId = resumeService.copyResume(request.resumeId()); - componentService.copy(request.resumeId(), copyResumeId); + Long copyResumeId = resumeProvider.copy(request.resumeId()); applyService.acceptMentee(new AcceptMenteeToEvent(eventId, user.id(), copyResumeId)); } diff --git a/src/main/java/org/devcourse/resumeme/business/resume/service/ResumeCopier.java b/src/main/java/org/devcourse/resumeme/business/resume/service/ResumeCopier.java new file mode 100644 index 000000000..415c14aac --- /dev/null +++ b/src/main/java/org/devcourse/resumeme/business/resume/service/ResumeCopier.java @@ -0,0 +1,22 @@ +package org.devcourse.resumeme.business.resume.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ResumeCopier implements ResumeProvider { + + private final ResumeService resumeService; + + private final ComponentService componentService; + + @Override + public Long copy(Long resumeId) { + Long copyResumeId = resumeService.copyResume(resumeId); + componentService.copy(resumeId, copyResumeId); + + return copyResumeId; + } + +} diff --git a/src/main/java/org/devcourse/resumeme/business/resume/service/ResumeProvider.java b/src/main/java/org/devcourse/resumeme/business/resume/service/ResumeProvider.java new file mode 100644 index 000000000..e257eb2a8 --- /dev/null +++ b/src/main/java/org/devcourse/resumeme/business/resume/service/ResumeProvider.java @@ -0,0 +1,7 @@ +package org.devcourse.resumeme.business.resume.service; + +public interface ResumeProvider { + + Long copy(Long resumeId); + +} From dda15a57ba004d751489e633367ddf0ca34f03a7 Mon Sep 17 00:00:00 2001 From: JuHongseok Date: Sun, 3 Dec 2023 16:09:09 +0900 Subject: [PATCH 5/5] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/EventControllerTest.java | 3 ++- .../event/service/EventServiceTest.java | 17 ++++------------- .../resume/controller/ResumeControllerTest.java | 3 ++- .../controller/UserEventControllerTest.java | 5 +++-- .../resumeme/common/ControllerUnitTest.java | 12 ++++++++++-- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/test/java/org/devcourse/resumeme/business/event/controller/EventControllerTest.java b/src/test/java/org/devcourse/resumeme/business/event/controller/EventControllerTest.java index 4259071e5..6db275b5a 100644 --- a/src/test/java/org/devcourse/resumeme/business/event/controller/EventControllerTest.java +++ b/src/test/java/org/devcourse/resumeme/business/event/controller/EventControllerTest.java @@ -15,6 +15,7 @@ import org.devcourse.resumeme.business.user.domain.Role; import org.devcourse.resumeme.business.user.domain.mentee.RequiredInfo; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.devcourse.resumeme.common.ControllerUnitTest; import org.devcourse.resumeme.common.support.WithMockCustomUser; import org.junit.jupiter.api.BeforeEach; @@ -270,7 +271,7 @@ void setUp() { Event event = new Event(openEvent, eventTimeInfo, 1L, List.of()); setId(event, 1L); - given(userService.getByIds(List.of(1L))).willReturn(List.of(mentor.from())); + given(userInfoProvider.getByIds(List.of(1L))).willReturn(List.of(new UserResponse(1L, "nickname", "name", "email", "01012345678", "url"))); given(eventService.getAllWithPage(new EventsFoundCondition(null, null), PageRequest.of(0, 10))).willReturn(new PageImpl<>(List.of(event))); given(eventPositionService.getAll(List.of(1L))).willReturn(List.of(new EventPosition(BACK, event, 1))); diff --git a/src/test/java/org/devcourse/resumeme/business/event/service/EventServiceTest.java b/src/test/java/org/devcourse/resumeme/business/event/service/EventServiceTest.java index 4f6f5b4ed..2a48fe549 100644 --- a/src/test/java/org/devcourse/resumeme/business/event/service/EventServiceTest.java +++ b/src/test/java/org/devcourse/resumeme/business/event/service/EventServiceTest.java @@ -10,7 +10,9 @@ import org.devcourse.resumeme.business.user.domain.Role; import org.devcourse.resumeme.business.user.domain.mentee.RequiredInfo; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; +import org.devcourse.resumeme.business.user.service.UserInfoProvider; import org.devcourse.resumeme.business.user.service.UserService; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -47,18 +49,11 @@ class EventServiceTest { private EventRepository eventRepository; @Mock - private UserService userService; + private UserInfoProvider userInfoProvider; @InjectMocks private EventService eventService; - private ExecutorService executorService; - - private CountDownLatch countDownLatch; - - private AtomicInteger successCount; - - private AtomicInteger failCount; int executeCount; @@ -67,10 +62,6 @@ class EventServiceTest { @BeforeEach void init() { executeCount = 10; - executorService = Executors.newFixedThreadPool(3); - countDownLatch = new CountDownLatch(executeCount); - successCount = new AtomicInteger(); - failCount = new AtomicInteger(); mentor = Mentor.builder() .id(1L) @@ -92,7 +83,7 @@ void init() { EventTimeInfo eventTimeInfo = EventTimeInfo.book(LocalDateTime.now(), LocalDateTime.now().plusHours(1L), LocalDateTime.now().plusHours(2L), LocalDateTime.now().plusHours(4L)); Event event = new Event(openEvent, eventTimeInfo, 1L, List.of()); - given(userService.getOne(1L)).willReturn(mentor.from()); + given(userInfoProvider.getOne(1L)).willReturn(new UserResponse(1L, "nickname", "name", "email", "01012345678", "url")); given(eventRepository.findAllByMentorId(1L)).willReturn(List.of()); given(eventRepository.save(event)).willReturn(event); doNothing().when(eventCreationPublisher).publishEventCreation(any(EventNoticeInfo.class)); diff --git a/src/test/java/org/devcourse/resumeme/business/resume/controller/ResumeControllerTest.java b/src/test/java/org/devcourse/resumeme/business/resume/controller/ResumeControllerTest.java index 41354b56c..2c92ee0bc 100644 --- a/src/test/java/org/devcourse/resumeme/business/resume/controller/ResumeControllerTest.java +++ b/src/test/java/org/devcourse/resumeme/business/resume/controller/ResumeControllerTest.java @@ -8,6 +8,7 @@ import org.devcourse.resumeme.business.user.domain.mentee.Mentee; import org.devcourse.resumeme.business.user.domain.mentee.RequiredInfo; import org.devcourse.resumeme.business.user.entity.User; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.devcourse.resumeme.common.ControllerUnitTest; import org.devcourse.resumeme.common.support.WithMockCustomUser; import org.junit.jupiter.api.BeforeEach; @@ -113,7 +114,7 @@ void init() { field.setAccessible(true); field.set(resume, 2L); given(resumeService.getOne(resumeId)).willReturn(resume); - given(userService.getOne(1L)).willReturn(mentee.from()); + given(userInfoProvider.getOne(1L)).willReturn(new UserResponse(1L, "nickname", "name", "email", "01012345678", "url")); // when ResultActions result = mvc.perform(get("/api/v1/resumes/{resumeId}/basic", resumeId)); diff --git a/src/test/java/org/devcourse/resumeme/business/userevent/controller/UserEventControllerTest.java b/src/test/java/org/devcourse/resumeme/business/userevent/controller/UserEventControllerTest.java index 5e05c4e70..e23317e28 100644 --- a/src/test/java/org/devcourse/resumeme/business/userevent/controller/UserEventControllerTest.java +++ b/src/test/java/org/devcourse/resumeme/business/userevent/controller/UserEventControllerTest.java @@ -11,6 +11,7 @@ import org.devcourse.resumeme.business.user.domain.mentee.Mentee; import org.devcourse.resumeme.business.user.domain.mentee.RequiredInfo; import org.devcourse.resumeme.business.user.domain.mentor.Mentor; +import org.devcourse.resumeme.business.user.service.vo.UserResponse; import org.devcourse.resumeme.common.ControllerUnitTest; import org.devcourse.resumeme.common.support.WithMockCustomUser; import org.junit.jupiter.api.BeforeEach; @@ -97,7 +98,7 @@ void init() throws NoSuchFieldException, IllegalAccessException { given(eventService.getAllWithPage(new EventsFoundCondition(mentorId, MENTOR), Pageable.unpaged())).willReturn(new PageImpl<>(List.of(event))); given(resumeService.getAll(List.of(1L))).willReturn(List.of(resume)); - given(userService.getByIds(List.of(1L))).willReturn(List.of(mentee.from())); + given(userInfoProvider.getByIds(List.of(1L))).willReturn(List.of(new UserResponse(1L, "nickname", "name", "email", "01012345678", "url"))); // when ResultActions result = mvc.perform(get("/api/v1/mentors/{mentorId}/events", mentorId)); @@ -143,7 +144,7 @@ void init() throws NoSuchFieldException, IllegalAccessException { Long menteeId = 1L; given(menteeToEventService.getByMenteeId(menteeId)).willReturn(List.of(new MenteeToEvent(event, menteeId, 1L))); - given(userService.getByIds(List.of(1L))).willReturn(List.of(mentor.from())); + given(userInfoProvider.getByIds(List.of(1L))).willReturn(List.of(new UserResponse(1L, "nickname", "name", "email", "01012345678", "url"))); given(resumeService.getAll(List.of(1L))).willReturn(List.of(resume)); // when ResultActions result = mvc.perform(get("/api/v1/mentees/{menteeId}/events", menteeId)); diff --git a/src/test/java/org/devcourse/resumeme/common/ControllerUnitTest.java b/src/test/java/org/devcourse/resumeme/common/ControllerUnitTest.java index 6924ba4ee..91f9a9184 100644 --- a/src/test/java/org/devcourse/resumeme/common/ControllerUnitTest.java +++ b/src/test/java/org/devcourse/resumeme/common/ControllerUnitTest.java @@ -16,15 +16,17 @@ import org.devcourse.resumeme.business.resume.controller.ResumeController; import org.devcourse.resumeme.business.resume.controller.ResumeControllerV2; import org.devcourse.resumeme.business.resume.service.ComponentService; +import org.devcourse.resumeme.business.resume.service.ResumeCopier; import org.devcourse.resumeme.business.resume.service.ResumeService; import org.devcourse.resumeme.business.snapshot.controller.SnapshotController; import org.devcourse.resumeme.business.snapshot.service.CommentCapture; import org.devcourse.resumeme.business.snapshot.service.SnapshotService; import org.devcourse.resumeme.business.user.controller.FollowController; -import org.devcourse.resumeme.business.user.controller.UserController; import org.devcourse.resumeme.business.user.controller.MentorApplicationController; -import org.devcourse.resumeme.business.user.service.UserService; +import org.devcourse.resumeme.business.user.controller.UserController; import org.devcourse.resumeme.business.user.service.AccountService; +import org.devcourse.resumeme.business.user.service.UserInfoProvider; +import org.devcourse.resumeme.business.user.service.UserService; import org.devcourse.resumeme.business.user.service.admin.MentorApplicationService; import org.devcourse.resumeme.business.user.service.mentee.FollowService; import org.devcourse.resumeme.business.userevent.controller.UserEventController; @@ -139,6 +141,12 @@ public abstract class ControllerUnitTest { @MockBean protected UserService userService; + @MockBean + protected UserInfoProvider userInfoProvider; + + @MockBean + protected ResumeCopier resumeCopier; + protected MockMvc mvc; @Autowired