From 6b07cb938c38193901eb10f82d9ed886a078d7f1 Mon Sep 17 00:00:00 2001 From: Bokyeom <79684339+k-kbk@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:54:02 +0900 Subject: [PATCH] [DEV-000] formatting (#283) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * style: formatting * style: formatting * chore: platform 옵션 삭제 * style: formatting --- infra/localcontainer/docker-compose.yml | 1 - .../api/signin/SignInApiPresentation.java | 7 +- .../auth/api/signin/SignInController.java | 15 +- .../api/signin/dto/request/SignInRequest.java | 4 +- .../auth/api/token/TokenApiPresentation.java | 7 +- .../auth/api/token/TokenController.java | 11 +- .../api/token/dto/request/TokenRequest.java | 4 +- .../port/FindRefreshTokenPort.java | 1 + .../port/SaveRefreshTokenPort.java | 2 +- .../service/signin/SignInService.java | 14 +- .../service/token/TokenService.java | 2 +- .../usecase/signin/SignInUseCase.java | 1 + .../usecase/token/TokenUseCase.java | 1 + .../repository/InMemoryTokenRepository.java | 13 +- .../auth/security/JwtAccessDeniedHandler.java | 27 ++- .../security/JwtAuthenticationEntryPoint.java | 28 ++- .../security/JwtAuthenticationProvider.java | 23 +- .../auth/security/JwtAuthenticationToken.java | 5 +- .../auth/security/JwtProperties.java | 6 +- .../security/LoginUserArgumentResolver.java | 9 +- .../security/TokenAuthenticationFilter.java | 26 +-- .../auth/security/TokenProvider.java | 14 +- .../FindCompletedCreditApiPresentation.java | 6 +- .../api/FindCompletedCreditsController.java | 16 +- .../api/dto/CompletedCreditResponse.java | 7 +- .../port/FindCompletedCreditPort.java | 3 +- .../GenerateOrModifyCompletedCreditPort.java | 3 +- .../service/FindCompletedCreditService.java | 7 +- ...enerateOrModifyCompletedCreditService.java | 89 +++++--- .../usecase/FindCompletedCreditUseCase.java | 4 +- .../domain/model/CompletedCredit.java | 17 +- .../DeletedCompletedCreditAdapter.java | 4 +- .../FindCompletedCreditAdapter.java | 9 +- ...nerateOrModifyCompletedCreditsAdapter.java | 15 +- .../entity/CompletedCreditJpaEntity.java | 9 +- .../CompletedCreditPersistenceMapper.java | 9 +- .../repository/CompletedCreditRepository.java | 7 +- .../core/EnvironmentCheck.java | 5 +- .../core/HealthCheckController.java | 6 +- .../core/config/JpaAuditingConfig.java | 1 + .../core/config/QuerydslConfig.java | 4 +- .../core/config/SecurityConfig.java | 68 +++--- .../core/config/SwaggerConfig.java | 5 +- .../core/config/WebMvcConfig.java | 5 +- .../core/entity/TimeBaseEntity.java | 10 +- .../exception/GlobalExceptionHandler.java | 37 ++-- .../core/exception/InvalidPdfException.java | 1 + .../core/exception/PdfParsingException.java | 3 +- .../core/exception/UnAuthorizedException.java | 3 +- .../core/meta/LoginUser.java | 3 +- .../core/meta/PersistenceAdapter.java | 1 - .../myongjigraduatebe/core/meta/UseCase.java | 1 - .../core/meta/WebAdapter.java | 1 - .../FindDetailGraduationApiPresentation.java | 4 +- .../api/FindDetailGraduationController.java | 8 +- .../api/dto/response/BasicInfoResponse.java | 7 +- .../dto/response/ChapelResultResponse.java | 4 +- ...etailGraduationCategoryResultResponse.java | 24 ++- .../DetailGraduationResultResponse.java | 15 +- .../api/dto/response/LectureResponse.java | 4 +- .../api/dto/response/MajorInfoResponse.java | 1 - .../api/dto/response/RestResultResponse.java | 7 +- ...sicAcademicalCultureGraduationService.java | 37 ++-- ...lculateCommonCultureGraduationService.java | 16 +- ...CalculateCoreCultureGraduationService.java | 15 +- .../service/CalculateGraduationService.java | 33 +-- .../CalculateMajorGraduationService.java | 59 +++-- ...alculateSingleDetailGraduationService.java | 22 +- .../CalculateDetailGraduationUseCase.java | 3 +- ...alculateSingleDetailGraduationUseCase.java | 3 +- .../graduation/domain/model/ChapelResult.java | 19 +- .../DefaultGraduationRequirementType.java | 24 ++- .../domain/model/DetailCategoryResult.java | 21 +- .../domain/model/DetailGraduationResult.java | 33 +-- .../DualMajorGraduationRequirementType.java | 4 +- .../model/FreeElectiveGraduationResult.java | 34 +-- .../domain/model/GraduationCategory.java | 1 - .../domain/model/GraduationRequirement.java | 28 +-- .../domain/model/GraduationResult.java | 16 +- .../graduation/domain/model/MajorType.java | 4 +- .../model/NormalCultureGraduationResult.java | 48 +++-- .../domain/service/GraduationManager.java | 9 +- .../BasicAcademicalGraduationManager.java | 12 +- ...inessBasicAcademicalGraduationManager.java | 30 +-- ...faultBasicAcademicalGraduationManager.java | 22 +- ...ScienceBasicAcademicGraduationManager.java | 19 +- .../CommonCultureDetailCategoryManager.java | 64 +++--- .../CommonGraduationManager.java | 38 ++-- .../CoreCultureDetailCategoryManager.java | 31 +-- .../coreculture/CoreGraduationManager.java | 24 ++- .../service/major/ElectiveMajorManager.java | 18 +- .../service/major/MajorGraduationManager.java | 45 ++-- .../service/major/MandatoryMajorManager.java | 25 +-- .../MandatoryMajorSpecialCaseHandler.java | 6 +- .../MandatorySpecialCaseInformation.java | 3 +- .../service/major/OptionalMandatory.java | 4 +- .../major/OptionalMandatoryMajorHandler.java | 45 ++-- .../major/ReplaceMandatoryMajorHandler.java | 40 ++-- .../submajor/SubMajorGraduationManager.java | 33 +-- .../api/SearchLectureApiPresentation.java | 10 +- .../lecture/api/SearchLectureController.java | 18 +- .../api/dto/response/LectureResponse.java | 5 +- .../dto/response/SearchLectureResponse.java | 19 +- .../port/FindBasicAcademicalCulturePort.java | 3 +- .../port/FindCommonCulturePort.java | 3 +- .../application/port/FindCoreCulturePort.java | 3 +- .../application/port/FindLecturePort.java | 3 +- .../application/port/FindMajorPort.java | 3 +- .../application/port/SearchLecturePort.java | 4 +- .../service/FindLecturesService.java | 10 +- .../service/SearchLectureService.java | 15 +- .../usecase/FindLecturesUseCase.java | 4 +- .../usecase/SearchLectureUseCase.java | 4 +- .../usecase/dto/SearchedLectureDto.java | 4 +- .../lecture/domain/model/CommonCulture.java | 3 +- .../domain/model/CommonCultureCategory.java | 9 +- .../lecture/domain/model/CoreCulture.java | 3 +- .../lecture/domain/model/Lecture.java | 15 +- .../lecture/domain/model/MajorLecture.java | 8 +- ...icAcademicalCulturePersistenceAdapter.java | 15 +- .../FindCommonCulturePersistenceAdapter.java | 30 ++- .../FindCoreCulturePersistenceAdapter.java | 13 +- .../FindMajorPersistenceAdapter.java | 13 +- .../LecturePersistenceAdapter.java | 12 +- ...asicAcademicalCultureLectureJpaEntity.java | 4 +- .../entity/CommonCultureJpaEntity.java | 4 +- .../entity/CoreCultureJpaEntity.java | 7 +- .../persistence/entity/LectureJpaEntity.java | 4 +- .../entity/MajorLectureJpaEntity.java | 4 +- .../persistence/mapper/LectureMapper.java | 16 +- .../BasicAcademicalCultureRepository.java | 13 +- .../repository/CommonCultureRepository.java | 16 +- .../repository/CoreCultureRepository.java | 4 +- .../repository/LectureQueryRepository.java | 9 +- .../repository/LectureRepository.java | 4 +- .../repository/MajorLectureRepository.java | 4 +- .../api/ParsingTextApiPresentation.java | 10 +- .../parsing/api/ParsingTextController.java | 22 +- .../api/dto/request/ParsingTextRequest.java | 3 +- .../port/SaveParsingTextHistoryPort.java | 1 + .../service/ParsingTextHistoryService.java | 10 +- .../service/ParsingTextService.java | 20 +- .../usecase/ParsingTextHistoryUseCase.java | 1 + .../parsing/domain/ParsingInformation.java | 32 +-- .../domain/ParsingStudentCategoryDto.java | 8 +- .../domain/ParsingTakenLectureDto.java | 2 +- .../parsing/domain/ParsingTextHistory.java | 5 +- .../ParsingTextHistoryAdapter.java | 5 +- .../entity/ParsingTextHistoryJpaEntity.java | 8 +- .../mapper/ParsingTextHistoryMapper.java | 7 +- .../repository/ParsingTextRepository.java | 3 +- .../api/FindTakenLectureApiPresentation.java | 1 - .../api/FindTakenLectureController.java | 6 +- .../UpdateTakenLectureApiPresentation.java | 9 +- .../api/UpdateTakenLectureController.java | 15 +- .../response/FindTakenLectureResponse.java | 14 +- .../dto/response/TakenLectureResponse.java | 19 +- .../port/DeleteTakenLecturePort.java | 3 +- .../port/FindTakenLecturePort.java | 5 +- .../port/SaveTakenLecturePort.java | 3 +- .../delete/DeleteTakenLectureService.java | 6 +- .../service/find/FindTakenLectureService.java | 9 +- ...GenerateCustomizedTakenLectureService.java | 7 +- ...aveTakenLectureFromParsingTextService.java | 30 +-- .../delete/DeleteTakenLectureUseCase.java | 1 + .../usecase/find/FindTakenLectureUseCase.java | 1 + ...GenerateCustomizedTakenLectureUseCase.java | 1 + ...aveTakenLectureFromParsingTextUseCase.java | 3 +- .../takenlecture/domain/model/Semester.java | 1 - .../domain/model/TakenLecture.java | 17 +- .../domain/model/TakenLectureInformation.java | 3 +- .../domain/model/TakenLectureInventory.java | 26 +-- .../TakenLecturePersistenceAdapter.java | 14 +- .../persistence/TakenLectureRepository.java | 9 +- .../entity/TakenLectureJpaEntity.java | 10 +- .../mapper/TakenLectureMapper.java | 9 +- .../findauthid/FindAuthIdApiPresentation.java | 8 +- .../api/findauthid/FindAuthIdController.java | 11 +- .../dto/response/UserAuthIdResponse.java | 3 +- .../FindUserInformationApiPresentation.java | 1 - .../FindUserInformationController.java | 8 +- .../dto/response/UserInformationResponse.java | 18 +- .../ResetPasswordApiPresentation.java | 15 +- .../ResetPasswordController.java | 22 +- .../dto/request/ResetPasswordRequest.java | 3 +- .../api/signup/SignUpApiPresentation.java | 13 +- .../user/api/signup/SignUpController.java | 19 +- .../api/signup/dto/request/SignUpRequest.java | 8 +- .../response/AuthIdDuplicationResponse.java | 1 + .../api/withdraw/WithDrawApiPresentation.java | 4 +- .../user/api/withdraw/WithDrawController.java | 8 +- .../withdraw/dto/request/WithDrawRequest.java | 4 +- .../user/application/port/CheckUserPort.java | 1 + .../user/application/port/FindUserPort.java | 4 +- .../user/application/port/SaveUserPort.java | 1 + .../user/application/port/UpdateUserPort.java | 1 + .../check/CheckAuthIdDuplicationService.java | 9 +- .../CheckStudentNumberDuplicationService.java | 12 +- .../service/find/FindUserAuthIdService.java | 4 +- .../find/FindUserInformationService.java | 5 +- .../service/find/FindUserService.java | 10 +- .../resetpassword/ResetPasswordService.java | 8 +- .../service/signup/SignUpService.java | 24 +-- .../UpdateStudentInformationService.java | 9 +- .../service/validate/ValidateUserService.java | 5 +- .../service/withdraw/WithDrawUserService.java | 8 +- .../usecase/find/FindUserUseCase.java | 1 + .../usecase/signup/SignUpCommand.java | 5 +- .../usecase/signup/SignUpUseCase.java | 1 + .../UpdateStudentInformationCommand.java | 11 +- .../UpdateStudentInformationUseCase.java | 1 + .../user/domain/model/College.java | 7 +- .../user/domain/model/StudentCategory.java | 44 ++-- .../user/domain/model/User.java | 49 +++-- .../persistence/UserPersistenceAdapter.java | 24 ++- .../persistence/entity/UserJpaEntity.java | 8 +- .../persistence/mapper/UserMapper.java | 5 +- .../repository/UserRepository.java | 5 +- src/main/resources/logback-spring.xml | 70 +++--- .../auth/api/signin/SignInControllerTest.java | 22 +- .../auth/api/token/TokenControllerTest.java | 17 +- .../service/signin/SignInServiceTest.java | 25 ++- .../service/token/TokenServiceTest.java | 17 +- .../InMemoryTokenRepositoryTest.java | 5 +- .../auth/security/TokenProviderTest.java | 3 +- .../FindCompletedCreditsControllerTest.java | 10 +- .../FindCompletedCreditServiceTest.java | 36 ++-- ...ateOrModifyCompletedCreditServiceTest.java | 62 +++--- ...teOrModifyCompletedCreditsAdapterTest.java | 25 +-- .../CompletedCreditPersistenceMapperTest.java | 39 ++-- .../CompletedCreditRepositoryTest.java | 37 ++-- .../BasicAcademicalLectureFixture.java | 6 +- .../fixture/CommonCultureCategoryFixture.java | 17 +- .../fixture/CommonCultureFixture.java | 31 +-- .../fixture/CoreCultureCategoryFixture.java | 9 +- .../fixture/CoreCultureFixture.java | 6 +- .../fixture/LectureFixture.java | 8 +- .../fixture/MajorFixture.java | 203 ++++++++++++------ .../fixture/UserFixture.java | 40 ++-- .../InternationalTradeFixture.java | 6 +- .../FindDetailGraduationsControllerTest.java | 71 +++--- ...cademicalCultureGraduationServiceTest.java | 78 ++++--- ...ateCommonCultureGraduationServiceTest.java | 48 +++-- ...ulateCoreCultureGraduationServiceTest.java | 37 ++-- .../CalculateMajorGraduationServiceTest.java | 177 ++++++++++----- ...lateSingleDetailGraduationServiceTest.java | 65 +++--- .../domain/model/ChapelResultTest.java | 27 ++- .../FreeElectiveGraduationResultTest.java | 34 +-- .../domain/model/GraduationCategoryTest.java | 3 +- .../model/GraduationRequirementTest.java | 19 +- .../domain/model/GraduationResultTest.java | 175 +++++++++------ .../domain/model/MajorTypeTest.java | 1 - .../NormalCultureGraduationResultTest.java | 43 ++-- ...sBasicAcademicalGraduationManagerTest.java | 27 +-- ...tBasicAcademicalGraduationManagerTest.java | 31 +-- ...SocialScienceBasicAcademicManagerTest.java | 27 +-- ...ommonCultureDetailCategoryManagerTest.java | 68 +++--- .../CommonCultureGraduationManagerTest.java | 27 ++- .../CoreCultureDetailCategoryManagerTest.java | 58 ++--- .../CoreCultureGraduationManagerTest.java | 16 +- .../major/DataTechnologyMajorTest.java | 71 +++--- .../major/InternationTradeMajorTest.java | 83 ++++--- .../OptionalMandatoryMajorHandlerTest.java | 13 +- .../ReplaceMandatoryMajorHandlerTest.java | 19 +- .../SubMajorGraduationManagerTest.java | 57 +++-- .../api/SearchLectureControllerTest.java | 17 +- .../find/FindLecturesByIdServiceTest.java | 19 +- .../FindLecturesByLectureCodeServiceTest.java | 13 +- .../search/SearchLectureServiceTest.java | 23 +- .../lecture/domain/model/LectureTest.java | 4 +- ...ademicalCulturePersistenceAdapterTest.java | 21 +- ...ndCommonCulturePersistenceAdapterTest.java | 33 +-- ...FindCoreCulturePersistenceAdapterTest.java | 21 +- .../FindMajorPersistenceAdapterTest.java | 24 +-- .../LecturePersistenceAdapterTest.java | 24 ++- .../persistence/mapper/LectureMapperTest.java | 40 ++-- .../query/LectureQueryRepositoryTest.java | 16 +- .../persistence/query/TestQuerydslConfig.java | 8 +- ...cademicalCultureLectureRepositoryTest.java | 52 +++-- .../CommonCultureRepositoryTest.java | 32 +-- .../repository/CoreCultureRepositoryTest.java | 16 +- .../MajorLectureRepositoryTest.java | 20 +- .../api/ParsingTextControllerTest.java | 25 ++- .../ParsingTextHistoryServiceTest.java | 32 +-- .../service/ParsingTextServiceTest.java | 52 +++-- .../domain/ParsingInformationTest.java | 35 +-- .../domain/ParsingTextHistoryTest.java | 9 +- .../ParsingTextHistoryAdapterTest.java | 14 +- .../mapper/ParsingTextHistoryMapperTest.java | 10 +- .../support/PersistenceTestSupport.java | 5 +- .../support/WebAdaptorTestSupport.java | 52 ++--- .../support/WithMockAuthenticationUser.java | 2 +- ...MockAuthenticationUserSecurityContext.java | 4 +- .../find/FindTakenLectureControllerTest.java | 35 +-- .../UpdateTakenLectureControllerTest.java | 16 +- .../delete/DeleteTakenLectureServiceTest.java | 23 +- .../find/FindTakenLectureServiceTest.java | 30 +-- .../save/GenerateTakenLectureServiceTest.java | 29 +-- ...akenLectureFromParsingTextServiceTest.java | 33 +-- .../model/TakenLectureInventoryTest.java | 19 +- .../domain/model/TakenLectureTest.java | 29 +-- .../TakenLecturePersistenceAdapterTest.java | 18 +- .../mapper/TakenLectureMapperTest.java | 50 +++-- .../TakenLectureRepositoryTest.java | 18 +- .../findauthid/FindAuthIdControllerTest.java | 3 +- .../FindUserInformationControllerTest.java | 8 +- .../ResetPasswordControllerTest.java | 17 +- .../user/api/signup/SignUpControllerTest.java | 25 ++- .../api/withdraw/WithDrawControllerTest.java | 13 +- .../CheckAuthIdDuplicationServiceTest.java | 11 +- ...ckStudentNumberDuplicationServiceTest.java | 10 +- .../find/FindUserAuthIdServiceTest.java | 5 +- .../find/FindUserInformationServiceTest.java | 12 +- .../service/find/FindUserServiceTest.java | 13 +- .../ResetPasswordServiceTest.java | 22 +- .../service/signup/SignUpServiceTest.java | 36 ++-- .../UpdateStudentInformationServiceTest.java | 14 +- .../validate/ValidateUserServiceTest.java | 15 +- .../withdraw/WithDrawUserServiceTest.java | 35 +-- .../DefaultGraduationRequirementTypeTest.java | 28 +-- .../domain/model/StudentCategoryTest.java | 11 +- .../user/domain/model/UserTest.java | 26 ++- .../UserPersistenceAdapterTest.java | 34 +-- .../persistence/mapper/UserMapperTest.java | 18 +- .../repository/UserRepositoryTest.java | 19 +- src/test/resources/logback-test.xml | 22 +- 326 files changed, 3215 insertions(+), 2701 deletions(-) diff --git a/infra/localcontainer/docker-compose.yml b/infra/localcontainer/docker-compose.yml index 75aec382..9dc8dfd9 100644 --- a/infra/localcontainer/docker-compose.yml +++ b/infra/localcontainer/docker-compose.yml @@ -22,7 +22,6 @@ services: environment: MYSQL_ROOT_PASSWORD: mysql MYSQL_DATABASE: myongji_graduate - platform: linux/x86_64 restart: always redis: diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInApiPresentation.java index bc96cc07..1af31593 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInApiPresentation.java @@ -1,16 +1,13 @@ package com.plzgraduate.myongjigraduatebe.auth.api.signin; -import javax.validation.Valid; - -import org.springframework.web.bind.annotation.RequestBody; - import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.request.SignInRequest; import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse; import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; - import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import javax.validation.Valid; +import org.springframework.web.bind.annotation.RequestBody; @Tag(name = "SignIn", description = "로그인 API") public interface SignInApiPresentation { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInController.java index 191e97ce..47e229c6 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInController.java @@ -1,19 +1,16 @@ package com.plzgraduate.myongjigraduatebe.auth.api.signin; -import javax.validation.Valid; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; - import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.request.SignInRequest; -import com.plzgraduate.myongjigraduatebe.auth.application.usecase.signin.SignInUseCase; import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse; +import com.plzgraduate.myongjigraduatebe.auth.application.usecase.signin.SignInUseCase; import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; - +import javax.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; @WebAdapter @RequestMapping("api/v1/auth") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/dto/request/SignInRequest.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/dto/request/SignInRequest.java index 73ac31b8..1a547436 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/dto/request/SignInRequest.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/dto/request/SignInRequest.java @@ -1,8 +1,7 @@ package com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.request; -import javax.validation.constraints.NotBlank; - import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.NotBlank; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -24,5 +23,4 @@ private SignInRequest(String authId, String password) { this.authId = authId; this.password = password; } - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenApiPresentation.java index 186dff52..d2da1133 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenApiPresentation.java @@ -1,13 +1,10 @@ package com.plzgraduate.myongjigraduatebe.auth.api.token; -import javax.validation.Valid; - -import org.springframework.web.bind.annotation.RequestBody; - import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.request.TokenRequest; import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.response.AccessTokenResponse; - import io.swagger.v3.oas.annotations.tags.Tag; +import javax.validation.Valid; +import org.springframework.web.bind.annotation.RequestBody; @Tag(name = "Token", description = "토큰 발급 API") public interface TokenApiPresentation { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenController.java index 04ad4a27..128e215b 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenController.java @@ -1,17 +1,14 @@ package com.plzgraduate.myongjigraduatebe.auth.api.token; -import javax.validation.Valid; - -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; - import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.request.TokenRequest; import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.response.AccessTokenResponse; import com.plzgraduate.myongjigraduatebe.auth.application.usecase.token.TokenUseCase; import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; - +import javax.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; @WebAdapter @RequiredArgsConstructor diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/dto/request/TokenRequest.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/dto/request/TokenRequest.java index 746a087b..e2a7a499 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/dto/request/TokenRequest.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/api/token/dto/request/TokenRequest.java @@ -1,8 +1,7 @@ package com.plzgraduate.myongjigraduatebe.auth.api.token.dto.request; -import javax.validation.constraints.NotBlank; - import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.NotBlank; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -19,5 +18,4 @@ public class TokenRequest { private TokenRequest(String refreshToken) { this.refreshToken = refreshToken; } - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/port/FindRefreshTokenPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/port/FindRefreshTokenPort.java index 1091014f..04448ee4 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/port/FindRefreshTokenPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/port/FindRefreshTokenPort.java @@ -3,5 +3,6 @@ import java.util.Optional; public interface FindRefreshTokenPort { + Optional findByRefreshToken(String refreshToken); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/port/SaveRefreshTokenPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/port/SaveRefreshTokenPort.java index 98c5b469..059023da 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/port/SaveRefreshTokenPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/port/SaveRefreshTokenPort.java @@ -1,6 +1,6 @@ package com.plzgraduate.myongjigraduatebe.auth.application.port; - public interface SaveRefreshTokenPort { + void saveRefreshToken(String refreshToken, Long userId); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/service/signin/SignInService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/service/signin/SignInService.java index 05c77410..60d9f65c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/service/signin/SignInService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/service/signin/SignInService.java @@ -1,18 +1,16 @@ package com.plzgraduate.myongjigraduatebe.auth.application.service.signin; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse; import com.plzgraduate.myongjigraduatebe.auth.application.port.SaveRefreshTokenPort; import com.plzgraduate.myongjigraduatebe.auth.application.usecase.signin.SignInUseCase; import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationToken; import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; - import lombok.RequiredArgsConstructor; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -37,8 +35,8 @@ private Authentication authenticateCommand(String authId, String password) { JwtAuthenticationToken authenticationToken = new JwtAuthenticationToken(authId, password); Authentication authentication = authenticationManager.authenticate(authenticationToken); - SecurityContextHolder.getContext().setAuthentication(authentication); + SecurityContextHolder.getContext() + .setAuthentication(authentication); return authentication; } - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/service/token/TokenService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/service/token/TokenService.java index fb17e6d0..ba725867 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/service/token/TokenService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/service/token/TokenService.java @@ -5,7 +5,6 @@ import com.plzgraduate.myongjigraduatebe.auth.application.usecase.token.TokenUseCase; import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; - import lombok.RequiredArgsConstructor; @UseCase @@ -15,6 +14,7 @@ public class TokenService implements TokenUseCase { private final TokenProvider tokenProvider; private final FindRefreshTokenPort findRefreshTokenPort; + @Override public AccessTokenResponse generateNewToken(String refreshToken) { Long userId = findByRefreshToken(refreshToken); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/usecase/signin/SignInUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/usecase/signin/SignInUseCase.java index 7050eedc..02839d1d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/usecase/signin/SignInUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/usecase/signin/SignInUseCase.java @@ -3,5 +3,6 @@ import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse; public interface SignInUseCase { + TokenResponse signIn(String authId, String password); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/usecase/token/TokenUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/usecase/token/TokenUseCase.java index 547d5576..f9177494 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/usecase/token/TokenUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/application/usecase/token/TokenUseCase.java @@ -3,5 +3,6 @@ import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.response.AccessTokenResponse; public interface TokenUseCase { + AccessTokenResponse generateNewToken(String refreshToken); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/infrastructure/adapter/repository/InMemoryTokenRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/infrastructure/adapter/repository/InMemoryTokenRepository.java index f7a863f7..2cb0d4a9 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/infrastructure/adapter/repository/InMemoryTokenRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/infrastructure/adapter/repository/InMemoryTokenRepository.java @@ -1,24 +1,22 @@ package com.plzgraduate.myongjigraduatebe.auth.infrastructure.adapter.repository; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -import org.springframework.stereotype.Component; - import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.plzgraduate.myongjigraduatebe.auth.application.port.FindRefreshTokenPort; import com.plzgraduate.myongjigraduatebe.auth.application.port.SaveRefreshTokenPort; - +import java.util.Optional; +import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor public class InMemoryTokenRepository implements FindRefreshTokenPort, SaveRefreshTokenPort { + private static final Cache TOKEN_REPOSITORY = CacheBuilder.newBuilder() .expireAfterWrite(15, TimeUnit.DAYS) .build(); - + @Override public void saveRefreshToken(String refreshToken, Long userId) { TOKEN_REPOSITORY.put(refreshToken, userId); @@ -28,5 +26,4 @@ public void saveRefreshToken(String refreshToken, Long userId) { public Optional findByRefreshToken(String refreshToken) { return Optional.ofNullable(TOKEN_REPOSITORY.getIfPresent(refreshToken)); } - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAccessDeniedHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAccessDeniedHandler.java index d34a1190..4bff27eb 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAccessDeniedHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAccessDeniedHandler.java @@ -1,29 +1,23 @@ package com.plzgraduate.myongjigraduatebe.auth.security; -import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.AUTHENTICATION_FAIL_FORBIDDEN; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.plzgraduate.myongjigraduatebe.core.exception.ExceptionResponse; import java.io.IOException; - -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - -import org.springframework.http.HttpStatus; +import lombok.RequiredArgsConstructor; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.web.access.AccessDeniedHandler; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; -import com.plzgraduate.myongjigraduatebe.core.exception.ExceptionResponse; - -import lombok.RequiredArgsConstructor; - @Component @RequiredArgsConstructor public class JwtAccessDeniedHandler implements AccessDeniedHandler { - private static final ExceptionResponse E403 = ExceptionResponse.from(AUTHENTICATION_FAIL_FORBIDDEN.toString()); + private static final ExceptionResponse E403 = ExceptionResponse.from( + AUTHENTICATION_FAIL_FORBIDDEN.toString()); private final ObjectMapper om; @@ -32,8 +26,11 @@ public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException { response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setHeader("content-type", "application/json"); - response.getWriter().write(om.writeValueAsString(E403)); - response.getWriter().flush(); - response.getWriter().close(); + response.getWriter() + .write(om.writeValueAsString(E403)); + response.getWriter() + .flush(); + response.getWriter() + .close(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationEntryPoint.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationEntryPoint.java index b42ed4a6..574043f8 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationEntryPoint.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationEntryPoint.java @@ -1,28 +1,23 @@ package com.plzgraduate.myongjigraduatebe.auth.security; -import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.AUTHENTICATION_FAIL_UNAUTHORIZED; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.plzgraduate.myongjigraduatebe.core.exception.ExceptionResponse; import java.io.IOException; - -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - -import org.springframework.http.HttpStatus; +import lombok.RequiredArgsConstructor; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; -import com.plzgraduate.myongjigraduatebe.core.exception.ExceptionResponse; - -import lombok.RequiredArgsConstructor; - @Component @RequiredArgsConstructor public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { - private static final ExceptionResponse E401 = ExceptionResponse.from(AUTHENTICATION_FAIL_UNAUTHORIZED.toString()); + + private static final ExceptionResponse E401 = ExceptionResponse.from( + AUTHENTICATION_FAIL_UNAUTHORIZED.toString()); private final ObjectMapper om; @@ -31,8 +26,11 @@ public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setHeader("content-type", "application/json"); - response.getWriter().write(om.writeValueAsString(E401)); - response.getWriter().flush(); - response.getWriter().close(); + response.getWriter() + .write(om.writeValueAsString(E401)); + response.getWriter() + .flush(); + response.getWriter() + .close(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationProvider.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationProvider.java index 6fba9d33..7c89f5d3 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationProvider.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationProvider.java @@ -1,23 +1,19 @@ package com.plzgraduate.myongjigraduatebe.auth.security; -import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.INCORRECT_PASSWORD; import static org.hibernate.validator.internal.util.TypeHelper.isAssignable; +import com.plzgraduate.myongjigraduatebe.core.exception.UnAuthorizedException; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.util.Collections; - +import lombok.RequiredArgsConstructor; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.crypto.password.PasswordEncoder; -import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; -import com.plzgraduate.myongjigraduatebe.core.exception.UnAuthorizedException; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -import lombok.RequiredArgsConstructor; - @RequiredArgsConstructor public class JwtAuthenticationProvider implements AuthenticationProvider { @@ -31,15 +27,18 @@ public boolean supports(Class authentication) { } @Override - public Authentication authenticate(Authentication authentication) throws AuthenticationException { + public Authentication authenticate(Authentication authentication) + throws AuthenticationException { JwtAuthenticationToken authenticationToken = (JwtAuthenticationToken) authentication; return processAuthentication(authenticationToken); } private Authentication processAuthentication(JwtAuthenticationToken authenticationToken) { - User user = findUserUseCase.findUserByAuthId(String.valueOf(authenticationToken.getPrincipal())); + User user = findUserUseCase.findUserByAuthId( + String.valueOf(authenticationToken.getPrincipal())); try { - user.matchPassword(passwordEncoder, String.valueOf(authenticationToken.getCredentials())); + user.matchPassword(passwordEncoder, + String.valueOf(authenticationToken.getCredentials())); return new JwtAuthenticationToken( user.getId(), null, Collections.singleton(new SimpleGrantedAuthority("ROLE_USER")) ); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationToken.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationToken.java index c487e968..75c66253 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationToken.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtAuthenticationToken.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.auth.security; import java.util.Collection; - import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.core.GrantedAuthority; @@ -19,7 +18,8 @@ public JwtAuthenticationToken(String principal, String credentials) { this.credentials = credentials; } - public JwtAuthenticationToken(Object principal, String credentials, Collection authorities) { + public JwtAuthenticationToken(Object principal, String credentials, + Collection authorities) { super(authorities); super.setAuthenticated(true); @@ -42,5 +42,4 @@ public void eraseCredentials() { super.eraseCredentials(); credentials = null; } - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtProperties.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtProperties.java index 256633e7..b9dc376d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtProperties.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/JwtProperties.java @@ -1,16 +1,16 @@ package com.plzgraduate.myongjigraduatebe.auth.security; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - import lombok.Getter; import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; @Getter @Setter @Component @ConfigurationProperties("jwt") public class JwtProperties { + private String issuer; private String secretKey; private int expirySeconds; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/LoginUserArgumentResolver.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/LoginUserArgumentResolver.java index 91f762f1..c39635bc 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/LoginUserArgumentResolver.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/LoginUserArgumentResolver.java @@ -1,5 +1,7 @@ package com.plzgraduate.myongjigraduatebe.auth.security; +import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; +import lombok.extern.slf4j.Slf4j; import org.springframework.core.MethodParameter; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -9,10 +11,6 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; -import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; - -import lombok.extern.slf4j.Slf4j; - @Slf4j @Component public class LoginUserArgumentResolver implements HandlerMethodArgumentResolver { @@ -26,7 +24,8 @@ public boolean supportsParameter(MethodParameter parameter) { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + Authentication authentication = SecurityContextHolder.getContext() + .getAuthentication(); if (authentication == null) { log.warn("authentication in security context is null"); return null; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenAuthenticationFilter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenAuthenticationFilter.java index 5c9a09a1..d754f847 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenAuthenticationFilter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenAuthenticationFilter.java @@ -2,47 +2,49 @@ import java.io.IOException; import java.util.Collections; - import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.filter.OncePerRequestFilter; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - @Slf4j @RequiredArgsConstructor public class TokenAuthenticationFilter extends OncePerRequestFilter { - private final TokenProvider tokenProvider; private static final String HEADER_AUTHORIZATION = "Authorization"; private static final String TOKEN_PREFIX = "Bearer "; + private final TokenProvider tokenProvider; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - if(SecurityContextHolder.getContext().getAuthentication() == null) { + if (SecurityContextHolder.getContext() + .getAuthentication() == null) { String authorizationHeader = request.getHeader(HEADER_AUTHORIZATION); String token = getAccessToken(authorizationHeader); - if(token != null) { + if (token != null) { try { Long userId = tokenProvider.extractUserId(token); Authentication authentication = new JwtAuthenticationToken( - userId, null, Collections.singleton(new SimpleGrantedAuthority("ROLE_USER"))); - SecurityContextHolder.getContext().setAuthentication(authentication); + userId, null, + Collections.singleton(new SimpleGrantedAuthority("ROLE_USER"))); + SecurityContextHolder.getContext() + .setAuthentication(authentication); } catch (Exception e) { log.warn("Jwt processing failed: {}", e.getMessage()); } } } else { - log.debug("SecurityContextHolder not populated with security token, as it already contained: '{}'", - SecurityContextHolder.getContext().getAuthentication()); + log.debug( + "SecurityContextHolder not populated with security token, as it already contained: '{}'", + SecurityContextHolder.getContext() + .getAuthentication()); } filterChain.doFilter(request, response); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenProvider.java b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenProvider.java index 2aca4be2..69e55bd0 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenProvider.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenProvider.java @@ -1,18 +1,17 @@ package com.plzgraduate.myongjigraduatebe.auth.security; -import java.util.Date; -import java.util.UUID; - -import org.springframework.stereotype.Component; - import com.auth0.jwt.JWT; import com.auth0.jwt.JWTVerifier; import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.interfaces.Claim; import com.auth0.jwt.interfaces.DecodedJWT; +import java.util.Date; +import java.util.UUID; +import org.springframework.stereotype.Component; @Component public class TokenProvider { + private final JwtProperties jwtProperties; public TokenProvider(JwtProperties jwtProperties) { @@ -35,12 +34,15 @@ public String generateRefreshToken() { } public Long extractUserId(String token) { - JWTVerifier jwtverifier = JWT.require(Algorithm.HMAC256(jwtProperties.getSecretKey())).withIssuer(jwtProperties.getIssuer()).build(); + JWTVerifier jwtverifier = JWT.require(Algorithm.HMAC256(jwtProperties.getSecretKey())) + .withIssuer(jwtProperties.getIssuer()) + .build(); Claims claims = new Claims(jwtverifier.verify(token)); return claims.id; } static class Claims { + Long id; Date iat; Date exp; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditApiPresentation.java index 28691b65..f9106e6e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditApiPresentation.java @@ -1,15 +1,13 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.api; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.completedcredit.api.dto.CompletedCreditResponse; import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; -@Tag(name = "CompletdCredit") +@Tag(name = "CompletedCredit") public interface FindCompletedCreditApiPresentation { @Operation(summary = "기이수 학점 조회", description = "유저의 기이수 학점 조회 API") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditsController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditsController.java index 8795f337..c2e347fa 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditsController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditsController.java @@ -1,28 +1,26 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.api; -import java.util.List; -import java.util.stream.Collectors; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - import com.plzgraduate.myongjigraduatebe.completedcredit.api.dto.CompletedCreditResponse; import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.FindCompletedCreditUseCase; import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; - +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; @WebAdapter @RequestMapping(value = "/api/v1/graduations/credits") @RequiredArgsConstructor -public class FindCompletedCreditsController implements FindCompletedCreditApiPresentation{ +public class FindCompletedCreditsController implements FindCompletedCreditApiPresentation { private final FindCompletedCreditUseCase findCompletedCreditUseCase; @GetMapping() public List getCompletedCredits(@LoginUser Long userId) { - return findCompletedCreditUseCase.findCompletedCredits(userId).stream() + return findCompletedCreditUseCase.findCompletedCredits(userId) + .stream() .filter(completedCredit -> completedCredit.getTotalCredit() != 0) .map(CompletedCreditResponse::from) .collect(Collectors.toList()); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/dto/CompletedCreditResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/dto/CompletedCreditResponse.java index 0d898703..aa7fa359 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/dto/CompletedCreditResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/dto/CompletedCreditResponse.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.api.dto; import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; - import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -16,7 +15,8 @@ public class CompletedCreditResponse { private boolean completed; @Builder - private CompletedCreditResponse(String category, int totalCredit, double takenCredit, boolean completed) { + private CompletedCreditResponse(String category, int totalCredit, double takenCredit, + boolean completed) { this.category = category; this.totalCredit = totalCredit; this.takenCredit = takenCredit; @@ -25,7 +25,8 @@ private CompletedCreditResponse(String category, int totalCredit, double takenCr public static CompletedCreditResponse from(CompletedCredit completedCredit) { return CompletedCreditResponse.builder() - .category(completedCredit.getGraduationCategory().name()) + .category(completedCredit.getGraduationCategory() + .name()) .totalCredit(completedCredit.getTotalCredit()) .takenCredit(completedCredit.getTakenCredit()) .completed(completedCredit.getTakenCredit() >= completedCredit.getTotalCredit()) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/port/FindCompletedCreditPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/port/FindCompletedCreditPort.java index 7c0f6ed3..2ff13a1e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/port/FindCompletedCreditPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/port/FindCompletedCreditPort.java @@ -1,9 +1,8 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.application.port; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.List; public interface FindCompletedCreditPort { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/port/GenerateOrModifyCompletedCreditPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/port/GenerateOrModifyCompletedCreditPort.java index f06c785b..e284c558 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/port/GenerateOrModifyCompletedCreditPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/port/GenerateOrModifyCompletedCreditPort.java @@ -1,9 +1,8 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.application.port; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.List; public interface GenerateOrModifyCompletedCreditPort { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/FindCompletedCreditService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/FindCompletedCreditService.java index 5ab64627..9f090ea7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/FindCompletedCreditService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/FindCompletedCreditService.java @@ -1,17 +1,14 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.application.service; -import java.util.List; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.FindCompletedCreditPort; import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.FindCompletedCreditUseCase; import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @RequiredArgsConstructor diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/GenerateOrModifyCompletedCreditService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/GenerateOrModifyCompletedCreditService.java index bbd7e619..fafc92c9 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/GenerateOrModifyCompletedCreditService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/GenerateOrModifyCompletedCreditService.java @@ -5,15 +5,6 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.FREE_ELECTIVE; import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.NORMAL_CULTURE; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.FindCompletedCreditPort; import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.GenerateOrModifyCompletedCreditPort; import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase; @@ -24,8 +15,14 @@ import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationResult; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional @@ -43,23 +40,29 @@ public void generateOrModifyCompletedCredit(User user) { GraduationResult graduationResult = calculateGraduationUseCase.calculateGraduation(user); List detailGraduationResults = graduationResult.getDetailGraduationResults(); - List updatedCompletedCredits = createGeneralCompletedCreditModel(completedCredits, + List updatedCompletedCredits = createGeneralCompletedCreditModel( + completedCredits, detailGraduationResults); - CompletedCredit chapelCompletedCreditModel = createOrUpdateChapelCompletedCreditModel(completedCredits, + CompletedCredit chapelCompletedCreditModel = createOrUpdateChapelCompletedCreditModel( + completedCredits, graduationResult); CompletedCredit normalCultureCompletedCreditModel = createOrUpdateNormalCultureCompletedCreditModel( completedCredits, graduationResult); CompletedCredit freeElectiveCompletedCreditModel = createOrUpdateFreeElectiveCompletedCreditModel( completedCredits, graduationResult); - ArrayList allCompletedCreditModels = new ArrayList<>(updatedCompletedCredits); + ArrayList allCompletedCreditModels = new ArrayList<>( + updatedCompletedCredits); allCompletedCreditModels.addAll( - List.of(chapelCompletedCreditModel, normalCultureCompletedCreditModel, freeElectiveCompletedCreditModel)); - generateOrModifyCompletedCreditPort.generateOrModifyCompletedCredits(user, allCompletedCreditModels); + List.of(chapelCompletedCreditModel, normalCultureCompletedCreditModel, + freeElectiveCompletedCreditModel)); + generateOrModifyCompletedCreditPort.generateOrModifyCompletedCredits(user, + allCompletedCreditModels); } private List createGeneralCompletedCreditModel( - List completedCredits, List detailGraduationResults) { + List completedCredits, + List detailGraduationResults) { Map> resultMap = detailGraduationResults.stream() .collect(Collectors.toMap( Function.identity(), @@ -68,54 +71,72 @@ private List createGeneralCompletedCreditModel( .equals(detailGraduationResult.getGraduationCategory())) .findFirst() )); - return resultMap.keySet().stream() + return resultMap.keySet() + .stream() .map(detailGraduationResult -> createCompletedCreditModel(detailGraduationResult, resultMap.get(detailGraduationResult))) .collect(Collectors.toList()); } - private CompletedCredit createCompletedCreditModel(DetailGraduationResult detailGraduationResult, + private CompletedCredit createCompletedCreditModel( + DetailGraduationResult detailGraduationResult, Optional completedCredit) { return CompletedCredit.builder() - .id(completedCredit.map(CompletedCredit::getId).orElse(null)) + .id(completedCredit.map(CompletedCredit::getId) + .orElse(null)) .totalCredit(detailGraduationResult.getTotalCredit()) .takenCredit(detailGraduationResult.getTakenCredit()) .graduationCategory(detailGraduationResult.getGraduationCategory()) .build(); } - private CompletedCredit createOrUpdateChapelCompletedCreditModel(List completedCredits, + private CompletedCredit createOrUpdateChapelCompletedCreditModel( + List completedCredits, GraduationResult graduationResult) { - Optional chapelCompletedCredit = findCompletedCreditByCategory(completedCredits, CHAPEL); + Optional chapelCompletedCredit = findCompletedCreditByCategory( + completedCredits, CHAPEL); return chapelCompletedCredit.map( completedCredit -> updateCompletedCredit(completedCredit, GRADUATION_COUNT / 2, - graduationResult.getChapelResult().getTakenChapelCredit())) - .orElseGet(() -> CompletedCredit.createChapelCompletedCreditModel(graduationResult.getChapelResult())); + graduationResult.getChapelResult() + .getTakenChapelCredit())) + .orElseGet(() -> CompletedCredit.createChapelCompletedCreditModel( + graduationResult.getChapelResult())); } - private CompletedCredit createOrUpdateNormalCultureCompletedCreditModel(List completedCredits, + private CompletedCredit createOrUpdateNormalCultureCompletedCreditModel( + List completedCredits, GraduationResult graduationResult) { - Optional normalCultureCompletedCredit = findCompletedCreditByCategory(completedCredits, + Optional normalCultureCompletedCredit = findCompletedCreditByCategory( + completedCredits, NORMAL_CULTURE); - return normalCultureCompletedCredit.map(completedCredit -> updateCompletedCredit(completedCredit, - graduationResult.getNormalCultureGraduationResult().getTotalCredit(), - graduationResult.getNormalCultureGraduationResult().getTakenCredit())) + return normalCultureCompletedCredit.map( + completedCredit -> updateCompletedCredit(completedCredit, + graduationResult.getNormalCultureGraduationResult() + .getTotalCredit(), + graduationResult.getNormalCultureGraduationResult() + .getTakenCredit())) .orElseGet(() -> CompletedCredit.createNormalCultureCompletedCreditModel( graduationResult.getNormalCultureGraduationResult())); } - private CompletedCredit createOrUpdateFreeElectiveCompletedCreditModel(List completedCredits, + private CompletedCredit createOrUpdateFreeElectiveCompletedCreditModel( + List completedCredits, GraduationResult graduationResult) { - Optional freeElectiveCompletedCredit = findCompletedCreditByCategory(completedCredits, + Optional freeElectiveCompletedCredit = findCompletedCreditByCategory( + completedCredits, FREE_ELECTIVE); - return freeElectiveCompletedCredit.map(completedCredit -> updateCompletedCredit(completedCredit, - graduationResult.getFreeElectiveGraduationResult().getTotalCredit(), - graduationResult.getFreeElectiveGraduationResult().getTakenCredit())) + return freeElectiveCompletedCredit.map( + completedCredit -> updateCompletedCredit(completedCredit, + graduationResult.getFreeElectiveGraduationResult() + .getTotalCredit(), + graduationResult.getFreeElectiveGraduationResult() + .getTakenCredit())) .orElseGet(() -> CompletedCredit.createFreeElectiveCompletedCreditModel( graduationResult.getFreeElectiveGraduationResult())); } - private Optional findCompletedCreditByCategory(List completedCredits, + private Optional findCompletedCreditByCategory( + List completedCredits, GraduationCategory category) { return completedCredits.stream() .filter(completedCredit -> completedCredit.getGraduationCategory() == category) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/usecase/FindCompletedCreditUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/usecase/FindCompletedCreditUseCase.java index 8ad96508..c4cb4d3b 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/usecase/FindCompletedCreditUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/usecase/FindCompletedCreditUseCase.java @@ -1,11 +1,9 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; +import java.util.List; public interface FindCompletedCreditUseCase { List findCompletedCredits(Long userId); - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/domain/model/CompletedCredit.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/domain/model/CompletedCredit.java index 60ccb25a..bc1c7a30 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/domain/model/CompletedCredit.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/domain/model/CompletedCredit.java @@ -1,13 +1,14 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.domain.model; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CHAPEL; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.FREE_ELECTIVE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.NORMAL_CULTURE; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.ChapelResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.FreeElectiveGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.NormalCultureGraduationResult; - import lombok.Builder; import lombok.Getter; @@ -32,14 +33,16 @@ public static CompletedCredit from(DetailGraduationResult detailGraduationResult return CompletedCredit.builder() .graduationCategory(detailGraduationResults.getGraduationCategory()) .totalCredit(detailGraduationResults.getTotalCredit()) - .takenCredit(detailGraduationResults.getTakenCredit()).build(); + .takenCredit(detailGraduationResults.getTakenCredit()) + .build(); } public static CompletedCredit createChapelCompletedCreditModel(ChapelResult chapelResult) { return CompletedCredit.builder() .graduationCategory(CHAPEL) .totalCredit(ChapelResult.GRADUATION_COUNT / 2) - .takenCredit(chapelResult.getTakenChapelCredit()).build(); + .takenCredit(chapelResult.getTakenChapelCredit()) + .build(); } public static CompletedCredit createNormalCultureCompletedCreditModel( @@ -47,7 +50,8 @@ public static CompletedCredit createNormalCultureCompletedCreditModel( return CompletedCredit.builder() .graduationCategory(NORMAL_CULTURE) .totalCredit(normalCultureGraduationResult.getTotalCredit()) - .takenCredit(normalCultureGraduationResult.getTakenCredit()).build(); + .takenCredit(normalCultureGraduationResult.getTakenCredit()) + .build(); } public static CompletedCredit createFreeElectiveCompletedCreditModel( @@ -55,7 +59,8 @@ public static CompletedCredit createFreeElectiveCompletedCreditModel( return CompletedCredit.builder() .graduationCategory(FREE_ELECTIVE) .totalCredit(freeElectiveGraduationResult.getTotalCredit()) - .takenCredit(freeElectiveGraduationResult.getTakenCredit()).build(); + .takenCredit(freeElectiveGraduationResult.getTakenCredit()) + .build(); } public void updateCredit(int totalCredit, double takenCredit) { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/DeletedCompletedCreditAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/DeletedCompletedCreditAdapter.java index 76e8919b..f51cbe3b 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/DeletedCompletedCreditAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/DeletedCompletedCreditAdapter.java @@ -1,14 +1,12 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.DeleteCompletedCreditPort; import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.repository.CompletedCreditRepository; import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.mapper.UserMapper; - import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @PersistenceAdapter @Transactional diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/FindCompletedCreditAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/FindCompletedCreditAdapter.java index 8e09162f..fd7ffd56 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/FindCompletedCreditAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/FindCompletedCreditAdapter.java @@ -1,8 +1,5 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence; -import java.util.List; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.FindCompletedCreditPort; import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.mapper.CompletedCreditPersistenceMapper; @@ -10,7 +7,8 @@ import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.mapper.UserMapper; - +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @PersistenceAdapter @@ -23,7 +21,8 @@ public class FindCompletedCreditAdapter implements FindCompletedCreditPort { @Override public List findCompletedCredit(User user) { - return completedCreditRepository.findAllByUserJpaEntity(userMapper.mapToJpaEntity(user)).stream() + return completedCreditRepository.findAllByUserJpaEntity(userMapper.mapToJpaEntity(user)) + .stream() .map(completedCreditPersistenceMapper::mapToDomainModel) .collect(Collectors.toList()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/GenerateOrModifyCompletedCreditsAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/GenerateOrModifyCompletedCreditsAdapter.java index 5f15d0da..e812269c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/GenerateOrModifyCompletedCreditsAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/GenerateOrModifyCompletedCreditsAdapter.java @@ -1,8 +1,5 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence; -import java.util.List; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.GenerateOrModifyCompletedCreditPort; import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.entity.CompletedCreditJpaEntity; @@ -10,20 +7,24 @@ import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.repository.CompletedCreditRepository; import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @PersistenceAdapter @RequiredArgsConstructor -public class GenerateOrModifyCompletedCreditsAdapter implements GenerateOrModifyCompletedCreditPort { +public class GenerateOrModifyCompletedCreditsAdapter implements + GenerateOrModifyCompletedCreditPort { private final CompletedCreditPersistenceMapper completedCreditPersistenceMapper; private final CompletedCreditRepository completedCreditRepository; @Override - public void generateOrModifyCompletedCredits(User user, List completedCredits) { + public void generateOrModifyCompletedCredits(User user, + List completedCredits) { List completedCreditJpaEntities = completedCredits.stream() - .map(completedCredit -> completedCreditPersistenceMapper.mapToJpaEntity(user, completedCredit)) + .map(completedCredit -> completedCreditPersistenceMapper.mapToJpaEntity(user, + completedCredit)) .collect(Collectors.toList()); completedCreditRepository.saveAll(completedCreditJpaEntities); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/entity/CompletedCreditJpaEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/entity/CompletedCreditJpaEntity.java index e7661ba7..fab6bfce 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/entity/CompletedCreditJpaEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/entity/CompletedCreditJpaEntity.java @@ -1,5 +1,7 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.entity; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -10,10 +12,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; - import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -41,7 +39,8 @@ public class CompletedCreditJpaEntity { private double takenCredit; @Builder - private CompletedCreditJpaEntity(Long id, UserJpaEntity userJpaEntity, GraduationCategory graduationCategory, + private CompletedCreditJpaEntity(Long id, UserJpaEntity userJpaEntity, + GraduationCategory graduationCategory, int totalCredit, double takenCredit) { this.id = id; this.userJpaEntity = userJpaEntity; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/mapper/CompletedCreditPersistenceMapper.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/mapper/CompletedCreditPersistenceMapper.java index 97e801d3..81217b8a 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/mapper/CompletedCreditPersistenceMapper.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/mapper/CompletedCreditPersistenceMapper.java @@ -1,11 +1,10 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.mapper; -import org.springframework.stereotype.Component; - import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.entity.CompletedCreditJpaEntity; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import org.springframework.stereotype.Component; @Component public class CompletedCreditPersistenceMapper { @@ -15,7 +14,8 @@ public CompletedCredit mapToDomainModel(CompletedCreditJpaEntity completedCredit .id(completedCreditJpaEntity.getId()) .graduationCategory(completedCreditJpaEntity.getGraduationCategory()) .totalCredit(completedCreditJpaEntity.getTotalCredit()) - .takenCredit(completedCreditJpaEntity.getTakenCredit()).build(); + .takenCredit(completedCreditJpaEntity.getTakenCredit()) + .build(); } public CompletedCreditJpaEntity mapToJpaEntity(User user, CompletedCredit completedCredit) { @@ -26,6 +26,7 @@ public CompletedCreditJpaEntity mapToJpaEntity(User user, CompletedCredit comple .id(user.getId()) .build()) .totalCredit(completedCredit.getTotalCredit()) - .takenCredit(completedCredit.getTakenCredit()).build(); + .takenCredit(completedCredit.getTakenCredit()) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/repository/CompletedCreditRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/repository/CompletedCreditRepository.java index b6f5d712..0e0f5fe2 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/repository/CompletedCreditRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/repository/CompletedCreditRepository.java @@ -1,16 +1,13 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.repository; -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; - import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.entity.CompletedCreditJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; public interface CompletedCreditRepository extends JpaRepository { List findAllByUserJpaEntity(UserJpaEntity userJpaEntity); void deleteAllByUserJpaEntity(UserJpaEntity userJpaEntity); - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/EnvironmentCheck.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/EnvironmentCheck.java index e2b995c8..1e9a49c3 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/EnvironmentCheck.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/EnvironmentCheck.java @@ -1,15 +1,14 @@ package com.plzgraduate.myongjigraduatebe.core; import javax.annotation.PostConstruct; - +import lombok.extern.slf4j.Slf4j; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import lombok.extern.slf4j.Slf4j; - @Slf4j @Component public class EnvironmentCheck { + private final Environment env; public EnvironmentCheck(Environment env) { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/HealthCheckController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/HealthCheckController.java index 064e7c9e..0b69a2f2 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/HealthCheckController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/HealthCheckController.java @@ -1,11 +1,9 @@ package com.plzgraduate.myongjigraduatebe.core; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; - import io.swagger.v3.oas.annotations.Hidden; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; @WebAdapter @RequestMapping("/api/v1") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/JpaAuditingConfig.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/JpaAuditingConfig.java index 8a4f0a44..9a49f2a5 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/JpaAuditingConfig.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/JpaAuditingConfig.java @@ -6,4 +6,5 @@ @Configuration @EnableJpaAuditing public class JpaAuditingConfig { + } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/QuerydslConfig.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/QuerydslConfig.java index 0a80033a..a6f1fc45 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/QuerydslConfig.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/QuerydslConfig.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.core.config; +import com.querydsl.jpa.impl.JPAQueryFactory; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.querydsl.jpa.impl.JPAQueryFactory; - @Configuration public class QuerydslConfig { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/SecurityConfig.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/SecurityConfig.java index ec886ccc..aa2d75f8 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/SecurityConfig.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/SecurityConfig.java @@ -1,5 +1,12 @@ package com.plzgraduate.myongjigraduatebe.core.config; +import com.plzgraduate.myongjigraduatebe.auth.security.JwtAccessDeniedHandler; +import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationEntryPoint; +import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationProvider; +import com.plzgraduate.myongjigraduatebe.auth.security.TokenAuthenticationFilter; +import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; @@ -15,15 +22,6 @@ import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationEntryPoint; -import com.plzgraduate.myongjigraduatebe.auth.security.JwtAccessDeniedHandler; -import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationProvider; -import com.plzgraduate.myongjigraduatebe.auth.security.TokenAuthenticationFilter; -import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; - -import lombok.RequiredArgsConstructor; - @Configuration @RequiredArgsConstructor @EnableWebSecurity @@ -38,24 +36,30 @@ public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http - .csrf().disable() - .headers().disable() - .formLogin().disable() - .httpBasic().disable() - .rememberMe().disable() - .logout().disable() + .csrf() + .disable() + .headers() + .disable() + .formLogin() + .disable() + .httpBasic() + .disable() + .rememberMe() + .disable() + .logout() + .disable() .exceptionHandling() - .accessDeniedHandler(jwtAccessDeniedHandler) - .authenticationEntryPoint(jwtAuthenticationEntryPoint) - .and() + .accessDeniedHandler(jwtAccessDeniedHandler) + .authenticationEntryPoint(jwtAuthenticationEntryPoint) + .and() .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() + .sessionCreationPolicy(SessionCreationPolicy.STATELESS) + .and() .authorizeRequests() .antMatchers( API_V1_PREFIX + "/users/sign-up/**", // 회원가입 API_V1_PREFIX + "/auth/sign-in", // 로그인 - API_V1_PREFIX + "/auth/token", //새 토큰 발급 + API_V1_PREFIX + "/auth/token", //새 토큰 발급 API_V1_PREFIX + "/users/{student-number}/auth-id", // 아이디 찾기 API_V1_PREFIX + "/users/{student-number}/validate", // 유저 검증 API_V1_PREFIX + "/users/password", // 비밀번호 재설정 @@ -66,13 +70,16 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { "/swagger-ui/**", "/api-docs/**", "/swagger-ui.html" - ).permitAll() - .anyRequest().authenticated() - .and() + ) + .permitAll() + .anyRequest() + .authenticated() + .and() .cors() - .configurationSource(corsConfigurationSource()) - .and() - .addFilterBefore(tokenAuthenticationFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class); + .configurationSource(corsConfigurationSource()) + .and() + .addFilterBefore(tokenAuthenticationFilter(tokenProvider), + UsernamePasswordAuthenticationFilter.class); return http.build(); } @@ -98,12 +105,14 @@ public PasswordEncoder passwordEncoder() { } @Bean - public AuthenticationManager authenticationManager(JwtAuthenticationProvider jwtAuthenticationProvider) { + public AuthenticationManager authenticationManager( + JwtAuthenticationProvider jwtAuthenticationProvider) { return new ProviderManager(jwtAuthenticationProvider); } @Bean - public JwtAuthenticationProvider jwtAuthenticationProvider(PasswordEncoder passwordEncoder, FindUserUseCase findUserUseCase) { + public JwtAuthenticationProvider jwtAuthenticationProvider(PasswordEncoder passwordEncoder, + FindUserUseCase findUserUseCase) { return new JwtAuthenticationProvider(passwordEncoder, findUserUseCase); } @@ -111,5 +120,4 @@ public JwtAuthenticationProvider jwtAuthenticationProvider(PasswordEncoder passw public TokenAuthenticationFilter tokenAuthenticationFilter(TokenProvider tokenProvider) { return new TokenAuthenticationFilter(tokenProvider); } - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/SwaggerConfig.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/SwaggerConfig.java index 69279cd6..4927c1c0 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/SwaggerConfig.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/SwaggerConfig.java @@ -1,10 +1,9 @@ package com.plzgraduate.myongjigraduatebe.core.config; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; @Configuration public class SwaggerConfig { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/WebMvcConfig.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/WebMvcConfig.java index b9f1f826..7c965f5b 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/WebMvcConfig.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/config/WebMvcConfig.java @@ -1,14 +1,11 @@ package com.plzgraduate.myongjigraduatebe.core.config; import java.util.List; - +import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -import lombok.RequiredArgsConstructor; - @Configuration @RequiredArgsConstructor public class WebMvcConfig implements WebMvcConfigurer { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/entity/TimeBaseEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/entity/TimeBaseEntity.java index f5fb9cfa..2f37c1ad 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/entity/TimeBaseEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/entity/TimeBaseEntity.java @@ -1,18 +1,15 @@ package com.plzgraduate.myongjigraduatebe.core.entity; import java.time.Instant; - import javax.persistence.Column; import javax.persistence.EntityListeners; import javax.persistence.MappedSuperclass; - -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @SuperBuilder @@ -28,5 +25,4 @@ public abstract class TimeBaseEntity { @LastModifiedDate @Column(nullable = false) private Instant updatedAt; - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/GlobalExceptionHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/GlobalExceptionHandler.java index c178fef9..ff3a7ab5 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/GlobalExceptionHandler.java @@ -3,10 +3,9 @@ import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; - import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; - +import lombok.extern.slf4j.Slf4j; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.http.HttpStatus; import org.springframework.http.converter.HttpMessageNotReadableException; @@ -17,8 +16,6 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; -import lombok.extern.slf4j.Slf4j; - @Slf4j @RestControllerAdvice public class GlobalExceptionHandler { @@ -57,15 +54,18 @@ public ExceptionResponse handleValidationException(ConstraintViolationException @ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) - public ExceptionResponse handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { - log.debug("validation exception occurred: {}", e.getMessage(), e); + public ExceptionResponse handleMethodArgumentNotValidException( + MethodArgumentNotValidException e) { + log.debug("validation exception occurred: {}", e.getMessage(), e); return ExceptionResponse.from(getBindingErrorMessage(e)); } @ExceptionHandler(MethodArgumentTypeMismatchException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) - public ExceptionResponse handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { - log.debug("graduation category mismatch exception occurred: {}", getMethodArgumentTypeMismatchErrorMessage(e)); + public ExceptionResponse handleMethodArgumentTypeMismatchException( + MethodArgumentTypeMismatchException e) { + log.debug("graduation category mismatch exception occurred: {}", + getMethodArgumentTypeMismatchErrorMessage(e)); return ExceptionResponse.from(ErrorCode.INVALIDATED_GRADUATION_CATEGORY.toString()); } @@ -84,16 +84,27 @@ public ExceptionResponse handleRuntimeException(RuntimeException e) { } private String getViolationErrorMessage(ConstraintViolationException e) { - return e.getConstraintViolations().stream().map(ConstraintViolation::getMessage).findFirst().orElse(null); + return e.getConstraintViolations() + .stream() + .map(ConstraintViolation::getMessage) + .findFirst() + .orElse(null); } private String getBindingErrorMessage(MethodArgumentNotValidException e) { - Optional objectError = e.getBindingResult().getAllErrors().stream().findFirst(); - return objectError.map(DefaultMessageSourceResolvable::getDefaultMessage).orElse(null); + Optional objectError = e.getBindingResult() + .getAllErrors() + .stream() + .findFirst(); + return objectError.map(DefaultMessageSourceResolvable::getDefaultMessage) + .orElse(null); } - private String getMethodArgumentTypeMismatchErrorMessage(MethodArgumentTypeMismatchException e) { - String errorMessage = Objects.requireNonNull(e.getMessage()).split("value '")[1].split("'")[0]; + private String getMethodArgumentTypeMismatchErrorMessage( + MethodArgumentTypeMismatchException e) { + String errorMessage = Objects.requireNonNull(e.getMessage()) + .split("value '")[1].split( + "'")[0]; return "Failed to convert value: " + errorMessage; } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/InvalidPdfException.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/InvalidPdfException.java index fed3ea39..c996ed09 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/InvalidPdfException.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/InvalidPdfException.java @@ -1,6 +1,7 @@ package com.plzgraduate.myongjigraduatebe.core.exception; public class InvalidPdfException extends RuntimeException { + public InvalidPdfException(String message) { super(message); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/PdfParsingException.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/PdfParsingException.java index c4dee086..25085c57 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/PdfParsingException.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/PdfParsingException.java @@ -1,6 +1,7 @@ package com.plzgraduate.myongjigraduatebe.core.exception; -public class PdfParsingException extends RuntimeException{ +public class PdfParsingException extends RuntimeException { + public PdfParsingException(String message) { super(message); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/UnAuthorizedException.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/UnAuthorizedException.java index e2c7584d..cf921199 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/UnAuthorizedException.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/exception/UnAuthorizedException.java @@ -1,6 +1,7 @@ package com.plzgraduate.myongjigraduatebe.core.exception; -public class UnAuthorizedException extends RuntimeException{ +public class UnAuthorizedException extends RuntimeException { + public UnAuthorizedException(String message) { super(message); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/LoginUser.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/LoginUser.java index 274b3c58..0e240f1b 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/LoginUser.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/LoginUser.java @@ -6,8 +6,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -@Target({ ElementType.PARAMETER, ElementType.ANNOTATION_TYPE }) +@Target({ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface LoginUser { + } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/PersistenceAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/PersistenceAdapter.java index dfdb781d..630a3518 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/PersistenceAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/PersistenceAdapter.java @@ -5,7 +5,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - import org.springframework.core.annotation.AliasFor; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/UseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/UseCase.java index 802eb84d..5ff523af 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/UseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/UseCase.java @@ -5,7 +5,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - import org.springframework.core.annotation.AliasFor; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/WebAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/WebAdapter.java index 363d9987..5064cb03 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/WebAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/core/meta/WebAdapter.java @@ -5,7 +5,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - import org.springframework.core.annotation.AliasFor; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ResponseBody; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationApiPresentation.java index 21f42451..3bc9bc53 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationApiPresentation.java @@ -1,14 +1,12 @@ package com.plzgraduate.myongjigraduatebe.graduation.api; -import org.springframework.web.bind.annotation.RequestParam; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.graduation.api.dto.response.DetailGraduationResultResponse; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.web.bind.annotation.RequestParam; @Tag(name = "Graduations") public interface FindDetailGraduationApiPresentation { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationController.java index 94862047..20d6fcc8 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationController.java @@ -1,17 +1,15 @@ package com.plzgraduate.myongjigraduatebe.graduation.api; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; import com.plzgraduate.myongjigraduatebe.graduation.api.dto.response.DetailGraduationResultResponse; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateSingleDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; - import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; @WebAdapter @RequestMapping("/api/v1/graduations/detail") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/BasicInfoResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/BasicInfoResponse.java index 52a33bc9..45077698 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/BasicInfoResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/BasicInfoResponse.java @@ -2,7 +2,6 @@ import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationResult; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; @@ -21,7 +20,8 @@ public class BasicInfoResponse { private final double takenCredit; @Builder - private BasicInfoResponse(String name, String studentNumber, MajorInfoResponse major, int totalCredit, double takenCredit) { + private BasicInfoResponse(String name, String studentNumber, MajorInfoResponse major, + int totalCredit, double takenCredit) { this.name = name; this.studentNumber = studentNumber; this.major = major; @@ -35,6 +35,7 @@ public static BasicInfoResponse of(User user, GraduationResult graduationResult) .studentNumber(user.getStudentNumber()) .major(MajorInfoResponse.from(user)) .totalCredit(graduationResult.getTotalCredit()) - .takenCredit(graduationResult.getTakenCredit()).build(); + .takenCredit(graduationResult.getTakenCredit()) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/ChapelResultResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/ChapelResultResponse.java index b957f9b3..fdf48404 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/ChapelResultResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/ChapelResultResponse.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.graduation.api.dto.response; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.ChapelResult; - import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; @@ -23,6 +22,7 @@ private ChapelResultResponse(int takenCount, boolean completed) { public static ChapelResultResponse from(ChapelResult chapelResult) { return ChapelResultResponse.builder() .takenCount(chapelResult.getTakenCount()) - .completed(chapelResult.isCompleted()).build(); + .completed(chapelResult.isCompleted()) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/DetailGraduationCategoryResultResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/DetailGraduationCategoryResultResponse.java index 70ceea87..8ebcedfc 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/DetailGraduationCategoryResultResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/DetailGraduationCategoryResultResponse.java @@ -1,11 +1,9 @@ package com.plzgraduate.myongjigraduatebe.graduation.api.dto.response; -import java.util.List; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; - import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; +import java.util.stream.Collectors; import lombok.Builder; import lombok.Getter; @@ -24,8 +22,10 @@ public class DetailGraduationCategoryResultResponse { private final boolean completed; @Builder - private DetailGraduationCategoryResultResponse(String categoryName, int totalCredit, int takenCredit, - List takenLectures, List haveToLectures, boolean completed) { + private DetailGraduationCategoryResultResponse(String categoryName, int totalCredit, + int takenCredit, + List takenLectures, List haveToLectures, + boolean completed) { this.categoryName = categoryName; this.totalCredit = totalCredit; this.takenCredit = takenCredit; @@ -34,17 +34,21 @@ private DetailGraduationCategoryResultResponse(String categoryName, int totalCre this.completed = completed; } - public static DetailGraduationCategoryResultResponse from(DetailCategoryResult detailCategoryResult) { + public static DetailGraduationCategoryResultResponse from( + DetailCategoryResult detailCategoryResult) { return DetailGraduationCategoryResultResponse.builder() .categoryName(detailCategoryResult.getDetailCategoryName()) .totalCredit(detailCategoryResult.getTotalCredits()) .takenCredit(detailCategoryResult.getTakenCredits()) - .takenLectures(detailCategoryResult.getTakenLectures().stream() + .takenLectures(detailCategoryResult.getTakenLectures() + .stream() .map(LectureResponse::from) .collect(Collectors.toList())) - .haveToLectures(detailCategoryResult.getHaveToLectures().stream() + .haveToLectures(detailCategoryResult.getHaveToLectures() + .stream() .map(LectureResponse::from) .collect(Collectors.toList())) - .completed(detailCategoryResult.isCompleted()).build(); + .completed(detailCategoryResult.isCompleted()) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/DetailGraduationResultResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/DetailGraduationResultResponse.java index 6f16fa3d..2c4ecae8 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/DetailGraduationResultResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/DetailGraduationResultResponse.java @@ -1,11 +1,9 @@ package com.plzgraduate.myongjigraduatebe.graduation.api.dto.response; -import java.util.List; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; - import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; +import java.util.stream.Collectors; import lombok.Builder; import lombok.Getter; @@ -29,13 +27,16 @@ private DetailGraduationResultResponse(int totalCredit, double takenCredit, this.completed = completed; } - public static DetailGraduationResultResponse from(DetailGraduationResult detailGraduationResult) { + public static DetailGraduationResultResponse from( + DetailGraduationResult detailGraduationResult) { return DetailGraduationResultResponse.builder() .totalCredit(detailGraduationResult.getTotalCredit()) .takenCredit(detailGraduationResult.getTakenCredit()) - .detailCategory(detailGraduationResult.getDetailCategory().stream() + .detailCategory(detailGraduationResult.getDetailCategory() + .stream() .map(DetailGraduationCategoryResultResponse::from) .collect(Collectors.toList())) - .completed(detailGraduationResult.isCompleted()).build(); + .completed(detailGraduationResult.isCompleted()) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/LectureResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/LectureResponse.java index a7c79467..2276869e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/LectureResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/LectureResponse.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.graduation.api.dto.response; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; @@ -31,6 +30,7 @@ public static LectureResponse from(Lecture lecture) { .id(lecture.getId()) .code(lecture.getLectureCode()) .name(lecture.getName()) - .credit(lecture.getCredit()).build(); + .credit(lecture.getCredit()) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/MajorInfoResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/MajorInfoResponse.java index 0514e477..e378e399 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/MajorInfoResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/MajorInfoResponse.java @@ -2,7 +2,6 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/RestResultResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/RestResultResponse.java index 740097f8..86ab2086 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/RestResultResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/dto/response/RestResultResponse.java @@ -2,7 +2,6 @@ import com.plzgraduate.myongjigraduatebe.graduation.domain.model.FreeElectiveGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.NormalCultureGraduationResult; - import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; @@ -29,7 +28,8 @@ public static RestResultResponse fromNormalCultureResult( return RestResultResponse.builder() .totalCredit(normalCultureGraduationResult.getTotalCredit()) .takenCredit(normalCultureGraduationResult.getTakenCredit()) - .completed(normalCultureGraduationResult.isCompleted()).build(); + .completed(normalCultureGraduationResult.isCompleted()) + .build(); } public static RestResultResponse fromFreeElectiveResult( @@ -37,6 +37,7 @@ public static RestResultResponse fromFreeElectiveResult( return RestResultResponse.builder() .totalCredit(freeElectiveGraduationResult.getTotalCredit()) .takenCredit(freeElectiveGraduationResult.getTakenCredit()) - .completed(freeElectiveGraduationResult.isCompleted()).build(); + .completed(freeElectiveGraduationResult.isCompleted()) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationService.java index 6d49fe81..f6172a9d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationService.java @@ -3,12 +3,6 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE; import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; @@ -24,13 +18,17 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.HashSet; +import java.util.List; +import java.util.Set; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @RequiredArgsConstructor -public class CalculateBasicAcademicalCultureGraduationService implements CalculateDetailGraduationUseCase { +public class CalculateBasicAcademicalCultureGraduationService implements + CalculateDetailGraduationUseCase { private final FindBasicAcademicalCulturePort findBasicAcademicalCulturePort; private final List basicAcademicalGraduationManagers; @@ -42,7 +40,8 @@ public boolean supports(GraduationCategory graduationCategory) { } @Override - public DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, + public DetailGraduationResult calculateSingleDetailGraduation(User user, + GraduationCategory graduationCategory, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { MajorType majorType = MajorType.from(graduationCategory); String userMajor = user.getMajorByMajorType(majorType); @@ -63,13 +62,16 @@ public List calculateAllDetailGraduation(User user, TakenLectureInventory copiedTakenLectureForPrimaryBasicAcademicalCulture = takenLectureInventory.copy(); TakenLectureInventory copiedTakenLectureForDualBasicAcademicalCulture = takenLectureInventory.copy(); DetailGraduationResult primaryBasicAcademicalCultureDetailGraduationResult = calculateSingleDetailGraduation( - user, PRIMARY_BASIC_ACADEMICAL_CULTURE, copiedTakenLectureForPrimaryBasicAcademicalCulture, + user, PRIMARY_BASIC_ACADEMICAL_CULTURE, + copiedTakenLectureForPrimaryBasicAcademicalCulture, graduationRequirement); DetailGraduationResult dualBasicAcademicalCultureDetailGraduationResult = calculateSingleDetailGraduation( - user, DUAL_BASIC_ACADEMICAL_CULTURE, copiedTakenLectureForDualBasicAcademicalCulture, + user, DUAL_BASIC_ACADEMICAL_CULTURE, + copiedTakenLectureForDualBasicAcademicalCulture, graduationRequirement); syncOriginalTakenLectureInventory(takenLectureInventory, - primaryBasicAcademicalCultureDetailGraduationResult, dualBasicAcademicalCultureDetailGraduationResult); + primaryBasicAcademicalCultureDetailGraduationResult, + dualBasicAcademicalCultureDetailGraduationResult); return List.of(primaryBasicAcademicalCultureDetailGraduationResult, dualBasicAcademicalCultureDetailGraduationResult); } @@ -86,13 +88,18 @@ private GraduationManager determineBasicAcademica .orElse(new DefaultBasicAcademicalGraduationManager()); } - private void syncOriginalTakenLectureInventory(TakenLectureInventory originalTakenLectureInventory, + private void syncOriginalTakenLectureInventory( + TakenLectureInventory originalTakenLectureInventory, DetailGraduationResult primaryBasicAcademicalCultureDetailGraduationResult, DetailGraduationResult dualBasicAcademicalCultureDetailGraduationResult) { List primaryBasicAcademicalCultureTakenLectures = - primaryBasicAcademicalCultureDetailGraduationResult.getDetailCategory().get(0).getTakenLectures(); + primaryBasicAcademicalCultureDetailGraduationResult.getDetailCategory() + .get(0) + .getTakenLectures(); List dualBasicAcademicalCultureTakenLectures = - dualBasicAcademicalCultureDetailGraduationResult.getDetailCategory().get(0).getTakenLectures(); + dualBasicAcademicalCultureDetailGraduationResult.getDetailCategory() + .get(0) + .getTakenLectures(); Set basicAcademicalCultureTakenLectures = new HashSet<>(); basicAcademicalCultureTakenLectures.addAll(primaryBasicAcademicalCultureTakenLectures); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationService.java index 7ace4a10..9c664958 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationService.java @@ -1,10 +1,6 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; - -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; @@ -16,8 +12,9 @@ import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.Set; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -33,10 +30,13 @@ public boolean supports(GraduationCategory graduationCategory) { } @Override - public DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, + public DetailGraduationResult calculateSingleDetailGraduation(User user, + GraduationCategory graduationCategory, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { Set graduationCommonCultures = findCommonCulturePort.findCommonCulture(user); + return commonCultureGraduationManager.createDetailGraduationResult( - user, takenLectureInventory, graduationCommonCultures, graduationRequirement.getCommonCultureCredit()); + user, takenLectureInventory, graduationCommonCultures, + graduationRequirement.getCommonCultureCredit()); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationService.java index d5422e28..e34df1d7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationService.java @@ -1,10 +1,6 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; - -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CORE_CULTURE; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; @@ -16,8 +12,9 @@ import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.Set; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -33,10 +30,12 @@ public boolean supports(GraduationCategory graduationCategory) { } @Override - public DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, + public DetailGraduationResult calculateSingleDetailGraduation(User user, + GraduationCategory graduationCategory, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { Set graduationCoreCultures = findCoreCulturePort.findCoreCulture(user); return coreCultureGraduationManager.createDetailGraduationResult( - user, takenLectureInventory, graduationCoreCultures, graduationRequirement.getCoreCultureCredit()); + user, takenLectureInventory, graduationCoreCultures, + graduationRequirement.getCoreCultureCredit()); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateGraduationService.java index c9dd1c3d..a447247c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateGraduationService.java @@ -1,10 +1,5 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; -import java.util.ArrayList; -import java.util.List; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.ChapelResult; @@ -21,8 +16,10 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.College; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.ArrayList; +import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional @@ -40,13 +37,15 @@ class CalculateGraduationService implements CalculateGraduationUseCase { @Override public GraduationResult calculateGraduation(User user) { GraduationRequirement graduationRequirement = determineGraduationRequirement(user); - TakenLectureInventory takenLectureInventory = findTakenLectureUseCase.findTakenLectures(user.getId()); + TakenLectureInventory takenLectureInventory = findTakenLectureUseCase.findTakenLectures( + user.getId()); ChapelResult chapelResult = generateChapelResult(takenLectureInventory); List detailGraduationResults = generateDetailGraduationResults(user, takenLectureInventory, graduationRequirement); - GraduationResult graduationResult = generateGraduationResult(chapelResult, detailGraduationResults, + GraduationResult graduationResult = generateGraduationResult(chapelResult, + detailGraduationResults, takenLectureInventory, graduationRequirement); handleDuplicatedTakenCredit(user, graduationResult); updateUserGraduationInformation(user, graduationResult); @@ -101,14 +100,17 @@ private List generateBasicAcademicalDetailGraduationResu private List generateMajorDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - return calculateMajorGraduationService.calculateAllDetailGraduation(user, takenLectureInventory, + return calculateMajorGraduationService.calculateAllDetailGraduation(user, + takenLectureInventory, graduationRequirement); } private GraduationResult generateGraduationResult(ChapelResult chapelResult, - List detailGraduationResults, TakenLectureInventory takenLectureInventory, + List detailGraduationResults, + TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - GraduationResult graduationResult = GraduationResult.create(chapelResult, detailGraduationResults); + GraduationResult graduationResult = GraduationResult.create(chapelResult, + detailGraduationResults); graduationResult.handleLeftTakenLectures(takenLectureInventory, graduationRequirement); graduationResult.checkGraduated(graduationRequirement); return graduationResult; @@ -117,15 +119,18 @@ private GraduationResult generateGraduationResult(ChapelResult chapelResult, private void handleDuplicatedTakenCredit(User user, GraduationResult graduationResult) { if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) { int duplicatedBasicAcademicalCultureCredit = - findBasicAcademicalCulturePort.findDuplicatedLecturesBetweenMajors(user).stream() - .mapToInt(basicAcademicalCulture -> basicAcademicalCulture.getLecture().getCredit()) + findBasicAcademicalCulturePort.findDuplicatedLecturesBetweenMajors(user) + .stream() + .mapToInt(basicAcademicalCulture -> basicAcademicalCulture.getLecture() + .getCredit()) .sum(); graduationResult.deductDuplicatedCredit(duplicatedBasicAcademicalCultureCredit); } } private void updateUserGraduationInformation(User user, GraduationResult graduationResult) { - UpdateStudentInformationCommand updateStudentInformationCommand = UpdateStudentInformationCommand.update(user, + UpdateStudentInformationCommand updateStudentInformationCommand = UpdateStudentInformationCommand.update( + user, graduationResult); updateStudentInformationUseCase.updateUser(updateStudentInformationCommand); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationService.java index 179e3683..9b22860f 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationService.java @@ -6,12 +6,6 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_MANDATORY_MAJOR; import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.SUB_MAJOR; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; @@ -26,8 +20,11 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.ArrayList; +import java.util.List; +import java.util.Set; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -48,21 +45,25 @@ public boolean supports(GraduationCategory graduationCategory) { } @Override - public DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, + public DetailGraduationResult calculateSingleDetailGraduation(User user, + GraduationCategory graduationCategory, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { MajorType majorType = MajorType.from(graduationCategory); if (majorType == MajorType.SUB) { - return generateSubMajorDetailGraduationResult(user, takenLectureInventory, graduationRequirement); + return generateSubMajorDetailGraduationResult(user, takenLectureInventory, + graduationRequirement); } - DetailGraduationResult majorDetailGraduationResult = generateMajorDetailGraduationResult(user, + DetailGraduationResult majorDetailGraduationResult = generateMajorDetailGraduationResult( + user, majorType, takenLectureInventory, graduationRequirement); boolean isMandatory = graduationCategory.checkMandatoryIfSeperatedByMandatoryAndElective(); if (isMandatory) { - DetailCategoryResult majorDetailCategoryResult = separateMandatoryMajor(graduationCategory, + DetailCategoryResult majorDetailCategoryResult = separateMandatoryMajor( + graduationCategory, majorDetailGraduationResult); return DetailGraduationResult.create(graduationCategory, majorDetailCategoryResult.getTotalCredits(), List.of(majorDetailCategoryResult)); @@ -77,7 +78,8 @@ public DetailGraduationResult calculateSingleDetailGraduation(User user, Graduat public List calculateAllDetailGraduation(User user, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - DetailGraduationResult primaryMajorDetailGraduationResult = generateMajorDetailGraduationResult(user, + DetailGraduationResult primaryMajorDetailGraduationResult = generateMajorDetailGraduationResult( + user, MajorType.PRIMARY, takenLectureInventory, graduationRequirement); DetailGraduationResult primaryMandatoryMajorDetailGraduationResult = isolateMandatoryMajorDetailGraduation( PRIMARY_MANDATORY_MAJOR, primaryMajorDetailGraduationResult); @@ -85,31 +87,38 @@ public List calculateAllDetailGraduation(User user, PRIMARY_ELECTIVE_MAJOR, primaryMajorDetailGraduationResult); List majorGraduationResults = new ArrayList<>( - List.of(primaryMandatoryMajorDetailGraduationResult, primaryElectiveMajorDetailGraduationResult)); + List.of(primaryMandatoryMajorDetailGraduationResult, + primaryElectiveMajorDetailGraduationResult)); if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) { - DetailGraduationResult dualMajorDetailGraduationResult = generateMajorDetailGraduationResult(user, + DetailGraduationResult dualMajorDetailGraduationResult = generateMajorDetailGraduationResult( + user, MajorType.DUAL, takenLectureInventory, graduationRequirement); DetailGraduationResult dualMandatoryMajorDetailGraduationResult = isolateMandatoryMajorDetailGraduation( DUAL_MANDATORY_MAJOR, dualMajorDetailGraduationResult); DetailGraduationResult dualElectiveMajorDetailGraduationResult = isolateElectiveMajorDetailGraduation( DUAL_ELECTIVE_MAJOR, dualMajorDetailGraduationResult); majorGraduationResults.addAll( - List.of(dualMandatoryMajorDetailGraduationResult, dualElectiveMajorDetailGraduationResult)); + List.of(dualMandatoryMajorDetailGraduationResult, + dualElectiveMajorDetailGraduationResult)); } if (user.getStudentCategory() == StudentCategory.SUB_MAJOR) { majorGraduationResults.add( - generateSubMajorDetailGraduationResult(user, takenLectureInventory, graduationRequirement)); + generateSubMajorDetailGraduationResult(user, takenLectureInventory, + graduationRequirement)); } return majorGraduationResults; } - private DetailGraduationResult generateMajorDetailGraduationResult(User user, MajorType majorType, + private DetailGraduationResult generateMajorDetailGraduationResult(User user, + MajorType majorType, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - Set graduationMajorLectures = findMajorPort.findMajor(user.getMajorByMajorType(majorType)); + Set graduationMajorLectures = findMajorPort.findMajor( + user.getMajorByMajorType(majorType)); return majorGraduationManager.createDetailGraduationResult(user, majorType, - takenLectureInventory, graduationMajorLectures, graduationRequirement.getMajorCreditByMajorType(majorType)); + takenLectureInventory, graduationMajorLectures, + graduationRequirement.getMajorCreditByMajorType(majorType)); } private DetailGraduationResult generateSubMajorDetailGraduationResult(User user, @@ -126,7 +135,8 @@ private DetailGraduationResult isolateMandatoryMajorDetailGraduation( DetailCategoryResult mandatoryMajorDetailCategoryResult = separateMandatoryMajor( graduationCategory, majorDetailGraduationResult); return DetailGraduationResult.create(graduationCategory, - mandatoryMajorDetailCategoryResult.getTotalCredits(), List.of(mandatoryMajorDetailCategoryResult)); + mandatoryMajorDetailCategoryResult.getTotalCredits(), + List.of(mandatoryMajorDetailCategoryResult)); } private DetailGraduationResult isolateElectiveMajorDetailGraduation( @@ -134,14 +144,16 @@ private DetailGraduationResult isolateElectiveMajorDetailGraduation( DetailCategoryResult electiveMajorDetailCategoryResult = separateElectiveMajor( graduationCategory, majorDetailGraduationResult); return DetailGraduationResult.create(graduationCategory, - electiveMajorDetailCategoryResult.getTotalCredits(), List.of(electiveMajorDetailCategoryResult)); + electiveMajorDetailCategoryResult.getTotalCredits(), + List.of(electiveMajorDetailCategoryResult)); } private DetailCategoryResult separateMandatoryMajor( GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) { DetailCategoryResult mandatoryMajorDetailCategoryResult = majorDetailGraduationResult.getDetailCategory() .stream() - .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName().equals("전공필수")) + .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName() + .equals("전공필수")) .findFirst() .orElseThrow(() -> new RuntimeException("Not Found DetailCategoryResult(전공 필수)")); mandatoryMajorDetailCategoryResult.assignDetailCategoryName(graduationCategory.getName()); @@ -152,7 +164,8 @@ private DetailCategoryResult separateElectiveMajor( GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) { DetailCategoryResult electiveMajorDetailCategoryResult = majorDetailGraduationResult.getDetailCategory() .stream() - .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName().equals("전공선택")) + .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName() + .equals("전공선택")) .findFirst() .orElseThrow(() -> new RuntimeException("Not Found DetailCategoryResult(전공 선택)")); electiveMajorDetailCategoryResult.assignDetailCategoryName(graduationCategory.getName()); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationService.java index cc976fb9..60fc5fa0 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationService.java @@ -1,9 +1,5 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; -import java.util.List; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateSingleDetailGraduationUseCase; @@ -16,35 +12,41 @@ import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.College; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @RequiredArgsConstructor -public class CalculateSingleDetailGraduationService implements CalculateSingleDetailGraduationUseCase { +public class CalculateSingleDetailGraduationService implements + CalculateSingleDetailGraduationUseCase { private final FindUserUseCase findUserUseCase; private final FindTakenLectureUseCase findTakenLectureUseCase; private final List calculateDetailGraduationUseCases; @Override - public DetailGraduationResult calculateSingleDetailGraduation(Long userId, GraduationCategory graduationCategory) { + public DetailGraduationResult calculateSingleDetailGraduation(Long userId, + GraduationCategory graduationCategory) { User user = findUserUseCase.findUserById(userId); - user.getStudentCategory().validateGraduationCategoryInclusion(graduationCategory); + user.getStudentCategory() + .validateGraduationCategoryInclusion(graduationCategory); TakenLectureInventory takenLectures = findTakenLectureUseCase.findTakenLectures(userId); CalculateDetailGraduationUseCase calculateDetailGraduationUseCase = determineCalculateDetailGraduationUseCase( graduationCategory); GraduationRequirement graduationRequirement = determineGraduationRequirement(user); - return calculateDetailGraduationUseCase.calculateSingleDetailGraduation(user, graduationCategory, takenLectures, + return calculateDetailGraduationUseCase.calculateSingleDetailGraduation(user, + graduationCategory, takenLectures, graduationRequirement); } private CalculateDetailGraduationUseCase determineCalculateDetailGraduationUseCase( GraduationCategory graduationCategory) { return calculateDetailGraduationUseCases.stream() - .filter(calculateDetailGraduationUseCase -> calculateDetailGraduationUseCase.supports(graduationCategory)) + .filter(calculateDetailGraduationUseCase -> calculateDetailGraduationUseCase.supports( + graduationCategory)) .findFirst() .orElseThrow(() -> new RuntimeException("No calculate detail graduation case found")); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDetailGraduationUseCase.java index 664ecd02..99364c87 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDetailGraduationUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDetailGraduationUseCase.java @@ -10,6 +10,7 @@ public interface CalculateDetailGraduationUseCase { boolean supports(GraduationCategory graduationCategory); - DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, TakenLectureInventory takenLectureInventory, + DetailGraduationResult calculateSingleDetailGraduation(User user, + GraduationCategory graduationCategory, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateSingleDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateSingleDetailGraduationUseCase.java index 997823e0..c09b3a6b 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateSingleDetailGraduationUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateSingleDetailGraduationUseCase.java @@ -5,6 +5,7 @@ public interface CalculateSingleDetailGraduationUseCase { - DetailGraduationResult calculateSingleDetailGraduation(Long userId, GraduationCategory graduationCategory); + DetailGraduationResult calculateSingleDetailGraduation(Long userId, + GraduationCategory graduationCategory); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/ChapelResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/ChapelResult.java index 290c467f..5ef3e300 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/ChapelResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/ChapelResult.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - import lombok.Builder; import lombok.Getter; @@ -24,7 +23,17 @@ public ChapelResult(int takenCount, boolean isCompleted) { public static ChapelResult create(TakenLectureInventory takenLectureInventory) { return ChapelResult.builder() .takenCount(countTakenChapel(takenLectureInventory)) - .isCompleted(false).build(); + .isCompleted(false) + .build(); + } + + private static int countTakenChapel(TakenLectureInventory takenLectureInventory) { + return (int) takenLectureInventory.getTakenLectures() + .stream() + .filter(takenLecture -> takenLecture.getLecture() + .getLectureCode() + .equals(CHAPEL_LECTURE_CODE)) + .count(); } public void checkCompleted() { @@ -34,10 +43,4 @@ public void checkCompleted() { public double getTakenChapelCredit() { return takenCount * CHAPEL_CREDIT; } - - private static int countTakenChapel(TakenLectureInventory takenLectureInventory) { - return (int)takenLectureInventory.getTakenLectures().stream() - .filter(takenLecture -> takenLecture.getLecture().getLectureCode().equals(CHAPEL_LECTURE_CODE)) - .count(); - } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DefaultGraduationRequirementType.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DefaultGraduationRequirementType.java index 86020402..983bf252 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DefaultGraduationRequirementType.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DefaultGraduationRequirementType.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; -import java.util.Arrays; -import java.util.NoSuchElementException; - import com.plzgraduate.myongjigraduatebe.user.domain.model.College; import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.Arrays; +import java.util.NoSuchElementException; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -37,10 +35,13 @@ public enum DefaultGraduationRequirementType { private final int startEntryYear; private final int endEntryYear; - public static DefaultGraduationRequirementType determineGraduationRequirement(College college, User user) { + public static DefaultGraduationRequirementType determineGraduationRequirement(College college, + User user) { return Arrays.stream(DefaultGraduationRequirementType.values()) - .filter(gr -> gr.getCollageName().equals(college.getName())) - .filter(gr -> gr.getStartEntryYear() <= user.getEntryYear() && gr.getEndEntryYear() >= user.getEntryYear()) + .filter(gr -> gr.getCollageName() + .equals(college.getName())) + .filter(gr -> gr.getStartEntryYear() <= user.getEntryYear() + && gr.getEndEntryYear() >= user.getEntryYear()) .findFirst() .orElseThrow(() -> new NoSuchElementException("일치하는 졸업 요건이 존재하지 않습니다.")); } @@ -56,20 +57,23 @@ public GraduationRequirement convertToProfitGraduationRequirement(User user) { .commonCultureCredit(this.commonCultureCredit) .coreCultureCredit(this.coreCultureCredit) .normalCultureCredit(this.normalLectureCredit) - .freeElectiveCredit(this.freeElectiveLectureCredit).build(); + .freeElectiveCredit(this.freeElectiveLectureCredit) + .build(); checkIsEnglishFreeUserAndTransferCredit(user, graduationRequirement); checkIsMultiMajorUserAndTransferCredit(user, graduationRequirement); return graduationRequirement; } - private void checkIsEnglishFreeUserAndTransferCredit(User user, GraduationRequirement graduationRequirement) { + private void checkIsEnglishFreeUserAndTransferCredit(User user, + GraduationRequirement graduationRequirement) { if (user.getEnglishLevel() == EnglishLevel.FREE) { graduationRequirement.transferEnglishCreditCommonToNormal(); } } - private void checkIsMultiMajorUserAndTransferCredit(User user, GraduationRequirement graduationRequirement) { + private void checkIsMultiMajorUserAndTransferCredit(User user, + GraduationRequirement graduationRequirement) { if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) { graduationRequirement.modifyCreditForDualMajor(user); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java index 80e096b7..bc9581c5 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java @@ -1,31 +1,31 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_ELECTIVE_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_MANDATORY_MAJOR; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import java.util.ArrayList; import java.util.List; import java.util.Set; - -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - import lombok.Builder; import lombok.Getter; @Getter public class DetailCategoryResult { - private String detailCategoryName; - private boolean isCompleted; private final boolean isSatisfiedMandatory; private final int totalCredits; + private final List takenLectures = new ArrayList<>(); + private final List haveToLectures = new ArrayList<>(); + private String detailCategoryName; + private boolean isCompleted; private int takenCredits; private int normalLeftCredit; private int freeElectiveLeftCredit; - private final List takenLectures = new ArrayList<>(); - private final List haveToLectures = new ArrayList<>(); @Builder - private DetailCategoryResult(String detailCategoryName, boolean isCompleted, boolean isSatisfiedMandatory, + private DetailCategoryResult(String detailCategoryName, boolean isCompleted, + boolean isSatisfiedMandatory, int totalCredits, int takenCredits, int normalLeftCredit, int freeElectiveLeftCredit) { this.detailCategoryName = detailCategoryName; this.isCompleted = isCompleted; @@ -36,7 +36,8 @@ private DetailCategoryResult(String detailCategoryName, boolean isCompleted, boo this.freeElectiveLeftCredit = freeElectiveLeftCredit; } - public static DetailCategoryResult create(String detailCategoryName, boolean isSatisfiedMandatory, + public static DetailCategoryResult create(String detailCategoryName, + boolean isSatisfiedMandatory, int totalCredits) { return DetailCategoryResult.builder() .detailCategoryName(detailCategoryName) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailGraduationResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailGraduationResult.java index b6176b57..1145ee56 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailGraduationResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailGraduationResult.java @@ -1,21 +1,21 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; import java.util.List; - import lombok.Builder; import lombok.Getter; @Getter public class DetailGraduationResult { - private GraduationCategory graduationCategory; private final boolean isCompleted; private final int totalCredit; - private double takenCredit; private final List detailCategory; + private GraduationCategory graduationCategory; + private double takenCredit; @Builder - private DetailGraduationResult(GraduationCategory graduationCategory, boolean isCompleted, int totalCredit, + private DetailGraduationResult(GraduationCategory graduationCategory, boolean isCompleted, + int totalCredit, double takenCredit, List detailCategory) { this.graduationCategory = graduationCategory; @@ -25,7 +25,8 @@ private DetailGraduationResult(GraduationCategory graduationCategory, boolean is this.detailCategory = detailCategory; } - public static DetailGraduationResult create(GraduationCategory graduationCategory, int totalCredit, + public static DetailGraduationResult create(GraduationCategory graduationCategory, + int totalCredit, List detailCategoryResults) { return DetailGraduationResult.builder() .graduationCategory(graduationCategory) @@ -46,6 +47,17 @@ public static DetailGraduationResult createNonCategorizedGraduationResult(int to .build(); } + private static boolean checkIsCompleted(List detailCategoryResults) { + return detailCategoryResults.stream() + .allMatch(DetailCategoryResult::isCompleted); + } + + private static int calculateTakenCredit(List detailCategoryResults) { + return detailCategoryResults.stream() + .mapToInt(DetailCategoryResult::getTakenCredits) + .sum(); + } + public void assignGraduationCategory(GraduationCategory graduationCategory) { this.graduationCategory = graduationCategory; } @@ -65,15 +77,4 @@ public int getFreeElectiveLeftCredit() { .mapToInt(DetailCategoryResult::getFreeElectiveLeftCredit) .sum(); } - - private static boolean checkIsCompleted(List detailCategoryResults) { - return detailCategoryResults.stream() - .allMatch(DetailCategoryResult::isCompleted); - } - - private static int calculateTakenCredit(List detailCategoryResults) { - return detailCategoryResults.stream() - .mapToInt(DetailCategoryResult::getTakenCredits) - .sum(); - } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DualMajorGraduationRequirementType.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DualMajorGraduationRequirementType.java index 5a22c6cb..b82e03d4 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DualMajorGraduationRequirementType.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DualMajorGraduationRequirementType.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; import java.util.Arrays; - import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -23,7 +22,8 @@ public static DualMajorGraduationRequirementType findBelongingDualMajorGraduatio String collageName) { return Arrays.stream(DualMajorGraduationRequirementType.values()) .filter(dualMajorGraduationRequirementType -> - dualMajorGraduationRequirementType.getCollageName().equals(collageName)) + dualMajorGraduationRequirementType.getCollageName() + .equals(collageName)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("소속 단과대가 존재하지 않습니다.")); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResult.java index f22bd25c..0c56eea0 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResult.java @@ -1,11 +1,9 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; - -import java.util.List; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.FREE_ELECTIVE; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - +import java.util.List; import lombok.Builder; import lombok.Getter; @@ -13,43 +11,49 @@ public class FreeElectiveGraduationResult { private final String categoryName; - private boolean isCompleted; private final int totalCredit; private final int takenCredit; + private boolean isCompleted; @Builder - private FreeElectiveGraduationResult(String categoryName, boolean isCompleted, int totalCredit, int takenCredit) { + private FreeElectiveGraduationResult(String categoryName, boolean isCompleted, int totalCredit, + int takenCredit) { this.categoryName = categoryName; this.isCompleted = isCompleted; this.totalCredit = totalCredit; this.takenCredit = takenCredit; } - public static FreeElectiveGraduationResult create(int totalCredit, TakenLectureInventory takenLectureInventory, + public static FreeElectiveGraduationResult create(int totalCredit, + TakenLectureInventory takenLectureInventory, List detailGraduationResults, int leftNormalCultureCredit) { return FreeElectiveGraduationResult.builder() .categoryName(FREE_ELECTIVE.getName()) .isCompleted(false) .totalCredit(totalCredit) .takenCredit( - calculateTakenCredit(takenLectureInventory, detailGraduationResults, leftNormalCultureCredit)) + calculateTakenCredit(takenLectureInventory, detailGraduationResults, + leftNormalCultureCredit)) .build(); } - public void checkCompleted() { - this.isCompleted = takenCredit >= totalCredit; - } - private static int calculateTakenCredit(TakenLectureInventory takenLectureInventory, List detailGraduationResults, int leftNormalCultureCredit) { int remainCreditByDetailGraduationResult = detailGraduationResults.stream() .mapToInt(DetailGraduationResult::getFreeElectiveLeftCredit) .sum(); - int remainCreditByTakenLectures = takenLectureInventory.getTakenLectures().stream() - .mapToInt(takenLecture -> takenLecture.getLecture().getCredit()) + int remainCreditByTakenLectures = takenLectureInventory.getTakenLectures() + .stream() + .mapToInt(takenLecture -> takenLecture.getLecture() + .getCredit()) .sum(); - return remainCreditByDetailGraduationResult + remainCreditByTakenLectures + leftNormalCultureCredit; + return remainCreditByDetailGraduationResult + remainCreditByTakenLectures + + leftNormalCultureCredit; + } + + public void checkCompleted() { + this.isCompleted = takenCredit >= totalCredit; } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategory.java index d160ab11..26010558 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategory.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategory.java @@ -2,7 +2,6 @@ import java.util.Arrays; import java.util.Objects; - import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirement.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirement.java index 094f511c..dd3f1841 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirement.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirement.java @@ -1,11 +1,10 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.DualMajorGraduationRequirementType.findBelongingDualMajorGraduationRequirementType; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.*; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.ENGLISH; import com.plzgraduate.myongjigraduatebe.user.domain.model.College; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.Builder; import lombok.Getter; @@ -13,19 +12,21 @@ public class GraduationRequirement { private final int totalCredit; + private final int primaryBasicAcademicalCultureCredit; + private final int coreCultureCredit; private int primaryMajorCredit; private int dualMajorCredit; private int subMajorCredit; - private final int primaryBasicAcademicalCultureCredit; private int dualBasicAcademicalCultureCredit; private int commonCultureCredit; - private final int coreCultureCredit; private int normalCultureCredit; private int freeElectiveCredit; @Builder - private GraduationRequirement(int totalCredit, int primaryMajorCredit, int dualMajorCredit, int subMajorCredit, - int primaryBasicAcademicalCultureCredit, int dualBasicAcademicalCultureCredit, int commonCultureCredit, + private GraduationRequirement(int totalCredit, int primaryMajorCredit, int dualMajorCredit, + int subMajorCredit, + int primaryBasicAcademicalCultureCredit, int dualBasicAcademicalCultureCredit, + int commonCultureCredit, int coreCultureCredit, int normalCultureCredit, int freeElectiveCredit) { this.totalCredit = totalCredit; @@ -53,10 +54,12 @@ public void modifyCreditForSubMajor() { public void modifyCreditForDualMajor(User user) { DualMajorGraduationRequirementType primaryMajorGraduationRequirementType = findBelongingDualMajorGraduationRequirementType( - College.findBelongingCollege(user.getPrimaryMajor()).getName()); + College.findBelongingCollege(user.getPrimaryMajor()) + .getName()); DualMajorGraduationRequirementType dualMajorGraduationRequirementType = findBelongingDualMajorGraduationRequirementType( - College.findBelongingCollege(user.getDualMajor()).getName()); + College.findBelongingCollege(user.getDualMajor()) + .getName()); primaryMajorCredit = primaryMajorGraduationRequirementType.getMajorCredit(); dualMajorCredit = dualMajorGraduationRequirementType.getMajorCredit(); @@ -67,22 +70,23 @@ public void modifyCreditForDualMajor(User user) { private int calculateFreeElectiveCreditWithDualMajorStudent() { int freeElectiveCredit = - totalCredit - commonCultureCredit - coreCultureCredit - primaryMajorCredit - dualMajorCredit + totalCredit - commonCultureCredit - coreCultureCredit - primaryMajorCredit + - dualMajorCredit - primaryBasicAcademicalCultureCredit - dualBasicAcademicalCultureCredit; return Math.max(freeElectiveCredit, 0); } public int getBasicCreditByMajorType(MajorType majorType) { - if(majorType == MajorType.PRIMARY) { + if (majorType == MajorType.PRIMARY) { return primaryBasicAcademicalCultureCredit; } return dualBasicAcademicalCultureCredit; } public int getMajorCreditByMajorType(MajorType majorType) { - if(majorType == MajorType.PRIMARY) { + if (majorType == MajorType.PRIMARY) { return primaryMajorCredit; - } else if(majorType == MajorType.DUAL) { + } else if (majorType == MajorType.DUAL) { return dualMajorCredit; } return subMajorCredit; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationResult.java index cf7929e7..7637aace 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationResult.java @@ -1,9 +1,7 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - +import java.util.List; import lombok.Builder; import lombok.Getter; @@ -19,7 +17,8 @@ public class GraduationResult { private boolean graduated; @Builder - private GraduationResult(ChapelResult chapelResult, List detailGraduationResults, + private GraduationResult(ChapelResult chapelResult, + List detailGraduationResults, NormalCultureGraduationResult normalCultureGraduationResult, FreeElectiveGraduationResult freeElectiveGraduationResult, int totalCredit, int takenCredit, boolean graduated) { @@ -56,7 +55,8 @@ public void checkGraduated(GraduationRequirement graduationRequirement) { boolean isAllDetailGraduationResultCompleted = detailGraduationResults.stream() .allMatch(DetailGraduationResult::isCompleted); this.graduated = chapelResult.isCompleted() && isAllDetailGraduationResultCompleted - && normalCultureGraduationResult.isCompleted() && freeElectiveGraduationResult.isCompleted(); + && normalCultureGraduationResult.isCompleted() + && freeElectiveGraduationResult.isCompleted(); } public void deductDuplicatedCredit(int duplicatedCredit) { @@ -88,7 +88,8 @@ private void addUpTakenCredit() { private void handleLeftTakenNormaCulture(TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { this.normalCultureGraduationResult = NormalCultureGraduationResult.create( - graduationRequirement.getNormalCultureCredit(), takenLectureInventory, detailGraduationResults); + graduationRequirement.getNormalCultureCredit(), takenLectureInventory, + detailGraduationResults); normalCultureGraduationResult.checkCompleted(); } @@ -97,7 +98,8 @@ private void handleLeftTakenFreeElective(TakenLectureInventory takenLectureInven GraduationRequirement graduationRequirement) { int leftNormalCultureCredit = normalCultureGraduationResult.getLeftCredit(); this.freeElectiveGraduationResult = FreeElectiveGraduationResult.create( - graduationRequirement.getFreeElectiveCredit(), takenLectureInventory, detailGraduationResults, + graduationRequirement.getFreeElectiveCredit(), takenLectureInventory, + detailGraduationResults, leftNormalCultureCredit); freeElectiveGraduationResult.checkCompleted(); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorType.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorType.java index 23013ddd..bc275a29 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorType.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorType.java @@ -9,11 +9,11 @@ public enum MajorType { SUB; public static MajorType from(GraduationCategory graduationCategory) { - if(graduationCategory == GraduationCategory.PRIMARY_MANDATORY_MAJOR + if (graduationCategory == GraduationCategory.PRIMARY_MANDATORY_MAJOR || graduationCategory == GraduationCategory.PRIMARY_ELECTIVE_MAJOR || graduationCategory == GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE) { return PRIMARY; - } else if(graduationCategory == GraduationCategory.DUAL_MANDATORY_MAJOR + } else if (graduationCategory == GraduationCategory.DUAL_MANDATORY_MAJOR || graduationCategory == GraduationCategory.DUAL_ELECTIVE_MAJOR || graduationCategory == GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE) { return DUAL; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResult.java index 304069de..bddbb187 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResult.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; - -import java.util.List; -import java.util.Set; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.NORMAL_CULTURE; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - +import java.util.List; +import java.util.Set; import lombok.Builder; import lombok.Getter; @@ -15,38 +13,28 @@ public class NormalCultureGraduationResult { private final String categoryName; - private boolean isCompleted; private final int totalCredit; + private boolean isCompleted; private int takenCredit; @Builder - private NormalCultureGraduationResult(String categoryName, boolean isCompleted, int totalCredit, int takenCredit) { + private NormalCultureGraduationResult(String categoryName, boolean isCompleted, int totalCredit, + int takenCredit) { this.categoryName = categoryName; this.isCompleted = isCompleted; this.totalCredit = totalCredit; this.takenCredit = takenCredit; } - public static NormalCultureGraduationResult create(int totalCredit, TakenLectureInventory takenLectureInventory, + public static NormalCultureGraduationResult create(int totalCredit, + TakenLectureInventory takenLectureInventory, List detailGraduationResults) { return NormalCultureGraduationResult.builder() .categoryName(NORMAL_CULTURE.getName()) .isCompleted(false) .totalCredit(totalCredit) - .takenCredit(calculateTakenCredit(takenLectureInventory, detailGraduationResults)).build(); - } - - public void checkCompleted() { - this.isCompleted = takenCredit >= totalCredit; - } - - public int getLeftCredit() { - if (totalCredit >= takenCredit) { - return 0; - } - int leftCredit = takenCredit - totalCredit; - this.takenCredit = totalCredit; - return leftCredit; + .takenCredit(calculateTakenCredit(takenLectureInventory, detailGraduationResults)) + .build(); } private static int calculateTakenCredit(TakenLectureInventory takenLectureInventory, @@ -57,10 +45,24 @@ private static int calculateTakenCredit(TakenLectureInventory takenLectureInvent Set remainTakenNormalCultures = takenLectureInventory.getCultureLectures(); int remainCreditByTakenLectures = remainTakenNormalCultures.stream() - .mapToInt(takenLecture -> takenLecture.getLecture().getCredit()) + .mapToInt(takenLecture -> takenLecture.getLecture() + .getCredit()) .sum(); takenLectureInventory.handleFinishedTakenLectures(remainTakenNormalCultures); return remainCreditByDetailGraduationResult + remainCreditByTakenLectures; } + + public void checkCompleted() { + this.isCompleted = takenCredit >= totalCredit; + } + + public int getLeftCredit() { + if (totalCredit >= takenCredit) { + return 0; + } + int leftCredit = takenCredit - totalCredit; + this.takenCredit = totalCredit; + return leftCredit; + } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/GraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/GraduationManager.java index 3241974e..568a419d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/GraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/GraduationManager.java @@ -1,12 +1,13 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service; -import java.util.Set; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.Set; public interface GraduationManager { + DetailGraduationResult createDetailGraduationResult(User user, - TakenLectureInventory takenLectureInventory, Set graduationLectures, int graduationResultTotalCredit); + TakenLectureInventory takenLectureInventory, Set graduationLectures, + int graduationResultTotalCredit); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalGraduationManager.java index 752b1923..776e9751 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalGraduationManager.java @@ -1,16 +1,18 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture; -import java.util.Set; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import java.util.Set; +import java.util.stream.Collectors; + +public interface BasicAcademicalGraduationManager extends + GraduationManager { -public interface BasicAcademicalGraduationManager extends GraduationManager { boolean isSatisfied(String major); - default Set convertToLectureSet(Set basicAcademicalCultureLectures) { + default Set convertToLectureSet( + Set basicAcademicalCultureLectures) { return basicAcademicalCultureLectures.stream() .map(BasicAcademicalCultureLecture::getLecture) .collect(Collectors.toSet()); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManager.java index db55fa66..e052869f 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManager.java @@ -1,20 +1,19 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture; -import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.*; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.springframework.stereotype.Component; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.BUSINESS; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.findBelongingCollege; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.springframework.stereotype.Component; @Component public class BusinessBasicAcademicalGraduationManager implements BasicAcademicalGraduationManager { @@ -39,17 +38,21 @@ public boolean isSatisfied(String major) { @Override public DetailGraduationResult createDetailGraduationResult(User user, - TakenLectureInventory takenLectureInventory, Set graduationLectures, + TakenLectureInventory takenLectureInventory, + Set graduationLectures, int basicAcademicalCredit) { Set basicAcademicalLectures = convertToLectureSet(graduationLectures); Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); - Set finalBasicAcademicalLectures = resetBasicAcademicalLectureSet(basicAcademicalLectures, + Set finalBasicAcademicalLectures = resetBasicAcademicalLectureSet( + basicAcademicalLectures, user); - takenLectureInventory.getTakenLectures().stream() - .filter(takenLecture -> finalBasicAcademicalLectures.contains(takenLecture.getLecture())) + takenLectureInventory.getTakenLectures() + .stream() + .filter( + takenLecture -> finalBasicAcademicalLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { finishedTakenLecture.add(takenLecture); taken.add(takenLecture.getLecture()); @@ -66,8 +69,9 @@ public DetailGraduationResult createDetailGraduationResult(User user, private Set resetBasicAcademicalLectureSet(Set basicAcademicalLectures, User user) { - if (!user.checkBeforeEntryYear(TWENTY)) + if (!user.checkBeforeEntryYear(TWENTY)) { return basicAcademicalLectures; + } if (user.checkMajor(BUSINESS_ADMINISTRATION) || user.checkMajor(MANAGEMENT_INFORMATION)) { return new HashSet<>(businessBefore20); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManager.java index f2754a96..178430b0 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManager.java @@ -5,21 +5,18 @@ import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.LAW; import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.findBelongingCollege; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.springframework.stereotype.Component; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import lombok.NoArgsConstructor; +import org.springframework.stereotype.Component; @Component @NoArgsConstructor @@ -27,18 +24,21 @@ public class DefaultBasicAcademicalGraduationManager implements BasicAcademicalG @Override public boolean isSatisfied(String major) { - return List.of(HUMANITIES, LAW, ICT).contains(findBelongingCollege(major)); + return List.of(HUMANITIES, LAW, ICT) + .contains(findBelongingCollege(major)); } @Override - public DetailGraduationResult createDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, + public DetailGraduationResult createDetailGraduationResult(User user, + TakenLectureInventory takenLectureInventory, Set graduationLectures, int basicAcademicalCredit) { Set basicAcademicalLectures = convertToLectureSet(graduationLectures); Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); - takenLectureInventory.getTakenLectures().stream() + takenLectureInventory.getTakenLectures() + .stream() .filter(takenLecture -> basicAcademicalLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { finishedTakenLecture.add(takenLecture); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicGraduationManager.java index df9ad3db..d3c12380 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicGraduationManager.java @@ -3,12 +3,6 @@ import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.SOCIAL_SCIENCE; import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.findBelongingCollege; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.springframework.stereotype.Component; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; @@ -16,9 +10,14 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.springframework.stereotype.Component; @Component -public class SocialScienceBasicAcademicGraduationManager implements BasicAcademicalGraduationManager { +public class SocialScienceBasicAcademicGraduationManager implements + BasicAcademicalGraduationManager { private static final int TWENTY_THREE_YEAR = 2023; private static final Set lecturesAcceptTakenAfter2023 = Set.of( @@ -40,14 +39,16 @@ public boolean isSatisfied(String major) { @Override public DetailGraduationResult createDetailGraduationResult(User user, - TakenLectureInventory takenLectureInventory, Set graduationLectures, + TakenLectureInventory takenLectureInventory, + Set graduationLectures, int basicAcademicalCredit) { Set basicAcademicalLectures = convertToLectureSet(graduationLectures); Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); - takenLectureInventory.getTakenLectures().stream() + takenLectureInventory.getTakenLectures() + .stream() .filter(takenLecture -> basicAcademicalLectures.contains(takenLecture.getLecture())) .filter(takenLecture -> lecturesAcceptTakenAfter2023.contains(takenLecture.getLecture()) && !takenLecture.takenAfter(TWENTY_THREE_YEAR)) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManager.java index 3b1fcccc..7d0cb18c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManager.java @@ -1,14 +1,11 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.*; -import static com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel.*; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.springframework.stereotype.Component; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_A; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.ENGLISH; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel.BASIC; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel.ENG12; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel.ENG34; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel.FREE; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; @@ -17,6 +14,11 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.springframework.stereotype.Component; @Component class CommonCultureDetailCategoryManager { @@ -31,16 +33,20 @@ class CommonCultureDetailCategoryManager { public DetailCategoryResult generate(User user, TakenLectureInventory takenLectureInventory, Set graduationLectures, CommonCultureCategory category) { - Set graduationCommonCultureLectures = categorizeCommonCultures(graduationLectures, category); + Set graduationCommonCultureLectures = categorizeCommonCultures(graduationLectures, + category); Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); - takenLectureInventory.getTakenLectures().stream() - .filter(takenLecture -> graduationCommonCultureLectures.contains(takenLecture.getLecture())) + takenLectureInventory.getTakenLectures() + .stream() + .filter( + takenLecture -> graduationCommonCultureLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { finishedTakenLecture.add(takenLecture); taken.add(takenLecture.getLecture()); }); - boolean isSatisfiedMandatory = checkMandatorySatisfaction(user, takenLectureInventory, category); + boolean isSatisfiedMandatory = checkMandatorySatisfaction(user, takenLectureInventory, + category); takenLectureInventory.handleFinishedTakenLectures(finishedTakenLecture); DetailCategoryResult commonCultureDetailCategoryResult = DetailCategoryResult.create( category.getName(), isSatisfiedMandatory, checkCategoryTotalCredit(user, category)); @@ -63,16 +69,20 @@ private Set categorizeCommonCultures(Set graduationLectu .collect(Collectors.toSet()); } - private boolean checkMandatorySatisfaction(User user, TakenLectureInventory takenLectureInventory, + private boolean checkMandatorySatisfaction(User user, + TakenLectureInventory takenLectureInventory, CommonCultureCategory category) { if (category == CHRISTIAN_A) { - return takenLectureInventory.getTakenLectures().stream() + return takenLectureInventory.getTakenLectures() + .stream() .anyMatch( takenLecture -> CHRISTAIN_MANDATORY_LECTURE_CODE_LIST - .contains(takenLecture.getLecture().getLectureCode())); + .contains(takenLecture.getLecture() + .getLectureCode())); } - if(user.getEnglishLevel() == BASIC && category == ENGLISH) { - return isTakenBasicEnglish(takenLectureInventory) && checkEnglish12Satisfaction(takenLectureInventory); + if (user.getEnglishLevel() == BASIC && category == ENGLISH) { + return isTakenBasicEnglish(takenLectureInventory) && checkEnglish12Satisfaction( + takenLectureInventory); } if (user.getEnglishLevel() == ENG12 && category == ENGLISH) { return checkEnglish12Satisfaction(takenLectureInventory); @@ -84,16 +94,20 @@ private boolean checkMandatorySatisfaction(User user, TakenLectureInventory take } private boolean isTakenBasicEnglish(TakenLectureInventory takenLectureInventory) { - return takenLectureInventory.getCultureLectures().stream() - .map(takenLecture -> takenLecture.getLecture().getLectureCode()) + return takenLectureInventory.getCultureLectures() + .stream() + .map(takenLecture -> takenLecture.getLecture() + .getLectureCode()) .collect(Collectors.toList()) .contains(BASIC_ENGLISH_LECTURE_CODE); } private boolean checkEnglish12Satisfaction(TakenLectureInventory takenLectureInventory) { for (String lectureCode : ENGLISH_12_MANDATORY_LECTURE_CODE_LIST) { - if (!takenLectureInventory.getCultureLectures().stream() - .map(takenLecture -> takenLecture.getLecture().getLectureCode()) + if (!takenLectureInventory.getCultureLectures() + .stream() + .map(takenLecture -> takenLecture.getLecture() + .getLectureCode()) .collect(Collectors.toList()) .contains(lectureCode)) { return false; @@ -104,8 +118,10 @@ private boolean checkEnglish12Satisfaction(TakenLectureInventory takenLectureInv private boolean checkEnglish34Satisfaction(TakenLectureInventory takenLectureInventory) { for (String lectureCode : ENGLISH_34_MANDATORY_LECTURE_CODE_LIST) { - if (!takenLectureInventory.getCultureLectures().stream() - .map(takenLecture -> takenLecture.getLecture().getLectureCode()) + if (!takenLectureInventory.getCultureLectures() + .stream() + .map(takenLecture -> takenLecture.getLecture() + .getLectureCode()) .collect(Collectors.toList()) .contains(lectureCode)) { return false; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonGraduationManager.java index 76e4dc18..698f0761 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonGraduationManager.java @@ -1,22 +1,21 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.ChapelResult.*; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.springframework.stereotype.Component; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.ChapelResult.CHAPEL_CREDIT; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.ChapelResult.CHAPEL_LECTURE_CODE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.springframework.stereotype.Component; @Component public class CommonGraduationManager implements GraduationManager { @@ -26,22 +25,29 @@ public DetailGraduationResult createDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, Set graduationLectures, int commonCultureGraduationTotalCredit) { CommonCultureDetailCategoryManager commonCultureDetailCategoryManager = new CommonCultureDetailCategoryManager(); - List commonCultureDetailCategoryResults = Arrays.stream(CommonCultureCategory.values()) + List commonCultureDetailCategoryResults = Arrays.stream( + CommonCultureCategory.values()) .filter( - commonCultureCategory -> commonCultureCategory.isContainsEntryYear(user.getEntryYear())) - .map(commonCultureCategory -> commonCultureDetailCategoryManager.generate(user, takenLectureInventory, + commonCultureCategory -> commonCultureCategory.isContainsEntryYear( + user.getEntryYear())) + .map(commonCultureCategory -> commonCultureDetailCategoryManager.generate(user, + takenLectureInventory, graduationLectures, commonCultureCategory)) .collect(Collectors.toList()); - DetailGraduationResult detailGraduationResult = DetailGraduationResult.create(COMMON_CULTURE, + DetailGraduationResult detailGraduationResult = DetailGraduationResult.create( + COMMON_CULTURE, commonCultureGraduationTotalCredit, commonCultureDetailCategoryResults); detailGraduationResult.addCredit(getTakenChapelCredits(takenLectureInventory)); return detailGraduationResult; } private double getTakenChapelCredits(TakenLectureInventory takenLectureInventory) { - int chapelCount = (int)takenLectureInventory.getTakenLectures().stream() - .filter(takenLecture -> takenLecture.getLecture().getLectureCode().equals(CHAPEL_LECTURE_CODE)) + int chapelCount = (int) takenLectureInventory.getTakenLectures() + .stream() + .filter(takenLecture -> takenLecture.getLecture() + .getLectureCode() + .equals(CHAPEL_LECTURE_CODE)) .count(); return chapelCount * CHAPEL_CREDIT; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManager.java index 16339019..40abd7e4 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManager.java @@ -1,21 +1,19 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.coreculture; -import static com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester.*; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.springframework.stereotype.Component; +import static com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester.FIRST; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.springframework.stereotype.Component; @Component public class CoreCultureDetailCategoryManager { @@ -31,11 +29,14 @@ public class CoreCultureDetailCategoryManager { public DetailCategoryResult generate(User user, TakenLectureInventory takenLectureInventory, Set graduationLectures, CoreCultureCategory category) { - Set graduationCoreCultureLectures = categorizeCoreCultures(graduationLectures, category); + Set graduationCoreCultureLectures = categorizeCoreCultures(graduationLectures, + category); Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); - takenLectureInventory.getTakenLectures().stream() - .filter(takenLecture -> graduationCoreCultureLectures.contains(takenLecture.getLecture())) + takenLectureInventory.getTakenLectures() + .stream() + .filter( + takenLecture -> graduationCoreCultureLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { finishedTakenLecture.add(takenLecture); taken.add(takenLecture.getLecture()); @@ -68,7 +69,8 @@ private void calculateFreeElectiveLeftCredit(User user, Set taken, } } - private void calculateNormalLeftCredit(Set taken, Set finishedTakenLecture, + private void calculateNormalLeftCredit(Set taken, + Set finishedTakenLecture, DetailCategoryResult commonCultureDetailCategoryResult) { List cultureAndArtExceptionLectures = finishedTakenLecture.stream() .filter(takenLecture -> 문화와예술_예외_과목.contains(takenLecture.getLecture()) @@ -80,7 +82,8 @@ private void calculateNormalLeftCredit(Set taken, Set fin .map(TakenLecture::getLecture) .forEach(taken::remove); int normalLeftCredit = cultureAndArtExceptionLectures.stream() - .mapToInt(exceptionLecture -> exceptionLecture.getLecture().getCredit()) + .mapToInt(exceptionLecture -> exceptionLecture.getLecture() + .getCredit()) .sum(); commonCultureDetailCategoryResult.addNormalLeftCredit(normalLeftCredit); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreGraduationManager.java index d41f7484..fe999008 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreGraduationManager.java @@ -2,29 +2,31 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CORE_CULTURE; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.springframework.stereotype.Component; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.springframework.stereotype.Component; @Component public class CoreGraduationManager implements GraduationManager { + @Override public DetailGraduationResult createDetailGraduationResult(User user, - TakenLectureInventory takenLectureInventory, Set graduationLectures, int coreCultureGraduationTotalCredit) { + TakenLectureInventory takenLectureInventory, Set graduationLectures, + int coreCultureGraduationTotalCredit) { CoreCultureDetailCategoryManager coreCultureDetailCategoryManager = new CoreCultureDetailCategoryManager(); - List coreCultureDetailCategoryResults = Arrays.stream(CoreCultureCategory.values()) - .map(coreCultureCategory -> coreCultureDetailCategoryManager.generate(user, takenLectureInventory, + List coreCultureDetailCategoryResults = Arrays.stream( + CoreCultureCategory.values()) + .map(coreCultureCategory -> coreCultureDetailCategoryManager.generate(user, + takenLectureInventory, graduationLectures, coreCultureCategory)) .collect(Collectors.toList()); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ElectiveMajorManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ElectiveMajorManager.java index 175b4a82..50744d1a 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ElectiveMajorManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ElectiveMajorManager.java @@ -1,30 +1,32 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import java.util.HashSet; -import java.util.Set; - -import org.springframework.stereotype.Component; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import java.util.HashSet; +import java.util.Set; +import org.springframework.stereotype.Component; @Component public class ElectiveMajorManager { private static final String ELECTIVE_MAJOR_NAME = "전공선택"; - public DetailCategoryResult createDetailCategoryResult(TakenLectureInventory takenLectureInventory, + + public DetailCategoryResult createDetailCategoryResult( + TakenLectureInventory takenLectureInventory, Set electiveLectures, int electiveMajorTotalCredit) { Set takenElective = new HashSet<>(); Set finishedTakenLecture = new HashSet<>(); - takenLectureInventory.getTakenLectures().stream() + takenLectureInventory.getTakenLectures() + .stream() .filter(takenLecture -> electiveLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { finishedTakenLecture.add(takenLecture); takenElective.add(takenLecture.getLecture()); }); - DetailCategoryResult electiveMajorResult = DetailCategoryResult.create(ELECTIVE_MAJOR_NAME, true, electiveMajorTotalCredit); + DetailCategoryResult electiveMajorResult = DetailCategoryResult.create(ELECTIVE_MAJOR_NAME, + true, electiveMajorTotalCredit); electiveMajorResult.calculate(takenElective, electiveLectures); takenLectureInventory.handleFinishedTakenLectures(finishedTakenLecture); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationManager.java index 7fdc0aac..f5320245 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationManager.java @@ -1,11 +1,5 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.springframework.stereotype.Component; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; @@ -14,8 +8,11 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor @@ -25,16 +22,16 @@ public class MajorGraduationManager { private final ElectiveMajorManager electiveMajorManager; /** - * - * @param user 사용자 - * @param majorType 주전공, 복수전공, 부전공 - * @param takenLectureInventory 수강과목 목록 - * @param majorLectures 해당 사용자의 전공과목 + * @param user 사용자 + * @param majorType 주전공, 복수전공, 부전공 + * @param takenLectureInventory 수강과목 목록 + * @param majorLectures 해당 사용자의 전공과목 * @param graduationResultTotalCredit 해당 사용자의 전공 졸업 학점 * @return 전공 카테고리에 대한 졸업 결과 반환 */ public DetailGraduationResult createDetailGraduationResult(User user, MajorType majorType, - TakenLectureInventory takenLectureInventory, Set majorLectures, int graduationResultTotalCredit) { + TakenLectureInventory takenLectureInventory, Set majorLectures, + int graduationResultTotalCredit) { removeDuplicateLectureIfTaken(takenLectureInventory, majorLectures); changeMandatoryToElectiveByMajorRange(user, majorLectures); @@ -45,11 +42,13 @@ public DetailGraduationResult createDetailGraduationResult(User user, MajorType DetailCategoryResult mandantoryDetailCategoryResult = mandatoryMajorManager.createDetailCategoryResult( user, takenLectureInventory, mandatoryLectures, electiveLectures, majorType); - int electiveMajorTotalCredit = graduationResultTotalCredit - mandantoryDetailCategoryResult.getTotalCredits(); + int electiveMajorTotalCredit = + graduationResultTotalCredit - mandantoryDetailCategoryResult.getTotalCredits(); DetailCategoryResult electiveDetailCategoryResult = electiveMajorManager.createDetailCategoryResult( takenLectureInventory, electiveLectures, electiveMajorTotalCredit); - return DetailGraduationResult.createNonCategorizedGraduationResult(graduationResultTotalCredit, + return DetailGraduationResult.createNonCategorizedGraduationResult( + graduationResultTotalCredit, List.of(mandantoryDetailCategoryResult, electiveDetailCategoryResult)); } @@ -74,10 +73,9 @@ private Set filterElectiveLectures(Set majorLectures) { } /** - * 전공과목에서 사용자의 수강과목 중 중복과목들을 삭제한다. - * ex) A(폐지) -> B(폐지) -> C(진행) 인 과목이 있다고하면 A,B,C의 과목중복코드는 같다. 사용자가 B과목을 들었다면 A,C는 전공과목에서 삭제한다. - * 사용자가 B과목을 들었다면 A,C는 전공과목에서 삭제한다. - * B과목만 takenLectures(수강했던 전공과목)에 넣어주면 되고 A,C 과목은 haveToTLectures(들어야하는 전공과목)에 넣어주면 안되기 떄문이다. + * 전공과목에서 사용자의 수강과목 중 중복과목들을 삭제한다. ex) A(폐지) -> B(폐지) -> C(진행) 인 과목이 있다고하면 A,B,C의 과목중복코드는 같다. + * 사용자가 B과목을 들었다면 A,C는 전공과목에서 삭제한다. 사용자가 B과목을 들었다면 A,C는 전공과목에서 삭제한다. B과목만 takenLectures(수강했던 + * 전공과목)에 넣어주면 되고 A,C 과목은 haveToTLectures(들어야하는 전공과목)에 넣어주면 안되기 떄문이다. */ private void removeDuplicateLectureIfTaken(TakenLectureInventory takenLectureInventory, Set graduationLectures) { @@ -87,17 +85,18 @@ private void removeDuplicateLectureIfTaken(TakenLectureInventory takenLectureInv .anyMatch(duplicatedTakenLecture -> !duplicatedTakenLecture.equals(graduationLecture.getLecture()) && duplicatedTakenLecture.getDuplicateCode() - .equals(graduationLecture.getLecture().getDuplicateCode()) + .equals(graduationLecture.getLecture() + .getDuplicateCode()) ) ); } /** - * 사용자의 수강과목에서 중복코드가 있고 폐지된 과목들을 반환한다. - * 중복코드가 있고 폐지된 과목일 경우 이미 해당 과목을 대체하는 과목이 있다는 뜻이기 때문. + * 사용자의 수강과목에서 중복코드가 있고 폐지된 과목들을 반환한다. 중복코드가 있고 폐지된 과목일 경우 이미 해당 과목을 대체하는 과목이 있다는 뜻이기 때문. */ private Set findDuplicatedTakenLecture(TakenLectureInventory takenLectureInventory) { - return takenLectureInventory.getTakenLectures().stream() + return takenLectureInventory.getTakenLectures() + .stream() .map(TakenLecture::getLecture) .filter(lecture -> lecture.getDuplicateCode() != null && lecture.getIsRevoked() == 1) .collect(Collectors.toSet()); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorManager.java index 81edbea5..da777878 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorManager.java @@ -1,19 +1,16 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.springframework.stereotype.Component; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor @@ -23,7 +20,8 @@ public class MandatoryMajorManager { private final List mandatoryMajorSpecialCaseHandlers; - public DetailCategoryResult createDetailCategoryResult(User user, TakenLectureInventory takenLectureInventory, + public DetailCategoryResult createDetailCategoryResult(User user, + TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures, MajorType majorType) { Set takenMandatory = new HashSet<>(); Set finishedTakenLecture = new HashSet<>(); @@ -39,20 +37,23 @@ public DetailCategoryResult createDetailCategoryResult(User user, TakenLectureIn } } - takenLectureInventory.getTakenLectures().stream() + takenLectureInventory.getTakenLectures() + .stream() .filter(takenLecture -> mandatoryLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { finishedTakenLecture.add(takenLecture); takenMandatory.add(takenLecture.getLecture()); }); - DetailCategoryResult majorMandatoryResult = DetailCategoryResult.create(MANDATORY_MAJOR_NAME, isSatisfiedMandatory, + DetailCategoryResult majorMandatoryResult = DetailCategoryResult.create( + MANDATORY_MAJOR_NAME, isSatisfiedMandatory, calculateTotalCredit(takenMandatory, mandatoryLectures, removeMandatoryTotalCredit)); majorMandatoryResult.calculate(takenMandatory, mandatoryLectures); takenLectureInventory.handleFinishedTakenLectures(finishedTakenLecture); return majorMandatoryResult; } - private int calculateTotalCredit(Set taken, Set mandatoryLectures, int removedCredit) { + private int calculateTotalCredit(Set taken, Set mandatoryLectures, + int removedCredit) { int totalCredit = 0; for (Lecture lecture : mandatoryLectures) { if (!taken.contains(lecture) && lecture.getIsRevoked() == 1) { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorSpecialCaseHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorSpecialCaseHandler.java index b04690f8..5c8b0174 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorSpecialCaseHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorSpecialCaseHandler.java @@ -1,13 +1,13 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import java.util.Set; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.Set; public interface MandatoryMajorSpecialCaseHandler { + boolean isSupport(User user, MajorType majorType); MandatorySpecialCaseInformation getMandatorySpecialCaseInformation( diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatorySpecialCaseInformation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatorySpecialCaseInformation.java index 8ede98a1..ce2fe109 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatorySpecialCaseInformation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatorySpecialCaseInformation.java @@ -13,7 +13,8 @@ public class MandatorySpecialCaseInformation { private final int removedMandatoryTotalCredit; - public static MandatorySpecialCaseInformation of(boolean completeMandatorySpecialCase, int removedMandatoryTotalCredit) { + public static MandatorySpecialCaseInformation of(boolean completeMandatorySpecialCase, + int removedMandatoryTotalCredit) { return MandatorySpecialCaseInformation.builder() .isCompleteMandatorySpecialCase(completeMandatorySpecialCase) .removedMandatoryTotalCredit(removedMandatoryTotalCredit) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatory.java index 7a85f2b0..a19ce958 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatory.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatory.java @@ -1,11 +1,9 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import java.util.Arrays; import java.util.Objects; import java.util.Set; - -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandler.java index 9df5a7ef..70e0125c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandler.java @@ -1,23 +1,20 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.springframework.stereotype.Component; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.springframework.stereotype.Component; /** - * N택 M의 선택과목이 있는 경우 처리하는 핸들러 클래스 - * 국제통상의 경우 회계원리, 마케팅원론, 재무관리 원론, 인적자원관리, 생산운영관리(폐지), 운영관리(구, 생산운영관리) 5개 중 4개 선택 - * 경영정보의 경우 인적자원관리, 마켓팅원론, 재무관리원론에서 ~18학번까지는 3개 모두 이수, 19학번 이후 택 2 - * 경영의 경우 국제통상원론, 국제경양, 경영정보 중 택1 + * N택 M의 선택과목이 있는 경우 처리하는 핸들러 클래스 국제통상의 경우 회계원리, 마케팅원론, 재무관리 원론, 인적자원관리, 생산운영관리(폐지), 운영관리(구, 생산운영관리) + * 5개 중 4개 선택 경영정보의 경우 인적자원관리, 마켓팅원론, 재무관리원론에서 ~18학번까지는 3개 모두 이수, 19학번 이후 택 2 경영의 경우 국제통상원론, 국제경양, + * 경영정보 중 택1 **/ @Component public class OptionalMandatoryMajorHandler implements MandatoryMajorSpecialCaseHandler { @@ -37,32 +34,39 @@ public boolean isSupport(User user, MajorType majorType) { if (calculatingMajor.equals(ADMINISTRATIONS) && user.getEntryYear() >= CLASS_OF_17) { return true; } - return List.of(BUSINESS, INTERNATIONAL_TRADE).contains(calculatingMajor); + return List.of(BUSINESS, INTERNATIONAL_TRADE) + .contains(calculatingMajor); } @Override public MandatorySpecialCaseInformation getMandatorySpecialCaseInformation(User user, MajorType majorType, TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures) { - OptionalMandatory optionalMandatory = OptionalMandatory.from(getCalculatingMajor(user, majorType)); + OptionalMandatory optionalMandatory = OptionalMandatory.from( + getCalculatingMajor(user, majorType)); int removedMandatoryTotalCredit = 0; - boolean isCompletedMandatorySpecialCase = checkCompleteOptionalMandatory(takenLectureInventory, mandatoryLectures, + boolean isCompletedMandatorySpecialCase = checkCompleteOptionalMandatory( + takenLectureInventory, mandatoryLectures, electiveLectures, optionalMandatory); - if (!isCompletedMandatorySpecialCase ) { + if (!isCompletedMandatorySpecialCase) { removedMandatoryTotalCredit = optionalMandatory.getTotalOptionalMandatoryCredit() - optionalMandatory.getChooseLectureCredit(); } - return MandatorySpecialCaseInformation.of(isCompletedMandatorySpecialCase , removedMandatoryTotalCredit); + return MandatorySpecialCaseInformation.of(isCompletedMandatorySpecialCase, + removedMandatoryTotalCredit); } private boolean checkCompleteOptionalMandatory(TakenLectureInventory takenLectureInventory, - Set mandatoryLectures, Set electiveLectures, OptionalMandatory optionalMandatory) { + Set mandatoryLectures, Set electiveLectures, + OptionalMandatory optionalMandatory) { int chooseNum = optionalMandatory.getChooseNumber(); /* * 전공과목 Set 에서 전공선택필수과목에 해당되는 과목들을 추출한다. */ - Set optionalMandatoryLectures = mandatoryLectures.stream().filter( - optionalMandatory.getOptionalMandatoryLectures()::contains).collect(Collectors.toSet()); + Set optionalMandatoryLectures = mandatoryLectures.stream() + .filter( + optionalMandatory.getOptionalMandatoryLectures()::contains) + .collect(Collectors.toSet()); /* remainingMandatoryLectures에 모든 전공선택필수 과목을 넣고 수강했을 시 제거한다. @@ -73,7 +77,8 @@ private boolean checkCompleteOptionalMandatory(TakenLectureInventory takenLectur Set remainingMandatoryLectures = new HashSet<>(optionalMandatoryLectures); int count = 0; for (TakenLecture takenLecture : takenLectureInventory.getTakenLectures()) { - if (optionalMandatoryLectures.contains(takenLecture.getLecture()) && count < chooseNum) { + if (optionalMandatoryLectures.contains(takenLecture.getLecture()) + && count < chooseNum) { count++; remainingMandatoryLectures.remove(takenLecture.getLecture()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ReplaceMandatoryMajorHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ReplaceMandatoryMajorHandler.java index 4a803ec0..8e550677 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ReplaceMandatoryMajorHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ReplaceMandatoryMajorHandler.java @@ -1,25 +1,23 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.stream.Collectors; - import org.springframework.stereotype.Component; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - /** - * 철학과의 경우 답사1, 답사2는 폐지 되었지만 2021번 이전까지 전공필수 - * '신유학의 이해' '유학사상의이해' 중 택1 이수 시 대체 인정 + * 철학과의 경우 답사1, 답사2는 폐지 되었지만 2021번 이전까지 전공필수 '신유학의 이해' '유학사상의이해' 중 택1 이수 시 대체 인정 */ @Component public class ReplaceMandatoryMajorHandler implements MandatoryMajorSpecialCaseHandler { + private static final List REPLACED_LECTURES = List.of( Lecture.of("HAI01110", "답사1", 1, 1, null), Lecture.of("HAI01111", "답사2", 1, 1, "HAI01111") @@ -39,13 +37,15 @@ public boolean isSupport(User user, MajorType majorType) { public MandatorySpecialCaseInformation getMandatorySpecialCaseInformation(User user, MajorType majorType, TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures) { - boolean completeMandatorySpecialCase = checkCompleteReplaceMandatory(takenLectureInventory, mandatoryLectures, + boolean completeMandatorySpecialCase = checkCompleteReplaceMandatory(takenLectureInventory, + mandatoryLectures, electiveLectures); int removedMandatoryTotalCredit = 0; if (!completeMandatorySpecialCase) { removedMandatoryTotalCredit = 3; } - return MandatorySpecialCaseInformation.of(completeMandatorySpecialCase, removedMandatoryTotalCredit); + return MandatorySpecialCaseInformation.of(completeMandatorySpecialCase, + removedMandatoryTotalCredit); } @@ -54,10 +54,13 @@ public boolean checkCompleteReplaceMandatory(TakenLectureInventory takenLectureI if (checkTakeReplacedLectures(takenLectureInventory)) { return true; } - List replacingLectures = filterTakenLecturesContainsReplacingLectures(takenLectureInventory); + List replacingLectures = filterTakenLecturesContainsReplacingLectures( + takenLectureInventory); if (!replacingLectures.isEmpty()) { - mandatoryLectures.add(replacingLectures.get(0).getLecture()); - electiveLectures.remove(replacingLectures.get(0).getLecture()); + mandatoryLectures.add(replacingLectures.get(0) + .getLecture()); + electiveLectures.remove(replacingLectures.get(0) + .getLecture()); return true; } mandatoryLectures.addAll(REPLACING_LECTURES); @@ -66,15 +69,18 @@ public boolean checkCompleteReplaceMandatory(TakenLectureInventory takenLectureI } private boolean checkTakeReplacedLectures(TakenLectureInventory takenLectureInventory) { - long replacedTaken = takenLectureInventory.getTakenLectures().stream() + long replacedTaken = takenLectureInventory.getTakenLectures() + .stream() .map(TakenLecture::getLecture) - .filter(REPLACED_LECTURES::contains).count(); + .filter(REPLACED_LECTURES::contains) + .count(); return replacedTaken == REPLACED_LECTURES.size(); } private List filterTakenLecturesContainsReplacingLectures( TakenLectureInventory takenLectureInventory) { - return takenLectureInventory.getTakenLectures().stream() + return takenLectureInventory.getTakenLectures() + .stream() .filter(takenLecture -> REPLACING_LECTURES.contains(takenLecture.getLecture())) .sorted(Comparator .comparingInt(TakenLecture::getYear) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManager.java index 29c2a3a3..1931bd23 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManager.java @@ -1,12 +1,5 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.submajor; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.springframework.stereotype.Component; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; @@ -16,39 +9,51 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.springframework.stereotype.Component; @Component public class SubMajorGraduationManager implements GraduationManager { @Override - public DetailGraduationResult createDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, + public DetailGraduationResult createDetailGraduationResult(User user, + TakenLectureInventory takenLectureInventory, Set graduationLectures, int graduationResultTotalCredit) { Set removedTakenLecture = new HashSet<>(); - DetailCategoryResult detailCategoryResult = generateDetailCategoryResult(takenLectureInventory, + DetailCategoryResult detailCategoryResult = generateDetailCategoryResult( + takenLectureInventory, graduationLectures, removedTakenLecture, graduationResultTotalCredit); takenLectureInventory.handleFinishedTakenLectures(removedTakenLecture); - return DetailGraduationResult.create(GraduationCategory.SUB_MAJOR, graduationResultTotalCredit, + return DetailGraduationResult.create(GraduationCategory.SUB_MAJOR, + graduationResultTotalCredit, List.of(detailCategoryResult)); } - private DetailCategoryResult generateDetailCategoryResult(TakenLectureInventory takenLectureInventory, - Set graduationLectures, Set removedTakenLecture, int graduationResultTotalCredit) { + private DetailCategoryResult generateDetailCategoryResult( + TakenLectureInventory takenLectureInventory, + Set graduationLectures, Set removedTakenLecture, + int graduationResultTotalCredit) { boolean isSatisfiedMandatory = true; Set subMajorGraduationLectures = graduationLectures.stream() .map(MajorLecture::getLecture) .collect(Collectors.toSet()); Set taken = new HashSet<>(); - takenLectureInventory.getTakenLectures().stream() + takenLectureInventory.getTakenLectures() + .stream() .filter(takenLecture -> subMajorGraduationLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { removedTakenLecture.add(takenLecture); taken.add(takenLecture.getLecture()); }); - DetailCategoryResult detailCategoryResult = DetailCategoryResult.create("전공선택", isSatisfiedMandatory, + DetailCategoryResult detailCategoryResult = DetailCategoryResult.create("전공선택", + isSatisfiedMandatory, graduationResultTotalCredit); detailCategoryResult.calculate(taken, subMajorGraduationLectures); return detailCategoryResult; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureApiPresentation.java index 69fc27b8..9b63bb90 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureApiPresentation.java @@ -1,16 +1,12 @@ package com.plzgraduate.myongjigraduatebe.lecture.api; -import java.util.List; - -import javax.validation.constraints.Size; - -import org.springframework.web.bind.annotation.RequestParam; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.lecture.api.dto.response.SearchLectureResponse; - import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; +import javax.validation.constraints.Size; +import org.springframework.web.bind.annotation.RequestParam; @Tag(name = "SearchLecture", description = "type과 keyword를 통해 과목정보를 검색하는 API") public interface SearchLectureApiPresentation { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureController.java index ac8e31a6..3013df4c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureController.java @@ -1,23 +1,18 @@ package com.plzgraduate.myongjigraduatebe.lecture.api; +import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; +import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; +import com.plzgraduate.myongjigraduatebe.lecture.api.dto.response.SearchLectureResponse; +import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.SearchLectureUseCase; import java.util.List; import java.util.stream.Collectors; - import javax.validation.constraints.Size; - +import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; -import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; -import com.plzgraduate.myongjigraduatebe.lecture.api.dto.response.SearchLectureResponse; -import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.SearchLectureUseCase; -import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto.SearchedLectureDto; - -import lombok.RequiredArgsConstructor; - @WebAdapter @RequiredArgsConstructor @RequestMapping("/api/v1/lectures") @@ -32,7 +27,8 @@ public List searchLecture( @RequestParam(defaultValue = "name") String type, @RequestParam @Size(min = 2, message = "검색어를 2자리 이상 입력해주세요.") String keyword ) { - return searchLectureUseCase.searchLectures(userId, type, keyword).stream() + return searchLectureUseCase.searchLectures(userId, type, keyword) + .stream() .map(SearchLectureResponse::from) .collect(Collectors.toList()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/dto/response/LectureResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/dto/response/LectureResponse.java index ed47fed9..839ea906 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/dto/response/LectureResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/dto/response/LectureResponse.java @@ -1,13 +1,13 @@ package com.plzgraduate.myongjigraduatebe.lecture.api.dto.response; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; @Getter public class LectureResponse { + @Schema(name = "id", example = "18") private final Long id; @Schema(name = "lectureCode", example = "KMA02137") @@ -20,7 +20,8 @@ public class LectureResponse { private final boolean isRevoked; @Builder - private LectureResponse(Long id, String lectureCode, String name, int credit, boolean isRevoked) { + private LectureResponse(Long id, String lectureCode, String name, int credit, + boolean isRevoked) { this.id = id; this.lectureCode = lectureCode; this.name = name; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/dto/response/SearchLectureResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/dto/response/SearchLectureResponse.java index 628d71cc..70531c72 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/dto/response/SearchLectureResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/api/dto/response/SearchLectureResponse.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.lecture.api.dto.response; import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto.SearchedLectureDto; - import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; @@ -23,7 +22,8 @@ public class SearchLectureResponse { private final boolean taken; @Builder - private SearchLectureResponse(Long id, String lectureCode, String name, int credit, boolean revoked, + private SearchLectureResponse(Long id, String lectureCode, String name, int credit, + boolean revoked, boolean taken) { this.id = id; this.lectureCode = lectureCode; @@ -35,11 +35,16 @@ private SearchLectureResponse(Long id, String lectureCode, String name, int cred public static SearchLectureResponse from(SearchedLectureDto searchedLectureDto) { return SearchLectureResponse.builder() - .id(searchedLectureDto.getLecture().getId()) - .lectureCode(searchedLectureDto.getLecture().getLectureCode()) - .name(searchedLectureDto.getLecture().getName()) - .credit(searchedLectureDto.getLecture().getCredit()) - .revoked(searchedLectureDto.getLecture().getIsRevoked() != 0) + .id(searchedLectureDto.getLecture() + .getId()) + .lectureCode(searchedLectureDto.getLecture() + .getLectureCode()) + .name(searchedLectureDto.getLecture() + .getName()) + .credit(searchedLectureDto.getLecture() + .getCredit()) + .revoked(searchedLectureDto.getLecture() + .getIsRevoked() != 0) .taken(searchedLectureDto.isAddable()) .build(); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindBasicAcademicalCulturePort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindBasicAcademicalCulturePort.java index 8ed91959..b7ee9eea 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindBasicAcademicalCulturePort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindBasicAcademicalCulturePort.java @@ -1,9 +1,8 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.port; -import java.util.Set; - import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.Set; public interface FindBasicAcademicalCulturePort { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindCommonCulturePort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindCommonCulturePort.java index ce02c80e..9a89ddb7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindCommonCulturePort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindCommonCulturePort.java @@ -1,9 +1,8 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.port; -import java.util.Set; - import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.Set; public interface FindCommonCulturePort { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindCoreCulturePort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindCoreCulturePort.java index 1bd9ffb3..fa3bbbf5 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindCoreCulturePort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindCoreCulturePort.java @@ -1,9 +1,8 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.port; -import java.util.Set; - import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.Set; public interface FindCoreCulturePort { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindLecturePort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindLecturePort.java index f65700b8..d169e62b 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindLecturePort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindLecturePort.java @@ -1,8 +1,7 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.port; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import java.util.List; public interface FindLecturePort { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindMajorPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindMajorPort.java index df3954cf..f5a01454 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindMajorPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/FindMajorPort.java @@ -1,8 +1,7 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.port; -import java.util.Set; - import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; +import java.util.Set; public interface FindMajorPort { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/SearchLecturePort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/SearchLecturePort.java index 1ed00380..9d7ac5f7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/SearchLecturePort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/port/SearchLecturePort.java @@ -1,9 +1,9 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.port; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import java.util.List; public interface SearchLecturePort { + List searchLectureByNameOrCode(String type, String keyword); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/FindLecturesService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/FindLecturesService.java index d23db504..7bb2d329 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/FindLecturesService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/FindLecturesService.java @@ -1,15 +1,12 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.service; -import java.util.List; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.FindLecturesUseCase; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort; +import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.FindLecturesUseCase; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - +import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -17,6 +14,7 @@ public class FindLecturesService implements FindLecturesUseCase { private final FindLecturePort findLecturePort; + @Override public List findLecturesByIds(List lectureIds) { return findLecturePort.findLecturesByIds(lectureIds); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/SearchLectureService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/SearchLectureService.java index 08f2b5e6..b295d9ae 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/SearchLectureService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/SearchLectureService.java @@ -1,10 +1,5 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.service; -import java.util.List; -import java.util.stream.Collectors; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.lecture.application.port.SearchLecturePort; import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.SearchLectureUseCase; @@ -13,8 +8,10 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -27,9 +24,11 @@ public class SearchLectureService implements SearchLectureUseCase { @Override public List searchLectures(Long userId, String type, String keyword) { List searchedLectures = searchLecturePort.searchLectureByNameOrCode(type, keyword); - TakenLectureInventory takenLectureInventory = findTakenLectureUseCase.findTakenLectures(userId); + TakenLectureInventory takenLectureInventory = findTakenLectureUseCase.findTakenLectures( + userId); - List takenLectures = takenLectureInventory.getTakenLectures().stream() + List takenLectures = takenLectureInventory.getTakenLectures() + .stream() .map(TakenLecture::getLecture) .collect(Collectors.toList()); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/FindLecturesUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/FindLecturesUseCase.java index 390dba1a..30de4474 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/FindLecturesUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/FindLecturesUseCase.java @@ -1,10 +1,10 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.usecase; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import java.util.List; public interface FindLecturesUseCase { + List findLecturesByIds(List lectureIds); List findLecturesByLectureCodes(List lectureCodes); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/SearchLectureUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/SearchLectureUseCase.java index 6bb2a4bd..6948a08c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/SearchLectureUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/SearchLectureUseCase.java @@ -1,9 +1,9 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.usecase; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto.SearchedLectureDto; +import java.util.List; public interface SearchLectureUseCase { + List searchLectures(Long userId, String type, String keyword); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/dto/SearchedLectureDto.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/dto/SearchedLectureDto.java index c6d12033..87fdc8e2 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/dto/SearchedLectureDto.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/application/usecase/dto/SearchedLectureDto.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - import lombok.Builder; import lombok.Getter; @@ -20,6 +19,7 @@ private SearchedLectureDto(boolean addable, Lecture lecture) { public static SearchedLectureDto of(boolean addable, Lecture lecture) { return SearchedLectureDto.builder() .addable(addable) - .lecture(lecture).build(); + .lecture(lecture) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CommonCulture.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CommonCulture.java index 804ea8ba..1d973426 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CommonCulture.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CommonCulture.java @@ -18,6 +18,7 @@ private CommonCulture(Lecture lecture, CommonCultureCategory commonCultureCatego public static CommonCulture of(Lecture lecture, CommonCultureCategory category) { return CommonCulture.builder() .lecture(lecture) - .commonCultureCategory(category).build(); + .commonCultureCategory(category) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CommonCultureCategory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CommonCultureCategory.java index 67c38d0d..f15c5ed6 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CommonCultureCategory.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CommonCultureCategory.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.lecture.domain.model; import java.util.List; - import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -9,11 +8,11 @@ @RequiredArgsConstructor public enum CommonCultureCategory { CHRISTIAN_A("기독교", 4, List.of(16, 17, 18, 19)), - CHRISTIAN_B("기독교",4, List.of(20, 21, 22, 23)), - EXPRESSION("사고와 표현", 3, List.of(16, 17, 18, 19, 20 ,21, 22, 23)), - ENGLISH("영어", 6, List.of(16, 17, 18, 19, 20 ,21, 22, 23)), + CHRISTIAN_B("기독교", 4, List.of(20, 21, 22, 23)), + EXPRESSION("사고와 표현", 3, List.of(16, 17, 18, 19, 20, 21, 22, 23)), + ENGLISH("영어", 6, List.of(16, 17, 18, 19, 20, 21, 22, 23)), CAREER("진로", 2, List.of(18, 19, 20, 21, 22)), - DIGITAL_LITERACY("진로와디지털리터러시", 2, List.of(23)); + DIGITAL_LITERACY("진로와디지털리터러시", 2, List.of(23)); private final String name; private final int totalCredit; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CoreCulture.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CoreCulture.java index 76ba1929..f5d5518a 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CoreCulture.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CoreCulture.java @@ -18,6 +18,7 @@ private CoreCulture(Lecture lecture, CoreCultureCategory coreCultureCategory) { public static CoreCulture of(Lecture lecture, CoreCultureCategory category) { return CoreCulture.builder() .lecture(lecture) - .coreCultureCategory(category).build(); + .coreCultureCategory(category) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java index 445ec4be..9fb8a4b5 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.lecture.domain.model; import java.util.Objects; - import lombok.Builder; import lombok.Getter; @@ -18,7 +17,8 @@ public class Lecture { private final int isRevoked; @Builder - private Lecture(Long id, String lectureCode, String name, int credit, int isRevoked, String duplicateCode) { + private Lecture(Long id, String lectureCode, String name, int credit, int isRevoked, + String duplicateCode) { this.id = id; this.lectureCode = lectureCode; this.name = name; @@ -33,7 +33,8 @@ public static Lecture from(String lectureCode) { .build(); } - public static Lecture of(String lectureCode, String name, int credit, int isRevoked, String duplicateCode) { + public static Lecture of(String lectureCode, String name, int credit, int isRevoked, + String duplicateCode) { return Lecture.builder() .lectureCode(lectureCode) .name(name) @@ -49,11 +50,13 @@ public boolean isCulture() { @Override public boolean equals(Object o) { - if (this == o) + if (this == o) { return true; - if (o == null || getClass() != o.getClass()) + } + if (o == null || getClass() != o.getClass()) { return false; - Lecture lecture = (Lecture)o; + } + Lecture lecture = (Lecture) o; return Objects.equals(lectureCode, lecture.lectureCode); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/MajorLecture.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/MajorLecture.java index 4759f3f3..d22c939f 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/MajorLecture.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/MajorLecture.java @@ -8,9 +8,9 @@ public class MajorLecture { private final Lecture lecture; private final String major; - private int isMandatory; private final int appliedStartEntryYear; private final int appliedEndEntryYear; + private int isMandatory; @Builder private MajorLecture(Lecture lecture, String major, int isMandatory, int appliedStartEntryYear, @@ -22,7 +22,8 @@ private MajorLecture(Lecture lecture, String major, int isMandatory, int applied this.appliedEndEntryYear = appliedEndEntryYear; } - public static MajorLecture of(Lecture lecture, String major, int isMandatory, int appliedStartEntryYear, + public static MajorLecture of(Lecture lecture, String major, int isMandatory, + int appliedStartEntryYear, int appliedEndEntryYear) { return MajorLecture.builder() .lecture(lecture) @@ -40,7 +41,8 @@ public void changeMandatoryToElectiveByEntryYearRange(int entryYear) { } private boolean checkMandatoryByEntryYear(int entryYear) { - return isMandatory == 1 && !(entryYear >= appliedStartEntryYear && entryYear <= appliedEndEntryYear); + return isMandatory == 1 && !(entryYear >= appliedStartEntryYear + && entryYear <= appliedEndEntryYear); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindBasicAcademicalCulturePersistenceAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindBasicAcademicalCulturePersistenceAdapter.java index c8e54cb7..a039727d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindBasicAcademicalCulturePersistenceAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindBasicAcademicalCulturePersistenceAdapter.java @@ -1,8 +1,5 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence; -import java.util.Set; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindBasicAcademicalCulturePort; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; @@ -10,12 +7,14 @@ import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.BasicAcademicalCultureRepository; import com.plzgraduate.myongjigraduatebe.user.domain.model.College; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.Set; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @PersistenceAdapter @RequiredArgsConstructor -public class FindBasicAcademicalCulturePersistenceAdapter implements FindBasicAcademicalCulturePort { +public class FindBasicAcademicalCulturePersistenceAdapter implements + FindBasicAcademicalCulturePort { private final BasicAcademicalCultureRepository basicAcademicalCultureRepository; private final LectureMapper lectureMapper; @@ -23,7 +22,8 @@ public class FindBasicAcademicalCulturePersistenceAdapter implements FindBasicAc @Override public Set findBasicAcademicalCulture(String major) { College userCollege = College.findBelongingCollege(major); - return basicAcademicalCultureRepository.findAllByCollege(userCollege.getName()).stream() + return basicAcademicalCultureRepository.findAllByCollege(userCollege.getName()) + .stream() .map(lectureMapper::mapToBasicAcademicalCultureLectureModel) .collect(Collectors.toSet()); } @@ -33,7 +33,8 @@ public Set findDuplicatedLecturesBetweenMajors(Us College primaryMajorCollage = College.findBelongingCollege(user.getPrimaryMajor()); College dualMajorCollage = College.findBelongingCollege(user.getDualMajor()); return basicAcademicalCultureRepository.findAllDuplicatedTakenByCollages(user.getId(), - primaryMajorCollage.getName(), dualMajorCollage.getName()).stream() + primaryMajorCollage.getName(), dualMajorCollage.getName()) + .stream() .map(lectureMapper::mapToBasicAcademicalCultureLectureModel) .collect(Collectors.toSet()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCommonCulturePersistenceAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCommonCulturePersistenceAdapter.java index ca4a1749..4945bc78 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCommonCulturePersistenceAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCommonCulturePersistenceAdapter.java @@ -1,17 +1,17 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence; -import static com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel.*; - -import java.util.Set; -import java.util.stream.Collectors; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel.BASIC; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel.ENG12; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel.ENG34; import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper.LectureMapper; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.CommonCultureRepository; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindCommonCulturePort; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper.LectureMapper; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.CommonCultureRepository; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.Set; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @PersistenceAdapter @@ -36,25 +36,33 @@ public Set findCommonCulture(User user) { } private Set findEngBasicCommonCultures(User user) { - return commonCultureRepository.findEngBasicGraduationCommonCulturesByEntryYear(user.getEntryYear()).stream() + return commonCultureRepository.findEngBasicGraduationCommonCulturesByEntryYear( + user.getEntryYear()) + .stream() .map(lectureMapper::mapToCommonCultureModel) .collect(Collectors.toSet()); } private Set findEng12CommonCultures(User user) { - return commonCultureRepository.findEng12GraduationCommonCulturesByEntryYear(user.getEntryYear()).stream() + return commonCultureRepository.findEng12GraduationCommonCulturesByEntryYear( + user.getEntryYear()) + .stream() .map(lectureMapper::mapToCommonCultureModel) .collect(Collectors.toSet()); } private Set findEng34CommonCultures(User user) { - return commonCultureRepository.findEng34GraduationCommonCulturesByEntryYear(user.getEntryYear()).stream() + return commonCultureRepository.findEng34GraduationCommonCulturesByEntryYear( + user.getEntryYear()) + .stream() .map(lectureMapper::mapToCommonCultureModel) .collect(Collectors.toSet()); } private Set findEngFreeCommonCultures(User user) { - return commonCultureRepository.findEngFreeGraduationCommonCulturesByEntryYear(user.getEntryYear()).stream() + return commonCultureRepository.findEngFreeGraduationCommonCulturesByEntryYear( + user.getEntryYear()) + .stream() .map(lectureMapper::mapToCommonCultureModel) .collect(Collectors.toSet()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCoreCulturePersistenceAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCoreCulturePersistenceAdapter.java index 273099bd..7c0e1dd6 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCoreCulturePersistenceAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCoreCulturePersistenceAdapter.java @@ -1,15 +1,13 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence; -import java.util.Set; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper.LectureMapper; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.CoreCultureRepository; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindCoreCulturePort; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper.LectureMapper; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.CoreCultureRepository; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.Set; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @PersistenceAdapter @@ -21,7 +19,8 @@ public class FindCoreCulturePersistenceAdapter implements FindCoreCulturePort { @Override public Set findCoreCulture(User user) { - return coreCultureRepository.findAllByEntryYear(user.getEntryYear()).stream() + return coreCultureRepository.findAllByEntryYear(user.getEntryYear()) + .stream() .map(lectureMapper::mapToCoreCultureModel) .collect(Collectors.toSet()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindMajorPersistenceAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindMajorPersistenceAdapter.java index b9a18e2c..8e48ecd4 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindMajorPersistenceAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindMajorPersistenceAdapter.java @@ -1,14 +1,12 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence; -import java.util.Set; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper.LectureMapper; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.MajorLectureRepository; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; - +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper.LectureMapper; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.MajorLectureRepository; +import java.util.Set; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @PersistenceAdapter @@ -20,7 +18,8 @@ public class FindMajorPersistenceAdapter implements FindMajorPort { @Override public Set findMajor(String major) { - return majorLectureRepository.findAllByMajor(major).stream() + return majorLectureRepository.findAllByMajor(major) + .stream() .map(mapper::mapToMajorLectureModel) .collect(Collectors.toSet()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/LecturePersistenceAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/LecturePersistenceAdapter.java index 334f7652..9dac3cbd 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/LecturePersistenceAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/LecturePersistenceAdapter.java @@ -1,8 +1,5 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence; -import java.util.List; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort; import com.plzgraduate.myongjigraduatebe.lecture.application.port.SearchLecturePort; @@ -11,7 +8,8 @@ import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper.LectureMapper; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureQueryRepository; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; - +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @PersistenceAdapter @@ -25,7 +23,8 @@ public class LecturePersistenceAdapter implements FindLecturePort, SearchLecture @Override public List findLecturesByLectureCodes(List lectureCodes) { - List lectureJpaEntities = lectureRepository.findByLectureCodeIn(lectureCodes); + List lectureJpaEntities = lectureRepository.findByLectureCodeIn( + lectureCodes); return lectureJpaEntities.stream() .map(lectureMapper::mapToLectureModel) .collect(Collectors.toList()); @@ -48,7 +47,8 @@ public Lecture findLectureById(final Long lectureId) { @Override public List searchLectureByNameOrCode(String type, String keyword) { - List lectureJpaEntities = lectureQueryRepository.searchByNameOrCode(type, keyword); + List lectureJpaEntities = lectureQueryRepository.searchByNameOrCode(type, + keyword); return lectureJpaEntities.stream() .map(lectureMapper::mapToLectureModel) .collect(Collectors.toList()); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/BasicAcademicalCultureLectureJpaEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/BasicAcademicalCultureLectureJpaEntity.java index 20da0ebd..9c53d735 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/BasicAcademicalCultureLectureJpaEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/BasicAcademicalCultureLectureJpaEntity.java @@ -8,7 +8,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; - import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -31,7 +30,8 @@ public class BasicAcademicalCultureLectureJpaEntity { private String college; @Builder - private BasicAcademicalCultureLectureJpaEntity(Long id, LectureJpaEntity lectureJpaEntity, String college) { + private BasicAcademicalCultureLectureJpaEntity(Long id, LectureJpaEntity lectureJpaEntity, + String college) { this.id = id; this.lectureJpaEntity = lectureJpaEntity; this.college = college; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/CommonCultureJpaEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/CommonCultureJpaEntity.java index b3fcc205..b49ba500 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/CommonCultureJpaEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/CommonCultureJpaEntity.java @@ -1,5 +1,6 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -10,9 +11,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; - -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory; - import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/CoreCultureJpaEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/CoreCultureJpaEntity.java index fe9d3ad2..38349be4 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/CoreCultureJpaEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/CoreCultureJpaEntity.java @@ -1,5 +1,6 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -10,9 +11,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; - -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory; - import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -40,7 +38,8 @@ public class CoreCultureJpaEntity { private int endEntryYear; @Builder - private CoreCultureJpaEntity(Long id, LectureJpaEntity lectureJpaEntity, CoreCultureCategory coreCultureCategory, + private CoreCultureJpaEntity(Long id, LectureJpaEntity lectureJpaEntity, + CoreCultureCategory coreCultureCategory, int startEntryYear, int endEntryYear) { this.id = id; this.lectureJpaEntity = lectureJpaEntity; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/LectureJpaEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/LectureJpaEntity.java index 7bcc18bd..a238833d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/LectureJpaEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/LectureJpaEntity.java @@ -6,7 +6,6 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; - import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -34,7 +33,8 @@ public class LectureJpaEntity { private int isRevoked; @Builder - private LectureJpaEntity(Long id, String lectureCode, String name, int credit, String duplicateCode, int isRevoked) { + private LectureJpaEntity(Long id, String lectureCode, String name, int credit, + String duplicateCode, int isRevoked) { this.id = id; this.lectureCode = lectureCode; this.name = name; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/MajorLectureJpaEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/MajorLectureJpaEntity.java index d70ac703..f4c5a3eb 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/MajorLectureJpaEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/entity/MajorLectureJpaEntity.java @@ -8,7 +8,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; - import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -37,7 +36,8 @@ public class MajorLectureJpaEntity { private int endEntryYear; @Builder - private MajorLectureJpaEntity(Long id, LectureJpaEntity lectureJpaEntity, String major, int mandatory, + private MajorLectureJpaEntity(Long id, LectureJpaEntity lectureJpaEntity, String major, + int mandatory, int startEntryYear, int endEntryYear) { this.id = id; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/mapper/LectureMapper.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/mapper/LectureMapper.java index cbe0ec18..7a48e157 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/mapper/LectureMapper.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/mapper/LectureMapper.java @@ -1,17 +1,16 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper; -import org.springframework.stereotype.Component; - -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.BasicAcademicalCultureLectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CommonCultureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CoreCultureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.MajorLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.BasicAcademicalCultureLectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CommonCultureJpaEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CoreCultureJpaEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.MajorLectureJpaEntity; +import org.springframework.stereotype.Component; @Component public class LectureMapper { @@ -96,6 +95,7 @@ public MajorLecture mapToMajorLectureModel(MajorLectureJpaEntity entity) { .major(entity.getMajor()) .appliedStartEntryYear(entity.getStartEntryYear()) .appliedEndEntryYear(entity.getEndEntryYear()) - .isMandatory(entity.getMandatory()).build(); + .isMandatory(entity.getMandatory()) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/BasicAcademicalCultureRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/BasicAcademicalCultureRepository.java index 0695ee28..bcfa11e7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/BasicAcademicalCultureRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/BasicAcademicalCultureRepository.java @@ -1,25 +1,26 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.BasicAcademicalCultureLectureJpaEntity; import java.util.List; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.BasicAcademicalCultureLectureJpaEntity; - -public interface BasicAcademicalCultureRepository extends JpaRepository { +public interface BasicAcademicalCultureRepository extends + JpaRepository { @Query("select bac from BasicAcademicalCultureLectureJpaEntity bac join fetch bac.lectureJpaEntity where bac.college = :college") List findAllByCollege(@Param("college") String college); @Query("SELECT pb " + "FROM BasicAcademicalCultureLectureJpaEntity pb " + - "JOIN BasicAcademicalCultureLectureJpaEntity db ON pb.lectureJpaEntity.id = db.lectureJpaEntity.id " + + "JOIN BasicAcademicalCultureLectureJpaEntity db ON pb.lectureJpaEntity.id = db.lectureJpaEntity.id " + + "JOIN TakenLectureJpaEntity tl ON pb.lectureJpaEntity.id = tl.lecture.id " + "WHERE tl.user.id = :userId " + "AND pb.college = :primary " + "AND db.college = :dual") - List findAllDuplicatedTakenByCollages(@Param("userId") Long id, + List findAllDuplicatedTakenByCollages( + @Param("userId") Long id, @Param("primary") String primaryMajorCollage, @Param("dual") String dualMajorCollage); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CommonCultureRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CommonCultureRepository.java index aa1e7d2f..6f62ec40 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CommonCultureRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CommonCultureRepository.java @@ -1,24 +1,26 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CommonCultureJpaEntity; import java.util.List; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CommonCultureJpaEntity; - public interface CommonCultureRepository extends JpaRepository { @Query("select cc from CommonCultureJpaEntity cc join fetch cc.lectureJpaEntity where cc.startEntryYear <= :entryYear and cc.endEntryYear >= :entryYear and cc.lectureJpaEntity.lectureCode not in ('KMA02123', 'KMA02124', 'KMA02125', 'KMA02126')") - List findEngBasicGraduationCommonCulturesByEntryYear(@Param("entryYear") int entryYear); + List findEngBasicGraduationCommonCulturesByEntryYear( + @Param("entryYear") int entryYear); @Query("select cc from CommonCultureJpaEntity cc join fetch cc.lectureJpaEntity where cc.startEntryYear <= :entryYear and cc.endEntryYear >= :entryYear and cc.lectureJpaEntity.lectureCode not in ('KMP02126','KMA02123', 'KMA02124', 'KMA02125', 'KMA02126')") - List findEng12GraduationCommonCulturesByEntryYear(@Param("entryYear") int entryYear); + List findEng12GraduationCommonCulturesByEntryYear( + @Param("entryYear") int entryYear); @Query("select cc from CommonCultureJpaEntity cc join fetch cc.lectureJpaEntity where cc.startEntryYear <= :entryYear and cc.endEntryYear >= :entryYear and cc.lectureJpaEntity.lectureCode not in ('KMP02126','KMA02106', 'KMA02107', 'KMA02108', 'KMA02109')") - List findEng34GraduationCommonCulturesByEntryYear(@Param("entryYear") int entryYear); + List findEng34GraduationCommonCulturesByEntryYear( + @Param("entryYear") int entryYear); @Query("select cc from CommonCultureJpaEntity cc join fetch cc.lectureJpaEntity where cc.startEntryYear <= :entryYear and cc.endEntryYear >= :entryYear and cc.commonCultureCategory != 'ENGLISH'") - List findEngFreeGraduationCommonCulturesByEntryYear(@Param("entryYear") int entryYear); + List findEngFreeGraduationCommonCulturesByEntryYear( + @Param("entryYear") int entryYear); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CoreCultureRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CoreCultureRepository.java index bca19e7a..18fc8062 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CoreCultureRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CoreCultureRepository.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CoreCultureJpaEntity; import java.util.List; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CoreCultureJpaEntity; - public interface CoreCultureRepository extends JpaRepository { @Query("select cc from CoreCultureJpaEntity cc join fetch cc.lectureJpaEntity where cc.startEntryYear <= :entryYear and cc.endEntryYear >= :entryYear") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/LectureQueryRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/LectureQueryRepository.java index b3ee17bd..6729709a 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/LectureQueryRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/LectureQueryRepository.java @@ -1,22 +1,19 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository; -import java.util.List; - -import org.springframework.stereotype.Repository; - import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.QLectureJpaEntity; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; - +import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; @Repository @RequiredArgsConstructor public class LectureQueryRepository { - private final JPAQueryFactory jpaQueryFactory; private static final QLectureJpaEntity lecture = QLectureJpaEntity.lectureJpaEntity; + private final JPAQueryFactory jpaQueryFactory; public List searchByNameOrCode(String type, String keyword) { return jpaQueryFactory.selectFrom(lecture) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/LectureRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/LectureRepository.java index 231131a6..f6f2ac2f 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/LectureRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/LectureRepository.java @@ -1,11 +1,9 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import java.util.List; - import org.springframework.data.jpa.repository.JpaRepository; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; - public interface LectureRepository extends JpaRepository { List findByLectureCodeIn(List lectureCodes); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepository.java index 0221acca..a2c804ff 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepository.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.MajorLectureJpaEntity; import java.util.List; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.MajorLectureJpaEntity; - public interface MajorLectureRepository extends JpaRepository { @Query("select m from MajorLectureJpaEntity m join fetch m.lectureJpaEntity where m.major = :major") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextApiPresentation.java index 13e868f2..5a5e2b38 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextApiPresentation.java @@ -1,18 +1,16 @@ package com.plzgraduate.myongjigraduatebe.parsing.api; -import javax.validation.Valid; - -import org.springframework.web.bind.annotation.RequestBody; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.parsing.api.dto.request.ParsingTextRequest; - import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import javax.validation.Valid; +import org.springframework.web.bind.annotation.RequestBody; @Tag(name = "ParsingText", description = "파싱 텍스트를 등록하는 API") public interface ParsingTextApiPresentation { @Parameter(name = "userId", description = "로그인한 유저의 PK값") - void enrollParsingText(@LoginUser Long userId, @Valid @RequestBody ParsingTextRequest parsingTextRequest); + void enrollParsingText(@LoginUser Long userId, + @Valid @RequestBody ParsingTextRequest parsingTextRequest); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextController.java index 2af6d648..7ee9618d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextController.java @@ -1,34 +1,34 @@ package com.plzgraduate.myongjigraduatebe.parsing.api; -import javax.validation.Valid; - -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; import com.plzgraduate.myongjigraduatebe.parsing.api.dto.request.ParsingTextRequest; import com.plzgraduate.myongjigraduatebe.parsing.application.usecase.ParsingTextHistoryUseCase; import com.plzgraduate.myongjigraduatebe.parsing.application.usecase.ParsingTextUseCase; - +import javax.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; @WebAdapter @RequestMapping("/api/v1/parsing-text") @RequiredArgsConstructor -public class ParsingTextController implements ParsingTextApiPresentation{ +public class ParsingTextController implements ParsingTextApiPresentation { private final ParsingTextUseCase parsingTextUseCase; private final ParsingTextHistoryUseCase parsingTextHistoryUseCase; @PostMapping - public void enrollParsingText(@LoginUser Long userId, @Valid @RequestBody ParsingTextRequest parsingTextRequest) { + public void enrollParsingText(@LoginUser Long userId, + @Valid @RequestBody ParsingTextRequest parsingTextRequest) { try { parsingTextUseCase.enrollParsingText(userId, parsingTextRequest.getParsingText()); - parsingTextHistoryUseCase.generateSucceedParsingTextHistory(userId, parsingTextRequest.getParsingText()); + parsingTextHistoryUseCase.generateSucceedParsingTextHistory(userId, + parsingTextRequest.getParsingText()); } catch (Exception e) { - parsingTextHistoryUseCase.generateFailedParsingTextHistory(userId, parsingTextRequest.getParsingText()); + parsingTextHistoryUseCase.generateFailedParsingTextHistory(userId, + parsingTextRequest.getParsingText()); throw e; } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/dto/request/ParsingTextRequest.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/dto/request/ParsingTextRequest.java index 1f0ccbbe..7ab96250 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/dto/request/ParsingTextRequest.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/api/dto/request/ParsingTextRequest.java @@ -1,8 +1,7 @@ package com.plzgraduate.myongjigraduatebe.parsing.api.dto.request; -import javax.validation.constraints.NotNull; - import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.NotNull; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/port/SaveParsingTextHistoryPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/port/SaveParsingTextHistoryPort.java index b0598c53..25fae48c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/port/SaveParsingTextHistoryPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/port/SaveParsingTextHistoryPort.java @@ -3,5 +3,6 @@ import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingTextHistory; public interface SaveParsingTextHistoryPort { + void saveParsingTextHistory(ParsingTextHistory parsingTextHistory); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextHistoryService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextHistoryService.java index 75f69cde..23a737d0 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextHistoryService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextHistoryService.java @@ -1,16 +1,14 @@ package com.plzgraduate.myongjigraduatebe.parsing.application.service; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.parsing.application.port.SaveParsingTextHistoryPort; import com.plzgraduate.myongjigraduatebe.parsing.application.usecase.ParsingTextHistoryUseCase; import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingTextHistory; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.transaction.annotation.Transactional; @Slf4j @UseCase @@ -24,12 +22,14 @@ class ParsingTextHistoryService implements ParsingTextHistoryUseCase { @Override public void generateSucceedParsingTextHistory(Long userId, String parsingText) { User user = findUserUseCase.findUserById(userId); - saveParsingTextHistoryPort.saveParsingTextHistory(ParsingTextHistory.success(user, parsingText)); + saveParsingTextHistoryPort.saveParsingTextHistory( + ParsingTextHistory.success(user, parsingText)); } @Override public void generateFailedParsingTextHistory(Long userId, String parsingText) { User user = findUserUseCase.findUserById(userId); - saveParsingTextHistoryPort.saveParsingTextHistory(ParsingTextHistory.fail(user, parsingText)); + saveParsingTextHistoryPort.saveParsingTextHistory( + ParsingTextHistory.fail(user, parsingText)); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextService.java index 6b1fa30b..52ef96f7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextService.java @@ -1,14 +1,9 @@ package com.plzgraduate.myongjigraduatebe.parsing.application.service; -import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.INCORRECT_STUDENT_NUMBER; import static com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory.ASSOCIATED_MAJOR; import static com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory.DOUBLE_SUB; -import java.util.List; -import java.util.stream.Collectors; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase; import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; import com.plzgraduate.myongjigraduatebe.core.exception.InvalidPdfException; @@ -24,9 +19,11 @@ import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationCommand; import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.transaction.annotation.Transactional; @Slf4j @UseCase @@ -66,17 +63,20 @@ private void deleteTakenLecturesIfAlreadyEnrolled(User user) { private void saveTakenLectures(User user, ParsingInformation parsingInformation) { List parsingTakenLectureDtoList = parsingInformation.getTakenLectureInformation(); - List saveTakenLectureCommand = getSaveTakenLectureCommand(parsingTakenLectureDtoList); + List saveTakenLectureCommand = getSaveTakenLectureCommand( + parsingTakenLectureDtoList); saveTakenLectureFromParsingTextUseCase.saveTakenLectures(user, saveTakenLectureCommand); } private User updateUser(User user, ParsingInformation parsingInformation) { - UpdateStudentInformationCommand updateStudentInfoCommand = UpdateStudentInformationCommand.of(user, parsingInformation); + UpdateStudentInformationCommand updateStudentInfoCommand = UpdateStudentInformationCommand.of( + user, parsingInformation); return updateStudentInformationUseCase.updateUser(updateStudentInfoCommand); } private void validateParsingText(String parsingText) { - if (parsingText.trim().isEmpty()) { + if (parsingText.trim() + .isEmpty()) { throw new InvalidPdfException("PDF를 인식하지 못했습니다. 채널톡으로 문의 바랍니다."); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/usecase/ParsingTextHistoryUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/usecase/ParsingTextHistoryUseCase.java index d7c3b6d2..6812ead2 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/usecase/ParsingTextHistoryUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/application/usecase/ParsingTextHistoryUseCase.java @@ -1,6 +1,7 @@ package com.plzgraduate.myongjigraduatebe.parsing.application.usecase; public interface ParsingTextHistoryUseCase { + void generateSucceedParsingTextHistory(Long userId, String parsingText); void generateFailedParsingTextHistory(Long userId, String parsingText); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingInformation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingInformation.java index 9e1e138c..101217bb 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingInformation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingInformation.java @@ -1,17 +1,16 @@ package com.plzgraduate.myongjigraduatebe.parsing.domain; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; +import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; - -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; -import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; - import lombok.Builder; import lombok.Getter; @Getter public class ParsingInformation { + private final String studentName; private final String studentNumber; private final String major; @@ -23,8 +22,10 @@ public class ParsingInformation { private final List takenLectureInformation; @Builder - public ParsingInformation(String studentName, String studentNumber, String major, String changeMajor, String subMajor, String dualMajor, - String associatedMajor, StudentCategory studentCategory, List takenLectureInformation) { + public ParsingInformation(String studentName, String studentNumber, String major, + String changeMajor, String subMajor, String dualMajor, + String associatedMajor, StudentCategory studentCategory, + List takenLectureInformation) { this.studentName = studentName; this.studentNumber = studentNumber; this.major = major; @@ -84,9 +85,9 @@ private static ParsingStudentCategoryDto parseStudentCategory(String[] splitText List categories = new ArrayList<>(); String[] parts = secondLineText.split(", "); String[] thirdLineParts = thirdLineText.split(", "); - if(thirdLineParts.length == 4) { + if (thirdLineParts.length == 4) { String part = thirdLineParts[3]; - if(part.startsWith("전과내역 -")) { + if (part.startsWith("전과내역 -")) { categories.add("전과"); changeMajor = part.substring("전과내역 - ".length()); } @@ -105,13 +106,15 @@ private static ParsingStudentCategoryDto parseStudentCategory(String[] splitText } } studentCategory = StudentCategory.from(categories); - return ParsingStudentCategoryDto.of(changeMajor, subMajor, dualMajor, associatedMajor, studentCategory); + return ParsingStudentCategoryDto.of(changeMajor, subMajor, dualMajor, associatedMajor, + studentCategory); } private static List parseTakenLectureInformation(String[] splitText) { List takenLectureInformation = new ArrayList<>(); for (int i = 16; i < splitText.length; i += 7) { - if (i + 3 < splitText.length && !Pattern.matches("^[A-Z]+$", splitText[i + 3].substring(0, 1))) { + if (i + 3 < splitText.length && !Pattern.matches("^[A-Z]+$", + splitText[i + 3].substring(0, 1))) { return takenLectureInformation; } int year = Integer.parseInt(splitText[i + 1].split(" ")[0].substring(0, 4)); @@ -119,7 +122,8 @@ private static List parseTakenLectureInformation(String[ String code = splitText[i + 3]; char grade = splitText[i + 6].charAt(0); if (grade != 'F' && grade != 'N' && grade != 'R') { - takenLectureInformation.add(ParsingTakenLectureDto.of(code, year, Semester.of(semester))); + takenLectureInformation.add( + ParsingTakenLectureDto.of(code, year, Semester.of(semester))); } if (i + 7 < splitText.length && Character.isDigit(splitText[i + 7].charAt(0))) { i++; @@ -131,9 +135,9 @@ private static List parseTakenLectureInformation(String[ private static int getIndexStudentNameAndNumber(String text) { String[] parts = text.split(", "); int index = 0; - for(String part: parts) { - if(part.startsWith("현학적 -")) { - return index-1; + for (String part : parts) { + if (part.startsWith("현학적 -")) { + return index - 1; } index++; } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingStudentCategoryDto.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingStudentCategoryDto.java index db086160..cf0dd16e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingStudentCategoryDto.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingStudentCategoryDto.java @@ -1,12 +1,12 @@ package com.plzgraduate.myongjigraduatebe.parsing.domain; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; - import lombok.Builder; import lombok.Getter; @Getter class ParsingStudentCategoryDto { + private final String changeMajor; private final String dualMajor; private final String subMajor; @@ -14,7 +14,8 @@ class ParsingStudentCategoryDto { private final StudentCategory studentCategory; @Builder - private ParsingStudentCategoryDto(String changeMajor, String dualMajor, String subMajor, String associatedMajor, + private ParsingStudentCategoryDto(String changeMajor, String dualMajor, String subMajor, + String associatedMajor, StudentCategory studentCategory) { this.changeMajor = changeMajor; this.dualMajor = dualMajor; @@ -23,7 +24,8 @@ private ParsingStudentCategoryDto(String changeMajor, String dualMajor, String s this.studentCategory = studentCategory; } - public static ParsingStudentCategoryDto of(String changeMajor, String subMajor, String dualMajor, + public static ParsingStudentCategoryDto of(String changeMajor, String subMajor, + String dualMajor, String associatedMajor, StudentCategory studentCategory) { return ParsingStudentCategoryDto.builder() .changeMajor(changeMajor) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTakenLectureDto.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTakenLectureDto.java index 1da2fe48..49a7243a 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTakenLectureDto.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTakenLectureDto.java @@ -1,12 +1,12 @@ package com.plzgraduate.myongjigraduatebe.parsing.domain; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; - import lombok.Builder; import lombok.Getter; @Getter public class ParsingTakenLectureDto { + private final String lectureCode; private final int year; private final Semester semester; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTextHistory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTextHistory.java index ca7a5916..e2c9c74c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTextHistory.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTextHistory.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.parsing.domain; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.Builder; import lombok.Getter; @@ -14,12 +13,14 @@ public class ParsingTextHistory { private final ParsingResult parsingResult; @Builder - private ParsingTextHistory(Long id, User user, String parsingText, ParsingResult parsingResult) { + private ParsingTextHistory(Long id, User user, String parsingText, + ParsingResult parsingResult) { this.id = id; this.user = user; this.parsingText = parsingText; this.parsingResult = parsingResult; } + public static ParsingTextHistory success(User user, String parsingText) { return ParsingTextHistory.builder() .user(user) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/ParsingTextHistoryAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/ParsingTextHistoryAdapter.java index d141a583..3bdf9fcb 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/ParsingTextHistoryAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/ParsingTextHistoryAdapter.java @@ -7,15 +7,16 @@ import com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.mapper.ParsingTextHistoryMapper; import com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.repository.ParsingTextRepository; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; @PersistenceAdapter @RequiredArgsConstructor -public class ParsingTextHistoryAdapter implements SaveParsingTextHistoryPort, DeleteParsingTextHistoryPort { +public class ParsingTextHistoryAdapter implements SaveParsingTextHistoryPort, + DeleteParsingTextHistoryPort { private final ParsingTextRepository parsingTextRepository; private final ParsingTextHistoryMapper parsingTextHistoryMapper; + @Override public void saveParsingTextHistory(ParsingTextHistory parsingTextHistory) { parsingTextRepository.save(parsingTextHistoryMapper.mapToJpaEntity(parsingTextHistory)); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/entity/ParsingTextHistoryJpaEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/entity/ParsingTextHistoryJpaEntity.java index 6b058582..b1382c85 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/entity/ParsingTextHistoryJpaEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/entity/ParsingTextHistoryJpaEntity.java @@ -1,5 +1,8 @@ package com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.entity; +import com.plzgraduate.myongjigraduatebe.core.entity.TimeBaseEntity; +import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingResult; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -10,11 +13,6 @@ import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.Table; - -import com.plzgraduate.myongjigraduatebe.core.entity.TimeBaseEntity; -import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingResult; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; - import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/mapper/ParsingTextHistoryMapper.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/mapper/ParsingTextHistoryMapper.java index a88846ac..46aa13a6 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/mapper/ParsingTextHistoryMapper.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/mapper/ParsingTextHistoryMapper.java @@ -1,11 +1,10 @@ package com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.mapper; -import org.springframework.stereotype.Component; - -import com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.entity.ParsingTextHistoryJpaEntity; import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingTextHistory; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.entity.ParsingTextHistoryJpaEntity; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import org.springframework.stereotype.Component; @Component public class ParsingTextHistoryMapper { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/repository/ParsingTextRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/repository/ParsingTextRepository.java index 9fdcbcd1..614792c1 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/repository/ParsingTextRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/repository/ParsingTextRepository.java @@ -1,9 +1,8 @@ package com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.repository; -import org.springframework.data.jpa.repository.JpaRepository; - import com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.entity.ParsingTextHistoryJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import org.springframework.data.jpa.repository.JpaRepository; public interface ParsingTextRepository extends JpaRepository { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/FindTakenLectureApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/FindTakenLectureApiPresentation.java index a14e7cc6..c0a7ffd7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/FindTakenLectureApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/FindTakenLectureApiPresentation.java @@ -2,7 +2,6 @@ import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.response.FindTakenLectureResponse; - import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/FindTakenLectureController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/FindTakenLectureController.java index 8b06749e..51753804 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/FindTakenLectureController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/FindTakenLectureController.java @@ -1,15 +1,13 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.api; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; import com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.response.FindTakenLectureResponse; import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; @WebAdapter @RequestMapping("/api/v1/taken-lectures") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/UpdateTakenLectureApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/UpdateTakenLectureApiPresentation.java index ce892149..7a993cb3 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/UpdateTakenLectureApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/UpdateTakenLectureApiPresentation.java @@ -1,15 +1,12 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.api; -import javax.validation.Valid; - -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.request.GenerateCustomizedTakenLectureRequest; - import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import javax.validation.Valid; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; @Tag(name = "UpdateTakenLecture", description = "수강과목을 수정하는 API") public interface UpdateTakenLectureApiPresentation { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/UpdateTakenLectureController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/UpdateTakenLectureController.java index 72cb17e3..fbe0b698 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/UpdateTakenLectureController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/UpdateTakenLectureController.java @@ -1,20 +1,17 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.api; -import javax.validation.Valid; - -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; import com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.request.GenerateCustomizedTakenLectureRequest; import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase; import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.save.GenerateCustomizedTakenLectureUseCase; - +import javax.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; @WebAdapter @RequestMapping("/api/v1/taken-lectures") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/dto/response/FindTakenLectureResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/dto/response/FindTakenLectureResponse.java index ebe76940..75e90ab7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/dto/response/FindTakenLectureResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/dto/response/FindTakenLectureResponse.java @@ -1,14 +1,12 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.response; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import io.swagger.v3.oas.annotations.media.Schema; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; - -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - -import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -30,9 +28,11 @@ private FindTakenLectureResponse(int totalCredit, List tak public static FindTakenLectureResponse from(TakenLectureInventory takenLectureInventory) { return FindTakenLectureResponse.builder() .totalCredit(takenLectureInventory.calculateTotalCredit()) - .takenLectures(takenLectureInventory.getTakenLectures().stream() + .takenLectures(takenLectureInventory.getTakenLectures() + .stream() .sorted(Comparator.comparing(TakenLecture::getYear, Collections.reverseOrder()) - .thenComparing(TakenLecture::getSemester, Comparator.nullsFirst(Comparator.reverseOrder())) + .thenComparing(TakenLecture::getSemester, + Comparator.nullsFirst(Comparator.reverseOrder())) .thenComparing(TakenLecture::getCreatedAt, Comparator.reverseOrder())) .map(TakenLectureResponse::from) .collect(Collectors.toList())) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/dto/response/TakenLectureResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/dto/response/TakenLectureResponse.java index 3413bf26..c7d68dc1 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/dto/response/TakenLectureResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/dto/response/TakenLectureResponse.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.response; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; - import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; @@ -23,7 +22,8 @@ public class TakenLectureResponse { private final int credit; @Builder - private TakenLectureResponse(Long id, String year, String semester, String lectureCode, String lectureName, + private TakenLectureResponse(Long id, String year, String semester, String lectureCode, + String lectureName, int credit) { this.id = id; this.year = year; @@ -36,11 +36,16 @@ private TakenLectureResponse(Long id, String year, String semester, String lectu public static TakenLectureResponse from(TakenLecture takenLecture) { return TakenLectureResponse.builder() .id(takenLecture.getId()) - .year(takenLecture.getYear() == 2099 ? "CUSTOM" : String.valueOf(takenLecture.getYear())) - .semester(takenLecture.getSemester() == null ? "CUSTOM" : takenLecture.getSemester().getName()) - .lectureCode(takenLecture.getLecture().getLectureCode()) - .lectureName(takenLecture.getLecture().getName()) - .credit(takenLecture.getLecture().getCredit()) + .year( + takenLecture.getYear() == 2099 ? "CUSTOM" : String.valueOf(takenLecture.getYear())) + .semester(takenLecture.getSemester() == null ? "CUSTOM" : takenLecture.getSemester() + .getName()) + .lectureCode(takenLecture.getLecture() + .getLectureCode()) + .lectureName(takenLecture.getLecture() + .getName()) + .credit(takenLecture.getLecture() + .getCredit()) .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/DeleteTakenLecturePort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/DeleteTakenLecturePort.java index a507487c..459fb663 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/DeleteTakenLecturePort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/DeleteTakenLecturePort.java @@ -1,10 +1,9 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.port; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.user.domain.model.User; public interface DeleteTakenLecturePort { + void deleteAllTakenLecturesByUser(User user); void deleteTakenLectureById(Long deleteId); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/FindTakenLecturePort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/FindTakenLecturePort.java index 52f4e363..79ba65f7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/FindTakenLecturePort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/FindTakenLecturePort.java @@ -1,10 +1,9 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.port; -import java.util.List; -import java.util.Set; - import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.List; +import java.util.Set; public interface FindTakenLecturePort { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/SaveTakenLecturePort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/SaveTakenLecturePort.java index 8dc5e3d6..43d214ed 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/SaveTakenLecturePort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/port/SaveTakenLecturePort.java @@ -1,8 +1,7 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.port; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; +import java.util.List; public interface SaveTakenLecturePort { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/delete/DeleteTakenLectureService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/delete/DeleteTakenLectureService.java index 5a7e0a13..7be87af3 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/delete/DeleteTakenLectureService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/delete/DeleteTakenLectureService.java @@ -1,15 +1,13 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.service.delete; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase; import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.DeleteTakenLecturePort; +import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/find/FindTakenLectureService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/find/FindTakenLectureService.java index 4644d888..5b0eb4e9 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/find/FindTakenLectureService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/find/FindTakenLectureService.java @@ -1,10 +1,5 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.service.find; -import java.util.HashSet; -import java.util.List; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.FindTakenLecturePort; import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; @@ -12,8 +7,10 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.HashSet; +import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/GenerateCustomizedTakenLectureService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/GenerateCustomizedTakenLectureService.java index 64631adb..58d08ee1 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/GenerateCustomizedTakenLectureService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/GenerateCustomizedTakenLectureService.java @@ -1,7 +1,5 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.service.save; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort; @@ -11,13 +9,14 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional @RequiredArgsConstructor -public class GenerateCustomizedTakenLectureService implements GenerateCustomizedTakenLectureUseCase { +public class GenerateCustomizedTakenLectureService implements + GenerateCustomizedTakenLectureUseCase { private final FindUserUseCase findUserUseCase; private final FindLecturePort findLecturePort; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/SaveTakenLectureFromParsingTextService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/SaveTakenLectureFromParsingTextService.java index e41532ed..28b2ade2 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/SaveTakenLectureFromParsingTextService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/SaveTakenLectureFromParsingTextService.java @@ -1,13 +1,5 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.service.save; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.FindLecturesUseCase; @@ -17,9 +9,14 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInformation; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional @@ -31,13 +28,16 @@ class SaveTakenLectureFromParsingTextService implements SaveTakenLectureFromPars private final FindLecturesUseCase findLecturesUseCase; @Override - public void saveTakenLectures(User user, List takenLectureInformationList) { + public void saveTakenLectures(User user, + List takenLectureInformationList) { Map lectureMap = makeLectureMapByLectureCodes(takenLectureInformationList); - List takenLectures = makeTakenLectures(user, takenLectureInformationList, lectureMap); + List takenLectures = makeTakenLectures(user, takenLectureInformationList, + lectureMap); saveTakenLecturePort.saveTakenLectures(takenLectures); } - private List makeTakenLectures(User user, List takenLectureInformationList, + private List makeTakenLectures(User user, + List takenLectureInformationList, Map lectureMap) { return takenLectureInformationList.stream() .map(takenLectureInformation -> { @@ -45,14 +45,16 @@ private List makeTakenLectures(User user, List lectureMap, TakenLectureInformation takenLectureInformation) { return Optional.ofNullable(lectureMap.get(takenLectureInformation.getLectureCode())) .orElseThrow(() -> { - log.warn("Not Found Lecture in Database: {}", takenLectureInformation.getLectureCode()); + log.warn("Not Found Lecture in Database: {}", + takenLectureInformation.getLectureCode()); return new IllegalArgumentException(ErrorCode.NON_EXISTED_LECTURE.toString()); }); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/delete/DeleteTakenLectureUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/delete/DeleteTakenLectureUseCase.java index e6164c71..8d518f2e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/delete/DeleteTakenLectureUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/delete/DeleteTakenLectureUseCase.java @@ -3,6 +3,7 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; public interface DeleteTakenLectureUseCase { + void deleteAllTakenLecturesByUser(User user); void deleteTakenLecture(Long userId, Long deletedTakenLectureId); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/find/FindTakenLectureUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/find/FindTakenLectureUseCase.java index 0d3912c5..2fed92cd 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/find/FindTakenLectureUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/find/FindTakenLectureUseCase.java @@ -3,5 +3,6 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; public interface FindTakenLectureUseCase { + TakenLectureInventory findTakenLectures(Long userId); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/save/GenerateCustomizedTakenLectureUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/save/GenerateCustomizedTakenLectureUseCase.java index c2b2f78f..e9dffc91 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/save/GenerateCustomizedTakenLectureUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/save/GenerateCustomizedTakenLectureUseCase.java @@ -2,5 +2,6 @@ public interface GenerateCustomizedTakenLectureUseCase { + void generateCustomizedTakenLecture(Long userId, Long addedTakenLectureId); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/save/SaveTakenLectureFromParsingTextUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/save/SaveTakenLectureFromParsingTextUseCase.java index cac9442a..a1b96702 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/save/SaveTakenLectureFromParsingTextUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/usecase/save/SaveTakenLectureFromParsingTextUseCase.java @@ -1,9 +1,8 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.save; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInformation; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.List; public interface SaveTakenLectureFromParsingTextUseCase { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/Semester.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/Semester.java index 63fc56e5..991e5e7e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/Semester.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/Semester.java @@ -2,7 +2,6 @@ import java.util.Arrays; import java.util.Objects; - import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLecture.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLecture.java index d1aa0f00..5a76aed5 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLecture.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLecture.java @@ -1,11 +1,9 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.domain.model; -import java.time.Instant; -import java.util.Objects; - import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - +import java.time.Instant; +import java.util.Objects; import lombok.Builder; import lombok.Getter; @@ -20,7 +18,8 @@ public class TakenLecture { private final Instant createdAt; @Builder - private TakenLecture(Long id, User user, Lecture lecture, Integer year, Semester semester, Instant createdAt) { + private TakenLecture(Long id, User user, Lecture lecture, Integer year, Semester semester, + Instant createdAt) { this.id = id; this.user = user; this.lecture = lecture; @@ -52,11 +51,13 @@ public boolean takenAfter(int year) { @Override public boolean equals(Object o) { - if (this == o) + if (this == o) { return true; - if (o == null || getClass() != o.getClass()) + } + if (o == null || getClass() != o.getClass()) { return false; - TakenLecture that = (TakenLecture)o; + } + TakenLecture that = (TakenLecture) o; return Objects.equals(user, that.user) && Objects.equals(lecture, that.lecture) && Objects.equals(year, that.year) && Objects.equals(semester, that.semester); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInformation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInformation.java index d45a0546..5be38fe9 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInformation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInformation.java @@ -17,7 +17,8 @@ private TakenLectureInformation(String lectureCode, int year, Semester semester) this.semester = semester; } - public static TakenLectureInformation createTakenLectureInformation(String lectureCode, int year, Semester semester) { + public static TakenLectureInformation createTakenLectureInformation(String lectureCode, + int year, Semester semester) { return TakenLectureInformation.builder() .lectureCode(lectureCode) .year(year) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventory.java index afafa30a..608674fd 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventory.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventory.java @@ -1,12 +1,10 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.domain.model; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; - -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - import lombok.Builder; public class TakenLectureInventory { @@ -18,6 +16,12 @@ private TakenLectureInventory(Set takenLecture) { this.takenLecture = takenLecture; } + public static TakenLectureInventory from(Set takenLectures) { + return TakenLectureInventory.builder() + .takenLecture(takenLectures) + .build(); + } + public Set getTakenLectures() { return Collections.unmodifiableSet(takenLecture); } @@ -28,16 +32,11 @@ public TakenLectureInventory copy() { public Set getCultureLectures() { return takenLecture.stream() - .filter(taken -> taken.getLecture().isCulture()) + .filter(taken -> taken.getLecture() + .isCulture()) .collect(Collectors.toSet()); } - public static TakenLectureInventory from(Set takenLectures) { - return TakenLectureInventory.builder() - .takenLecture(takenLectures) - .build(); - } - public void handleFinishedTakenLectures(Set finishedTakenLecture) { takenLecture.removeAll(finishedTakenLecture); } @@ -53,7 +52,8 @@ public void sync(Set finishedLectures) { public int calculateTotalCredit() { int totalCredit = this.takenLecture .stream() - .mapToInt(takenLecture -> takenLecture.getLecture().getCredit()) + .mapToInt(takenLecture -> takenLecture.getLecture() + .getCredit()) .sum(); if (checkChapelCountIsFour(this.takenLecture)) { totalCredit += 2; @@ -64,7 +64,9 @@ public int calculateTotalCredit() { private boolean checkChapelCountIsFour(Set takenLectures) { long chapelCount = takenLectures .stream() - .filter(takenLecture -> takenLecture.getLecture().getLectureCode().equals("KMA02101")) + .filter(takenLecture -> takenLecture.getLecture() + .getLectureCode() + .equals("KMA02101")) .count(); return chapelCount >= 4; } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLecturePersistenceAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLecturePersistenceAdapter.java index 054d7035..9a51dc12 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLecturePersistenceAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLecturePersistenceAdapter.java @@ -1,9 +1,5 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.DeleteTakenLecturePort; import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.FindTakenLecturePort; @@ -13,12 +9,15 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.mapper.TakenLectureMapper; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; - +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @PersistenceAdapter @RequiredArgsConstructor -class TakenLecturePersistenceAdapter implements FindTakenLecturePort, SaveTakenLecturePort, DeleteTakenLecturePort { +class TakenLecturePersistenceAdapter implements FindTakenLecturePort, SaveTakenLecturePort, + DeleteTakenLecturePort { private final TakenLectureRepository takenLectureRepository; private final TakenLectureMapper takenLectureMapper; @@ -54,7 +53,8 @@ public void saveTakenLectures(List takenLectures) { @Override public void saveTakenLecture(final TakenLecture takenLecture) { - TakenLectureJpaEntity takenLectureJpaEntity = takenLectureMapper.mapToJpaEntity(takenLecture); + TakenLectureJpaEntity takenLectureJpaEntity = takenLectureMapper.mapToJpaEntity( + takenLecture); takenLectureRepository.save(takenLectureJpaEntity); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLectureRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLectureRepository.java index 6ba91b45..084d969d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLectureRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLectureRepository.java @@ -1,15 +1,13 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence; +import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import java.util.List; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; - public interface TakenLectureRepository extends JpaRepository { @Query("delete from TakenLectureJpaEntity t where t.user = :user") @@ -17,5 +15,6 @@ public interface TakenLectureRepository extends JpaRepository findTakenLectureJpaEntityWithLectureByUser(@Param("user") UserJpaEntity user); + List findTakenLectureJpaEntityWithLectureByUser( + @Param("user") UserJpaEntity user); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/entity/TakenLectureJpaEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/entity/TakenLectureJpaEntity.java index 73dbd543..3cdf24e2 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/entity/TakenLectureJpaEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/entity/TakenLectureJpaEntity.java @@ -1,5 +1,9 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity; +import com.plzgraduate.myongjigraduatebe.core.entity.TimeBaseEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -9,12 +13,6 @@ import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.Table; - -import com.plzgraduate.myongjigraduatebe.core.entity.TimeBaseEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; - import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/mapper/TakenLectureMapper.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/mapper/TakenLectureMapper.java index 951274f3..4b5b7c29 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/mapper/TakenLectureMapper.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/mapper/TakenLectureMapper.java @@ -1,13 +1,12 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.mapper; -import org.springframework.stereotype.Component; - -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import org.springframework.stereotype.Component; @Component public class TakenLectureMapper { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdApiPresentation.java index 35a43988..e51dff8d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdApiPresentation.java @@ -1,15 +1,11 @@ package com.plzgraduate.myongjigraduatebe.user.api.findauthid; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Pattern; - -import org.springframework.web.bind.annotation.PathVariable; - import com.plzgraduate.myongjigraduatebe.user.api.findauthid.dto.response.UserAuthIdResponse; - import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; +import javax.validation.constraints.Pattern; +import org.springframework.web.bind.annotation.PathVariable; @Tag(name = "FindAuthId", description = "학번으로 해당 학생의 아이디를 조회하는 API") public interface FindAuthIdApiPresentation { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdController.java index bda63075..218a589e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdController.java @@ -1,18 +1,15 @@ package com.plzgraduate.myongjigraduatebe.user.api.findauthid; +import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; +import com.plzgraduate.myongjigraduatebe.user.api.findauthid.dto.response.UserAuthIdResponse; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserAuthIdUseCase; import javax.validation.constraints.Pattern; - +import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; -import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; -import com.plzgraduate.myongjigraduatebe.user.api.findauthid.dto.response.UserAuthIdResponse; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserAuthIdUseCase; - -import lombok.RequiredArgsConstructor; - @WebAdapter @RequestMapping("/api/v1/users") @RequiredArgsConstructor diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/dto/response/UserAuthIdResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/dto/response/UserAuthIdResponse.java index 3274382d..3d067bda 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/dto/response/UserAuthIdResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/dto/response/UserAuthIdResponse.java @@ -23,6 +23,7 @@ private UserAuthIdResponse(String authId, String studentNumber) { public static UserAuthIdResponse of(String encryptedAutId, String studentNumber) { return UserAuthIdResponse.builder() .authId(encryptedAutId) - .studentNumber(studentNumber).build(); + .studentNumber(studentNumber) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationApiPresentation.java index 76b95205..d3dad2ee 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationApiPresentation.java @@ -2,7 +2,6 @@ import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.user.api.finduserinformation.dto.response.UserInformationResponse; - import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationController.java index 9a04f5da..ed0a6107 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationController.java @@ -1,15 +1,13 @@ package com.plzgraduate.myongjigraduatebe.user.api.finduserinformation; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserInformationUseCase; import com.plzgraduate.myongjigraduatebe.user.api.finduserinformation.dto.response.UserInformationResponse; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserInformationUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; @WebAdapter @RequestMapping("/api/v1/users/me") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/dto/response/UserInformationResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/dto/response/UserInformationResponse.java index c40c2f98..3ebd9ef2 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/dto/response/UserInformationResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/dto/response/UserInformationResponse.java @@ -1,11 +1,9 @@ package com.plzgraduate.myongjigraduatebe.user.api.finduserinformation.dto.response; -import java.util.ArrayList; -import java.util.List; - import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import io.swagger.v3.oas.annotations.media.Schema; +import java.util.ArrayList; +import java.util.List; import lombok.Builder; import lombok.Getter; @@ -23,7 +21,8 @@ public class UserInformationResponse { private final boolean graduated; @Builder - private UserInformationResponse(String studentNumber, String studentName, int totalCredit, double takenCredit, + private UserInformationResponse(String studentNumber, String studentName, int totalCredit, + double takenCredit, boolean graduated) { this.studentNumber = studentNumber; this.studentName = studentName; @@ -41,13 +40,16 @@ public static UserInformationResponse from(User user) { .graduated(user.isGraduated()) .build(); if (user.getPrimaryMajor() != null) { - userInformation.getCompleteDivision().add(CompleteDivisionResponse.of("PRIMARY", user.getPrimaryMajor())); + userInformation.getCompleteDivision() + .add(CompleteDivisionResponse.of("PRIMARY", user.getPrimaryMajor())); } if (user.getDualMajor() != null) { - userInformation.getCompleteDivision().add(CompleteDivisionResponse.of("DUAL", user.getDualMajor())); + userInformation.getCompleteDivision() + .add(CompleteDivisionResponse.of("DUAL", user.getDualMajor())); } if (user.getSubMajor() != null) { - userInformation.getCompleteDivision().add(CompleteDivisionResponse.of("SUB", user.getSubMajor())); + userInformation.getCompleteDivision() + .add(CompleteDivisionResponse.of("SUB", user.getSubMajor())); } return userInformation; } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordApiPresentation.java index 9ae3b03c..5f24f46e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordApiPresentation.java @@ -1,20 +1,17 @@ package com.plzgraduate.myongjigraduatebe.user.api.resetpassword; -import javax.validation.Valid; -import javax.validation.constraints.Pattern; - -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - import com.plzgraduate.myongjigraduatebe.user.api.resetpassword.dto.request.ResetPasswordRequest; import com.plzgraduate.myongjigraduatebe.user.api.resetpassword.dto.response.ValidateUserResponse; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; +import javax.validation.Valid; +import javax.validation.constraints.Pattern; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; @Tag(name = "ResetPassword", description = "학번으로 유저 정보 조회 후 로그인 이아디와 일치하는지 확인하는 API") public interface ResetPasswordApiPresentation { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordController.java index ebacbe8e..adebee75 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordController.java @@ -1,8 +1,13 @@ package com.plzgraduate.myongjigraduatebe.user.api.resetpassword; +import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; +import com.plzgraduate.myongjigraduatebe.user.api.resetpassword.dto.request.ResetPasswordRequest; +import com.plzgraduate.myongjigraduatebe.user.api.resetpassword.dto.response.ValidateUserResponse; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.resetpassword.ResetPasswordUseCase; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.validate.ValidateUserUseCase; import javax.validation.Valid; import javax.validation.constraints.Pattern; - +import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; @@ -11,14 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; -import com.plzgraduate.myongjigraduatebe.user.api.resetpassword.dto.request.ResetPasswordRequest; -import com.plzgraduate.myongjigraduatebe.user.api.resetpassword.dto.response.ValidateUserResponse; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.resetpassword.ResetPasswordUseCase; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.validate.ValidateUserUseCase; - -import lombok.RequiredArgsConstructor; - @WebAdapter @RequestMapping("api/v1/users") @RequiredArgsConstructor @@ -33,12 +30,15 @@ public ValidateUserResponse validateUser( @PathVariable @Pattern(regexp = "^60\\d{6}$", message = "INVALIDATED_STUDENT_NUMBER_TYPE") String studentNumber, @RequestParam("auth-id") String authId) { boolean validated = validateUserUseCase.validateUser(studentNumber, authId); - return ValidateUserResponse.builder().passedUserValidation(validated).build(); + return ValidateUserResponse.builder() + .passedUserValidation(validated) + .build(); } @PatchMapping("/password") public void resetPassword(@Valid @RequestBody ResetPasswordRequest resetPasswordRequest) { - resetPasswordUseCase.resetPassword(resetPasswordRequest.getAuthId(), resetPasswordRequest.getNewPassword(), + resetPasswordUseCase.resetPassword(resetPasswordRequest.getAuthId(), + resetPasswordRequest.getNewPassword(), resetPasswordRequest.getPasswordCheck()); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/dto/request/ResetPasswordRequest.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/dto/request/ResetPasswordRequest.java index aac51d16..f2820f06 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/dto/request/ResetPasswordRequest.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/dto/request/ResetPasswordRequest.java @@ -1,9 +1,8 @@ package com.plzgraduate.myongjigraduatebe.user.api.resetpassword.dto.request; +import io.swagger.v3.oas.annotations.media.Schema; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; - -import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpApiPresentation.java index e6b84116..e7dc7ddc 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpApiPresentation.java @@ -1,19 +1,16 @@ package com.plzgraduate.myongjigraduatebe.user.api.signup; -import javax.validation.Valid; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; - -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.request.SignUpRequest; import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.AuthIdDuplicationResponse; import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.StudentNumberDuplicationResponse; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import javax.validation.Valid; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; @Tag(name = "SignUp", description = "회원가입을 진행하는 API") public interface SignUpApiPresentation { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpController.java index 7280ffe8..e7820961 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpController.java @@ -1,9 +1,16 @@ package com.plzgraduate.myongjigraduatebe.user.api.signup; +import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; +import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.request.SignUpRequest; +import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.AuthIdDuplicationResponse; +import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.StudentNumberDuplicationResponse; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.check.CheckAuthIdDuplicationUseCase; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.check.CheckStudentNumberDuplicationUseCase; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpUseCase; import javax.validation.Valid; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; - +import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -11,16 +18,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; -import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.request.SignUpRequest; -import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.AuthIdDuplicationResponse; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.check.CheckAuthIdDuplicationUseCase; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.check.CheckStudentNumberDuplicationUseCase; -import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.StudentNumberDuplicationResponse; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpUseCase; - -import lombok.RequiredArgsConstructor; - @WebAdapter @RequestMapping("/api/v1/users") @RequiredArgsConstructor diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/dto/request/SignUpRequest.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/dto/request/SignUpRequest.java index fad85c66..d21315dd 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/dto/request/SignUpRequest.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/dto/request/SignUpRequest.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.user.api.signup.dto.request; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; - import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpCommand; import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; - import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/dto/response/AuthIdDuplicationResponse.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/dto/response/AuthIdDuplicationResponse.java index 72a8cad0..4fb5fb32 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/dto/response/AuthIdDuplicationResponse.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/signup/dto/response/AuthIdDuplicationResponse.java @@ -6,6 +6,7 @@ @Getter public class AuthIdDuplicationResponse { + @Schema(name = "authId", example = "plzgraduate") private final String authId; @Schema(name = "notDuplicated", example = "true") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawApiPresentation.java index ef62b832..6fdc595a 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawApiPresentation.java @@ -1,12 +1,10 @@ package com.plzgraduate.myongjigraduatebe.user.api.withdraw; -import org.springframework.web.bind.annotation.RequestBody; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.user.api.withdraw.dto.request.WithDrawRequest; - import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.web.bind.annotation.RequestBody; @Tag(name = "WithDraw", description = "유저의 회원 탈퇴 요청을 수행하는 API") public interface WithDrawApiPresentation { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawController.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawController.java index a7f3fc1c..63a1d631 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawController.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawController.java @@ -1,15 +1,13 @@ package com.plzgraduate.myongjigraduatebe.user.api.withdraw; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; - import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser; import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; import com.plzgraduate.myongjigraduatebe.user.api.withdraw.dto.request.WithDrawRequest; import com.plzgraduate.myongjigraduatebe.user.application.usecase.withdraw.WithDrawUserUseCase; - import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; @WebAdapter @RequestMapping("/api/v1/users/me") diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/dto/request/WithDrawRequest.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/dto/request/WithDrawRequest.java index 637fb121..5738fd52 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/dto/request/WithDrawRequest.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/dto/request/WithDrawRequest.java @@ -1,9 +1,7 @@ package com.plzgraduate.myongjigraduatebe.user.api.withdraw.dto.request; -import javax.validation.constraints.NotBlank; - - import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.NotBlank; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/CheckUserPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/CheckUserPort.java index 444dabb7..0ba014eb 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/CheckUserPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/CheckUserPort.java @@ -1,6 +1,7 @@ package com.plzgraduate.myongjigraduatebe.user.application.port; public interface CheckUserPort { + boolean checkDuplicateAuthId(String authId); boolean checkDuplicateStudentNumber(String studentNumber); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/FindUserPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/FindUserPort.java index 249d30d9..93bd907d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/FindUserPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/FindUserPort.java @@ -1,12 +1,12 @@ package com.plzgraduate.myongjigraduatebe.user.application.port; -import java.util.Optional; - import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.Optional; public interface FindUserPort { Optional findUserById(Long id); + Optional findUserByAuthId(String authId); Optional findUserByStudentNumber(String studentNumber); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/SaveUserPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/SaveUserPort.java index 9aac0cf8..f4d544db 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/SaveUserPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/SaveUserPort.java @@ -3,5 +3,6 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; public interface SaveUserPort { + void saveUser(User user); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/UpdateUserPort.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/UpdateUserPort.java index ce29763b..aac9e632 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/UpdateUserPort.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/UpdateUserPort.java @@ -3,5 +3,6 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; public interface UpdateUserPort { + void updateUser(User user); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckAuthIdDuplicationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckAuthIdDuplicationService.java index b2145274..4b129747 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckAuthIdDuplicationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckAuthIdDuplicationService.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.check; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.AuthIdDuplicationResponse; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.check.CheckAuthIdDuplicationUseCase; import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; - +import com.plzgraduate.myongjigraduatebe.user.application.usecase.check.CheckAuthIdDuplicationUseCase; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -21,6 +19,7 @@ public AuthIdDuplicationResponse checkAuthIdDuplication(String authId) { boolean authIdDuplication = !checkUserPort.checkDuplicateAuthId(authId); return AuthIdDuplicationResponse.builder() .authId(authId) - .notDuplicated(authIdDuplication).build(); + .notDuplicated(authIdDuplication) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckStudentNumberDuplicationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckStudentNumberDuplicationService.java index aaf635eb..1b50d4e7 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckStudentNumberDuplicationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckStudentNumberDuplicationService.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.check; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.check.CheckStudentNumberDuplicationUseCase; import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.StudentNumberDuplicationResponse; import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; - +import com.plzgraduate.myongjigraduatebe.user.application.usecase.check.CheckStudentNumberDuplicationUseCase; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -18,9 +16,11 @@ class CheckStudentNumberDuplicationService implements CheckStudentNumberDuplicat @Override public StudentNumberDuplicationResponse checkStudentNumberDuplication(String studentNumber) { - boolean studentNumberDuplication = !checkUserPort.checkDuplicateStudentNumber(studentNumber); + boolean studentNumberDuplication = !checkUserPort.checkDuplicateStudentNumber( + studentNumber); return StudentNumberDuplicationResponse.builder() .studentNumber(studentNumber) - .notDuplicated(studentNumberDuplication).build(); + .notDuplicated(studentNumberDuplication) + .build(); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserAuthIdService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserAuthIdService.java index 2856c9a1..5ddd2f5e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserAuthIdService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserAuthIdService.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.find; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserAuthIdUseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserInformationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserInformationService.java index 7fe06069..30389904 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserInformationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserInformationService.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.find; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserInformationUseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -15,6 +13,7 @@ class FindUserInformationService implements FindUserInformationUseCase { private final FindUserUseCase findUserUseCase; + @Override public User findUserInformation(Long userId) { return findUserUseCase.findUserById(userId); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserService.java index 63736e5d..03b053f3 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserService.java @@ -1,16 +1,14 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.find; -import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.NOT_FOUND_AUTHID; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.UNREGISTERED_USER; -import org.springframework.transaction.annotation.Transactional; - -import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.application.port.FindUserPort; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @RequiredArgsConstructor diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/resetpassword/ResetPasswordService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/resetpassword/ResetPasswordService.java index 7c3dbc71..c519ad27 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/resetpassword/ResetPasswordService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/resetpassword/ResetPasswordService.java @@ -1,16 +1,14 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.resetpassword; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.user.application.port.UpdateUserPort; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.resetpassword.ResetPasswordUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional @@ -29,7 +27,7 @@ public void resetPassword(String authId, String newPassword, String passwordChec updateUserPort.updateUser(user); } - private void checkMatchPassword(String newPassword,String passwordCheck) { + private void checkMatchPassword(String newPassword, String passwordCheck) { if (!newPassword.equals(passwordCheck)) { throw new IllegalArgumentException(ErrorCode.MISMATCHED_PASSWORD.toString()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/signup/SignUpService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/signup/SignUpService.java index f96e0f17..4953ec8c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/signup/SignUpService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/signup/SignUpService.java @@ -1,19 +1,18 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.signup; -import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.DUPLICATED_AUTHID; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.DUPLICATED_STUDENT_NUMBER; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.UNSUPPORTED_STUDENT_NUMBER; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.transaction.annotation.Transactional; - -import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpUseCase; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpCommand; import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; import com.plzgraduate.myongjigraduatebe.user.application.port.SaveUserPort; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpCommand; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional @@ -30,23 +29,24 @@ class SignUpService implements SignUpUseCase { public void signUp(SignUpCommand signUpCommand) { checkDuplicateUser(signUpCommand); String encodedPassword = passwordEncoder.encode(signUpCommand.getPassword()); - User newUser = User.create(signUpCommand.getAuthId(), encodedPassword, signUpCommand.getEngLv(), + User newUser = User.create(signUpCommand.getAuthId(), encodedPassword, + signUpCommand.getEngLv(), signUpCommand.getStudentNumber()); checkStudentNumberOver16(newUser); saveUserPort.saveUser(newUser); } private void checkStudentNumberOver16(User user) { - if(user.checkBeforeEntryYear(CLASS_OF_2016)) { + if (user.checkBeforeEntryYear(CLASS_OF_2016)) { throw new IllegalArgumentException(UNSUPPORTED_STUDENT_NUMBER.toString()); } } private void checkDuplicateUser(SignUpCommand signUpCommand) { - if(checkUserPort.checkDuplicateAuthId(signUpCommand.getAuthId())) { + if (checkUserPort.checkDuplicateAuthId(signUpCommand.getAuthId())) { throw new IllegalArgumentException(DUPLICATED_AUTHID.toString()); } - if(checkUserPort.checkDuplicateStudentNumber(signUpCommand.getStudentNumber())) { + if (checkUserPort.checkDuplicateStudentNumber(signUpCommand.getStudentNumber())) { throw new IllegalArgumentException(DUPLICATED_STUDENT_NUMBER.toString()); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/update/UpdateStudentInformationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/update/UpdateStudentInformationService.java index 5a86e7af..7795d6db 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/update/UpdateStudentInformationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/update/UpdateStudentInformationService.java @@ -1,19 +1,18 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.update; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationUseCase; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationCommand; import com.plzgraduate.myongjigraduatebe.user.application.port.UpdateUserPort; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationCommand; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional @RequiredArgsConstructor class UpdateStudentInformationService implements UpdateStudentInformationUseCase { + private final UpdateUserPort updateUserPort; @Override diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/validate/ValidateUserService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/validate/ValidateUserService.java index bf642923..6994bb57 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/validate/ValidateUserService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/validate/ValidateUserService.java @@ -1,13 +1,11 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.validate; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.validate.ValidateUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional(readOnly = true) @@ -15,6 +13,7 @@ class ValidateUserService implements ValidateUserUseCase { private final FindUserUseCase findUserUseCase; + @Override public boolean validateUser(String studentNumber, String authId) { User user = findUserUseCase.findUserByStudentNumber(studentNumber); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/withdraw/WithDrawUserService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/withdraw/WithDrawUserService.java index 09430edb..1214fada 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/withdraw/WithDrawUserService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/service/withdraw/WithDrawUserService.java @@ -1,8 +1,5 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.withdraw; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.transaction.annotation.Transactional; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.DeleteCompletedCreditPort; import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; @@ -12,8 +9,9 @@ import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.withdraw.WithDrawUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.transaction.annotation.Transactional; @UseCase @Transactional @@ -30,7 +28,7 @@ class WithDrawUserService implements WithDrawUserUseCase { @Override public void withDraw(Long userId, String password) { User user = findUserUseCase.findUserById(userId); - if(!user.matchPassword(passwordEncoder, password)){ + if (!user.matchPassword(passwordEncoder, password)) { throw new IllegalArgumentException(ErrorCode.INCORRECT_PASSWORD.toString()); } deleteTakenLectureByUserUseCase.deleteAllTakenLecturesByUser(user); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/find/FindUserUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/find/FindUserUseCase.java index 480bd97c..6436c056 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/find/FindUserUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/find/FindUserUseCase.java @@ -3,6 +3,7 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; public interface FindUserUseCase { + User findUserById(Long id); User findUserByAuthId(String authId); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/signup/SignUpCommand.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/signup/SignUpCommand.java index a37e3096..c3a69380 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/signup/SignUpCommand.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/signup/SignUpCommand.java @@ -1,7 +1,6 @@ package com.plzgraduate.myongjigraduatebe.user.application.usecase.signup; import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; - import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -9,6 +8,7 @@ @Getter @NoArgsConstructor public class SignUpCommand { + private String authId; private String password; @@ -18,7 +18,8 @@ public class SignUpCommand { private EnglishLevel engLv; @Builder - private SignUpCommand(String authId, String password, String studentNumber, EnglishLevel engLv) { + private SignUpCommand(String authId, String password, String studentNumber, + EnglishLevel engLv) { this.authId = authId; this.password = password; this.studentNumber = studentNumber; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/signup/SignUpUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/signup/SignUpUseCase.java index c846cbf3..54064703 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/signup/SignUpUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/signup/SignUpUseCase.java @@ -1,5 +1,6 @@ package com.plzgraduate.myongjigraduatebe.user.application.usecase.signup; public interface SignUpUseCase { + void signUp(SignUpCommand signUpCommand); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationCommand.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationCommand.java index ca5233b5..8e06991a 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationCommand.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationCommand.java @@ -4,7 +4,6 @@ import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingInformation; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,6 +11,7 @@ @Getter @NoArgsConstructor public class UpdateStudentInformationCommand { + private User user; private String name; @@ -32,7 +32,8 @@ public class UpdateStudentInformationCommand { @Builder private UpdateStudentInformationCommand(User user, String name, String major, String dualMajor, - String subMajor, StudentCategory studentCategory, int totalCredit, double takenCredit, boolean graduate) { + String subMajor, StudentCategory studentCategory, int totalCredit, double takenCredit, + boolean graduate) { this.user = user; this.name = name; this.major = major; @@ -44,7 +45,8 @@ private UpdateStudentInformationCommand(User user, String name, String major, St this.graduate = graduate; } - public static UpdateStudentInformationCommand of(User user, ParsingInformation parsingInformation) { + public static UpdateStudentInformationCommand of(User user, + ParsingInformation parsingInformation) { return UpdateStudentInformationCommand.builder() .user(user) .name(parsingInformation.getStudentName()) @@ -55,7 +57,8 @@ public static UpdateStudentInformationCommand of(User user, ParsingInformation p .build(); } - public static UpdateStudentInformationCommand update(User user, GraduationResult graduationResult) { + public static UpdateStudentInformationCommand update(User user, + GraduationResult graduationResult) { return UpdateStudentInformationCommand.builder() .user(user) .name(user.getName()) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationUseCase.java index df6ab31e..e84f34c5 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationUseCase.java @@ -3,5 +3,6 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; public interface UpdateStudentInformationUseCase { + User updateUser(UpdateStudentInformationCommand updateStudentInformationCommand); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/College.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/College.java index 4d00c680..40430cfd 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/College.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/College.java @@ -2,7 +2,6 @@ import java.util.Arrays; import java.util.List; - import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -11,7 +10,8 @@ public enum College { HUMANITIES("인문대", - List.of("국어국문학과", "문예창작학과", "영어영문학과", "중어중문학과", "일어일문학과", "문헌정보학과", "미술사학과", "아랍지역학과", "사학과", "철학과")), + List.of("국어국문학과", "문예창작학과", "영어영문학과", "중어중문학과", "일어일문학과", "문헌정보학과", "미술사학과", "아랍지역학과", + "사학과", "철학과")), SOCIAL_SCIENCE("사회과학대", List.of("행정학과", "경제학과", "정치외교학과", "디지털미디어학과", "아동학과", "청소년지도학과")), BUSINESS("경영대", List.of("경영학과", "경영정보학과", "국제통상학과")), LAW("법대", List.of("법학과")), @@ -22,7 +22,8 @@ public enum College { public static College findBelongingCollege(String major) { return Arrays.stream(College.values()) - .filter(college -> college.getHoldingMajors().contains(major)) + .filter(college -> college.getHoldingMajors() + .contains(major)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("소속 단과대가 존재하지 않습니다.")); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategory.java index 7e6f048e..a11fe513 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategory.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategory.java @@ -1,15 +1,23 @@ package com.plzgraduate.myongjigraduatebe.user.domain.model; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; - -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CHAPEL; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CORE_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_ELECTIVE_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_MANDATORY_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.FREE_ELECTIVE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.NORMAL_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_ELECTIVE_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_MANDATORY_MAJOR; import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; import com.plzgraduate.myongjigraduatebe.core.exception.PdfParsingException; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; - +import java.util.Arrays; +import java.util.List; +import java.util.Objects; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -17,25 +25,33 @@ @RequiredArgsConstructor public enum StudentCategory { NORMAL(List.of(), - List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, PRIMARY_MANDATORY_MAJOR, + List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, + PRIMARY_MANDATORY_MAJOR, PRIMARY_ELECTIVE_MAJOR, NORMAL_CULTURE, FREE_ELECTIVE, CHAPEL)), CHANGE_MAJOR(List.of("전과"), - List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, PRIMARY_MANDATORY_MAJOR, + List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, + PRIMARY_MANDATORY_MAJOR, PRIMARY_ELECTIVE_MAJOR, NORMAL_CULTURE, FREE_ELECTIVE, CHAPEL)), SUB_MAJOR(List.of("부전공"), - List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, PRIMARY_MANDATORY_MAJOR, - PRIMARY_ELECTIVE_MAJOR, GraduationCategory.SUB_MAJOR, NORMAL_CULTURE, FREE_ELECTIVE, CHAPEL)), + List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, + PRIMARY_MANDATORY_MAJOR, + PRIMARY_ELECTIVE_MAJOR, GraduationCategory.SUB_MAJOR, NORMAL_CULTURE, FREE_ELECTIVE, + CHAPEL)), DUAL_MAJOR(List.of("복수전공"), - List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, DUAL_BASIC_ACADEMICAL_CULTURE, - PRIMARY_MANDATORY_MAJOR, PRIMARY_ELECTIVE_MAJOR, DUAL_MANDATORY_MAJOR, DUAL_ELECTIVE_MAJOR, NORMAL_CULTURE, + List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, + DUAL_BASIC_ACADEMICAL_CULTURE, + PRIMARY_MANDATORY_MAJOR, PRIMARY_ELECTIVE_MAJOR, DUAL_MANDATORY_MAJOR, + DUAL_ELECTIVE_MAJOR, NORMAL_CULTURE, FREE_ELECTIVE, CHAPEL)), ASSOCIATED_MAJOR(List.of("연계전공"), // 현재 미지원 - List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, PRIMARY_MANDATORY_MAJOR, + List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, + PRIMARY_MANDATORY_MAJOR, PRIMARY_ELECTIVE_MAJOR, NORMAL_CULTURE, FREE_ELECTIVE, CHAPEL)), DOUBLE_SUB(List.of("복수전공", "부전공"), // 현재 미지원 - List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, PRIMARY_MANDATORY_MAJOR, + List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, + PRIMARY_MANDATORY_MAJOR, PRIMARY_ELECTIVE_MAJOR, NORMAL_CULTURE, FREE_ELECTIVE, CHAPEL)); private final List categories; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/User.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/User.java index 176aa136..b2804fcd 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/User.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/User.java @@ -3,26 +3,25 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType.DUAL; import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType.PRIMARY; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import java.time.Instant; import java.util.Objects; - -import org.springframework.security.crypto.password.PasswordEncoder; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; - import lombok.Builder; import lombok.Getter; +import org.springframework.security.crypto.password.PasswordEncoder; @Getter public class User { private final Long id; private final String authId; - private String password; private final EnglishLevel englishLevel; - private String name; private final String studentNumber; private final int entryYear; + private final Instant createdAt; + private final Instant updatedAt; + private String password; + private String name; private String primaryMajor; private String subMajor; private String dualMajor; @@ -30,13 +29,14 @@ public class User { private int totalCredit; private double takenCredit; private boolean graduated; - private final Instant createdAt; - private Instant updatedAt; @Builder - private User(Long id, String authId, String password, EnglishLevel englishLevel, String name, String studentNumber, - int entryYear, String primaryMajor, String subMajor, String dualMajor, StudentCategory studentCategory, - int totalCredit, double takenCredit, boolean graduated, Instant createdAt, Instant updatedAt) { + private User(Long id, String authId, String password, EnglishLevel englishLevel, String name, + String studentNumber, + int entryYear, String primaryMajor, String subMajor, String dualMajor, + StudentCategory studentCategory, + int totalCredit, double takenCredit, boolean graduated, Instant createdAt, + Instant updatedAt) { this.id = id; this.authId = authId; this.password = password; @@ -55,7 +55,8 @@ private User(Long id, String authId, String password, EnglishLevel englishLevel, this.updatedAt = updatedAt; } - public static User create(String authId, String password, EnglishLevel englishLevel, String studentNumber) { + public static User create(String authId, String password, EnglishLevel englishLevel, + String studentNumber) { return User.builder() .authId(authId) .password(password) @@ -68,7 +69,12 @@ public static User create(String authId, String password, EnglishLevel englishLe .build(); } - public void updateStudentInformation(String name, String major, String dualMajor, String subMajor, + private static int parseEntryYearInStudentNumber(String studentNumber) { + return Integer.parseInt(studentNumber.substring(2, 4)); + } + + public void updateStudentInformation(String name, String major, String dualMajor, + String subMajor, StudentCategory studentCategory, int totalCredit, double takenCredit, boolean graduate) { this.name = name; this.primaryMajor = major; @@ -117,18 +123,17 @@ public String getMajorByMajorType(MajorType majorType) { return subMajor; } - private static int parseEntryYearInStudentNumber(String studentNumber) { - return Integer.parseInt(studentNumber.substring(2, 4)); - } - @Override public boolean equals(Object o) { - if (this == o) + if (this == o) { return true; - if (o == null || getClass() != o.getClass()) + } + if (o == null || getClass() != o.getClass()) { return false; - User user = (User)o; - return Objects.equals(authId, user.authId) && Objects.equals(studentNumber, user.studentNumber); + } + User user = (User) o; + return Objects.equals(authId, user.authId) && Objects.equals(studentNumber, + user.studentNumber); } @Override diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapter.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapter.java index 83cc973d..31848c29 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapter.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapter.java @@ -1,25 +1,24 @@ package com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence; -import java.util.Optional; - import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; import com.plzgraduate.myongjigraduatebe.user.application.port.DeleteUserPort; import com.plzgraduate.myongjigraduatebe.user.application.port.FindUserPort; import com.plzgraduate.myongjigraduatebe.user.application.port.SaveUserPort; import com.plzgraduate.myongjigraduatebe.user.application.port.UpdateUserPort; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.mapper.UserMapper; - +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; +import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @PersistenceAdapter @Slf4j @RequiredArgsConstructor -public class UserPersistenceAdapter implements FindUserPort, SaveUserPort, CheckUserPort, UpdateUserPort, DeleteUserPort { +public class UserPersistenceAdapter implements FindUserPort, SaveUserPort, CheckUserPort, + UpdateUserPort, DeleteUserPort { private final UserMapper userMapper; @@ -32,8 +31,9 @@ public void saveUser(User user) { @Override public Optional findUserById(Long id) { - UserJpaEntity userJpaEntity = userRepository.findById(id).orElse(null); - if(userJpaEntity == null) { + UserJpaEntity userJpaEntity = userRepository.findById(id) + .orElse(null); + if (userJpaEntity == null) { return Optional.empty(); } return Optional.of(userMapper.mapToDomainEntity(userJpaEntity)); @@ -41,8 +41,9 @@ public Optional findUserById(Long id) { @Override public Optional findUserByAuthId(String authId) { - UserJpaEntity userJpaEntity = userRepository.findByAuthId(authId).orElse(null); - if(userJpaEntity == null) { + UserJpaEntity userJpaEntity = userRepository.findByAuthId(authId) + .orElse(null); + if (userJpaEntity == null) { return Optional.empty(); } return Optional.of(userMapper.mapToDomainEntity(userJpaEntity)); @@ -50,7 +51,8 @@ public Optional findUserByAuthId(String authId) { @Override public Optional findUserByStudentNumber(String studentNumber) { - return userRepository.findByStudentNumber(studentNumber).map(userMapper::mapToDomainEntity); + return userRepository.findByStudentNumber(studentNumber) + .map(userMapper::mapToDomainEntity); } @Override diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/entity/UserJpaEntity.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/entity/UserJpaEntity.java index 211a7746..36953356 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/entity/UserJpaEntity.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/entity/UserJpaEntity.java @@ -1,5 +1,8 @@ package com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity; +import com.plzgraduate.myongjigraduatebe.core.entity.TimeBaseEntity; +import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; +import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -8,11 +11,6 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; - -import com.plzgraduate.myongjigraduatebe.core.entity.TimeBaseEntity; -import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; -import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; - import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/mapper/UserMapper.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/mapper/UserMapper.java index 25e16e58..42cdd1cd 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/mapper/UserMapper.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/mapper/UserMapper.java @@ -1,9 +1,8 @@ package com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.mapper; -import org.springframework.stereotype.Component; - -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import org.springframework.stereotype.Component; @Component public class UserMapper { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/repository/UserRepository.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/repository/UserRepository.java index cebf64eb..cd8fa1bb 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/repository/UserRepository.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/repository/UserRepository.java @@ -1,12 +1,11 @@ package com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import java.util.Optional; - import org.springframework.data.jpa.repository.JpaRepository; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; - public interface UserRepository extends JpaRepository { + Optional findByAuthId(String authId); Optional findByStudentNumber(String studentNumber); diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 25aced88..41ce56f9 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -1,38 +1,44 @@ - - - - [%d{yyyy-MM-dd HH:mm:ss}] %green([%thread]) %highlight(%-5level) %boldWhite([%C.%M:%yellow(%L)]) - %msg%n - - - - - - + + + + [%d{yyyy-MM-dd HH:mm:ss}] %green([%thread]) %highlight(%-5level) + %boldWhite([%C.%M:%yellow(%L)]) - %msg%n + + + + + + + - - - - [%d{yyyy-MM-dd HH:mm:ss}] %green([%thread]) %highlight(%-5level) %boldWhite([%C.%M:%yellow(%L)]) - %msg%n - - - - app.log - - app.%d{yyyy-MM-dd}.log - 20 - - - [%d{yyyy-MM-dd HH:mm:ss}] %green([%thread]) %highlight(%-5level) %boldWhite([%C.%M:%yellow(%L)]) - %msg%n - - - - + + + + [%d{yyyy-MM-dd HH:mm:ss}] %green([%thread]) %highlight(%-5level) + %boldWhite([%C.%M:%yellow(%L)]) - %msg%n + + + + + + [%d{yyyy-MM-dd HH:mm:ss}] %green([%thread]) %highlight(%-5level) + %boldWhite([%C.%M:%yellow(%L)]) - %msg%n + + + app.log + + app.%d{yyyy-MM-dd}.log + 20 + + + + - - - - + + + + diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInControllerTest.java index 54648b12..d2d825b9 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/api/signin/SignInControllerTest.java @@ -7,31 +7,30 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.http.MediaType; - import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.request.SignInRequest; import com.plzgraduate.myongjigraduatebe.core.exception.UnAuthorizedException; import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; class SignInControllerTest extends WebAdaptorTestSupport { @DisplayName("로그인을 진행한다.") @Test void signIn() throws Exception { - //given + //given SignInRequest request = SignInRequest.builder() .authId("mju-graduate") .password("1q2w3e4r!") .build(); - //when //then + //when //then mockMvc.perform( - post("/api/v1/auth/sign-in") - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON) - ) + post("/api/v1/auth/sign-in") + .content(objectMapper.writeValueAsString(request)) + .contentType(MediaType.APPLICATION_JSON) + ) .andDo(print()) .andExpect(status().isOk()); } @@ -82,7 +81,8 @@ void invalidUser() throws Exception { .authId("mju-graduate") .password("1q2w3e4r") .build(); - given(signInUseCase.signIn(any(), any())).willThrow(new UnAuthorizedException("아이디 혹은 비밀번호가 일치하지 않습니다.")); + given(signInUseCase.signIn(any(), any())).willThrow( + new UnAuthorizedException("아이디 혹은 비밀번호가 일치하지 않습니다.")); //when //then mockMvc.perform( post("/api/v1/auth/sign-in") diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenControllerTest.java index f545e6a3..a8046a2f 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/api/token/TokenControllerTest.java @@ -1,21 +1,20 @@ package com.plzgraduate.myongjigraduatebe.auth.api.token; -import static org.mockito.BDDMockito.given; -import static org.mockito.ArgumentMatchers.any; import static org.hamcrest.Matchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.http.MediaType; - import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.request.TokenRequest; import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.response.AccessTokenResponse; import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; class TokenControllerTest extends WebAdaptorTestSupport { @@ -30,8 +29,8 @@ void newToken() throws Exception { .build(); AccessTokenResponse response = AccessTokenResponse.builder() - .accessToken(accessToken) - .build(); + .accessToken(accessToken) + .build(); given(tokenUseCase.generateNewToken(any())).willReturn(response); //when //then mockMvc.perform( @@ -65,6 +64,6 @@ void invalidRefreshToken() throws Exception { ) .andDo(print()) .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errorCode", is("유효하지 않은 토큰입니다.")));; + .andExpect(jsonPath("$.errorCode", is("유효하지 않은 토큰입니다."))); } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/application/service/signin/SignInServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/application/service/signin/SignInServiceTest.java index a87657c5..0bddd0ac 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/application/service/signin/SignInServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/application/service/signin/SignInServiceTest.java @@ -1,10 +1,16 @@ package com.plzgraduate.myongjigraduatebe.auth.application.service.signin; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.BDDMockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.BDDMockito.times; +import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse; +import com.plzgraduate.myongjigraduatebe.auth.application.port.SaveRefreshTokenPort; +import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationToken; +import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider; import java.util.Collections; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -15,11 +21,6 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.authority.SimpleGrantedAuthority; -import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse; -import com.plzgraduate.myongjigraduatebe.auth.application.port.SaveRefreshTokenPort; -import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationToken; -import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider; - @ExtendWith(MockitoExtension.class) class SignInServiceTest { @@ -32,12 +33,10 @@ class SignInServiceTest { @InjectMocks private SignInService signInService; - - @DisplayName("로그인을 진행한다.") @Test void singIn() { - //given + //given String authId = "mju-graduate"; String password = "1q2w3e4r!"; Long userId = 1L; @@ -56,9 +55,9 @@ void singIn() { TokenResponse tokenResponse = signInService.signIn(authId, password); //then - then(saveRefreshTokenPort).should(times(1)).saveRefreshToken(refreshToken, userId); + then(saveRefreshTokenPort).should(times(1)) + .saveRefreshToken(refreshToken, userId); assertThat(tokenResponse.getAccessToken()).isEqualTo(accessToken); assertThat(tokenResponse.getRefreshToken()).isEqualTo(refreshToken); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/application/service/token/TokenServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/application/service/token/TokenServiceTest.java index cbfc7fcc..d6047ee9 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/application/service/token/TokenServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/application/service/token/TokenServiceTest.java @@ -8,8 +8,10 @@ import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.times; +import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.response.AccessTokenResponse; +import com.plzgraduate.myongjigraduatebe.auth.application.port.FindRefreshTokenPort; +import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider; import java.util.Optional; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -17,10 +19,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.response.AccessTokenResponse; -import com.plzgraduate.myongjigraduatebe.auth.application.port.FindRefreshTokenPort; -import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider; - @ExtendWith(MockitoExtension.class) class TokenServiceTest { @@ -40,7 +38,8 @@ void generateNewToken() { Long userId = 1L; String refreshToken = "refreshToken"; String accessToken = "accessToken"; - given(findRefreshTokenPort.findByRefreshToken(refreshToken)).willReturn(Optional.of(userId)); + given(findRefreshTokenPort.findByRefreshToken(refreshToken)).willReturn( + Optional.of(userId)); given(tokenProvider.generateToken(userId)).willReturn(accessToken); //when @@ -63,7 +62,9 @@ void illegalArgumentExceptionIfInvalidToken() { .hasMessage("유효하지 않은 토큰입니다."); //then - then(findRefreshTokenPort).should(times(1)).findByRefreshToken(refreshToken); - then(tokenProvider).should(never()).generateToken(anyLong()); + then(findRefreshTokenPort).should(times(1)) + .findByRefreshToken(refreshToken); + then(tokenProvider).should(never()) + .generateToken(anyLong()); } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/infrastructure/adapter/repository/InMemoryTokenRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/infrastructure/adapter/repository/InMemoryTokenRepositoryTest.java index 5f4a6e53..3916fe1e 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/infrastructure/adapter/repository/InMemoryTokenRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/infrastructure/adapter/repository/InMemoryTokenRepositoryTest.java @@ -3,17 +3,15 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.auth.infrastructure.adapter.repository.InMemoryTokenRepository; - @ExtendWith(MockitoExtension.class) class InMemoryTokenRepositoryTest { + @InjectMocks private InMemoryTokenRepository inMemoryTokenRepository; @@ -51,5 +49,4 @@ void findByRefreshToken() { assertThat(userIdFromCache).isPresent(); assertThat(userId2).isEqualTo(userIdFromCache.get()); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenProviderTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenProviderTest.java index b8def3f1..30f280f4 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenProviderTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/auth/security/TokenProviderTest.java @@ -1,6 +1,6 @@ package com.plzgraduate.myongjigraduatebe.auth.security; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -12,6 +12,7 @@ @ExtendWith(MockitoExtension.class) class TokenProviderTest { + @Mock private JwtProperties jwtProperties; @InjectMocks diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditsControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditsControllerTest.java index c475517d..94d6cbf3 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditsControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/api/FindCompletedCreditsControllerTest.java @@ -6,15 +6,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; import com.plzgraduate.myongjigraduatebe.support.WithMockAuthenticationUser; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class FindCompletedCreditsControllerTest extends WebAdaptorTestSupport { @@ -49,10 +47,8 @@ void findCompletedCredits() throws Exception { .andExpect(jsonPath("$[1].totalCredit").value(10)) .andExpect(jsonPath("$[1].takenCredit").value(5)) .andExpect(jsonPath("$[1].completed").value(false)); - } - @WithMockAuthenticationUser @DisplayName("유저의 이수 학점을 조회 시 totalCredit이 0인 CompletedCredit은 조회하지 않는다.") @Test diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/FindCompletedCreditServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/FindCompletedCreditServiceTest.java index 6ca941ee..791f8d73 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/FindCompletedCreditServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/FindCompletedCreditServiceTest.java @@ -1,13 +1,13 @@ package com.plzgraduate.myongjigraduatebe.completedcredit.application.service; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; -import java.math.BigDecimal; +import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.FindCompletedCreditPort; +import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.util.List; - -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -15,11 +15,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.FindCompletedCreditPort; -import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class FindCompletedCreditServiceTest { @@ -29,25 +24,28 @@ class FindCompletedCreditServiceTest { private FindCompletedCreditPort findCompletedCreditPort; @InjectMocks private FindCompletedCreditService findCompletedCreditService; - + @DisplayName("유저의 기이수 학점을 조회한다.") @Test void findCompletedCredits() { - //given + //given User user = User.builder() - .id(1L).build(); + .id(1L) + .build(); given(findUserUseCase.findUserById(1L)).willReturn(user); given(findCompletedCreditPort.findCompletedCredit(user)).willReturn(List.of( - CompletedCredit.builder().build(), - CompletedCredit.builder().build(), - CompletedCredit.builder().build() + CompletedCredit.builder() + .build(), + CompletedCredit.builder() + .build(), + CompletedCredit.builder() + .build() )); - //when + //when List result = findCompletedCreditService.findCompletedCredits(1L); //then - assertThat(result).hasSize(3); + assertThat(result).hasSize(3); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/GenerateOrModifyCompletedCreditServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/GenerateOrModifyCompletedCreditServiceTest.java index 9e1094ed..ab139cf8 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/GenerateOrModifyCompletedCreditServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/application/service/GenerateOrModifyCompletedCreditServiceTest.java @@ -4,17 +4,6 @@ import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; -import java.util.List; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.FindCompletedCreditPort; import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.GenerateOrModifyCompletedCreditPort; import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; @@ -26,6 +15,15 @@ import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.NormalCultureGraduationResult; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.List; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class GenerateOrModifyCompletedCreditServiceTest { @@ -44,7 +42,8 @@ class GenerateOrModifyCompletedCreditServiceTest { void generateOrModifyCompletedCreditPort() { //given User user = User.builder() - .id(1L).build(); + .id(1L) + .build(); given(findCompletedCreditPort.findCompletedCredit(user)).willReturn(List.of()); int eachDetailGraduationResultTotalCredit = 10; @@ -71,7 +70,8 @@ void generateOrModifyCompletedCreditPort() { .build()) .build(); given(calculateGraduationUseCase.calculateGraduation(user)).willReturn(graduationResult); - ArgumentCaptor> completedCreditArgumentCaptor = ArgumentCaptor.forClass(List.class); + ArgumentCaptor> completedCreditArgumentCaptor = ArgumentCaptor.forClass( + List.class); ArgumentCaptor userArgumentCaptor = ArgumentCaptor.forClass(User.class); //when @@ -79,34 +79,40 @@ void generateOrModifyCompletedCreditPort() { //then then(generateOrModifyCompletedCreditPort).should() - .generateOrModifyCompletedCredits(userArgumentCaptor.capture(), completedCreditArgumentCaptor.capture()); + .generateOrModifyCompletedCredits(userArgumentCaptor.capture(), + completedCreditArgumentCaptor.capture()); List savedCompletedCredits = completedCreditArgumentCaptor.getValue(); - Assertions.assertThat(savedCompletedCredits).hasSize(detailGraduationResults.size() + 3) + Assertions.assertThat(savedCompletedCredits) + .hasSize(detailGraduationResults.size() + 3) .extracting("graduationCategory", "totalCredit", "takenCredit") .containsOnly( tuple(GraduationCategory.COMMON_CULTURE, eachDetailGraduationResultTotalCredit, - (double)eachDetailGraduationResultTakenCredit), + (double) eachDetailGraduationResultTakenCredit), tuple(GraduationCategory.CORE_CULTURE, eachDetailGraduationResultTotalCredit, - (double)eachDetailGraduationResultTakenCredit), - tuple(GraduationCategory.PRIMARY_MANDATORY_MAJOR, eachDetailGraduationResultTotalCredit, - (double)eachDetailGraduationResultTakenCredit), - tuple(GraduationCategory.PRIMARY_ELECTIVE_MAJOR, eachDetailGraduationResultTotalCredit, - (double)eachDetailGraduationResultTakenCredit), - tuple(GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE, eachDetailGraduationResultTotalCredit, - (double)eachDetailGraduationResultTakenCredit), + (double) eachDetailGraduationResultTakenCredit), + tuple(GraduationCategory.PRIMARY_MANDATORY_MAJOR, + eachDetailGraduationResultTotalCredit, + (double) eachDetailGraduationResultTakenCredit), + tuple(GraduationCategory.PRIMARY_ELECTIVE_MAJOR, + eachDetailGraduationResultTotalCredit, + (double) eachDetailGraduationResultTakenCredit), + tuple(GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE, + eachDetailGraduationResultTotalCredit, + (double) eachDetailGraduationResultTakenCredit), tuple(GraduationCategory.CHAPEL, 2, 1.5), tuple(GraduationCategory.NORMAL_CULTURE, eachDetailGraduationResultTotalCredit, - (double)eachDetailGraduationResultTakenCredit), + (double) eachDetailGraduationResultTakenCredit), tuple(GraduationCategory.FREE_ELECTIVE, eachDetailGraduationResultTotalCredit, - (double)eachDetailGraduationResultTakenCredit)); - + (double) eachDetailGraduationResultTakenCredit)); } - private List createDetailGraduationResults(int totalCredit, int takenCredit) { + private List createDetailGraduationResults(int totalCredit, + int takenCredit) { return List.of(DetailGraduationResult.builder() .graduationCategory(GraduationCategory.COMMON_CULTURE) .totalCredit(totalCredit) - .takenCredit(takenCredit).build(), + .takenCredit(takenCredit) + .build(), DetailGraduationResult.builder() .graduationCategory(GraduationCategory.CORE_CULTURE) .totalCredit(totalCredit) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/GenerateOrModifyCompletedCreditsAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/GenerateOrModifyCompletedCreditsAdapterTest.java index df52a445..0789d7d9 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/GenerateOrModifyCompletedCreditsAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/GenerateOrModifyCompletedCreditsAdapterTest.java @@ -2,12 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.entity.CompletedCreditJpaEntity; import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.repository.CompletedCreditRepository; @@ -16,6 +10,10 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class GenerateOrModifyCompletedCreditsAdapterTest extends PersistenceTestSupport { @@ -30,10 +28,11 @@ class GenerateOrModifyCompletedCreditsAdapterTest extends PersistenceTestSupport @Test void saveOrModifyCompletedCredits() { //given - UserJpaEntity userJpaEntity = userRepository.save( UserJpaEntity.builder() + UserJpaEntity userJpaEntity = userRepository.save(UserJpaEntity.builder() .authId("test") .password("test") - .studentNumber("60191111").build()); + .studentNumber("60191111") + .build()); User user = User.builder() .id(userJpaEntity.getId()) .build(); @@ -42,14 +41,17 @@ void saveOrModifyCompletedCredits() { .id(1L) .graduationCategory(GraduationCategory.COMMON_CULTURE) .totalCredit(10) - .takenCredit(5).build(), + .takenCredit(5) + .build(), CompletedCredit.builder() .graduationCategory(GraduationCategory.COMMON_CULTURE) .totalCredit(10) - .takenCredit(5).build()); + .takenCredit(5) + .build()); //when - generateOrModifyCompletedCreditsAdapter.generateOrModifyCompletedCredits(user, completedCredits); + generateOrModifyCompletedCreditsAdapter.generateOrModifyCompletedCredits(user, + completedCredits); //then List foundCompletedCredits = completedCreditRepository.findAllByUserJpaEntity( @@ -58,5 +60,4 @@ void saveOrModifyCompletedCredits() { .extracting("userJpaEntity.id") .contains(user.getId()); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/mapper/CompletedCreditPersistenceMapperTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/mapper/CompletedCreditPersistenceMapperTest.java index 1b47daee..b4196f9a 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/mapper/CompletedCreditPersistenceMapperTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/mapper/CompletedCreditPersistenceMapperTest.java @@ -3,13 +3,12 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.completedcredit.domain.model.CompletedCredit; import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.entity.CompletedCreditJpaEntity; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class CompletedCreditPersistenceMapperTest { @@ -26,15 +25,20 @@ void mapToDomainModel() { .build()) .graduationCategory(COMMON_CULTURE) .totalCredit(10) - .takenCredit(5).build(); + .takenCredit(5) + .build(); //when - CompletedCredit completedCredit = completedCreditPersistenceMapper.mapToDomainModel(completedCreditJpaEntity); + CompletedCredit completedCredit = completedCreditPersistenceMapper.mapToDomainModel( + completedCreditJpaEntity); //then - assertThat(completedCredit.getGraduationCategory()).isEqualTo(completedCreditJpaEntity.getGraduationCategory()); - assertThat(completedCredit.getTotalCredit()).isEqualTo(completedCreditJpaEntity.getTotalCredit()); - assertThat(completedCredit.getTakenCredit()).isEqualTo(completedCreditJpaEntity.getTakenCredit()); + assertThat(completedCredit.getGraduationCategory()).isEqualTo( + completedCreditJpaEntity.getGraduationCategory()); + assertThat(completedCredit.getTotalCredit()).isEqualTo( + completedCreditJpaEntity.getTotalCredit()); + assertThat(completedCredit.getTakenCredit()).isEqualTo( + completedCreditJpaEntity.getTakenCredit()); } @DisplayName("CompletedCredit 도메인 모델을 JpaEntity로 매핑한다.") @@ -48,18 +52,23 @@ void mapToJpaEntity() { .id(1L) .graduationCategory(COMMON_CULTURE) .totalCredit(10) - .takenCredit(5).build(); + .takenCredit(5) + .build(); //when - CompletedCreditJpaEntity completedCreditJpaEntity = completedCreditPersistenceMapper.mapToJpaEntity(user, + CompletedCreditJpaEntity completedCreditJpaEntity = completedCreditPersistenceMapper.mapToJpaEntity( + user, completedCredit); //then assertThat(completedCreditJpaEntity.getId()).isEqualTo(completedCredit.getId()); - assertThat(completedCreditJpaEntity.getUserJpaEntity().getId()).isEqualTo(user.getId()); - assertThat(completedCreditJpaEntity.getGraduationCategory()).isEqualTo(completedCredit.getGraduationCategory()); - assertThat(completedCreditJpaEntity.getTotalCredit()).isEqualTo(completedCredit.getTotalCredit()); - assertThat(completedCreditJpaEntity.getTakenCredit()).isEqualTo(completedCredit.getTakenCredit()); + assertThat(completedCreditJpaEntity.getUserJpaEntity() + .getId()).isEqualTo(user.getId()); + assertThat(completedCreditJpaEntity.getGraduationCategory()).isEqualTo( + completedCredit.getGraduationCategory()); + assertThat(completedCreditJpaEntity.getTotalCredit()).isEqualTo( + completedCredit.getTotalCredit()); + assertThat(completedCreditJpaEntity.getTakenCredit()).isEqualTo( + completedCredit.getTakenCredit()); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/repository/CompletedCreditRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/repository/CompletedCreditRepositoryTest.java index a5fa5029..f2c99227 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/repository/CompletedCreditRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/completedcredit/infrastructure/persistence/repository/CompletedCreditRepositoryTest.java @@ -2,17 +2,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.entity.CompletedCreditJpaEntity; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class CompletedCreditRepositoryTest extends PersistenceTestSupport { @@ -28,20 +26,23 @@ void findAllByUserJpaEntity() { UserJpaEntity userJpaEntity = UserJpaEntity.builder() .authId("test1234") .password("test") - .studentNumber("60191112").build(); + .studentNumber("60191112") + .build(); userRepository.save(userJpaEntity); CompletedCreditJpaEntity commonCultureCompletedCreditJpaEntity = CompletedCreditJpaEntity.builder() .userJpaEntity(userJpaEntity) .graduationCategory(GraduationCategory.COMMON_CULTURE) .totalCredit(10) - .takenCredit(10).build(); + .takenCredit(10) + .build(); CompletedCreditJpaEntity coreCultureCompletedCreditJpaEntity = CompletedCreditJpaEntity.builder() .userJpaEntity(userJpaEntity) .graduationCategory(GraduationCategory.CORE_CULTURE) .totalCredit(10) - .takenCredit(10).build(); + .takenCredit(10) + .build(); completedCreditRepository.saveAll( List.of(commonCultureCompletedCreditJpaEntity, coreCultureCompletedCreditJpaEntity)); @@ -59,35 +60,37 @@ void findAllByUserJpaEntity() { @DisplayName("유저의 모든 이수학점 내역을 삭제한다.") @Test void deleteAllByUserJpaEntity() { - //given + //given UserJpaEntity userJpaEntity = UserJpaEntity.builder() .authId("test1234") .password("test") - .studentNumber("60191112").build(); + .studentNumber("60191112") + .build(); userRepository.save(userJpaEntity); CompletedCreditJpaEntity commonCultureCompletedCreditJpaEntity = CompletedCreditJpaEntity.builder() .userJpaEntity(userJpaEntity) .graduationCategory(GraduationCategory.COMMON_CULTURE) .totalCredit(10) - .takenCredit(10).build(); + .takenCredit(10) + .build(); CompletedCreditJpaEntity coreCultureCompletedCreditJpaEntity = CompletedCreditJpaEntity.builder() .userJpaEntity(userJpaEntity) .graduationCategory(GraduationCategory.CORE_CULTURE) .totalCredit(10) - .takenCredit(10).build(); + .takenCredit(10) + .build(); completedCreditRepository.saveAll( List.of(commonCultureCompletedCreditJpaEntity, coreCultureCompletedCreditJpaEntity)); - //when + //when completedCreditRepository.deleteAllByUserJpaEntity(userJpaEntity); - //then + //then List foundCompletedCredits = completedCreditRepository.findAllByUserJpaEntity( userJpaEntity); - assertThat(foundCompletedCredits).isEmpty(); + assertThat(foundCompletedCredits).isEmpty(); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/BasicAcademicalLectureFixture.java b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/BasicAcademicalLectureFixture.java index b25b65fb..05e0cfb3 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/BasicAcademicalLectureFixture.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/BasicAcademicalLectureFixture.java @@ -1,14 +1,14 @@ package com.plzgraduate.myongjigraduatebe.fixture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import java.util.HashSet; import java.util.Map; import java.util.Set; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - public class BasicAcademicalLectureFixture { + public static final String 인문대 = "인문대"; public static final String 사회과학대 = "사회과학대"; public static final String 경영대 = "경영대"; diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CommonCultureCategoryFixture.java b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CommonCultureCategoryFixture.java index aed9804a..7721e911 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CommonCultureCategoryFixture.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CommonCultureCategoryFixture.java @@ -1,15 +1,24 @@ package com.plzgraduate.myongjigraduatebe.fixture; -import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.*; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.*; +import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.공통교양_16_17; +import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.공통교양_18_19; +import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.공통교양_20_21_22; +import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.공통교양_23; +import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.영어레벨_12; +import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.영어레벨_34; +import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.영어레벨_Basic; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CAREER; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_A; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_B; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.DIGITAL_LITERACY; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.ENGLISH; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.EXPRESSION; import java.util.stream.Stream; - import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; - public class CommonCultureCategoryFixture implements ArgumentsProvider { @Override diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CommonCultureFixture.java b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CommonCultureFixture.java index 51533dab..21d48b9d 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CommonCultureFixture.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CommonCultureFixture.java @@ -1,6 +1,9 @@ package com.plzgraduate.myongjigraduatebe.fixture; -import static com.plzgraduate.myongjigraduatebe.fixture.UserFixture.*; +import static com.plzgraduate.myongjigraduatebe.fixture.UserFixture.경영학과_23학번; +import static com.plzgraduate.myongjigraduatebe.fixture.UserFixture.영문학과_16학번; +import static com.plzgraduate.myongjigraduatebe.fixture.UserFixture.영문학과_18학번; +import static com.plzgraduate.myongjigraduatebe.fixture.UserFixture.행정학과_21학번; import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CAREER; import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_A; import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_B; @@ -8,32 +11,20 @@ import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.ENGLISH; import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.EXPRESSION; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.stream.Stream; - import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - public class CommonCultureFixture implements ArgumentsProvider { public static final Map mockLectureMap = LectureFixture.getMockLectureMap(); - @Override - public Stream provideArguments(ExtensionContext context) throws Exception { - return Stream.of( - Arguments.arguments(영문학과_16학번(), 공통교양_16_17()), - Arguments.arguments(영문학과_18학번(), 공통교양_18_19()), - Arguments.arguments(행정학과_21학번(), 공통교양_20_21_22()), - Arguments.arguments(경영학과_23학번(), 공통교양_23()) - ); - } - public static Set 공통교양_16_17() { Set lectureSet = new HashSet<>(); lectureSet.add(CommonCulture.of(mockLectureMap.get("KMA02100"), CHRISTIAN_A)); @@ -129,4 +120,14 @@ public Stream provideArguments(ExtensionContext context) th lectureSet.add(CommonCulture.of(mockLectureMap.get("KMA02126"), ENGLISH)); return lectureSet; } + + @Override + public Stream provideArguments(ExtensionContext context) throws Exception { + return Stream.of( + Arguments.arguments(영문학과_16학번(), 공통교양_16_17()), + Arguments.arguments(영문학과_18학번(), 공통교양_18_19()), + Arguments.arguments(행정학과_21학번(), 공통교양_20_21_22()), + Arguments.arguments(경영학과_23학번(), 공통교양_23()) + ); + } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CoreCultureCategoryFixture.java b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CoreCultureCategoryFixture.java index 697cb674..40ecb60d 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CoreCultureCategoryFixture.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CoreCultureCategoryFixture.java @@ -4,11 +4,12 @@ import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_문화와예술; import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_사회와공동체; import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_역사와철학; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.*; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.CULTURE_ART; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.HISTORY_PHILOSOPHY; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.SCIENCE_TECHNOLOGY; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.SOCIETY_COMMUNITY; -import java.util.Map; import java.util.stream.Stream; - import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; @@ -19,7 +20,7 @@ public class CoreCultureCategoryFixture implements ArgumentsProvider { @Override public Stream provideArguments(ExtensionContext context) throws Exception { return Stream.of( - Arguments.arguments(HISTORY_PHILOSOPHY,핵심교양_역사와철학()), + Arguments.arguments(HISTORY_PHILOSOPHY, 핵심교양_역사와철학()), Arguments.arguments(SOCIETY_COMMUNITY, 핵심교양_사회와공동체()), Arguments.arguments(CULTURE_ART, 핵심교양_문화와예술()), Arguments.arguments(SCIENCE_TECHNOLOGY, 핵심교양_과학과기술()) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CoreCultureFixture.java b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CoreCultureFixture.java index 9bff5fea..04e0060f 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CoreCultureFixture.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CoreCultureFixture.java @@ -5,14 +5,12 @@ import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.SCIENCE_TECHNOLOGY; import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.SOCIETY_COMMUNITY; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import java.util.HashSet; import java.util.Map; import java.util.Set; - -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - public class CoreCultureFixture { public static final Map mockLectureMap = LectureFixture.getMockLectureMap(); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/LectureFixture.java b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/LectureFixture.java index ca53a256..1c37cb99 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/LectureFixture.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/LectureFixture.java @@ -1,19 +1,18 @@ package com.plzgraduate.myongjigraduatebe.fixture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; - import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - public class LectureFixture { + private static final Map mockLectureMap; static { @@ -30,7 +29,7 @@ private static void setUpMockLectureMap() { Resource resource = resourceLoader.getResource("/lecture.csv"); try (InputStream inputStream = resource.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; while ((line = reader.readLine()) != null) { @@ -48,5 +47,4 @@ private static void setUpMockLectureMap() { e.printStackTrace(); } } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/MajorFixture.java b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/MajorFixture.java index df197d84..3c887d1c 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/MajorFixture.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/MajorFixture.java @@ -1,12 +1,11 @@ package com.plzgraduate.myongjigraduatebe.fixture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; import java.util.HashSet; import java.util.Map; import java.util.Set; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; - public class MajorFixture { public static final Map mockLectureMap = LectureFixture.getMockLectureMap(); @@ -17,7 +16,8 @@ public class MajorFixture { public static Set 국제통상_전공() { Set lectureSet = new HashSet<>(); lectureSet.add(MajorLecture.of(mockLectureMap.get("HBX01128"), 국제통상학과, 1, 16, 99)); //국제통상원론 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HBX01129"), 국제통상학과, 1, 16, 99)); //글로벌경영전략 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HBX01129"), 국제통상학과, 1, 16, 99)); //글로벌경영전략 lectureSet.add(MajorLecture.of(mockLectureMap.get("HBX01127"), 국제통상학과, 1, 16, 99)); //국제경영학 lectureSet.add(MajorLecture.of(mockLectureMap.get("HBX01104"), 국제통상학과, 1, 16, 99)); //회계원리 lectureSet.add(MajorLecture.of(mockLectureMap.get("HBX01106"), 국제통상학과, 1, 16, 99)); //마켓팅원론 @@ -26,9 +26,11 @@ public class MajorFixture { lectureSet.add(MajorLecture.of(mockLectureMap.get("HBX01114"), 국제통상학과, 1, 16, 99)); //생산운영관리 lectureSet.add(MajorLecture.of(mockLectureMap.get("HBX01143"), 국제통상학과, 1, 16, 99)); //운영관리 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HBX01142"), 국제통상학과, 0, 16, 99)); //창업과경영캡스톤 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HBX01142"), 국제통상학과, 0, 16, 99)); //창업과경영캡스톤 lectureSet.add(MajorLecture.of(mockLectureMap.get("HBW01202"), 국제통상학과, 0, 16, 99)); //국제금융론 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HBW01203"), 국제통상학과, 0, 16, 99)); //파생금융상품론 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HBW01203"), 국제통상학과, 0, 16, 99)); //파생금융상품론 lectureSet.add(MajorLecture.of(mockLectureMap.get("HBW01309"), 국제통상학과, 0, 16, 99)); //국제마케팅 lectureSet.add(MajorLecture.of(mockLectureMap.get("HBW01401"), 국제통상학과, 0, 16, 99)); //외환론 lectureSet.add(MajorLecture.of(mockLectureMap.get("HBV01301"), 국제통상학과, 0, 16, 99)); //전자상거래 @@ -36,86 +38,149 @@ public class MajorFixture { lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04236"), 국제통상학과, 0, 16, 99)); //무역실무 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04310"), 국제통상학과, 0, 16, 99)); //무역영어 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04312"), 국제통상학과, 0, 16, 99)); //신흥시장연구 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04320"), 국제통상학과, 0, 16, 99)); //국제통상정책론 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04320"), 국제통상학과, 0, 16, 99)); //국제통상정책론 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04322"), 국제통상학과, 0, 16, 99)); //국제협상전략 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04338"), 국제통상학과, 0, 16, 99)); //경제통합론 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04343"), 국제통상학과, 0, 16, 99)); //해외시장조사론 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04346"), 국제통상학과, 0, 16, 99)); //글로벌혁신연구 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04343"), 국제통상학과, 0, 16, 99)); //해외시장조사론 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04346"), 국제통상학과, 0, 16, 99)); //글로벌혁신연구 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04349"), 국제통상학과, 0, 16, 99)); //국제무역연구 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04350"), 국제통상학과, 0, 16, 99)); //EU통상론 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04351"), 국제통상학과, 0, 16, 99)); //국제물류론 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04395"), 국제통상학과, 0, 16, 99)); //개방경제론 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04397"), 국제통상학과, 0, 16, 99)); //국제통상취업세미나 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04398"), 국제통상학과, 0, 16, 99)); //국제개발협력론 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04397"), 국제통상학과, 0, 16, 99)); //국제통상취업세미나 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04398"), 국제통상학과, 0, 16, 99)); //국제개발협력론 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04426"), 국제통상학과, 0, 16, 99)); //다국적기업론 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04432"), 국제통상학과, 0, 16, 99)); //해상보험론 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04444"), 국제통상학과, 0, 16, 99)); //글로벌경영전략사례연구 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04450"), 국제통상학과, 0, 16, 99)); //국제유통경영론 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04455"), 국제통상학과, 0, 16, 99)); //무역과개발협력 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04444"), 국제통상학과, 0, 16, 99)); //글로벌경영전략사례연구 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04450"), 국제통상학과, 0, 16, 99)); //국제유통경영론 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04455"), 국제통상학과, 0, 16, 99)); //무역과개발협력 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04456"), 국제통상학과, 0, 16, 99)); //미국경제론 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04457"), 국제통상학과, 0, 16, 99)); //WTO연구 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04461"), 국제통상학과, 0, 16, 99)); //국제통상세미나 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04463"), 국제통상학과, 0, 16, 99)); //국제경영세미나 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04461"), 국제통상학과, 0, 16, 99)); //국제통상세미나 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04463"), 국제통상학과, 0, 16, 99)); //국제경영세미나 lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04495"), 국제통상학과, 0, 16, 99)); //국제물류실무 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HCC04496"), 국제통상학과, 0, 16, 99)); //글로벌전략계획 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HCC04496"), 국제통상학과, 0, 16, 99)); //글로벌전략계획 return lectureSet; } public static Set 데이터테크놀로지_전공() { Set lectureSet = new HashSet<>(); - lectureSet.add(MajorLecture.of(mockLectureMap.get("HEB01102"), 데이터테크놀로지전공, 1, 16, 99)); //기초프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HEB01104"), 데이터테크놀로지전공, 1, 16, 99)); //객체지향프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HEB01105"), 데이터테크놀로지전공, 1, 16, 99)); //기초프로그래밍2 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01201"), 데이터테크놀로지전공, 1, 16, 99)); //자료구조 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01202"), 데이터테크놀로지전공, 1, 16, 99)); //R통계분석 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01203"), 데이터테크놀로지전공, 1, 16, 99)); //데이터베이스 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01206"), 데이터테크놀로지전공, 1, 16, 16)); //기초웹프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HEB01202"), 데이터테크놀로지전공, 1, 16, 16)); //기초웹프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HEB01201"), 데이터테크놀로지전공, 1, 16, 16)); //기초웹프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01307"), 데이터테크놀로지전공, 1, 16, 99)); //알고리즘 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01301"), 데이터테크놀로지전공, 1, 16, 99)); //소프트웨어공학 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01303"), 데이터테크놀로지전공, 1, 16, 99)); //운영체제 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01306"), 데이터테크놀로지전공, 1, 16, 99)); //빅데이터프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01308"), 데이터테크놀로지전공, 1, 16, 16)); //UX디자인 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01317"), 데이터테크놀로지전공, 1, 16, 16)); //데이터베이스프로젝트 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01302"), 데이터테크놀로지전공, 1, 16, 16)); //데이터베이스프로그래처 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01315"), 데이터테크놀로지전공, 1, 17, 99)); //인공지능 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01413"), 데이터테크놀로지전공, 1, 17, 99)); //캡스톤디자인 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01401"), 데이터테크놀로지전공, 1, 17, 99)); //캡스톤디자인1 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01402"), 데이터테크놀로지전공, 1, 17, 99)); //캡스톤디자인2 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HEB01102"), 데이터테크놀로지전공, 1, 16, 99)); //기초프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HEB01104"), 데이터테크놀로지전공, 1, 16, 99)); //객체지향프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HEB01105"), 데이터테크놀로지전공, 1, 16, 99)); //기초프로그래밍2 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01201"), 데이터테크놀로지전공, 1, 16, 99)); //자료구조 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01202"), 데이터테크놀로지전공, 1, 16, 99)); //R통계분석 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01203"), 데이터테크놀로지전공, 1, 16, 99)); //데이터베이스 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01206"), 데이터테크놀로지전공, 1, 16, 16)); //기초웹프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HEB01202"), 데이터테크놀로지전공, 1, 16, 16)); //기초웹프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HEB01201"), 데이터테크놀로지전공, 1, 16, 16)); //기초웹프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01307"), 데이터테크놀로지전공, 1, 16, 99)); //알고리즘 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01301"), 데이터테크놀로지전공, 1, 16, 99)); //소프트웨어공학 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01303"), 데이터테크놀로지전공, 1, 16, 99)); //운영체제 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01306"), 데이터테크놀로지전공, 1, 16, 99)); //빅데이터프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01308"), 데이터테크놀로지전공, 1, 16, 16)); //UX디자인 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01317"), 데이터테크놀로지전공, 1, 16, 16)); //데이터베이스프로젝트 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01302"), 데이터테크놀로지전공, 1, 16, 16)); //데이터베이스프로그래처 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01315"), 데이터테크놀로지전공, 1, 17, 99)); //인공지능 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01413"), 데이터테크놀로지전공, 1, 17, 99)); //캡스톤디자인 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01401"), 데이터테크놀로지전공, 1, 17, 99)); //캡스톤디자인1 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01402"), 데이터테크놀로지전공, 1, 17, 99)); //캡스톤디자인2 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01102"), 데이터테크놀로지전공, 0, 16, 99)); //데이터사이언스개론 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01103"), 데이터테크놀로지전공, 0, 16, 99)); //소프트웨어인턴십 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01204"), 데이터테크놀로지전공, 0, 16, 99)); //객체지향디자인패턴 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01205"), 데이터테크놀로지전공, 0, 16, 99)); //통계적데이터분석 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01207"), 데이터테크놀로지전공, 0, 16, 99)); //융합심화R통계분석 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01208"), 데이터테크놀로지전공, 0, 16, 99)); //융합데이터베이스 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01304"), 데이터테크놀로지전공, 0, 16, 99)); //고급서버프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01305"), 데이터테크놀로지전공, 0, 16, 99)); //인터랙티브인포그래픽 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01309"), 데이터테크놀로지전공, 0, 16, 99)); //컴퓨터아키텍처 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01310"), 데이터테크놀로지전공, 0, 16, 99)); //모바일컴퓨팅 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01311"), 데이터테크놀로지전공, 0, 16, 99)); //자기주도학습 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01312"), 데이터테크놀로지전공, 0, 16, 99)); //소프트웨어세미나 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01313"), 데이터테크놀로지전공, 0, 16, 99)); //컴퓨터통신 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01314"), 데이터테크놀로지전공, 0, 16, 99)); //게임프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01315"), 데이터테크놀로지전공, 0, 16, 99)); //인공지능 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01316"), 데이터테크놀로지전공, 0, 16, 99)); //고급웹프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01318"), 데이터테크놀로지전공, 0, 16, 99)); //모바일컴퓨팅 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01403"), 데이터테크놀로지전공, 0, 16, 99)); //블록체인기초 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01404"), 데이터테크놀로지전공, 0, 16, 99)); //빅데이터기술특론1 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01405"), 데이터테크놀로지전공, 0, 16, 99)); //빅데이터기술특론2 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01406"), 데이터테크놀로지전공, 0, 16, 99)); //클라우드시스템 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01407"), 데이터테크놀로지전공, 0, 16, 99)); //딥러닝 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01408"), 데이터테크놀로지전공, 0, 16, 99)); //데이터사이언스 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01409"), 데이터테크놀로지전공, 0, 16, 99)); //현장실무교육 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01411"), 데이터테크놀로지전공, 0, 16, 99)); //인터랙션디자인 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01410"), 데이터테크놀로지전공, 0, 16, 99)); //빅데이터시스템특론(대학원) - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01412"), 데이터테크놀로지전공, 0, 16, 99)); //대용량데이터베이스특론(대학원) - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01414"), 데이터테크놀로지전공, 0, 16, 99)); //빅데이터컴퓨팅(대학원) - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01415"), 데이터테크놀로지전공, 0, 16, 99)); //논문연구(대학원) - lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01416"), 데이터테크놀로지전공, 0, 16, 99)); //고급딥러닝(대학원) - lectureSet.add(MajorLecture.of(mockLectureMap.get("HEB01101"), 데이터테크놀로지전공, 0, 16, 99)); //절차적사고와프로그래밍 - lectureSet.add(MajorLecture.of(mockLectureMap.get("HEB01103"), 데이터테크놀로지전공, 0, 16, 99)); //객체지향적사고와프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01102"), 데이터테크놀로지전공, 0, 16, 99)); //데이터사이언스개론 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01103"), 데이터테크놀로지전공, 0, 16, 99)); //소프트웨어인턴십 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01204"), 데이터테크놀로지전공, 0, 16, 99)); //객체지향디자인패턴 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01205"), 데이터테크놀로지전공, 0, 16, 99)); //통계적데이터분석 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01207"), 데이터테크놀로지전공, 0, 16, 99)); //융합심화R통계분석 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01208"), 데이터테크놀로지전공, 0, 16, 99)); //융합데이터베이스 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01304"), 데이터테크놀로지전공, 0, 16, 99)); //고급서버프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01305"), 데이터테크놀로지전공, 0, 16, 99)); //인터랙티브인포그래픽 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01309"), 데이터테크놀로지전공, 0, 16, 99)); //컴퓨터아키텍처 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01310"), 데이터테크놀로지전공, 0, 16, 99)); //모바일컴퓨팅 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01311"), 데이터테크놀로지전공, 0, 16, 99)); //자기주도학습 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01312"), 데이터테크놀로지전공, 0, 16, 99)); //소프트웨어세미나 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01313"), 데이터테크놀로지전공, 0, 16, 99)); //컴퓨터통신 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01314"), 데이터테크놀로지전공, 0, 16, 99)); //게임프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01315"), 데이터테크놀로지전공, 0, 16, 99)); //인공지능 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01316"), 데이터테크놀로지전공, 0, 16, 99)); //고급웹프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01318"), 데이터테크놀로지전공, 0, 16, 99)); //모바일컴퓨팅 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01403"), 데이터테크놀로지전공, 0, 16, 99)); //블록체인기초 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01404"), 데이터테크놀로지전공, 0, 16, 99)); //빅데이터기술특론1 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01405"), 데이터테크놀로지전공, 0, 16, 99)); //빅데이터기술특론2 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01406"), 데이터테크놀로지전공, 0, 16, 99)); //클라우드시스템 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01407"), 데이터테크놀로지전공, 0, 16, 99)); //딥러닝 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01408"), 데이터테크놀로지전공, 0, 16, 99)); //데이터사이언스 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01409"), 데이터테크놀로지전공, 0, 16, 99)); //현장실무교육 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01411"), 데이터테크놀로지전공, 0, 16, 99)); //인터랙션디자인 + lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01410"), 데이터테크놀로지전공, 0, 16, + 99)); //빅데이터시스템특론(대학원) + lectureSet.add(MajorLecture.of(mockLectureMap.get("HED01412"), 데이터테크놀로지전공, 0, 16, + 99)); //대용량데이터베이스특론(대학원) + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01414"), 데이터테크놀로지전공, 0, 16, 99)); //빅데이터컴퓨팅(대학원) + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01415"), 데이터테크놀로지전공, 0, 16, 99)); //논문연구(대학원) + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HED01416"), 데이터테크놀로지전공, 0, 16, 99)); //고급딥러닝(대학원) + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HEB01101"), 데이터테크놀로지전공, 0, 16, 99)); //절차적사고와프로그래밍 + lectureSet.add( + MajorLecture.of(mockLectureMap.get("HEB01103"), 데이터테크놀로지전공, 0, 16, 99)); //객체지향적사고와프로그래밍 return lectureSet; } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/UserFixture.java b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/UserFixture.java index d866723d..dbd22e9e 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/UserFixture.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/UserFixture.java @@ -37,7 +37,8 @@ public class UserFixture { } public static User 경영학과_19학번_영어_면제() { - return createUser("mj21", "1234", EnglishLevel.FREE, "김경영", "60191021", 19, "경영학과", null, StudentCategory.NORMAL); + return createUser("mj21", "1234", EnglishLevel.FREE, "김경영", "60191021", 19, "경영학과", null, + StudentCategory.NORMAL); } public static User 경영학과_22학번() { @@ -51,7 +52,8 @@ public class UserFixture { } public static User 경영학과_23학번_국제통상학과_부전공() { - return createUser("mj22", "1234", EnglishLevel.ENG34, "김경영", "60231022", 23, "경영학과", "국제통상학과", + return createUser("mj22", "1234", EnglishLevel.ENG34, "김경영", "60231022", 23, "경영학과", + "국제통상학과", StudentCategory.SUB_MAJOR); } @@ -61,56 +63,67 @@ public class UserFixture { } public static User 데이테크놀로지학과_16학번() { - return createUser("mj1001", "1234", EnglishLevel.ENG12, "정데테", "60161666", 16, "데이터테크놀로지전공", null, + return createUser("mj1001", "1234", EnglishLevel.ENG12, "정데테", "60161666", 16, "데이터테크놀로지전공", + null, StudentCategory.NORMAL); } public static User 데이테크놀로지학과_16학번_Eng34() { - return createUser("mj1001", "1234", EnglishLevel.ENG34, "정데테", "60161666", 16, "데이터테크놀로지전공", null, + return createUser("mj1001", "1234", EnglishLevel.ENG34, "정데테", "60161666", 16, "데이터테크놀로지전공", + null, StudentCategory.NORMAL); } public static User 데이테크놀로지학과_18학번_Basic_Eng() { - return createUser("mj1001", "1234", EnglishLevel.BASIC, "정데테", "60181666", 18, "데이터테크놀로지전공", null, + return createUser("mj1001", "1234", EnglishLevel.BASIC, "정데테", "60181666", 18, "데이터테크놀로지전공", + null, StudentCategory.NORMAL); } public static User 데이테크놀로지학과_18학번() { - return createUser("mj1003", "1234", EnglishLevel.ENG12, "정데테", "60181666", 18, "데이터테크놀로지전공", null, + return createUser("mj1003", "1234", EnglishLevel.ENG12, "정데테", "60181666", 18, "데이터테크놀로지전공", + null, StudentCategory.NORMAL); } public static User 응용소프트웨어학과_17학번() { - return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60171022", 17, "응용소프트웨어전공", null, + return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60171022", 17, "응용소프트웨어전공", + null, StudentCategory.NORMAL); } public static User 응용소프트웨어학과_19학번() { - return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60191022", 19, "응용소프트웨어전공", null, + return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60191022", 19, "응용소프트웨어전공", + null, StudentCategory.NORMAL); } public static User 응용소프트웨어학과_19학번_영어_면제() { - return createUser("mj22", "1234", EnglishLevel.FREE, "김응용", "60191022", 19, "응용소프트웨어전공", null, + return createUser("mj22", "1234", EnglishLevel.FREE, "김응용", "60191022", 19, "응용소프트웨어전공", + null, StudentCategory.NORMAL); } public static User 데이터테크놀로지학과_19학번() { - return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60191022", 19, "데이터테크놀로지전공", null, + return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60191022", 19, "데이터테크놀로지전공", + null, StudentCategory.NORMAL); } public static User 디지털콘텐츠디자인학과_19학번() { - return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60191022", 19, "디지털콘텐츠디자인학과", null, + return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60191022", 19, "디지털콘텐츠디자인학과", + null, StudentCategory.NORMAL); } public static User 디지털콘텐츠디자인학과_23학번() { - return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60231022", 23, "디지털콘텐츠디자인학과", null, + return createUser("mj22", "1234", EnglishLevel.ENG34, "김응용", "60231022", 23, "디지털콘텐츠디자인학과", + null, StudentCategory.NORMAL); } - public static User createUser(String authId, String password, EnglishLevel englishLevel, String name, + public static User createUser(String authId, String password, EnglishLevel englishLevel, + String name, String studentNumber, int entryYear, String major, String subMajor, StudentCategory studentCategory) { return User.builder() @@ -126,5 +139,4 @@ public static User createUser(String authId, String password, EnglishLevel engli .studentCategory(studentCategory) .build(); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/majorfixture/InternationalTradeFixture.java b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/majorfixture/InternationalTradeFixture.java index 28c5a5c1..0929637b 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/majorfixture/InternationalTradeFixture.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/fixture/majorfixture/InternationalTradeFixture.java @@ -1,12 +1,10 @@ package com.plzgraduate.myongjigraduatebe.fixture.majorfixture; -import java.util.Map; - import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import java.util.Map; public class InternationalTradeFixture { + public static final Map mockLectureMap = LectureFixture.getMockLectureMap(); - - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationsControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationsControllerTest.java index b3ca4d6e..222c0633 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationsControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationsControllerTest.java @@ -12,17 +12,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.http.HttpStatus; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; import com.plzgraduate.myongjigraduatebe.support.WithMockAuthenticationUser; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class FindDetailGraduationsControllerTest extends WebAdaptorTestSupport { @@ -32,10 +28,14 @@ class FindDetailGraduationsControllerTest extends WebAdaptorTestSupport { void getCommonDetailGraduations() throws Exception { //given List detailCategories = List.of( - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build() + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build() ); DetailGraduationResult detailGraduationResult = DetailGraduationResult.builder() .graduationCategory(COMMON_CULTURE) @@ -65,10 +65,14 @@ void getCommonDetailGraduations() throws Exception { void getCoreDetailGraduations() throws Exception { //given List detailCategories = List.of( - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build() + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build() ); DetailGraduationResult detailGraduationResult = DetailGraduationResult.builder() .graduationCategory(CORE_CULTURE) @@ -98,10 +102,14 @@ void getCoreDetailGraduations() throws Exception { void getPrimaryMandatoryMajorDetailGraduations() throws Exception { //given List detailCategories = List.of( - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build() + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build() ); DetailGraduationResult detailGraduationResult = DetailGraduationResult.builder() .graduationCategory(PRIMARY_MANDATORY_MAJOR) @@ -131,10 +139,14 @@ void getPrimaryMandatoryMajorDetailGraduations() throws Exception { void getPrimaryElectiveMajorDetailGraduations() throws Exception { //given List detailCategories = List.of( - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build() + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build() ); DetailGraduationResult detailGraduationResult = DetailGraduationResult.builder() .graduationCategory(PRIMARY_ELECTIVE_MAJOR) @@ -164,10 +176,14 @@ void getPrimaryElectiveMajorDetailGraduations() throws Exception { void getPrimaryBasicAcademicalCultureMajorDetailGraduations() throws Exception { //given List detailCategories = List.of( - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build(), - DetailCategoryResult.builder().build() + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build(), + DetailCategoryResult.builder() + .build() ); DetailGraduationResult detailGraduationResult = DetailGraduationResult.builder() .graduationCategory(PRIMARY_BASIC_ACADEMICAL_CULTURE) @@ -205,5 +221,4 @@ void getDetailGraduationsWithInvalidGraduationCategory() throws Exception { .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errorCode").value(INVALIDATED_GRADUATION_CATEGORY.toString())); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationServiceTest.java index 27cea0de..b17edc9c 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationServiceTest.java @@ -1,25 +1,18 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CORE_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE; import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.BUSINESS; import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.ICT; -import static com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory.*; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory.DUAL_MAJOR; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.BasicAcademicalGraduationManager; @@ -32,6 +25,15 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class CalculateBasicAcademicalCultureGraduationServiceTest { @@ -46,43 +48,53 @@ class CalculateBasicAcademicalCultureGraduationServiceTest { @BeforeEach void setUp() { List basicAcademicalGraduationManagers = - List.of(new DefaultBasicAcademicalGraduationManager(), new BusinessBasicAcademicalGraduationManager(), new SocialScienceBasicAcademicGraduationManager()); - calculateBasicAcademicalCultureGraduationService = new CalculateBasicAcademicalCultureGraduationService(findBasicAcademicalCulturePort, basicAcademicalGraduationManagers); + List.of(new DefaultBasicAcademicalGraduationManager(), + new BusinessBasicAcademicalGraduationManager(), + new SocialScienceBasicAcademicGraduationManager()); + calculateBasicAcademicalCultureGraduationService = new CalculateBasicAcademicalCultureGraduationService( + findBasicAcademicalCulturePort, basicAcademicalGraduationManagers); user = User.builder() .id(1L) .primaryMajor("응용소프트웨어전공") .dualMajor("경영학과") .studentCategory(DUAL_MAJOR) - .entryYear(19).build(); + .entryYear(19) + .build(); } @DisplayName("BASIC_ACADEMICAL_CULTURE 관련 카테고리 일때만 BasicAcademicalCultureGraduationService를 호출한다.") @Test void shouldSupportBasicAcademicalCultureCategory() { - assertTrue(calculateBasicAcademicalCultureGraduationService.supports(PRIMARY_BASIC_ACADEMICAL_CULTURE)); - assertTrue(calculateBasicAcademicalCultureGraduationService.supports(DUAL_BASIC_ACADEMICAL_CULTURE)); + assertTrue(calculateBasicAcademicalCultureGraduationService.supports( + PRIMARY_BASIC_ACADEMICAL_CULTURE)); + assertTrue(calculateBasicAcademicalCultureGraduationService.supports( + DUAL_BASIC_ACADEMICAL_CULTURE)); assertFalse(calculateBasicAcademicalCultureGraduationService.supports(CORE_CULTURE)); assertFalse(calculateBasicAcademicalCultureGraduationService.supports(COMMON_CULTURE)); } - @DisplayName("카테고리별 계산 시 유저의 핵심교양 상세 졸업결과를 계산한다.") @Test void shouldCalculateSingleDetailGraduationIfPrimaryCategory() { //given HashSet graduationCoreCultures = new HashSet<>( Set.of(BasicAcademicalCultureLecture.of(Lecture.from("KMA02128"), ICT.getName()))); - given(findBasicAcademicalCulturePort.findBasicAcademicalCulture(anyString())).willReturn(graduationCoreCultures); + given(findBasicAcademicalCulturePort.findBasicAcademicalCulture(anyString())).willReturn( + graduationCoreCultures); HashSet takenLectures = new HashSet<>( Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("KMA02128") - .credit(3).build()).build())); + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("KMA02128") + .credit(3) + .build()) + .build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .primaryBasicAcademicalCultureCredit(18).build(); + .primaryBasicAcademicalCultureCredit(18) + .build(); //when DetailGraduationResult detailCoreCultureGraduationResult = calculateBasicAcademicalCultureGraduationService.calculateSingleDetailGraduation( @@ -103,16 +115,20 @@ void shouldCalculateSingleDetailGraduationIfDualCategory() { HashSet takenLectures = new HashSet<>( Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("KMA02128") - .credit(3).build()).build())); + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("KMA02128") + .credit(3) + .build()) + .build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .dualBasicAcademicalCultureCredit(18).build(); - + .dualBasicAcademicalCultureCredit(18) + .build(); - given(findBasicAcademicalCulturePort.findBasicAcademicalCulture(anyString())).willReturn(graduationBasicAcademicalCultures); + given(findBasicAcademicalCulturePort.findBasicAcademicalCulture(anyString())).willReturn( + graduationBasicAcademicalCultures); //when DetailGraduationResult detailCoreCultureGraduationResult = calculateBasicAcademicalCultureGraduationService.calculateSingleDetailGraduation( diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationServiceTest.java index 4e813e34..0e1ea1cf 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationServiceTest.java @@ -3,20 +3,10 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_A; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.BDDMockito.given; -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; @@ -27,6 +17,15 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class CalculateCommonCultureGraduationServiceTest { @@ -40,15 +39,18 @@ class CalculateCommonCultureGraduationServiceTest { @BeforeEach void setUp() { CommonGraduationManager commonGraduationManager = new CommonGraduationManager(); - calculateCommonCultureGraduationService = new CalculateCommonCultureGraduationService(findCommonCulturePort, + calculateCommonCultureGraduationService = new CalculateCommonCultureGraduationService( + findCommonCulturePort, commonGraduationManager); } @DisplayName("COMMON_CULTURE 카테고리 일때만 CommonCultureGraduationService를 호출한다.") @Test void shouldSupportCommonCultureCategory() { - assertTrue(calculateCommonCultureGraduationService.supports(GraduationCategory.COMMON_CULTURE)); - assertFalse(calculateCommonCultureGraduationService.supports(GraduationCategory.CORE_CULTURE)); + assertTrue( + calculateCommonCultureGraduationService.supports(GraduationCategory.COMMON_CULTURE)); + assertFalse( + calculateCommonCultureGraduationService.supports(GraduationCategory.CORE_CULTURE)); } @DisplayName("유저의 공통교양 상세 졸업결과를 계산한다.") @@ -58,17 +60,22 @@ void shouldCalculateCommonCulture() { User user = User.builder() .id(1L) .primaryMajor("응용소프트웨어전공") - .entryYear(19).build(); + .entryYear(19) + .build(); HashSet graduationCommonCultures = new HashSet<>( Set.of(CommonCulture.of(Lecture.from("KMA00101"), CHRISTIAN_A))); HashSet takenLectures = new HashSet<>( Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("KMA00101") - .credit(2).build()).build())); + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("KMA00101") + .credit(2) + .build()) + .build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .commonCultureCredit(17).build(); + .commonCultureCredit(17) + .build(); given(findCommonCulturePort.findCommonCulture(user)).willReturn(graduationCommonCultures); @@ -81,5 +88,4 @@ void shouldCalculateCommonCulture() { .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") .contains(COMMON_CULTURE, false, 17, 2.0); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationServiceTest.java index c4b48953..9dc28a42 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationServiceTest.java @@ -7,16 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.BDDMockito.given; -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; @@ -27,6 +17,14 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class CalculateCoreCultureGraduationServiceTest { @@ -37,14 +35,16 @@ class CalculateCoreCultureGraduationServiceTest { @BeforeEach void setUp() { - calculateCoreCultureGraduationService = new CalculateCoreCultureGraduationService(findCoreCulturePort, new CoreGraduationManager()); + calculateCoreCultureGraduationService = new CalculateCoreCultureGraduationService( + findCoreCulturePort, new CoreGraduationManager()); } @DisplayName("CORE_CULTURE 카테고리 일때만 CoreCultureGraduationService를 호출한다.") @Test void shouldSupportCoreCultureCategory() { assertTrue(calculateCoreCultureGraduationService.supports(GraduationCategory.CORE_CULTURE)); - assertFalse(calculateCoreCultureGraduationService.supports(GraduationCategory.COMMON_CULTURE)); + assertFalse( + calculateCoreCultureGraduationService.supports(GraduationCategory.COMMON_CULTURE)); } @DisplayName("유저의 핵심교양 상세 졸업결과를 계산한다.") @@ -62,12 +62,16 @@ void shouldCalculateCoreCulture() { HashSet takenLectures = new HashSet<>( Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("KMA02128") - .credit(3).build()).build())); + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("KMA02128") + .credit(3) + .build()) + .build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .coreCultureCredit(coreCultureTotalCredit).build(); + .coreCultureCredit(coreCultureTotalCredit) + .build(); given(findCoreCulturePort.findCoreCulture(user)).willReturn(graduationCoreCultures); @@ -80,5 +84,4 @@ void shouldCalculateCoreCulture() { .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") .contains(CORE_CULTURE, false, 12, 3.0); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationServiceTest.java index 2a20f493..fd3f596d 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationServiceTest.java @@ -1,22 +1,19 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CORE_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_ELECTIVE_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_MANDATORY_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_ELECTIVE_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_MANDATORY_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.SUB_MAJOR; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.BDDMockito.given; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.ElectiveMajorManager; @@ -31,6 +28,15 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class CalculateMajorGraduationServiceTest { @@ -47,8 +53,10 @@ void setUp() { List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); SubMajorGraduationManager subMajorGraduationManager = new SubMajorGraduationManager(); - MajorGraduationManager majorGraduationManager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); - calculateMajorGraduationService = new CalculateMajorGraduationService(findMajorPort, majorGraduationManager, subMajorGraduationManager); + MajorGraduationManager majorGraduationManager = new MajorGraduationManager( + mandatoryMajorManager, electiveMajorManager); + calculateMajorGraduationService = new CalculateMajorGraduationService(findMajorPort, + majorGraduationManager, subMajorGraduationManager); } @DisplayName("MAJOR 관련 카테고리 일때만 MajorGraduationService를 호출한다.") @@ -72,25 +80,39 @@ void shouldCalculateSingleDetailGraduationIfPrimaryMandatory() { User user = User.builder() .id(1L) .primaryMajor("응용소프트웨어전공") - .entryYear(19).build(); + .entryYear(19) + .build(); HashSet graduationMajorLectures = new HashSet<>( Set.of( - MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), - MajorLecture.of(Lecture.builder().lectureCode("HEC01204").credit(3).build(), "응용소프트웨어전공", 1, 16, 23))); + MajorLecture.of(Lecture.builder() + .lectureCode("HEC01211") + .credit(3) + .build(), "응용소프트웨어전공", 1, 16, 23), + MajorLecture.of(Lecture.builder() + .lectureCode("HEC01204") + .credit(3) + .build(), "응용소프트웨어전공", 1, 16, 23))); given(findMajorPort.findMajor(user.getPrimaryMajor())).willReturn(graduationMajorLectures); HashSet takenLectures = new HashSet<>( Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01211") //전공 필수 - .credit(3).build()).build(), - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01305") //전공 선택 - .credit(3).build()).build())); + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("HEC01211") //전공 필수 + .credit(3) + .build()) + .build(), + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("HEC01305") //전공 선택 + .credit(3) + .build()) + .build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .primaryMajorCredit(70).build(); + .primaryMajorCredit(70) + .build(); //when DetailGraduationResult detailPrimaryMandatoryMajorGraduationResult = calculateMajorGraduationService.calculateSingleDetailGraduation( @@ -109,29 +131,46 @@ void calculateSingleDetailGraduationIfPrimaryElective() { User user = User.builder() .id(1L) .primaryMajor("응용소프트웨어전공") - .entryYear(19).build(); + .entryYear(19) + .build(); HashSet graduationMajorLectures = new HashSet<>( Set.of( // 전공 필수 - MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), + MajorLecture.of(Lecture.builder() + .lectureCode("HEC01211") + .credit(3) + .build(), "응용소프트웨어전공", 1, 16, 23), // 전공 선택 - MajorLecture.of(Lecture.builder().lectureCode("HEC01305").credit(3).build(), "응용소프트웨어전공", 0, 16, 23), + MajorLecture.of(Lecture.builder() + .lectureCode("HEC01305") + .credit(3) + .build(), "응용소프트웨어전공", 0, 16, 23), // 전공 선택 - MajorLecture.of(Lecture.builder().lectureCode("HEC01318").credit(3).build(), "응용소프트웨어전공", 0, 16, 23))); + MajorLecture.of(Lecture.builder() + .lectureCode("HEC01318") + .credit(3) + .build(), "응용소프트웨어전공", 0, 16, 23))); given(findMajorPort.findMajor(user.getPrimaryMajor())).willReturn(graduationMajorLectures); HashSet takenLectures = new HashSet<>( Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01211") //전공 필수 - .credit(3).build()).build(), - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01305") //전공 선택 - .credit(3).build()).build())); + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("HEC01211") //전공 필수 + .credit(3) + .build()) + .build(), + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("HEC01305") //전공 선택 + .credit(3) + .build()) + .build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .primaryMajorCredit(70).build(); + .primaryMajorCredit(70) + .build(); //when DetailGraduationResult detailPrimaryElectiveMajorGraduationResult = calculateMajorGraduationService.calculateSingleDetailGraduation( @@ -150,25 +189,39 @@ void calculateSingleDetailGraduationIfDualMandatory() { User user = User.builder() .id(1L) .dualMajor("응용소프트웨어전공") - .entryYear(19).build(); + .entryYear(19) + .build(); HashSet graduationMajorLectures = new HashSet<>( Set.of( - MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), - MajorLecture.of(Lecture.builder().lectureCode("HEC01204").credit(3).build(), "응용소프트웨어전공", 1, 16, 23))); + MajorLecture.of(Lecture.builder() + .lectureCode("HEC01211") + .credit(3) + .build(), "응용소프트웨어전공", 1, 16, 23), + MajorLecture.of(Lecture.builder() + .lectureCode("HEC01204") + .credit(3) + .build(), "응용소프트웨어전공", 1, 16, 23))); given(findMajorPort.findMajor(user.getDualMajor())).willReturn(graduationMajorLectures); HashSet takenLectures = new HashSet<>( Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01211") //전공 필수 - .credit(3).build()).build(), - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01305") //전공 선택 - .credit(3).build()).build())); + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("HEC01211") //전공 필수 + .credit(3) + .build()) + .build(), + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("HEC01305") //전공 선택 + .credit(3) + .build()) + .build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .dualMajorCredit(70).build(); + .dualMajorCredit(70) + .build(); //when DetailGraduationResult detailDualMandatoryMajorGraduationResult = calculateMajorGraduationService.calculateSingleDetailGraduation( @@ -187,25 +240,39 @@ void calculateCoreCulture() { User user = User.builder() .id(1L) .dualMajor("응용소프트웨어전공") - .entryYear(19).build(); + .entryYear(19) + .build(); HashSet graduationMajorLectures = new HashSet<>( Set.of( - MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), - MajorLecture.of(Lecture.builder().lectureCode("HEC01304").credit(3).build(), "응용소프트웨어전공", 0, 16, 23))); + MajorLecture.of(Lecture.builder() + .lectureCode("HEC01211") + .credit(3) + .build(), "응용소프트웨어전공", 1, 16, 23), + MajorLecture.of(Lecture.builder() + .lectureCode("HEC01304") + .credit(3) + .build(), "응용소프트웨어전공", 0, 16, 23))); given(findMajorPort.findMajor(user.getDualMajor())).willReturn(graduationMajorLectures); HashSet takenLectures = new HashSet<>( Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01211") //전공 필수 - .credit(3).build()).build(), - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01304") //전공 선택 - .credit(3).build()).build())); + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("HEC01211") //전공 필수 + .credit(3) + .build()) + .build(), + TakenLecture.builder() + .lecture(Lecture.builder() + .lectureCode("HEC01304") //전공 선택 + .credit(3) + .build()) + .build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .dualMajorCredit(70).build(); + .dualMajorCredit(70) + .build(); //when DetailGraduationResult detailDualMandatoryMajorGraduationResult = calculateMajorGraduationService.calculateSingleDetailGraduation( diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationServiceTest.java index c961beff..efcd4887 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationServiceTest.java @@ -1,16 +1,25 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; -import static com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory.*; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory.DUAL_MAJOR; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory.NORMAL; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory.SUB_MAJOR; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; +import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; +import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.util.HashSet; import java.util.List; import java.util.stream.Stream; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -19,16 +28,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class CalculateSingleDetailGraduationServiceTest { @@ -54,15 +53,18 @@ void calculateSingleDetailGraduationForNormalAndChange(String graduationCategory .id(1L) .entryYear(19) .studentCategory(NORMAL) - .primaryMajor("응용소프트웨어전공").build(); + .primaryMajor("응용소프트웨어전공") + .build(); GraduationCategory graduationCategory = GraduationCategory.valueOf(graduationCategoryName); CalculateDetailGraduationUseCase calculateDetailGraduationUseCase = mock( CalculateDetailGraduationUseCase.class); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(new HashSet<>()); given(findUserUseCase.findUserById(user.getId())).willReturn(user); - given(findTakenLectureUseCase.findTakenLectures(user.getId())).willReturn(takenLectureInventory); - given(calculateDetailGraduationUseCases.stream()).willReturn(Stream.of(calculateDetailGraduationUseCase)); + given(findTakenLectureUseCase.findTakenLectures(user.getId())).willReturn( + takenLectureInventory); + given(calculateDetailGraduationUseCases.stream()).willReturn( + Stream.of(calculateDetailGraduationUseCase)); given(calculateDetailGraduationUseCase.supports(graduationCategory)).willReturn(true); given(calculateDetailGraduationUseCase.calculateSingleDetailGraduation( any(User.class), any(GraduationCategory.class), @@ -71,7 +73,8 @@ void calculateSingleDetailGraduationForNormalAndChange(String graduationCategory // when DetailGraduationResult result = - calculateSingleDetailGraduationService.calculateSingleDetailGraduation(1L, graduationCategory); + calculateSingleDetailGraduationService.calculateSingleDetailGraduation(1L, + graduationCategory); // then assertNotNull(result); @@ -83,8 +86,10 @@ void calculateSingleDetailGraduationForNormalAndChange(String graduationCategory @DisplayName("이수구분 DUAL: 단일 카테고리 졸업상세결과를 조회한다.") @ValueSource(strings = - {"COMMON_CULTURE", "CORE_CULTURE", "PRIMARY_MANDATORY_MAJOR", "PRIMARY_ELECTIVE_MAJOR", "DUAL_MANDATORY_MAJOR", - "DUAL_ELECTIVE_MAJOR", "PRIMARY_BASIC_ACADEMICAL_CULTURE", "DUAL_BASIC_ACADEMICAL_CULTURE", + {"COMMON_CULTURE", "CORE_CULTURE", "PRIMARY_MANDATORY_MAJOR", "PRIMARY_ELECTIVE_MAJOR", + "DUAL_MANDATORY_MAJOR", + "DUAL_ELECTIVE_MAJOR", "PRIMARY_BASIC_ACADEMICAL_CULTURE", + "DUAL_BASIC_ACADEMICAL_CULTURE", "NORMAL_CULTURE", "FREE_ELECTIVE" }) @ParameterizedTest @@ -103,8 +108,10 @@ void calculateSingleDetailGraduationForDual(String graduationCategoryName) { TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(new HashSet<>()); given(findUserUseCase.findUserById(user.getId())).willReturn(user); - given(findTakenLectureUseCase.findTakenLectures(user.getId())).willReturn(takenLectureInventory); - given(calculateDetailGraduationUseCases.stream()).willReturn(Stream.of(calculateDetailGraduationUseCase)); + given(findTakenLectureUseCase.findTakenLectures(user.getId())).willReturn( + takenLectureInventory); + given(calculateDetailGraduationUseCases.stream()).willReturn( + Stream.of(calculateDetailGraduationUseCase)); given(calculateDetailGraduationUseCase.supports(graduationCategory)).willReturn(true); given(calculateDetailGraduationUseCase.calculateSingleDetailGraduation( any(User.class), any(GraduationCategory.class), @@ -113,7 +120,8 @@ void calculateSingleDetailGraduationForDual(String graduationCategoryName) { // when DetailGraduationResult result = - calculateSingleDetailGraduationService.calculateSingleDetailGraduation(1L, graduationCategory); + calculateSingleDetailGraduationService.calculateSingleDetailGraduation(1L, + graduationCategory); // then assertNotNull(result); @@ -125,7 +133,8 @@ void calculateSingleDetailGraduationForDual(String graduationCategoryName) { @DisplayName("이수구분 SUB: 단일 카테고리 졸업상세결과를 조회한다.") @ValueSource(strings = - {"COMMON_CULTURE", "CORE_CULTURE", "PRIMARY_MANDATORY_MAJOR", "PRIMARY_ELECTIVE_MAJOR", "SUB_MAJOR", + {"COMMON_CULTURE", "CORE_CULTURE", "PRIMARY_MANDATORY_MAJOR", "PRIMARY_ELECTIVE_MAJOR", + "SUB_MAJOR", "PRIMARY_BASIC_ACADEMICAL_CULTURE", "NORMAL_CULTURE", "FREE_ELECTIVE" }) @ParameterizedTest @@ -135,15 +144,18 @@ void calculateSingleDetailGraduationForSub(String graduationCategoryName) { .id(1L) .entryYear(19) .studentCategory(SUB_MAJOR) - .primaryMajor("응용소프트웨어전공").build(); + .primaryMajor("응용소프트웨어전공") + .build(); GraduationCategory graduationCategory = GraduationCategory.valueOf(graduationCategoryName); CalculateDetailGraduationUseCase calculateDetailGraduationUseCase = mock( CalculateDetailGraduationUseCase.class); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(new HashSet<>()); given(findUserUseCase.findUserById(user.getId())).willReturn(user); - given(findTakenLectureUseCase.findTakenLectures(user.getId())).willReturn(takenLectureInventory); - given(calculateDetailGraduationUseCases.stream()).willReturn(Stream.of(calculateDetailGraduationUseCase)); + given(findTakenLectureUseCase.findTakenLectures(user.getId())).willReturn( + takenLectureInventory); + given(calculateDetailGraduationUseCases.stream()).willReturn( + Stream.of(calculateDetailGraduationUseCase)); given(calculateDetailGraduationUseCase.supports(graduationCategory)).willReturn(true); given(calculateDetailGraduationUseCase.calculateSingleDetailGraduation( any(User.class), any(GraduationCategory.class), @@ -152,7 +164,8 @@ void calculateSingleDetailGraduationForSub(String graduationCategoryName) { // when DetailGraduationResult result = - calculateSingleDetailGraduationService.calculateSingleDetailGraduation(1L, graduationCategory); + calculateSingleDetailGraduationService.calculateSingleDetailGraduation(1L, + graduationCategory); // then assertNotNull(result); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/ChapelResultTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/ChapelResultTest.java index 5ea7db54..112ebd60 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/ChapelResultTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/ChapelResultTest.java @@ -2,15 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; @@ -18,6 +9,13 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; class ChapelResultTest { @@ -47,7 +45,7 @@ void completedChapelResult() { @DisplayName("채플 수강 과목이 4개 미만일 경우 채플 졸업 결과는 미이수 이다.") @Test void unCompletedChapelResult() { - //given + //given User user = UserFixture.경영학과_19학번_ENG34(); Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("KMA02101"), 2019, Semester.FIRST), //채플 @@ -57,10 +55,10 @@ void unCompletedChapelResult() { TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); ChapelResult chapelResult = ChapelResult.create(takenLectureInventory); - //when + //when chapelResult.checkCompleted(); - //then + //then assertThat(chapelResult.isCompleted()).isFalse(); } @@ -68,9 +66,10 @@ void unCompletedChapelResult() { @ParameterizedTest @ValueSource(ints = {1, 2, 3, 4}) void getTakenChapelCredit(int takenCount) { - //given + //given ChapelResult chapelResult = ChapelResult.builder() - .takenCount(takenCount).build(); + .takenCount(takenCount) + .build(); //when double takenChapelCredit = chapelResult.getTakenChapelCredit(); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResultTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResultTest.java index 3e28a8c3..1131e53b 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResultTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResultTest.java @@ -2,17 +2,9 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.FREE_ELECTIVE; import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_A; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.*; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.SCIENCE_TECHNOLOGY; import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; @@ -20,6 +12,12 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class FreeElectiveGraduationResultTest { @@ -44,20 +42,26 @@ void createFreeElectiveGraduationResult() { .detailCategory(List.of( DetailCategoryResult.builder() .detailCategoryName(CHRISTIAN_A.getName()) - .freeElectiveLeftCredit(3).build(), + .freeElectiveLeftCredit(3) + .build(), DetailCategoryResult.builder() .detailCategoryName(SCIENCE_TECHNOLOGY.getName()) - .freeElectiveLeftCredit(3).build() - )).build(); + .freeElectiveLeftCredit(3) + .build() + )) + .build(); - int remainCreditByTakenLectures = takenLectureInventory.getTakenLectures().stream() - .mapToInt(takenLecture -> takenLecture.getLecture().getCredit()) + int remainCreditByTakenLectures = takenLectureInventory.getTakenLectures() + .stream() + .mapToInt(takenLecture -> takenLecture.getLecture() + .getCredit()) .sum(); int freeElectiveLeftCredit = detailGraduationResult.getFreeElectiveLeftCredit(); int leftNormalCultureCredit = 5; //when - FreeElectiveGraduationResult freeElectiveGraduationResult = FreeElectiveGraduationResult.create(7, + FreeElectiveGraduationResult freeElectiveGraduationResult = FreeElectiveGraduationResult.create( + 7, takenLectureInventory, List.of(detailGraduationResult), leftNormalCultureCredit); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategoryTest.java index 9f6f08ec..fc1f5d42 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategoryTest.java @@ -9,7 +9,8 @@ class GraduationCategoryTest { @DisplayName("전공 관련 GraduationCategory인 경우 전공 필수인지 선택인지 확인한다.") - @CsvSource({"PRIMARY_MANDATORY_MAJOR, true", "DUAL_MANDATORY_MAJOR, true", "PRIMARY_ELECTIVE_MAJOR, false"}) + @CsvSource({"PRIMARY_MANDATORY_MAJOR, true", "DUAL_MANDATORY_MAJOR, true", + "PRIMARY_ELECTIVE_MAJOR, false"}) @ParameterizedTest void checkMandatoryOrElective(GraduationCategory graduationCategory, boolean isMandatory) { //when diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirementTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirementTest.java index f2f6264b..2db9da7a 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirementTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirementTest.java @@ -1,14 +1,14 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.DualMajorGraduationRequirementType.*; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.*; -import static org.assertj.core.api.Assertions.*; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.DualMajorGraduationRequirementType.BUSINESS; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.DualMajorGraduationRequirementType.ICT; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.ENGLISH; +import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - class GraduationRequirementTest { @DisplayName("공통교양의 영어카테고리 학점(6점)을 일반교양 학점으로 이관한다.") @@ -19,7 +19,8 @@ void transferEnglishCategoryCredit() { int beforeTransferNormalCultureCredit = 0; GraduationRequirement graduationRequirement = GraduationRequirement.builder() .commonCultureCredit(beforeTransferCommonCultureCredit) - .normalCultureCredit(beforeTransferNormalCultureCredit).build(); + .normalCultureCredit(beforeTransferNormalCultureCredit) + .build(); //when graduationRequirement.transferEnglishCreditCommonToNormal(); @@ -49,7 +50,8 @@ void modifyCreditForDualMajor() { .primaryBasicAcademicalCultureCredit(10) .dualBasicAcademicalCultureCredit(10) .normalCultureCredit(10) - .freeElectiveCredit(10).build(); + .freeElectiveCredit(10) + .build(); //when graduationRequirement.modifyCreditForDualMajor(user); @@ -68,7 +70,8 @@ void modifyCreditForDualMajor() { void deleteFreeElectiveCredit() { //given GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .freeElectiveCredit(10).build(); + .freeElectiveCredit(10) + .build(); //when graduationRequirement.modifyCreditForSubMajor(); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationResultTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationResultTest.java index c75c6534..d0ef24d9 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationResultTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationResultTest.java @@ -1,32 +1,97 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; -import static org.assertj.core.api.Assertions.*; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.FREE_ELECTIVE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.NORMAL_CULTURE; +import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; +import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Stream; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; -import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - class GraduationResultTest { Map mockLectureMap = LectureFixture.getMockLectureMap(); + static Stream graduationResultFields() { + return Stream.of( + Arguments.arguments( + ChapelResult.builder() + .isCompleted(true) + .build(), + List.of(DetailGraduationResult.builder() + .isCompleted(true) + .graduationCategory(COMMON_CULTURE) + .build()), + NormalCultureGraduationResult.builder() + .isCompleted(true) + .build(), + FreeElectiveGraduationResult.builder() + .isCompleted(false) + .build() + ), + Arguments.arguments( + ChapelResult.builder() + .isCompleted(true) + .build(), + List.of(DetailGraduationResult.builder() + .isCompleted(true) + .graduationCategory(COMMON_CULTURE) + .build()), + NormalCultureGraduationResult.builder() + .isCompleted(false) + .build(), + FreeElectiveGraduationResult.builder() + .isCompleted(true) + .build() + ), + Arguments.arguments( + ChapelResult.builder() + .isCompleted(true) + .build(), + List.of(DetailGraduationResult.builder() + .isCompleted(false) + .graduationCategory(COMMON_CULTURE) + .build()), + NormalCultureGraduationResult.builder() + .isCompleted(true) + .build(), + FreeElectiveGraduationResult.builder() + .isCompleted(true) + .build() + ), + Arguments.arguments( + ChapelResult.builder() + .isCompleted(false) + .build(), + List.of(DetailGraduationResult.builder() + .isCompleted(true) + .graduationCategory(COMMON_CULTURE) + .build()), + NormalCultureGraduationResult.builder() + .isCompleted(true) + .build(), + FreeElectiveGraduationResult.builder() + .isCompleted(true) + .build() + ) + ); + } + @DisplayName("전체 졸업 결과는 남은 수강 과목으로 일반교양, 자유선택 졸업 결과를 처리한다.") @Test void handleLeftTakenLectures() { @@ -36,8 +101,10 @@ void handleLeftTakenLectures() { TakenLecture.of(user, mockLectureMap.get("KMA02110"), 2020, Semester.FIRST), //철학과인간 TakenLecture.of(user, mockLectureMap.get("KMA02111"), 2020, Semester.FIRST), //한국근현대사의이해 TakenLecture.of(user, mockLectureMap.get("KMA02112"), 2020, Semester.FIRST), //역사와문명 - TakenLecture.of(user, mockLectureMap.get("KMA02140"), 2020, Semester.FIRST), //4차산업혁명을위한비판적사고 - TakenLecture.of(user, mockLectureMap.get("KMA02158"), 2020, Semester.FIRST), //디지털콘텐츠로만나는한국의문화유산 + TakenLecture.of(user, mockLectureMap.get("KMA02140"), 2020, Semester.FIRST), + //4차산업혁명을위한비판적사고 + TakenLecture.of(user, mockLectureMap.get("KMA02158"), 2020, Semester.FIRST), + //디지털콘텐츠로만나는한국의문화유산 TakenLecture.of(user, mockLectureMap.get("KMA02113"), 2020, Semester.FIRST), //세계화와사회변화 TakenLecture.of(user, mockLectureMap.get("KMA02114"), 2020, Semester.FIRST), //민주주의와현대사회 TakenLecture.of(user, mockLectureMap.get("HBX01105"), 2020, Semester.SECOND), //재무관리원론 @@ -50,7 +117,8 @@ void handleLeftTakenLectures() { GraduationRequirement graduationRequirement = GraduationRequirement.builder() .normalCultureCredit(15) - .freeElectiveCredit(12).build(); + .freeElectiveCredit(12) + .build(); GraduationResult graduationResult = GraduationResult.builder() .detailGraduationResults(List.of()) .build(); @@ -62,11 +130,13 @@ void handleLeftTakenLectures() { assertThat(graduationResult.getNormalCultureGraduationResult()) .extracting("categoryName", "totalCredit", "takenCredit") .contains(NORMAL_CULTURE.getName(), graduationRequirement.getNormalCultureCredit(), - takenNormalCultureCredit - (takenNormalCultureCredit - graduationRequirement.getNormalCultureCredit())); + takenNormalCultureCredit - (takenNormalCultureCredit + - graduationRequirement.getNormalCultureCredit())); assertThat(graduationResult.getFreeElectiveGraduationResult()) .extracting("categoryName", "totalCredit", "takenCredit") .contains(FREE_ELECTIVE.getName(), graduationRequirement.getFreeElectiveCredit(), - takenNormalCultureCredit - graduationRequirement.getNormalCultureCredit() + takenFreeElectiveCredit); + takenNormalCultureCredit - graduationRequirement.getNormalCultureCredit() + + takenFreeElectiveCredit); } @DisplayName("채플 졸업 결과, 모든 세부 졸업 결과, 일반교양 졸업 결과, 자유선택 졸업 결과가 이수 완료일 시 전체 졸업 결과가 이수 완료이다.") @@ -81,29 +151,37 @@ void checkCompletedGraduated() { int freeElectiveTakenCredit = 7; ChapelResult chapelResult = ChapelResult.builder() - .isCompleted(true).build(); - List detailGraduationResults = List.of(DetailGraduationResult.builder() .isCompleted(true) - .graduationCategory(COMMON_CULTURE) - .totalCredit(detailCategoryTotalCredit) - .takenCredit(detailCategoryTakenCredit).build()); + .build(); + List detailGraduationResults = List.of( + DetailGraduationResult.builder() + .isCompleted(true) + .graduationCategory(COMMON_CULTURE) + .totalCredit(detailCategoryTotalCredit) + .takenCredit(detailCategoryTakenCredit) + .build()); NormalCultureGraduationResult normalCultureGraduationResult = NormalCultureGraduationResult.builder() .isCompleted(true) .totalCredit(normalCultureTotalCredit) - .takenCredit(normalCultureTakenCredit).build(); + .takenCredit(normalCultureTakenCredit) + .build(); FreeElectiveGraduationResult freeElectiveGraduationResult = FreeElectiveGraduationResult.builder() .isCompleted(true) .totalCredit(freeElectiveTotalCredit) - .takenCredit(freeElectiveTakenCredit).build(); + .takenCredit(freeElectiveTakenCredit) + .build(); GraduationResult graduationResult = GraduationResult.builder() .chapelResult(chapelResult) .detailGraduationResults(detailGraduationResults) .normalCultureGraduationResult(normalCultureGraduationResult) - .freeElectiveGraduationResult(freeElectiveGraduationResult).build(); + .freeElectiveGraduationResult(freeElectiveGraduationResult) + .build(); //when - graduationResult.checkGraduated(GraduationRequirement.builder().totalCredit(134).build()); + graduationResult.checkGraduated(GraduationRequirement.builder() + .totalCredit(134) + .build()); //then assertThat(graduationResult.isGraduated()).isTrue(); @@ -116,7 +194,8 @@ void checkCompletedGraduated() { @DisplayName("채플 졸업 결과, 모든 세부 졸업 결과, 일반교양 졸업 결과, 자유선택 졸업 결과 중 하나라도 미이수일 시 전체 졸업 결과가 미이수이다.") @ParameterizedTest @MethodSource("graduationResultFields") - void checkUnCompletedGraduated(ChapelResult chapelResult, List detailGraduationResults, + void checkUnCompletedGraduated(ChapelResult chapelResult, + List detailGraduationResults, NormalCultureGraduationResult normalCultureGraduationResult, FreeElectiveGraduationResult freeElectiveGraduationResult) { //given @@ -124,50 +203,16 @@ void checkUnCompletedGraduated(ChapelResult chapelResult, List graduationResultFields() { - return Stream.of( - Arguments.arguments( - ChapelResult.builder().isCompleted(true).build(), - List.of(DetailGraduationResult.builder() - .isCompleted(true) - .graduationCategory(COMMON_CULTURE).build()), - NormalCultureGraduationResult.builder().isCompleted(true).build(), - FreeElectiveGraduationResult.builder().isCompleted(false).build() - ), - Arguments.arguments( - ChapelResult.builder().isCompleted(true).build(), - List.of(DetailGraduationResult.builder() - .isCompleted(true) - .graduationCategory(COMMON_CULTURE).build()), - NormalCultureGraduationResult.builder().isCompleted(false).build(), - FreeElectiveGraduationResult.builder().isCompleted(true).build() - ), - Arguments.arguments( - ChapelResult.builder().isCompleted(true).build(), - List.of(DetailGraduationResult.builder() - .isCompleted(false) - .graduationCategory(COMMON_CULTURE).build()), - NormalCultureGraduationResult.builder().isCompleted(true).build(), - FreeElectiveGraduationResult.builder().isCompleted(true).build() - ), - Arguments.arguments( - ChapelResult.builder().isCompleted(false).build(), - List.of(DetailGraduationResult.builder() - .isCompleted(true) - .graduationCategory(COMMON_CULTURE).build()), - NormalCultureGraduationResult.builder().isCompleted(true).build(), - FreeElectiveGraduationResult.builder().isCompleted(true).build() - ) - ); - } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorTypeTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorTypeTest.java index 674c5c89..3db39807 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorTypeTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorTypeTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.stream.Stream; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResultTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResultTest.java index d7627193..287f47b5 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResultTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResultTest.java @@ -1,17 +1,11 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.model; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.*; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.NORMAL_CULTURE; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CAREER; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_A; import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; @@ -19,6 +13,12 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class NormalCultureGraduationResultTest { @@ -35,7 +35,7 @@ void createNormalCultureGraduationResult() { TakenLecture.of(user, mockLectureMap.get("KMA02122"), 2019, Semester.FIRST), TakenLecture.of(user, mockLectureMap.get("KMA02104"), 2023, Semester.FIRST), TakenLecture.of(user, mockLectureMap.get("KMA02141"), 2023, Semester.FIRST) - ))); + ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); DetailGraduationResult detailGraduationResult = DetailGraduationResult.builder() @@ -43,26 +43,33 @@ void createNormalCultureGraduationResult() { .detailCategory(List.of( DetailCategoryResult.builder() .detailCategoryName(CHRISTIAN_A.getName()) - .normalLeftCredit(3).build(), + .normalLeftCredit(3) + .build(), DetailCategoryResult.builder() .detailCategoryName(CAREER.getName()) - .normalLeftCredit(3).build() - )).build(); + .normalLeftCredit(3) + .build() + )) + .build(); - int remainTakenNormalCultureCredit = takenLectureInventory.getCultureLectures().stream() - .mapToInt(takenLecture -> takenLecture.getLecture().getCredit()) + int remainTakenNormalCultureCredit = takenLectureInventory.getCultureLectures() + .stream() + .mapToInt(takenLecture -> takenLecture.getLecture() + .getCredit()) .sum(); int remainCreditByDetailGraduationResult = detailGraduationResult.getNormalLeftCredit(); //when - NormalCultureGraduationResult normalCultureGraduationResult = NormalCultureGraduationResult.create(15, + NormalCultureGraduationResult normalCultureGraduationResult = NormalCultureGraduationResult.create( + 15, takenLectureInventory, List.of(detailGraduationResult)); //then assertThat(normalCultureGraduationResult) .extracting("categoryName", "takenCredit") - .contains(NORMAL_CULTURE.getName(), remainTakenNormalCultureCredit + remainCreditByDetailGraduationResult); + .contains(NORMAL_CULTURE.getName(), + remainTakenNormalCultureCredit + remainCreditByDetailGraduationResult); } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManagerTest.java index c8a66f1b..33c59f27 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManagerTest.java @@ -2,16 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.BasicAcademicalLectureFixture; - import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; @@ -22,6 +13,12 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; @DisplayName("경영대의 학문기초교양 결과를 반환한다.") class BusinessBasicAcademicalGraduationManagerTest { @@ -47,10 +44,12 @@ class 경영학과_학문기초교양 { BasicAcademicalGraduationManager manager = new BusinessBasicAcademicalGraduationManager(); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult( + user, takenLectureInventory, basicAcademicalLectures, 6); - DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory().get(0); + DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory() + .get(0); //then assertThat(detailGraduationResult) @@ -80,10 +79,12 @@ class 경영학과_학문기초교양 { BasicAcademicalGraduationManager manager = new BusinessBasicAcademicalGraduationManager(); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult( + user, takenLectureInventory, basicAcademicalLectures, 6); - DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory().get(0); + DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory() + .get(0); //then assertThat(detailGraduationResult) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManagerTest.java index f9bdaf0c..394109a1 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManagerTest.java @@ -1,14 +1,6 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture; -import static org.assertj.core.api.Assertions.*; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; import com.plzgraduate.myongjigraduatebe.fixture.BasicAcademicalLectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; @@ -21,6 +13,12 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; @DisplayName("기본 단과대에 대해 학문기초교양 결과를 반환한다.") class DefaultBasicAcademicalGraduationManagerTest { @@ -28,6 +26,7 @@ class DefaultBasicAcademicalGraduationManagerTest { @DisplayName("인문대의 학문기초교양을 계산한다.") @Nested class 인문대_학문기초교양 { + User user = UserFixture.영문학과_18학번(); Map mockLectureMap = LectureFixture.getMockLectureMap(); Set basicAcademicalLectures = BasicAcademicalLectureFixture.인문대_학문기초교양(); @@ -47,14 +46,16 @@ class 인문대_학문기초교양 { BasicAcademicalGraduationManager manager = new DefaultBasicAcademicalGraduationManager(); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult( + user, takenLectureInventory, basicAcademicalLectures, 12); - DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory().get(0); + DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory() + .get(0); //then assertThat(detailGraduationResult) - .extracting( "isCompleted", "totalCredit", "takenCredit") + .extracting("isCompleted", "totalCredit", "takenCredit") .contains(true, 12, 12); assertThat(detailCategoryResult) @@ -78,10 +79,12 @@ class 인문대_학문기초교양 { BasicAcademicalGraduationManager manager = new DefaultBasicAcademicalGraduationManager(); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult( + user, takenLectureInventory, basicAcademicalLectures, 12); - DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory().get(0); + DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory() + .get(0); //then assertThat(detailGraduationResult) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManagerTest.java index bdd89557..cd1d15c9 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManagerTest.java @@ -2,14 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.BasicAcademicalLectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; @@ -21,6 +13,12 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; @DisplayName("사회과학대의 학문기초교양 결과를 반환한다.") class SocialScienceBasicAcademicManagerTest { @@ -28,6 +26,7 @@ class SocialScienceBasicAcademicManagerTest { @DisplayName("2023년도 1학기 이후 교과목을 포함한다.") @Nested class 이십삼년도_이후_교과목_포함 { + User user = UserFixture.행정학과_21학번(); Map mockLectureMap = LectureFixture.getMockLectureMap(); Set basicAcademicalLectures = BasicAcademicalLectureFixture.사회과학대_학문기초교양(); @@ -46,10 +45,12 @@ class 이십삼년도_이후_교과목_포함 { BasicAcademicalGraduationManager manager = new DefaultBasicAcademicalGraduationManager(); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult( + user, takenLectureInventory, basicAcademicalLectures, 12); - DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory().get(0); + DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory() + .get(0); //then assertThat(detailGraduationResult) @@ -79,9 +80,11 @@ class 이십삼년도_이후_교과목_포함 { BasicAcademicalGraduationManager manager = new SocialScienceBasicAcademicGraduationManager(); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult( + user, takenLectureInventory, basicAcademicalLectures, 12); - DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory().get(0); + DetailCategoryResult detailCategoryResult = detailGraduationResult.getDetailCategory() + .get(0); //then assertThat(detailGraduationResult) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManagerTest.java index 9e90b437..73c44bf7 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManagerTest.java @@ -1,17 +1,9 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture; -import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.*; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.*; -import static org.assertj.core.api.Assertions.*; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ArgumentsSource; +import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.공통교양_16_17; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_A; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.ENGLISH; +import static org.assertj.core.api.Assertions.assertThat; import com.plzgraduate.myongjigraduatebe.fixture.CommonCultureCategoryFixture; import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; @@ -24,6 +16,13 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; @DisplayName("각 공통교양 세부 카테고리 별 카테고리 이름, 총 학점, 이수 여부를 포함한 카테고리 졸업 결과를 생성한다.") class CommonCultureDetailCategoryManagerTest { @@ -34,7 +33,8 @@ class CommonCultureDetailCategoryManagerTest { @DisplayName("영어 레벨 기초: 각 카테고리의 해당하는 과목의 이수 학점을 만족한 경우 이수 완료의 카테고리 졸업 결과를 생성한다.") @ParameterizedTest @ArgumentsSource(CommonCultureCategoryFixture.class) - void generateEngBasicCompletedCommonCultureDetailCategory(CommonCultureCategory commonCultureCategory, + void generateEngBasicCompletedCommonCultureDetailCategory( + CommonCultureCategory commonCultureCategory, Set graduationLectures) { //given User user = UserFixture.데이테크놀로지학과_18학번_Basic_Eng(); @@ -59,7 +59,8 @@ void generateEngBasicCompletedCommonCultureDetailCategory(CommonCultureCategory int categoryTotalCredit = commonCultureCategory.getTotalCredit(); //when - DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, graduationLectures, + DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, + graduationLectures, commonCultureCategory); //then @@ -71,7 +72,8 @@ void generateEngBasicCompletedCommonCultureDetailCategory(CommonCultureCategory @DisplayName("영어 레벨 12: 각 카테고리의 해당하는 과목의 이수 학점을 만족한 경우 이수 완료의 카테고리 졸업 결과를 생성한다.") @ParameterizedTest @ArgumentsSource(CommonCultureCategoryFixture.class) - void generateEng12CompletedCommonCultureDetailCategory(CommonCultureCategory commonCultureCategory, + void generateEng12CompletedCommonCultureDetailCategory( + CommonCultureCategory commonCultureCategory, Set graduationLectures) { //given User user = UserFixture.경영학과_19학번_ENG12(); @@ -95,7 +97,8 @@ void generateEng12CompletedCommonCultureDetailCategory(CommonCultureCategory com int categoryTotalCredit = commonCultureCategory.getTotalCredit(); //when - DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, graduationLectures, + DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, + graduationLectures, commonCultureCategory); //then @@ -107,7 +110,8 @@ void generateEng12CompletedCommonCultureDetailCategory(CommonCultureCategory com @DisplayName("영어 레벨 34: 각 카테고리의 해당하는 과목의 이수 학점을 만족한 경우 이수 완료의 카테고리 졸업 결과를 생성한다.") @ParameterizedTest @ArgumentsSource(CommonCultureCategoryFixture.class) - void generateEng34CompletedCommonCultureDetailCategory(CommonCultureCategory commonCultureCategory, + void generateEng34CompletedCommonCultureDetailCategory( + CommonCultureCategory commonCultureCategory, Set graduationLectures) { //given User user = UserFixture.경영학과_19학번_ENG34(); @@ -130,7 +134,8 @@ void generateEng34CompletedCommonCultureDetailCategory(CommonCultureCategory com String commonCultureCategoryName = commonCultureCategory.getName(); //when - DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, graduationLectures, + DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, + graduationLectures, commonCultureCategory); //then @@ -142,7 +147,8 @@ void generateEng34CompletedCommonCultureDetailCategory(CommonCultureCategory com @DisplayName("영어 레벨 FREE: 각 카테고리의 해당하는 과목의 이수 학점을 만족한 경우 이수 완료의 카테고리 졸업 결과를 생성한다.") @ParameterizedTest @ArgumentsSource(CommonCultureCategoryFixture.class) - void generateEngFreeCompletedCommonCultureDetailCategory(CommonCultureCategory commonCultureCategory, + void generateEngFreeCompletedCommonCultureDetailCategory( + CommonCultureCategory commonCultureCategory, Set graduationLectures) { //given User user = UserFixture.경영학과_19학번_영어_면제(); @@ -157,7 +163,8 @@ void generateEngFreeCompletedCommonCultureDetailCategory(CommonCultureCategory c String commonCultureCategoryName = commonCultureCategory.getName(); //when - DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, graduationLectures, + DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, + graduationLectures, commonCultureCategory); //then @@ -190,7 +197,8 @@ void generateEngBasicUnCompletedCommonCultureDetailCategory() { int categoryTotalCredit = commonCultureCategory.getTotalCredit(); //when - DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, graduationLectures, + DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, + graduationLectures, commonCultureCategory); //then @@ -202,7 +210,8 @@ void generateEngBasicUnCompletedCommonCultureDetailCategory() { @DisplayName("영어 레벨 12: 각 카테고리의 해당하는 과목의 이수 학점을 만족하지 못한 경우 이수 미 완료의 카테고리 졸업 결과를 생성한다.") @ParameterizedTest @ArgumentsSource(CommonCultureCategoryFixture.class) - void generateEng12UnCompletedCommonCultureDetailCategory(CommonCultureCategory commonCultureCategory, + void generateEng12UnCompletedCommonCultureDetailCategory( + CommonCultureCategory commonCultureCategory, Set graduationLectures) { //given User user = UserFixture.경영학과_19학번_ENG12(); @@ -211,7 +220,8 @@ void generateEng12UnCompletedCommonCultureDetailCategory(CommonCultureCategory c int categoryTotalCredit = commonCultureCategory.getTotalCredit(); //when - DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, graduationLectures, + DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, + graduationLectures, commonCultureCategory); //then @@ -223,7 +233,8 @@ void generateEng12UnCompletedCommonCultureDetailCategory(CommonCultureCategory c @DisplayName("영어 레벨 34: 각 카테고리의 해당하는 과목의 이수 학점을 만족하지 못한 경우 이수 미 완료의 카테고리 졸업 결과를 생성한다.") @ParameterizedTest @ArgumentsSource(CommonCultureCategoryFixture.class) - void generateEng34UnCompletedCommonCultureDetailCategory(CommonCultureCategory commonCultureCategory, + void generateEng34UnCompletedCommonCultureDetailCategory( + CommonCultureCategory commonCultureCategory, Set graduationLectures) { //given User user = UserFixture.경영학과_19학번_ENG34(); @@ -232,7 +243,8 @@ void generateEng34UnCompletedCommonCultureDetailCategory(CommonCultureCategory c int categoryTotalCredit = commonCultureCategory.getTotalCredit(); //when - DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, graduationLectures, + DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, + graduationLectures, commonCultureCategory); //then @@ -262,7 +274,8 @@ void generateMandatorySatisfactionCommonCultureDetailCategory() { Set graduationLectures = 공통교양_16_17(); // == 공통교양_18_19 //when - DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, graduationLectures, + DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, + graduationLectures, CHRISTIAN_A); //then @@ -285,7 +298,8 @@ void generateMandatoryUnSatisfactionCommonCultureDetailCategory() { Set graduationLectures = 공통교양_16_17(); // == 공통교양_18_19 //when - DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, graduationLectures, + DetailCategoryResult detailCategoryResult = manager.generate(user, takenLectureInventory, + graduationLectures, CHRISTIAN_A); //then diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManagerTest.java index 12225ea8..bef14467 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManagerTest.java @@ -1,16 +1,8 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; -import static org.assertj.core.api.Assertions.*; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ArgumentsSource; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; +import static org.assertj.core.api.Assertions.assertThat; import com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture; import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; @@ -22,6 +14,12 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; @DisplayName("각 공통교양 세부 카테고리 졸업 결과를 포함한 공통교양 전체 졸업 결과를 생성한다.") class CommonCultureGraduationManagerTest { @@ -33,7 +31,7 @@ class CommonCultureGraduationManagerTest { @ParameterizedTest @ArgumentsSource(CommonCultureFixture.class) void generateCompletedDetailGraduationResult(User user, Set graduationLectures) { - //given + //given Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("KMA00101"), 2019, Semester.FIRST), TakenLecture.of(user, mockLectureMap.get("KMA02102"), 2019, Semester.FIRST), @@ -54,7 +52,7 @@ void generateCompletedDetailGraduationResult(User user, Set gradu //when DetailGraduationResult detailGraduationResult = graduationManager.createDetailGraduationResult( user, takenLectureInventory, graduationLectures, 17); - + //then assertThat(detailGraduationResult) .extracting("graduationCategory", "isCompleted") @@ -64,7 +62,8 @@ void generateCompletedDetailGraduationResult(User user, Set gradu @DisplayName("모든 공통교양 세부 카테고리가 이수 완료가 아닐 경우 이수 미 완료 공통교양 전체 졸업 결과를 생성한다.") @ParameterizedTest @ArgumentsSource(CommonCultureFixture.class) - void generateUnCompletedDetailGraduationResult(User user, Set graduationLectures) { + void generateUnCompletedDetailGraduationResult(User user, + Set graduationLectures) { //given Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("KMA02122"), 2019, Semester.FIRST), @@ -76,7 +75,7 @@ void generateUnCompletedDetailGraduationResult(User user, Set gra //when DetailGraduationResult detailGraduationResult = graduationManager.createDetailGraduationResult( user, takenLectureInventory, graduationLectures, 17); - + //then assertThat(detailGraduationResult) .extracting("graduationCategory", "isCompleted") diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManagerTest.java index 92cefcb4..2a28fb7e 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManagerTest.java @@ -1,21 +1,11 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.coreculture; -import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.*; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.*; +import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_과학과기술; +import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_문화와예술; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.CULTURE_ART; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.SCIENCE_TECHNOLOGY; import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.stream.Stream; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsSource; -import org.junit.jupiter.params.provider.MethodSource; - import com.plzgraduate.myongjigraduatebe.fixture.CoreCultureCategoryFixture; import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; @@ -27,6 +17,16 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.stream.Stream; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsSource; +import org.junit.jupiter.params.provider.MethodSource; @DisplayName("각 핵심교양 세부 카테고리 별 카테고리 이름, 총 학점, 이수 여부를 포함한 카테고리 졸업 결과를 생성한다.") class CoreCultureDetailCategoryManagerTest { @@ -34,12 +34,20 @@ class CoreCultureDetailCategoryManagerTest { Map mockLectureMap = LectureFixture.getMockLectureMap(); CoreCultureDetailCategoryManager manager = new CoreCultureDetailCategoryManager(); + static Stream ictUsers() { + return Stream.of( + Arguments.arguments(UserFixture.응용소프트웨어학과_19학번()), + Arguments.arguments(UserFixture.데이터테크놀로지학과_19학번()), + Arguments.arguments(UserFixture.디지털콘텐츠디자인학과_19학번()) + ); + } + @DisplayName("각 카테고리의 해당하는 과목의 이수 학점을 만족한 경우 이수 완료의 카테고리 졸업 결과를 생성한다.") @ParameterizedTest @ArgumentsSource(CoreCultureCategoryFixture.class) void generateCompletedCoreCultureDetailCategoryResult(CoreCultureCategory coreCultureCategory, Set graduationLectures) { - + //given User user = UserFixture.경영학과_19학번_ENG34(); Set takenLectures = new HashSet<>((Set.of( @@ -86,7 +94,7 @@ void generateCompletedCoreCultureDetailCategoryResult(CoreCultureCategory coreCu @ArgumentsSource(CoreCultureCategoryFixture.class) void generateUnCompletedCoreCultureDetailCategoryResult(CoreCultureCategory coreCultureCategory, Set graduationLectures) { - + //given User user = UserFixture.경영학과_19학번_ENG34(); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(new HashSet<>()); @@ -107,7 +115,7 @@ void generateUnCompletedCoreCultureDetailCategoryResult(CoreCultureCategory core @ParameterizedTest @MethodSource("ictUsers") void generateUnCompletedScienceTechnologyDetailCategoryResultWithICT(User user) { - + //given Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("KMA02135"), 2019, Semester.FIRST), @@ -130,14 +138,6 @@ void generateUnCompletedScienceTechnologyDetailCategoryResultWithICT(User user) .contains(coreCultureCategory.getName(), true, categoryTotalCredit, 3, 3); } - static Stream ictUsers() { - return Stream.of( - Arguments.arguments(UserFixture.응용소프트웨어학과_19학번()), - Arguments.arguments(UserFixture.데이터테크놀로지학과_19학번()), - Arguments.arguments(UserFixture.디지털콘텐츠디자인학과_19학번()) - ); - } - @DisplayName("4차산업혁명시대의예술 과목은 2022년 1학기 이후 수강한 경우에는 핵심교양으로 인정된다.") @Test void generateCompletedCultureArtDetailCategoryResult_Case_A() { @@ -161,7 +161,8 @@ void generateCompletedCultureArtDetailCategoryResult_Case_A() { .extracting("detailCategoryName", "isCompleted", "totalCredits", "normalLeftCredit", "freeElectiveLeftCredit") .contains(coreCultureCategory.getName(), true, categoryTotalCredit, 0, 0); - assertThat(detailCategoryResult.getTakenLectures()).contains(mockLectureMap.get("KMA02155")); + assertThat(detailCategoryResult.getTakenLectures()).contains( + mockLectureMap.get("KMA02155")); } @DisplayName("문화리터러시와창의적스토리텔링 과목은 2022년 1학기 이후 수강한 경우에는 핵심교양으로 인정된다.") @@ -187,13 +188,14 @@ void generateCompletedCultureArtDetailCategoryResult_Case_B() { .extracting("detailCategoryName", "isCompleted", "totalCredits", "normalLeftCredit", "freeElectiveLeftCredit") .contains(coreCultureCategory.getName(), true, categoryTotalCredit, 0, 0); - assertThat(detailCategoryResult.getTakenLectures()).contains(mockLectureMap.get("KMA02156")); + assertThat(detailCategoryResult.getTakenLectures()).contains( + mockLectureMap.get("KMA02156")); } @DisplayName("4차산업혁명시대의예술, 문화리터러시와창의적스토리텔링 과목은 2022년 1학기에 수강한 경우에는 핵심교양이 아닌 일반교양으로 인정된다.") @Test void generateUnCompletedCultureArtDetailCategoryResultWith_2022_First() { - + //given User user = UserFixture.경영학과_19학번_ENG34(); Set takenLectures = new HashSet<>((Set.of( diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManagerTest.java index e55eaa6f..f088c5da 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManagerTest.java @@ -3,13 +3,6 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CORE_CULTURE; import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture; import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; @@ -21,6 +14,11 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; @DisplayName("각 핵심교양 세부 카테고리 졸업 결과를 포함한 공통교양 전체 졸업 결과를 생성한다.") class CoreCultureGraduationManagerTest { @@ -31,7 +29,7 @@ class CoreCultureGraduationManagerTest { @DisplayName("모든 핵심교양 세부 카테고리가 이수 완료일 경우 이수 완료 핵심교양 전체 졸업 결과를 생성한다.") @Test void generateCompletedDetailGraduationResult() { - + //given User user = UserFixture.영문학과_16학번(); Set takenLectures = new HashSet<>((Set.of( @@ -75,7 +73,7 @@ void generateCompletedDetailGraduationResult() { @DisplayName("모든 핵심교양 세부 카테고리가 이수 완료가 아닐 경우 이수 미 완료 핵심교양 전체 졸업 결과를 생성한다.") @Test void generateUnCompletedDetailGraduationResult() { - + //given User user = UserFixture.영문학과_16학번(); Set takenLectures = new HashSet<>((Set.of( diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/DataTechnologyMajorTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/DataTechnologyMajorTest.java index 18efa985..0a39022d 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/DataTechnologyMajorTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/DataTechnologyMajorTest.java @@ -3,14 +3,6 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType.PRIMARY; import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.MajorFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; @@ -22,20 +14,28 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; @DisplayName("데이터테크놀로지학과의 전공 달성 여부를 계산한다.") class DataTechnologyMajorTest { + private static final Map mockLectureMap = LectureFixture.getMockLectureMap(); @DisplayName("(16학번 해당학번 전공필수과목 적용 확인) 전공 필수과목을 다 듣고, 전공 기준 학점을 넘었을 경우 전공 카테고리를 충족한다.") @Test - void 전공필수_기준학점_충족 () { - + void 전공필수_기준학점_충족() { + //given User user = UserFixture.데이테크놀로지학과_16학번(); Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("HEB01102"), 2016, Semester.FIRST), //기초프로그래밍 - TakenLecture.of(user, mockLectureMap.get("HEB01103"), 2016, Semester.SECOND), //객체지향적사고와프로그래밍 + TakenLecture.of(user, mockLectureMap.get("HEB01103"), 2016, Semester.SECOND), + //객체지향적사고와프로그래밍 TakenLecture.of(user, mockLectureMap.get("HED01201"), 2017, Semester.FIRST), //자료구조 TakenLecture.of(user, mockLectureMap.get("HED01202"), 2017, Semester.FIRST), //R통계분석 TakenLecture.of(user, mockLectureMap.get("HEB01105"), 2019, Semester.SECOND), //기초프로그래밍2 @@ -49,29 +49,35 @@ class DataTechnologyMajorTest { TakenLecture.of(user, mockLectureMap.get("HED01309"), 2020, Semester.SECOND), //컴퓨터아키텍처 TakenLecture.of(user, mockLectureMap.get("HED01307"), 2020, Semester.SECOND), //알고리즘 TakenLecture.of(user, mockLectureMap.get("HED01303"), 2020, Semester.SECOND), //운영체제 - TakenLecture.of(user, mockLectureMap.get("HED01306"), 2020, Semester.SECOND), //빅데이터프로그래밍 + TakenLecture.of(user, mockLectureMap.get("HED01306"), 2020, Semester.SECOND), + //빅데이터프로그래밍 TakenLecture.of(user, mockLectureMap.get("HED01308"), 2021, Semester.SECOND), //UX디자인 TakenLecture.of(user, mockLectureMap.get("HED01403"), 2020, Semester.SECOND), //블록체인기초 TakenLecture.of(user, mockLectureMap.get("HED01318"), 2021, Semester.FIRST), //모바일컴퓨팅 - TakenLecture.of(user, mockLectureMap.get("HED01317"), 2021, Semester.FIRST), //데이터베이스프로젝트 + TakenLecture.of(user, mockLectureMap.get("HED01317"), 2021, Semester.FIRST), + //데이터베이스프로젝트 TakenLecture.of(user, mockLectureMap.get("HED01401"), 2021, Semester.FIRST), //캡스톤디자인1 TakenLecture.of(user, mockLectureMap.get("HED01404"), 2021, Semester.FIRST), //빅데이터기술특론1 TakenLecture.of(user, mockLectureMap.get("HED01407"), 2021, Semester.FIRST), //딥러닝 - TakenLecture.of(user, mockLectureMap.get("HED01405"), 2021, Semester.SECOND), //빅데이터기술특론2 + TakenLecture.of(user, mockLectureMap.get("HED01405"), 2021, Semester.SECOND), + //빅데이터기술특론2 TakenLecture.of(user, mockLectureMap.get("HED01406"), 2021, Semester.SECOND), //클라우드컴퓨팅 TakenLecture.of(user, mockLectureMap.get("HED01311"), 2021, Semester.SECOND) //자기주도학 ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 데이터테크놀로지_전공 = MajorFixture.데이터테크놀로지_전공(); - MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager( + List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); - MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, + electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + PRIMARY, takenLectureInventory, 데이터테크놀로지_전공, 70); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -95,13 +101,14 @@ class DataTechnologyMajorTest { @DisplayName("(18학번) 전공 필수과목을 다 듣지 않고, 전공 기준 학점을 넘지 못했을 경우 경우 전공 카테고리를 충족하지 못한다.") @Test - void 전공필수_기준학점_미충족 () { - + void 전공필수_기준학점_미충족() { + //given User user = UserFixture.데이테크놀로지학과_18학번(); Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("HEB01102"), 2018, Semester.FIRST), //기초프로그래밍 - TakenLecture.of(user, mockLectureMap.get("HEB01104"), 2018, Semester.SECOND), //객체지향프로그래밍 + TakenLecture.of(user, mockLectureMap.get("HEB01104"), 2018, Semester.SECOND), + //객체지향프로그래밍 TakenLecture.of(user, mockLectureMap.get("HED01201"), 2019, Semester.FIRST), //자료구조 TakenLecture.of(user, mockLectureMap.get("HED01202"), 2019, Semester.FIRST), //R통계분석 @@ -115,22 +122,28 @@ class DataTechnologyMajorTest { TakenLecture.of(user, mockLectureMap.get("HED01309"), 2020, Semester.SECOND), //컴퓨터아키텍처 TakenLecture.of(user, mockLectureMap.get("HED01307"), 2020, Semester.SECOND), //알고리즘 TakenLecture.of(user, mockLectureMap.get("HED01303"), 2020, Semester.SECOND), //운영체제 - TakenLecture.of(user, mockLectureMap.get("HED01306"), 2020, Semester.SECOND), //빅데이터프로그래밍 + TakenLecture.of(user, mockLectureMap.get("HED01306"), 2020, Semester.SECOND), + //빅데이터프로그래밍 TakenLecture.of(user, mockLectureMap.get("HED01403"), 2020, Semester.SECOND), //블록체인기초 TakenLecture.of(user, mockLectureMap.get("HED01318"), 2023, Semester.FIRST), //모바일컴퓨팅 - TakenLecture.of(user, mockLectureMap.get("HED01317"), 2023, Semester.FIRST), //데이터베이스프로젝트 - TakenLecture.of(user, mockLectureMap.get("HED01404"), 2023, Semester.FIRST), //빅데이터프로그래밍1 + TakenLecture.of(user, mockLectureMap.get("HED01317"), 2023, Semester.FIRST), + //데이터베이스프로젝트 + TakenLecture.of(user, mockLectureMap.get("HED01404"), 2023, Semester.FIRST), + //빅데이터프로그래밍1 TakenLecture.of(user, mockLectureMap.get("HED01407"), 2023, Semester.FIRST) //딥러닝 ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 데이터테크놀로지_전공 = MajorFixture.데이터테크놀로지_전공(); - MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager( + List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); - MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, + electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + PRIMARY, takenLectureInventory, 데이터테크놀로지_전공, 70); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -144,11 +157,13 @@ class DataTechnologyMajorTest { .extracting("isCompleted", "isSatisfiedMandatory", "totalCredits", "takenCredits") .contains(false, false, 33, 30); assertThat(mandatoryDetailCategory.getTakenLectures()).hasSize(10); - assertThat(mandatoryDetailCategory.getHaveToLectures()).contains(mockLectureMap.get("HED01413")); //캡스톤을 포함 + assertThat(mandatoryDetailCategory.getHaveToLectures()).contains( + mockLectureMap.get("HED01413")); //캡스톤을 포함 assertThat(electiveDetailCategory) .extracting("isCompleted", "totalCredits", "takenCredits") .contains(false, 37, 27); assertThat(electiveDetailCategory.getTakenLectures()).hasSize(9); - assertThat(electiveDetailCategory.getHaveToLectures()).contains(mockLectureMap.get("HED01308")); //UX디자인을 포함 + assertThat(electiveDetailCategory.getHaveToLectures()).contains( + mockLectureMap.get("HED01308")); //UX디자인을 포함 } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/InternationTradeMajorTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/InternationTradeMajorTest.java index 8ca058a5..f5e8c5bb 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/InternationTradeMajorTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/InternationTradeMajorTest.java @@ -1,16 +1,8 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType.*; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType.PRIMARY; import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.MajorFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; @@ -22,16 +14,23 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; @DisplayName("국제통상학과의 전공 달성여부를 계산한다.") class InternationTradeMajorTest { + private static final User user = UserFixture.국제통상학과_19학번(); private static final Map mockLectureMap = LectureFixture.getMockLectureMap(); @DisplayName("전공 필수과목을 다 듣고, 전공 기준 학점을 넘겼을 경우 전공 카테고리를 충족한다.") @Test void 전공필수_기준학점_충족() { - + //given Set takenLectures = new HashSet<>((Set.of( //전공필수 -> 21학점 @@ -60,12 +59,15 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager( + List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); - MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, + electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + PRIMARY, takenLectureInventory, 국제통상_전공, 63); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -90,7 +92,7 @@ class InternationTradeMajorTest { @DisplayName("전공 기준학점을 넘겼으나 전공 필수를 다 듣지 않은 경우 충족하지 못한다.") @Test void 기준학점_충족_전공필수_미충족() { - + //given Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, Semester.FIRST), //국제통상원론 @@ -118,12 +120,15 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager( + List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); - MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, + electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + PRIMARY, takenLectureInventory, 국제통상_전공, 63); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -149,7 +154,7 @@ class InternationTradeMajorTest { @DisplayName("전공선택필수를 다 듣지 않은 경우 충족하지 못한다.") @Test void 전공선택필수_미충족() { - + //given Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, Semester.FIRST), //국제통상원론 @@ -177,12 +182,15 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager( + List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); - MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, + electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + PRIMARY, takenLectureInventory, 국제통상_전공, 63); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -207,7 +215,7 @@ class InternationTradeMajorTest { @DisplayName("전공선택학점을 다 채우지 못한 경우 전공 카테고리를 충족 못한다.") @Test void 전공선택_기준학점_미충족() { - + //given Set takenLectures = new HashSet<>((Set.of( //전공필수 @@ -233,12 +241,15 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager( + List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); - MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, + electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + PRIMARY, takenLectureInventory, 국제통상_전공, 63); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -263,7 +274,7 @@ class InternationTradeMajorTest { @DisplayName("전공선택필수 과목을 만족하고 추가로 들었을 경우 전공선택으로 인정된다.") @Test void 전공필수_추가과목_전공선택인정() { - + //given Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("HBX01104"), 2019, Semester.FIRST), //회계원리 @@ -274,12 +285,15 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager( + List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); - MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, + electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + PRIMARY, takenLectureInventory, 국제통상_전공, 70); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -297,7 +311,7 @@ class InternationTradeMajorTest { @DisplayName("전공선택필수에서 수강한 과목에 중복과목이 추천과목에 뜨지 않아야한다.") @Test void 중복과목_추천과목제외() { - + //given Set takenLectures = new HashSet<>((Set.of( TakenLecture.of(user, mockLectureMap.get("HBX01104"), 2019, Semester.FIRST), //회계원리 @@ -307,12 +321,15 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager( + List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); - MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, + electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + PRIMARY, takenLectureInventory, 국제통상_전공, 70); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult electiveDetailCategory = detailCategory.get(1); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandlerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandlerTest.java index 1ff67a32..1d31a9c0 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandlerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandlerTest.java @@ -2,13 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; @@ -17,9 +10,15 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; @DisplayName("N개 중에 M개 이상을 수강할 경우 세부조건을 달성한다.") class OptionalMandatoryMajorHandlerTest { + private static final User user = UserFixture.경영학과_19학번_ENG12(); private static final MajorType MAJOR_TYPE = MajorType.PRIMARY; private static final Map mockLectureMap = LectureFixture.getMockLectureMap(); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandlerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandlerTest.java index 6059f84a..b4c9c224 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandlerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandlerTest.java @@ -2,13 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; @@ -20,9 +13,15 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; @DisplayName("21학번 이전 철학과 학생의 경우 폐지된 전공필수의 대체 과목을 인정한다.") class ReplaceMandatoryMajorHandlerTest { + private static final User user = UserFixture.철학과_20학번(); private static final MajorType MAJOR_TYPE = MajorType.PRIMARY; private static final Map mockLectureMap = LectureFixture.getMockLectureMap(); @@ -94,8 +93,10 @@ class ReplaceMandatoryMajorHandlerTest { //then assertThat(isCompleteMandatorySpecialCase).isTrue(); assertThat(removedMandatoryTotalCredit).isZero(); - assertThat(mandatoryLectures).hasSize(5).contains(mockLectureMap.get("HAI01348")); - assertThat(electiveLectures).hasSize(1).contains(mockLectureMap.get("HAI01247")); + assertThat(mandatoryLectures).hasSize(5) + .contains(mockLectureMap.get("HAI01348")); + assertThat(electiveLectures).hasSize(1) + .contains(mockLectureMap.get("HAI01247")); } @DisplayName("답사1,답사2를 수강했을 못했고, 대체과목을 수강하지 못했을 경우 대체과목은 전공필수 과목으로 이동한다.") diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManagerTest.java index a3fba8eb..e1310a58 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManagerTest.java @@ -4,12 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; @@ -19,6 +13,10 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.HashSet; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class SubMajorGraduationManagerTest { @@ -28,13 +26,34 @@ void createDetailGraduationResult() { //given User user = UserFixture.응용소프트웨어학과_19학번(); Set takenLectures = new HashSet<>((Set.of( - TakenLecture.of(user, Lecture.builder().lectureCode("HEC01313").credit(3).build(), 2019, Semester.FIRST), - TakenLecture.of(user, Lecture.builder().lectureCode("HEC01310").credit(3).build(), 2020, Semester.FIRST), - TakenLecture.of(user, Lecture.builder().lectureCode("HEC01309").credit(3).build(), 2021, Semester.FIRST), - TakenLecture.of(user, Lecture.builder().lectureCode("HEC01306").credit(3).build(), 2021, Semester.SECOND), - TakenLecture.of(user, Lecture.builder().lectureCode("HEC01304").credit(3).build(), 2022, Semester.FIRST), - TakenLecture.of(user, Lecture.builder().lectureCode("HEC01212").credit(3).build(), 2023, Semester.FIRST), - TakenLecture.of(user, Lecture.builder().lectureCode("HEC01209").credit(3).build(), 2023, Semester.SECOND) + TakenLecture.of(user, Lecture.builder() + .lectureCode("HEC01313") + .credit(3) + .build(), 2019, Semester.FIRST), + TakenLecture.of(user, Lecture.builder() + .lectureCode("HEC01310") + .credit(3) + .build(), 2020, Semester.FIRST), + TakenLecture.of(user, Lecture.builder() + .lectureCode("HEC01309") + .credit(3) + .build(), 2021, Semester.FIRST), + TakenLecture.of(user, Lecture.builder() + .lectureCode("HEC01306") + .credit(3) + .build(), 2021, Semester.SECOND), + TakenLecture.of(user, Lecture.builder() + .lectureCode("HEC01304") + .credit(3) + .build(), 2022, Semester.FIRST), + TakenLecture.of(user, Lecture.builder() + .lectureCode("HEC01212") + .credit(3) + .build(), 2023, Semester.FIRST), + TakenLecture.of(user, Lecture.builder() + .lectureCode("HEC01209") + .credit(3) + .build(), 2023, Semester.SECOND) ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set graduationLectures = lectureSet(); @@ -44,18 +63,22 @@ void createDetailGraduationResult() { GraduationManager subMajorManager = new SubMajorGraduationManager(); //when - DetailGraduationResult detailGraduationResult = subMajorManager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = subMajorManager.createDetailGraduationResult( + user, takenLectureInventory, graduationLectures, subMajorGraduationCredit); //then int majorCredit = 3; assertThat(detailGraduationResult.getDetailCategory()).hasSize(1) - .extracting("detailCategoryName", "isCompleted", "isSatisfiedMandatory", "totalCredits", "takenCredits") + .extracting("detailCategoryName", "isCompleted", "isSatisfiedMandatory", "totalCredits", + "takenCredits") .contains( - tuple("전공선택", true, true, subMajorGraduationCredit, majorCredit * takenLecturesCount)); + tuple("전공선택", true, true, subMajorGraduationCredit, + majorCredit * takenLecturesCount)); assertThat(detailGraduationResult) .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") - .contains(SUB_MAJOR, true, subMajorGraduationCredit, (double)majorCredit * takenLecturesCount); + .contains(SUB_MAJOR, true, subMajorGraduationCredit, + (double) majorCredit * takenLecturesCount); } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureControllerTest.java index 933d39e8..4d39021a 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/api/SearchLectureControllerTest.java @@ -11,15 +11,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto.SearchedLectureDto; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; import com.plzgraduate.myongjigraduatebe.support.WithMockAuthenticationUser; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class SearchLectureControllerTest extends WebAdaptorTestSupport { @@ -28,8 +26,10 @@ class SearchLectureControllerTest extends WebAdaptorTestSupport { @Test void searchLecture() throws Exception { //given - List searchedLectures = List.of(SearchedLectureDto.of(true, Lecture.from("code"))); - given(searchLectureUseCase.searchLectures(anyLong(), any(), any())).willReturn(searchedLectures); + List searchedLectures = List.of( + SearchedLectureDto.of(true, Lecture.from("code"))); + given(searchLectureUseCase.searchLectures(anyLong(), any(), any())).willReturn( + searchedLectures); //when //then mockMvc.perform(get("/api/v1/lectures") @@ -40,7 +40,8 @@ void searchLecture() throws Exception { .andExpect(jsonPath("$", hasSize(searchedLectures.size()))) .andExpect(jsonPath("$.[0].taken").value(true)); - then(searchLectureUseCase).should(times(1)).searchLectures(anyLong(), any(), any()); + then(searchLectureUseCase).should(times(1)) + .searchLectures(anyLong(), any(), any()); } @WithMockAuthenticationUser diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/find/FindLecturesByIdServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/find/FindLecturesByIdServiceTest.java index 6b2dc3d9..c7a9280a 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/find/FindLecturesByIdServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/find/FindLecturesByIdServiceTest.java @@ -1,10 +1,12 @@ package com.plzgraduate.myongjigraduatebe.lecture.application.service.find; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.BDDMockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort; +import com.plzgraduate.myongjigraduatebe.lecture.application.service.FindLecturesService; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import java.util.List; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -12,10 +14,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort; -import com.plzgraduate.myongjigraduatebe.lecture.application.service.FindLecturesService; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - @ExtendWith(MockitoExtension.class) class FindLecturesByIdServiceTest { @@ -28,7 +26,7 @@ class FindLecturesByIdServiceTest { @DisplayName("과목 아이디 리스트에 포함되는 과목들을 반환한다.") @Test void test() { - //given + //given List lectureIds = List.of(1L, 2L, 3L); List lectures = List.of( createLecture(1L, "KMA00101", "성서와 인간이해", 2, 0, null), @@ -38,14 +36,15 @@ void test() { given(findLecturePort.findLecturesByIds(lectureIds)).willReturn(lectures); - //when + //when List result = findLecturesByIdService.findLecturesByIds(lectureIds); //then assertThat(result).isEqualTo(lectures); } - private Lecture createLecture(Long id, String lectureCode, String name, int credit, int isRevoked, String duplicateCode) { + private Lecture createLecture(Long id, String lectureCode, String name, int credit, + int isRevoked, String duplicateCode) { return Lecture.builder() .id(id) .lectureCode(lectureCode) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/find/FindLecturesByLectureCodeServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/find/FindLecturesByLectureCodeServiceTest.java index d0ecc875..bbd63d5f 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/find/FindLecturesByLectureCodeServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/find/FindLecturesByLectureCodeServiceTest.java @@ -3,8 +3,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort; +import com.plzgraduate.myongjigraduatebe.lecture.application.service.FindLecturesService; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import java.util.List; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -12,10 +14,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort; -import com.plzgraduate.myongjigraduatebe.lecture.application.service.FindLecturesService; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - @ExtendWith(MockitoExtension.class) class FindLecturesByLectureCodeServiceTest { @@ -28,7 +26,7 @@ class FindLecturesByLectureCodeServiceTest { @DisplayName("과목 코드 리스트에 포함되는 과목들을 반환한다.") @Test void findLecturesByLectureCodes() { - //given + //given List lectureCodes = List.of("KMA00101", "KMA02104", "KMA02106"); List lectures = List.of( createLecture(1L, "KMA00101", "성서와 인간이해", 2, 0, null), @@ -44,7 +42,8 @@ void findLecturesByLectureCodes() { assertThat(result).isEqualTo(lectures); } - private Lecture createLecture(Long id, String lectureCode, String name, int credit, int isRevoked, String duplicateCode) { + private Lecture createLecture(Long id, String lectureCode, String name, int credit, + int isRevoked, String duplicateCode) { return Lecture.builder() .id(id) .lectureCode(lectureCode) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/search/SearchLectureServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/search/SearchLectureServiceTest.java index 390c3ee9..588d2150 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/search/SearchLectureServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/application/service/search/SearchLectureServiceTest.java @@ -4,9 +4,15 @@ import static org.assertj.core.api.Assertions.tuple; import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.lecture.application.port.SearchLecturePort; +import com.plzgraduate.myongjigraduatebe.lecture.application.service.SearchLectureService; +import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto.SearchedLectureDto; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import java.util.List; import java.util.Set; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -14,16 +20,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.SearchLecturePort; -import com.plzgraduate.myongjigraduatebe.lecture.application.service.SearchLectureService; -import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto.SearchedLectureDto; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; - @ExtendWith(MockitoExtension.class) class SearchLectureServiceTest { + @Mock private SearchLecturePort searchLecturePort; @Mock @@ -50,7 +49,8 @@ void searchLectures() { given(findTakenLectureUseCase.findTakenLectures(userId)).willReturn(takenLectureInventory); //when - List searchedLectureDtos = searchLectureService.searchLectures(userId, type, + List searchedLectureDtos = searchLectureService.searchLectures(userId, + type, keyword); //then @@ -63,7 +63,8 @@ void searchLectures() { ); } - private Lecture createLecture(Long id, String lectureCode, String name, int credit, int isRevoked) { + private Lecture createLecture(Long id, String lectureCode, String name, int credit, + int isRevoked) { return Lecture.builder() .id(id) .lectureCode(lectureCode) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/LectureTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/LectureTest.java index 307f5ef5..a1ebb9cc 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/LectureTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/LectureTest.java @@ -1,6 +1,6 @@ package com.plzgraduate.myongjigraduatebe.lecture.domain.model; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -10,7 +10,7 @@ class LectureTest { @DisplayName("과목코드가 'KM'으로 시작하는 과목은 교양과목이다.") @Test void checkIsCulture() { - //given + //given String lectureCode = "KMA02100"; Lecture lecture = Lecture.from(lectureCode); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindBasicAcademicalCulturePersistenceAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindBasicAcademicalCulturePersistenceAdapterTest.java index 54c82b30..ac9501b5 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindBasicAcademicalCulturePersistenceAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindBasicAcademicalCulturePersistenceAdapterTest.java @@ -4,13 +4,6 @@ import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.ICT; import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.BasicAcademicalCultureLectureJpaEntity; @@ -19,6 +12,11 @@ import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class FindBasicAcademicalCulturePersistenceAdapterTest extends PersistenceTestSupport { @@ -44,13 +42,16 @@ void findBasicAcademicalCulture() { BasicAcademicalCultureLectureJpaEntity basicAcademicalCultureLectureJpaEntityA = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntityA) - .college(ICT.getName()).build(); + .college(ICT.getName()) + .build(); BasicAcademicalCultureLectureJpaEntity basicAcademicalCultureLectureJpaEntityB = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntityA) - .college(BUSINESS.getName()).build(); + .college(BUSINESS.getName()) + .build(); basicAcademicalCultureRepository.saveAll( - List.of(basicAcademicalCultureLectureJpaEntityA, basicAcademicalCultureLectureJpaEntityB)); + List.of(basicAcademicalCultureLectureJpaEntityA, + basicAcademicalCultureLectureJpaEntityB)); //when Set basicAcademicalCulture = basicAcademicalCulturePersistenceAdapter.findBasicAcademicalCulture( diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCommonCulturePersistenceAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCommonCulturePersistenceAdapterTest.java index bdeaf9c7..e2053252 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCommonCulturePersistenceAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCommonCulturePersistenceAdapterTest.java @@ -3,13 +3,6 @@ import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.ENGLISH; import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CommonCultureJpaEntity; @@ -18,6 +11,11 @@ import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class FindCommonCulturePersistenceAdapterTest extends PersistenceTestSupport { @@ -40,7 +38,8 @@ void findBasicEngCommonCulture() { createCommonCultures(); //when - Set commonCultures = commonCulturePersistenceAdapter.findCommonCulture(basicEngUser); + Set commonCultures = commonCulturePersistenceAdapter.findCommonCulture( + basicEngUser); //then assertThat(commonCultures).hasSize(2) @@ -56,7 +55,8 @@ void findEng12CommonCulture() { createCommonCultures(); //when - Set commonCultures = commonCulturePersistenceAdapter.findCommonCulture(eng12User); + Set commonCultures = commonCulturePersistenceAdapter.findCommonCulture( + eng12User); //then assertThat(commonCultures).hasSize(1) @@ -72,7 +72,8 @@ void findEng34CommonCulture() { createCommonCultures(); //when - Set commonCultures = commonCulturePersistenceAdapter.findCommonCulture(eng34User); + Set commonCultures = commonCulturePersistenceAdapter.findCommonCulture( + eng34User); //then assertThat(commonCultures).hasSize(1) @@ -88,7 +89,8 @@ void findEngFreeCommonCulture() { createCommonCultures(); //when - Set commonCultures = commonCulturePersistenceAdapter.findCommonCulture(engFreeUser); + Set commonCultures = commonCulturePersistenceAdapter.findCommonCulture( + engFreeUser); //then assertThat(commonCultures).hasSize(0); @@ -110,17 +112,20 @@ private void createCommonCultures() { .lectureJpaEntity(lectureJpaEntityA) .commonCultureCategory(ENGLISH) .startEntryYear(18) - .endEntryYear(23).build(); + .endEntryYear(23) + .build(); CommonCultureJpaEntity commonCultureJpaEntityB = CommonCultureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntityB) .commonCultureCategory(ENGLISH) .startEntryYear(16) - .endEntryYear(17).build(); + .endEntryYear(17) + .build(); CommonCultureJpaEntity commonCultureJpaEntityC = CommonCultureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntityC) .commonCultureCategory(ENGLISH) .startEntryYear(16) - .endEntryYear(99).build(); + .endEntryYear(99) + .build(); commonCultureRepository.saveAll( List.of(commonCultureJpaEntityA, commonCultureJpaEntityB, commonCultureJpaEntityC)); } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCoreCulturePersistenceAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCoreCulturePersistenceAdapterTest.java index 24b58aa2..1b03712c 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCoreCulturePersistenceAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindCoreCulturePersistenceAdapterTest.java @@ -4,22 +4,19 @@ import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.SOCIETY_COMMUNITY; import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.FindCoreCulturePersistenceAdapter; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CoreCultureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.CoreCultureRepository; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class FindCoreCulturePersistenceAdapterTest extends PersistenceTestSupport { @@ -48,12 +45,14 @@ void findCoreCulture() { .lectureJpaEntity(lectureJpaEntityA) .coreCultureCategory(CULTURE_ART) .startEntryYear(16) - .endEntryYear(18).build(); + .endEntryYear(18) + .build(); CoreCultureJpaEntity coreCultureJpaEntityB = CoreCultureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntityA) .coreCultureCategory(SOCIETY_COMMUNITY) .startEntryYear(19) - .endEntryYear(23).build(); + .endEntryYear(23) + .build(); coreCultureRepository.saveAll(List.of(coreCultureJpaEntityA, coreCultureJpaEntityB)); //when diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindMajorPersistenceAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindMajorPersistenceAdapterTest.java index 3484aa44..fc2dde51 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindMajorPersistenceAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/FindMajorPersistenceAdapterTest.java @@ -2,21 +2,19 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.MajorLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.MajorLectureRepository; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class FindMajorPersistenceAdapterTest extends PersistenceTestSupport { @@ -30,7 +28,7 @@ class FindMajorPersistenceAdapterTest extends PersistenceTestSupport { @DisplayName("유저의 전공에 해당하는 전공 과목을 조회한다.") @Test void findMajor() { - //given + //given User user = UserFixture.응용소프트웨어학과_19학번(); LectureJpaEntity lectureJpaEntityA = LectureJpaEntity.builder() .lectureCode("testA") @@ -42,14 +40,16 @@ void findMajor() { MajorLectureJpaEntity majorLectureJpaEntityA = MajorLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntityA) - .major(user.getPrimaryMajor()).build(); + .major(user.getPrimaryMajor()) + .build(); MajorLectureJpaEntity majorLectureJpaEntityB = MajorLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntityA) - .major("데이터테크놀로지").build(); + .major("데이터테크놀로지") + .build(); majorLectureRepository.saveAll(List.of(majorLectureJpaEntityA, majorLectureJpaEntityB)); - //when + //when Set majors = majorPersistenceAdapter.findMajor(user.getPrimaryMajor()); //then diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/LecturePersistenceAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/LecturePersistenceAdapterTest.java index 9f6be87d..3e78cc3a 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/LecturePersistenceAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/LecturePersistenceAdapterTest.java @@ -1,21 +1,20 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureQueryRepository; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; +import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import java.util.ArrayList; import java.util.List; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureQueryRepository; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; -import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; - class LecturePersistenceAdapterTest extends PersistenceTestSupport { @Autowired @@ -92,7 +91,8 @@ void findLectureById() { //given String lectureCode = "code"; String lectureName = "name"; - LectureJpaEntity lectureJpaEntity = lectureRepository.save(createLectureJpaEntity(lectureCode, lectureName)); + LectureJpaEntity lectureJpaEntity = lectureRepository.save( + createLectureJpaEntity(lectureCode, lectureName)); //when Lecture lecture = lecturePersistenceAdapter.findLectureById(lectureJpaEntity.getId()); @@ -116,7 +116,8 @@ void searchLectureByNameOrCode() { )); //when - List lectures = lecturePersistenceAdapter.searchLectureByNameOrCode("name", "name"); + List lectures = lecturePersistenceAdapter.searchLectureByNameOrCode("name", + "name"); //then assertThat(lectures) @@ -128,7 +129,8 @@ void searchLectureByNameOrCode() { ); } - private Lecture createLecture(String lectureCode, String name, int credit, int isRevoked, String duplicateCode) { + private Lecture createLecture(String lectureCode, String name, int credit, int isRevoked, + String duplicateCode) { return Lecture.builder() .lectureCode(lectureCode) .name(name) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/mapper/LectureMapperTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/mapper/LectureMapperTest.java index 2efb0da8..3178147b 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/mapper/LectureMapperTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/mapper/LectureMapperTest.java @@ -4,21 +4,19 @@ import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.CULTURE_ART; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper.LectureMapper; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.BasicAcademicalCultureLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CommonCultureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CoreCultureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.MajorLectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class LectureMapperTest extends PersistenceTestSupport { @@ -30,8 +28,10 @@ class LectureMapperTest extends PersistenceTestSupport { void mapToCommonCulture() { //given CommonCultureJpaEntity commonCultureJpaEntity = CommonCultureJpaEntity.builder() - .lectureJpaEntity(LectureJpaEntity.builder().build()) - .commonCultureCategory(CAREER).build(); + .lectureJpaEntity(LectureJpaEntity.builder() + .build()) + .commonCultureCategory(CAREER) + .build(); //when CommonCulture commonCulture = lectureMapper.mapToCommonCultureModel(commonCultureJpaEntity); @@ -45,8 +45,10 @@ void mapToCommonCulture() { void mapToCoreCulture() { //given CoreCultureJpaEntity commonCultureJpaEntity = CoreCultureJpaEntity.builder() - .lectureJpaEntity(LectureJpaEntity.builder().build()) - .coreCultureCategory(CULTURE_ART).build(); + .lectureJpaEntity(LectureJpaEntity.builder() + .build()) + .coreCultureCategory(CULTURE_ART) + .build(); //when CoreCulture coreCulture = lectureMapper.mapToCoreCultureModel(commonCultureJpaEntity); @@ -60,8 +62,10 @@ void mapToCoreCulture() { void mapToCBasicAcademicalCulture() { //given BasicAcademicalCultureLectureJpaEntity basicAcademicalCultureEntity = BasicAcademicalCultureLectureJpaEntity.builder() - .lectureJpaEntity(LectureJpaEntity.builder().build()) - .college("인문대").build(); + .lectureJpaEntity(LectureJpaEntity.builder() + .build()) + .college("인문대") + .build(); //when BasicAcademicalCultureLecture basicAcademicalCultureLecture = lectureMapper.mapToBasicAcademicalCultureLectureModel( @@ -76,8 +80,10 @@ void mapToCBasicAcademicalCulture() { void mapToMajor() { //given MajorLectureJpaEntity majorEntity = MajorLectureJpaEntity.builder() - .lectureJpaEntity(LectureJpaEntity.builder().build()) - .major("응용소프트웨어").build(); + .lectureJpaEntity(LectureJpaEntity.builder() + .build()) + .major("응용소프트웨어") + .build(); //when MajorLecture basicAcademicalCulture = lectureMapper.mapToMajorLectureModel(majorEntity); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/query/LectureQueryRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/query/LectureQueryRepositoryTest.java index 44d140c4..d2f0e79a 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/query/LectureQueryRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/query/LectureQueryRepositoryTest.java @@ -2,16 +2,14 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureQueryRepository; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class LectureQueryRepositoryTest extends PersistenceTestSupport { @@ -26,10 +24,10 @@ class LectureQueryRepositoryTest extends PersistenceTestSupport { void searchLectureByCode() { //given List lectureJpaEntities = List.of( - createLectureJpaEntity( "HEB01102", "기초프로그래밍"), + createLectureJpaEntity("HEB01102", "기초프로그래밍"), createLectureJpaEntity("HED01315", "인공지능"), - createLectureJpaEntity( "KMI02118", "엑셀기초및실무활용"), - createLectureJpaEntity( "KMI02123", "웹과앱기초") + createLectureJpaEntity("KMI02118", "엑셀기초및실무활용"), + createLectureJpaEntity("KMI02123", "웹과앱기초") ); lectureRepository.saveAll(lectureJpaEntities); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/query/TestQuerydslConfig.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/query/TestQuerydslConfig.java index f83a90bd..9e81a914 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/query/TestQuerydslConfig.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/query/TestQuerydslConfig.java @@ -1,16 +1,15 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.query; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureQueryRepository; +import com.querydsl.jpa.impl.JPAQueryFactory; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; - import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureQueryRepository; -import com.querydsl.jpa.impl.JPAQueryFactory; - @TestConfiguration public class TestQuerydslConfig { + @PersistenceContext private EntityManager entityManager; @@ -23,5 +22,4 @@ public JPAQueryFactory jpaQueryFactory() { public LectureQueryRepository lectureQueryRepository() { return new LectureQueryRepository(jpaQueryFactory()); } - } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/BasicAcademicalCultureLectureRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/BasicAcademicalCultureLectureRepositoryTest.java index b98ca7b7..04429b2b 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/BasicAcademicalCultureLectureRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/BasicAcademicalCultureLectureRepositoryTest.java @@ -1,15 +1,8 @@ package com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository; -import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.*; -import static org.assertj.core.api.Assertions.*; - -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.BUSINESS; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.ICT; +import static org.assertj.core.api.Assertions.assertThat; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.BasicAcademicalCultureLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; @@ -18,6 +11,12 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; class BasicAcademicalCultureLectureRepositoryTest extends PersistenceTestSupport { @@ -62,12 +61,15 @@ void findAllDuplicatedTakenCountByCollages() { .password("test") .studentNumber("12341234") .major("응용소프트웨어전공") - .dualMajor("경영학과").build()); + .dualMajor("경영학과") + .build()); LectureJpaEntity lectureJpaEntityA = LectureJpaEntity.builder() - .lectureCode("TESTA").build(); + .lectureCode("TESTA") + .build(); LectureJpaEntity lectureJpaEntityB = LectureJpaEntity.builder() - .lectureCode("TESTB").build(); + .lectureCode("TESTB") + .build(); List lectureJpaEntities = lectureRepository.saveAll( List.of(lectureJpaEntityA, lectureJpaEntityB)); @@ -83,13 +85,16 @@ void findAllDuplicatedTakenCountByCollages() { BasicAcademicalCultureLectureJpaEntity ictBasicAcademicalCultureJpaEntity = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntities.get(0)) - .college(ICT.getName()).build(); + .college(ICT.getName()) + .build(); BasicAcademicalCultureLectureJpaEntity businessBasicAcademicalCultureJpaEntity = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntities.get(1)) - .college(BUSINESS.getName()).build(); + .college(BUSINESS.getName()) + .build(); BasicAcademicalCultureLectureJpaEntity bothBasicAcademicalCultureJpaEntity = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntities.get(0)) - .college(BUSINESS.getName()).build(); + .college(BUSINESS.getName()) + .build(); basicAcademicalCultureRepository.saveAll( List.of(ictBasicAcademicalCultureJpaEntity, businessBasicAcademicalCultureJpaEntity, bothBasicAcademicalCultureJpaEntity)); @@ -106,19 +111,24 @@ private List createBasicAcademicalCultur LectureJpaEntity lectureJpaEntity) { BasicAcademicalCultureLectureJpaEntity humanities = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntity) - .college("인문대").build(); + .college("인문대") + .build(); BasicAcademicalCultureLectureJpaEntity socialScience = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntity) - .college("사회과학대").build(); + .college("사회과학대") + .build(); BasicAcademicalCultureLectureJpaEntity business = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntity) - .college("경영대").build(); + .college("경영대") + .build(); BasicAcademicalCultureLectureJpaEntity law = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntity) - .college("법대").build(); + .college("법대") + .build(); BasicAcademicalCultureLectureJpaEntity ict = BasicAcademicalCultureLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntity) - .college("ICT융합대").build(); + .college("ICT융합대") + .build(); return List.of(humanities, socialScience, business, law, ict); } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CommonCultureRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CommonCultureRepositoryTest.java index dd9f3668..c24c8514 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CommonCultureRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CommonCultureRepositoryTest.java @@ -2,18 +2,16 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CommonCultureJpaEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import java.util.List; import java.util.stream.Collectors; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CommonCultureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; - class CommonCultureRepositoryTest extends PersistenceTestSupport { private static final String BASIC_ENGLISH_CODE = "KMP02126"; @@ -48,7 +46,8 @@ void findEngBasicAllByEntryYear(int entryYear) { .contains(entryYear); List lectureCodes = commonCultureGraduationLectures.stream() - .map(commonCultureJpaEntity -> commonCultureJpaEntity.getLectureJpaEntity().getLectureCode()) + .map(commonCultureJpaEntity -> commonCultureJpaEntity.getLectureJpaEntity() + .getLectureCode()) .collect(Collectors.toList()); assertThat(lectureCodes).contains(BASIC_ENGLISH_CODE); assertThat(lectureCodes).doesNotContain(ENGLISH3_CODE); @@ -74,7 +73,8 @@ void findEng12AllByEntryYear(int entryYears) { .contains(entryYears); List lectureCodes = commonCultureGraduationLectures.stream() - .map(commonCultureJpaEntity -> commonCultureJpaEntity.getLectureJpaEntity().getLectureCode()) + .map(commonCultureJpaEntity -> commonCultureJpaEntity.getLectureJpaEntity() + .getLectureCode()) .collect(Collectors.toList()); assertThat(lectureCodes).doesNotContain(BASIC_ENGLISH_CODE); assertThat(lectureCodes).doesNotContain(ENGLISH3_CODE); @@ -100,7 +100,8 @@ void findEng34AllAllByEntryYear(int entryYears) { .contains(entryYears); List lectureCodes = commonCultureGraduationLectures.stream() - .map(commonCultureJpaEntity -> commonCultureJpaEntity.getLectureJpaEntity().getLectureCode()) + .map(commonCultureJpaEntity -> commonCultureJpaEntity.getLectureJpaEntity() + .getLectureCode()) .collect(Collectors.toList()); assertThat(lectureCodes).doesNotContain(BASIC_ENGLISH_CODE); assertThat(lectureCodes).doesNotContain(ENGLISH1_CODE); @@ -152,26 +153,31 @@ private void saveEnglishLectures() { LectureJpaEntity 영어회화4 = LectureJpaEntity.builder() .lectureCode(ENGLISH_CONVERSATION4_CODE) .build(); - List englishLectures = List.of(기초영어, 영어1, 영어2, 영어3, 영어4, 영어회화1, 영어회화2, 영어회화3, 영어회화4); + List englishLectures = List.of(기초영어, 영어1, 영어2, 영어3, 영어4, 영어회화1, 영어회화2, + 영어회화3, 영어회화4); lectureRepository.saveAll(englishLectures); for (LectureJpaEntity englishLecture : englishLectures) { CommonCultureJpaEntity commonCultureJpaEntityA = CommonCultureJpaEntity.builder() .lectureJpaEntity(englishLecture) .startEntryYear(16) - .endEntryYear(17).build(); + .endEntryYear(17) + .build(); CommonCultureJpaEntity commonCultureJpaEntityB = CommonCultureJpaEntity.builder() .lectureJpaEntity(englishLecture) .startEntryYear(18) - .endEntryYear(19).build(); + .endEntryYear(19) + .build(); CommonCultureJpaEntity commonCultureJpaEntityC = CommonCultureJpaEntity.builder() .lectureJpaEntity(englishLecture) .startEntryYear(20) - .endEntryYear(22).build(); + .endEntryYear(22) + .build(); CommonCultureJpaEntity commonCultureJpaEntityD = CommonCultureJpaEntity.builder() .lectureJpaEntity(englishLecture) .startEntryYear(23) - .endEntryYear(99).build(); + .endEntryYear(99) + .build(); commonCultureRepository.saveAll( List.of(commonCultureJpaEntityA, commonCultureJpaEntityB, commonCultureJpaEntityC, commonCultureJpaEntityD)); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CoreCultureRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CoreCultureRepositoryTest.java index 13e3951a..5112434c 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CoreCultureRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/CoreCultureRepositoryTest.java @@ -2,19 +2,15 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CoreCultureJpaEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import java.util.List; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.CoreCultureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.CoreCultureRepository; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; -import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; - class CoreCultureRepositoryTest extends PersistenceTestSupport { @Autowired @@ -35,11 +31,13 @@ void findAllByEntryYear(int entryYears) { CoreCultureJpaEntity coreCultureJpaEntityA = CoreCultureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntity) .startEntryYear(16) - .endEntryYear(17).build(); + .endEntryYear(17) + .build(); CoreCultureJpaEntity coreCultureJpaEntityB = CoreCultureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntity) .startEntryYear(18) - .endEntryYear(99).build(); + .endEntryYear(99) + .build(); coreCultureRepository.saveAll( List.of(coreCultureJpaEntityA, coreCultureJpaEntityB)); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepositoryTest.java index 593b0e3e..e5b2c555 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/lecture/infrastructure/adapter/persistence/repository/MajorLectureRepositoryTest.java @@ -2,18 +2,14 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.MajorLectureJpaEntity; +import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import java.util.List; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.MajorLectureJpaEntity; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.MajorLectureRepository; -import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; - class MajorLectureRepositoryTest extends PersistenceTestSupport { @Autowired @@ -25,7 +21,7 @@ class MajorLectureRepositoryTest extends PersistenceTestSupport { @DisplayName("유저의 전공에 해당하는 전공 과목을 조회한다.") @Test void findAllByMajor() { - //given + //given LectureJpaEntity lectureJpaEntity = LectureJpaEntity.builder() .lectureCode("TEST") .build(); @@ -33,15 +29,17 @@ void findAllByMajor() { MajorLectureJpaEntity majorLectureJpaEntityA = MajorLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntity) - .major("응용소프트웨어").build(); + .major("응용소프트웨어") + .build(); MajorLectureJpaEntity majorLectureJpaEntityB = MajorLectureJpaEntity.builder() .lectureJpaEntity(lectureJpaEntity) - .major("데이터테크놀로지").build(); + .major("데이터테크놀로지") + .build(); majorLectureRepository.saveAll(List.of(majorLectureJpaEntityA, majorLectureJpaEntityB)); String major = "응용소프트웨어"; - //when + //when List majorLectures = majorLectureRepository.findAllByMajor(major); //then diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextControllerTest.java index f316d154..026c602b 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/api/ParsingTextControllerTest.java @@ -9,15 +9,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.ResultActions; - import com.plzgraduate.myongjigraduatebe.core.exception.InvalidPdfException; import com.plzgraduate.myongjigraduatebe.parsing.api.dto.request.ParsingTextRequest; import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; import com.plzgraduate.myongjigraduatebe.support.WithMockAuthenticationUser; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; class ParsingTextControllerTest extends WebAdaptorTestSupport { @@ -25,7 +24,7 @@ class ParsingTextControllerTest extends WebAdaptorTestSupport { @DisplayName("파싱 텍스트를 등록한다.") @Test void enrollParsingText() throws Exception { - //given + //given String parsingText = "parsingText"; ParsingTextRequest request = ParsingTextRequest.builder() .parsingText(parsingText) @@ -39,13 +38,15 @@ void enrollParsingText() throws Exception { .with(csrf()) ); - //then + //then actions .andDo(print()) .andExpect(status().isOk()); - then(parsingTextUseCase).should().enrollParsingText(any(Long.class), any(String.class)); - then(parsingTextHistoryUseCase).should().generateSucceedParsingTextHistory(any(Long.class), any(String.class)); + then(parsingTextUseCase).should() + .enrollParsingText(any(Long.class), any(String.class)); + then(parsingTextHistoryUseCase).should() + .generateSucceedParsingTextHistory(any(Long.class), any(String.class)); } @@ -59,7 +60,8 @@ void failToEnrollParsingText() throws Exception { .parsingText(parsingText) .build(); - doThrow(new InvalidPdfException("")).when(parsingTextUseCase).enrollParsingText(any(Long.class), any(String.class)); + doThrow(new InvalidPdfException("")).when(parsingTextUseCase) + .enrollParsingText(any(Long.class), any(String.class)); //when ResultActions actions = mockMvc.perform( @@ -75,7 +77,8 @@ void failToEnrollParsingText() throws Exception { .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errorCode").value("")); - then(parsingTextHistoryUseCase).should().generateFailedParsingTextHistory(any(Long.class), any(String.class)); + then(parsingTextHistoryUseCase).should() + .generateFailedParsingTextHistory(any(Long.class), any(String.class)); } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextHistoryServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextHistoryServiceTest.java index 63495dfd..10bb6f6d 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextHistoryServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextHistoryServiceTest.java @@ -4,6 +4,12 @@ import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; +import com.plzgraduate.myongjigraduatebe.parsing.application.port.SaveParsingTextHistoryPort; +import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingTextHistory; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; +import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -12,15 +18,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.parsing.application.port.SaveParsingTextHistoryPort; -import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingTextHistory; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; -import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class ParsingTextHistoryServiceTest { + @Mock private SaveParsingTextHistoryPort saveParsingTextHistoryPort; @Mock @@ -37,12 +37,14 @@ void generateSucceedParsingTextHistory() { "60181666", 18, "융합소프트웨어학부", null, StudentCategory.NORMAL); String parsingText = "parsingText"; given(findUserUseCase.findUserById(userId)).willReturn(user); - ArgumentCaptor captor = ArgumentCaptor.forClass(ParsingTextHistory.class); + ArgumentCaptor captor = ArgumentCaptor.forClass( + ParsingTextHistory.class); //when parsingTextHistoryService.generateSucceedParsingTextHistory(userId, parsingText); //then - then(saveParsingTextHistoryPort).should().saveParsingTextHistory(captor.capture()); + then(saveParsingTextHistoryPort).should() + .saveParsingTextHistory(captor.capture()); ParsingTextHistory captureArgument = captor.getValue(); assertThat(captureArgument.getUser()).isEqualTo(user); assertThat(captureArgument.getParsingText()).isEqualTo(parsingText); @@ -57,19 +59,23 @@ void generateFailedParsingTextHistory() { "60181666", 18, "융합소프트웨어학부", null, StudentCategory.NORMAL); String parsingText = "parsingText"; given(findUserUseCase.findUserById(userId)).willReturn(user); - ArgumentCaptor captor = ArgumentCaptor.forClass(ParsingTextHistory.class); + ArgumentCaptor captor = ArgumentCaptor.forClass( + ParsingTextHistory.class); //when parsingTextHistoryService.generateFailedParsingTextHistory(userId, parsingText); //then - then(saveParsingTextHistoryPort).should().saveParsingTextHistory(captor.capture()); + then(saveParsingTextHistoryPort).should() + .saveParsingTextHistory(captor.capture()); ParsingTextHistory captureArgument = captor.getValue(); assertThat(captureArgument.getUser()).isEqualTo(user); assertThat(captureArgument.getParsingText()).isEqualTo(parsingText); } - private User createUser(Long id, String authId, String password, EnglishLevel englishLevel, String name, - String studentNumber, int entryYear, String major, String subMajor, StudentCategory studentCategory) { + private User createUser(Long id, String authId, String password, EnglishLevel englishLevel, + String name, + String studentNumber, int entryYear, String major, String subMajor, + StudentCategory studentCategory) { return User.builder() .id(id) .authId(authId) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextServiceTest.java index 05ac256b..4150764a 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/application/service/ParsingTextServiceTest.java @@ -8,13 +8,6 @@ import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase; import com.plzgraduate.myongjigraduatebe.core.exception.InvalidPdfException; import com.plzgraduate.myongjigraduatebe.core.exception.PdfParsingException; @@ -26,9 +19,16 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class ParsingTextServiceTest{ +class ParsingTextServiceTest { + @Mock private FindUserUseCase findUserUseCase; @Mock @@ -45,7 +45,7 @@ class ParsingTextServiceTest{ @DisplayName("파싱 텍스트에서 정보를 추출해 성공적으로 메서드를 호출한다.") @Test void 성공() { - //given + //given User user = createUser( "60181666"); String parsingText = "출력일자 : 2023/09/01|1/1" @@ -61,22 +61,25 @@ class ParsingTextServiceTest{ //when parsingTextService.enrollParsingText(1L, parsingText); - //then + //then User updatedUser = then(updateStudentInformationUseCase).should() .updateUser(any(UpdateStudentInformationCommand.class)); - then(deleteTakenLectureByUserUseCase).should().deleteAllTakenLecturesByUser(updatedUser); - then(saveTakenLectureFromParsingTextUseCase).should().saveTakenLectures(any(), any()); - then(generateOrModifyCompletedCreditUseCase).should().generateOrModifyCompletedCredit(updatedUser); + then(deleteTakenLectureByUserUseCase).should() + .deleteAllTakenLecturesByUser(updatedUser); + then(saveTakenLectureFromParsingTextUseCase).should() + .saveTakenLectures(any(), any()); + then(generateOrModifyCompletedCreditUseCase).should() + .generateOrModifyCompletedCredit(updatedUser); } @DisplayName("PDF 파싱 텍스트가 빈 문자열로 오면 InvalidPdfException을 반환한다.") @Test void 파싱_텍스트_빈문자열() { - //given + //given String emptyParsingText = " "; - //when //then - assertThatThrownBy(() -> parsingTextService.enrollParsingText(1L, emptyParsingText)) + //when //then + assertThatThrownBy(() -> parsingTextService.enrollParsingText(1L, emptyParsingText)) .isInstanceOf(InvalidPdfException.class) .hasMessage("PDF를 인식하지 못했습니다. 채널톡으로 문의 바랍니다."); } @@ -84,7 +87,7 @@ class ParsingTextServiceTest{ @DisplayName("사용자의 학번과 PDF의 학번이 다를때 InvalidPdfException을 반환한다.") @Test void 서로다른_PDF_학번() { - //given + //given String parsingText = "출력일자 : 2023/09/01|1/1" + "|ICT융합대학 융합소프트웨어학부 데이터테크놀로지전공, 정지환(60181666), 현학적 - 재학, 이수 - 7, 입학 - 신입학(2018/03/02)" + "|토익 - 570, 영어교과목면제 - 면제없음, 최종학적변동 - 불일치복학(2022/07/15)" @@ -99,7 +102,7 @@ class ParsingTextServiceTest{ given(findUserUseCase.findUserById(anyLong())).willReturn(user); - //when //then + //when //then assertThatThrownBy(() -> parsingTextService.enrollParsingText(1L, parsingText)) .isInstanceOf(InvalidPdfException.class) @@ -109,7 +112,7 @@ class ParsingTextServiceTest{ @DisplayName("RuntimeException이 발생했을 경우 PdfParsingException을 반환한다.") @Test void PDF_파싱_예외처리() { - //given + //given String parsingText = "출력일자 : 2023/09/01|1/1" + "|ICT융합대학 융합소프트웨어학부 데이터테크놀로지전공, 정지환(60181666), 현학적 - 재학, 이수 - 7, 입학 - 신입학(2018/03/02)" + "|토익 - 570, 영어교과목면제 - 면제없음, 최종학적변동 - 불일치복학(2022/07/15)" @@ -122,7 +125,7 @@ class ParsingTextServiceTest{ User user = createUser( "60181666"); - //when + //when given(findUserUseCase.findUserById(anyLong())).willReturn(user); doThrow(NullPointerException.class).when(saveTakenLectureFromParsingTextUseCase) .saveTakenLectures(any(User.class), any()); @@ -156,9 +159,12 @@ class ParsingTextServiceTest{ //then User updatedUser = then(updateStudentInformationUseCase).should() .updateUser(any(UpdateStudentInformationCommand.class)); - then(deleteTakenLectureByUserUseCase).should().deleteAllTakenLecturesByUser(updatedUser); - then(saveTakenLectureFromParsingTextUseCase).should().saveTakenLectures(any(), any()); - then(generateOrModifyCompletedCreditUseCase).should().generateOrModifyCompletedCredit(updatedUser); + then(deleteTakenLectureByUserUseCase).should() + .deleteAllTakenLecturesByUser(updatedUser); + then(saveTakenLectureFromParsingTextUseCase).should() + .saveTakenLectures(any(), any()); + then(generateOrModifyCompletedCreditUseCase).should() + .generateOrModifyCompletedCredit(updatedUser); } private User createUser(String studentNumber) { diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingInformationTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingInformationTest.java index 8e3d6a39..62dc534d 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingInformationTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingInformationTest.java @@ -2,17 +2,16 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; - class ParsingInformationTest { @DisplayName("ParsingInformation 생성 시 파싱 텍스트에서 필요한 정보들을 추출한다.") @Test void createParsingInformation() { - //given + //given String parsingText = "출력일자 : 2022/11/14|1/1" + "|경영대학 경영학과, 이아현(60191000), 현학적 - 재학, 이수 - 6, 입학 - 신입학(2019/03/04)" + "|토익 - 625, 영어교과목면제 - 면제없음, 최종학적변동 - 불일치복학(2021/07/20)" @@ -27,14 +26,15 @@ void createParsingInformation() { //then assertThat(parsingInformation) - .extracting("studentName", "studentNumber", "major", "subMajor", "associatedMajor", "studentCategory") + .extracting("studentName", "studentNumber", "major", "subMajor", "associatedMajor", + "studentCategory") .contains("이아현", "60191000", "경영학과", null, null, StudentCategory.NORMAL); } @DisplayName("복수전공을 할 경우 StudentCategory는 DUAL MAJOR이다.") @Test void 복수전공생_확인() { - //given + //given String parsingText = "출력일자 : 2022/11/14|1/1" + "|사회과학대학 정치외교학과, 복수전공 - 경제학과, 이인구(60161000), 현학적 - 재학, 이수 - 7, 입학 - 신입학(2015/03/02)" + "|토익 - 690, 영어교과목면제 - 면제없음, 최종학적변동 - 일반복학(2021/01/06)" @@ -43,11 +43,12 @@ void createParsingInformation() { + "|공통교양 15, 핵심교양 12, 학문기초교양 9, 일반교양 14, 전공 33, 복수전공 27, 연계전공 9, 부전공 0, 교직 0, 자유선택 3" + "|총 취득학점 - 122, 총점 - 414, 평균평점 - 3.51" + "|이수구분|수강년도/학기|한글코드|과목코드|과목명|학점|등급|중복|공통교양 (구 필수교양)|2016년 2학기|교필105|KMA02105|발표와토의|3|A0|공통교양 (구 필수교양)|2015년 1학기|교필100|KMA02100|성경개론|2|A+|공통교양 (구 필수교양)|2015년 1학기|교필123|KMA02123|영어3|2|A0|공통교양 (구 필수교양)|2019년 1학기|교필124|KMA02124|영어4|2|A+|공통교양 (구 필수교양)|2015년 1학기|교필125|KMA02125|영어회화3|1|A+|공통교양 (구 필수교양)|2016년 2학기|교필126|KMA02126|영어회화4|1|B+|공통교양 (구 필수교양)|2019년 1학기|교필101|KMA02101|채플|0.5|P|공통교양 (구 필수교양)|2019년 2학기|교필101|KMA02101|채플|0.5|P|공통교양 (구 필수교양)|2021년 1학기|교필101|KMA02101|채플|0.5|P|공통교양 (구 필수교양)|2021년 2학기|교필101|KMA02101|채플|0.5|P|공통교양 (구 필수교양)|2016년 2학기|교필102|KMA02102|현대사회와기독교윤리|2|A0|핵심교양 (구 선택교양)|2016년 2학기|교선114|KMA02114|민주주의와현대사회|3|A+|핵심교양 (구 선택교양)|2021년 2학기|교선132|KMA02132|예술과창조성|3|D+|핵심교양 (구 선택교양)|2021년 1학기|교선127|KMA02127|창업입문|3|C+|핵심교양 (구 선택교양)|2019년 1학기|교선111|KMA02111|한국근현대사의이해|3|A+|학문기초교양 (구 기초교양)|2016년 2학기|기사123|KMD02123|경제학원론|3|B+|학문기초교양 (구 기초교양)|2016년 2학기|기사111|KMD02111|동북아정세론|3|A+|학문기초교양 (구 기초교양)|2019년 2학기|기사116|KMD02116|청소년지도학|3|A0|일반교양 (구 균형교양)|2015년 1학기|균여219|KMO02119|교양바둑|2|A0|일반교양 (구 균형교양)|2022년 1학기|균여115|KMO02115|교양축구|2|B+|6|일반교양 (구 균형교양)|2016년 2학기|균기113|KMJ02113|기독교와상담|2|A+|일반교양 (구 균형교양)|2022년 1학기|기사114|KMD02114|미시경제학원론|3|A0|4|일반교양 (구 균형교양)|2015년 1학기|기사110|KMD02110|시민사회와행정|3|C+|일반교양 (구 균형교양)|2015년 1학기|균사133|KMM02133|진로선택과대학생활|2|P|전공1단계|2019년 2학기|정외212|HBB01212|국제정치론|3|A+|전공1단계|2022년 1학기|정외100|HBB01100|글로벌위기시대의한국과세계정치|3|B0|1|전공1단계|2021년 1학기|정외333|HBB01333|미국정치론|3|B+|전공1단계|2021년 2학기|정외242|HBB01242|비교정치론|3|B0|전공1단계|2019년 1학기|정외224|HBB01224|여론과정치참여|3|B+|전공1단계|2019년 1학기|정외257|HBB01257|여성정치론|3|B+|전공1단계|2019년 1학기|정외351|HBB01351|유럽연합정치학입문|3|B+|전공1단계|2015년 1학기|정외101|HBB01101|정치학개론|3|A0|전공1단계|2021년 2학기|정외256|HBB01256|정치학인턴쉽|3|A0|전공1단계|2019년 1학기|정외272|HBB01272|한반도와세계정치|3|A0|전공1단계|2019년 2학기|정외315|HBB01315|현대정치사상|3|B+|복수전공|2022년 1학기|경제104|HBE01493|Stata를이용한경제데이터분석론|3|B+|3|복수전공|2019년 2학기|경제204|HBE01204|경제수학|3|B+|복수전공|2019년 2학기|경제103|HBE01103|국민경제론|3|B+|복수전공|2021년 1학기|경제437|HBE01437|금융상품론|3|B+|복수전공|2021년 2학기|경제439|HBE01439|금융혁신과경제|3|B0|복수전공|2022년 1학기|경제413|HBE01413|기업금융론|3|B0|2|복수전공|2021년 1학기|경제327|HBE01327|벤처기업론|3|D+|복수전공|2021년 1학기|경제102|HBE01102|시장및기업이론|3|C+|복수전공|2021년 2학기|경제240|HBE01240|창업과혁신|3|C0|연계전공|2022년 1학기|혁신103|HGA01103|사회문제Prototype개발|3|A0|5|연계전공|2021년 1학기|혁신104|HGA01104|사회문제융합과제의실천|3|B+|연계전공|2021년 2학기|혁신102|HGA01102|사회문제의발견과융합|3|B+|자유선택|2018년 동계계절|균컴113|KMQ01113|SNS로톡하고빅데이터로놀아보자(KCU)|3|B+|2022년 1학기|경제104|HBE01493|Stata를이용한경제데이터분석론|3|3|2022년 1학기|균여115|KMO02115|교양축구|2|6|2022년 1학기|정외100|HBB01100|글로벌위기시대의한국과세계정치|3|1|2022년 1학기|경제413|HBE01413|기업금융론|3|2|2022년 1학기|기사114|KMD02114|미시경제학원론|3|4|2022년 1학기|혁신103|HGA01103|사회문제Prototype개발|3|5|일반교양 (구 균형교양)|2015년 1학기|균명102|KMR02102|성공학특강|2|N|"; - //when + //when ParsingInformation parsingInformation = ParsingInformation.parsing(parsingText); //then assertThat(parsingInformation) - .extracting("studentName", "studentNumber", "major", "dualMajor", "associatedMajor", "studentCategory") + .extracting("studentName", "studentNumber", "major", "dualMajor", "associatedMajor", + "studentCategory") .contains("이인구", "60161000", "정치외교학과", "경제학과", null, StudentCategory.DUAL_MAJOR); } @@ -68,7 +69,8 @@ void createParsingInformation() { //then assertThat(parsingInformation) - .extracting("studentName", "studentNumber", "major", "subMajor", "associatedMajor", "studentCategory") + .extracting("studentName", "studentNumber", "major", "subMajor", "associatedMajor", + "studentCategory") .contains("나경호", "60202455", "데이터테크놀로지전공", null, null, StudentCategory.CHANGE_MAJOR); } @@ -90,16 +92,18 @@ void createParsingInformation() { //then assertThat(parsingInformation) - .extracting("studentName", "studentNumber", "major", "subMajor", "associatedMajor", "studentCategory") - .contains("정지환", "60181666", "데이터테크놀로지전공", null, "응용소프트웨어전공", StudentCategory.SUB_MAJOR); + .extracting("studentName", "studentNumber", "major", "subMajor", "associatedMajor", + "studentCategory") + .contains("정지환", "60181666", "데이터테크놀로지전공", null, "응용소프트웨어전공", + StudentCategory.SUB_MAJOR); } @DisplayName("재수강, F학점, Non pass인 경우 수강 정보를 추출하지 않는다.") @Test void RFN인경우_수강정보제외() { - //given - String parsingText = "출력일자 : 2023/09/01|1/1" + //given + String parsingText = "출력일자 : 2023/09/01|1/1" + "|ICT융합대학 융합소프트웨어학부 데이터테크놀로지전공, 정지환(60181666), 현학적 - 재학, 이수 - 7, 입학 - 신입학(2018/03/02)" + "|토익 - 570, 영어교과목면제 - 면제없음, 최종학적변동 - 불일치복학(2022/07/15)" + "|편입생 인정학점 - 교양 0, 전공 0, 자유선택 0, 성경과인간이해 0" @@ -107,13 +111,14 @@ void createParsingInformation() { + "|공통교양 17, 핵심교양 12, 학문기초교양 18, 일반교양 5, 전공 63, 복수전공 0, 연계전공 0, 부전공 0, 교직 0, 자유선택 3" + "|총 취득학점 - 118, 총점 - 436, 평균평점 - 3.82" + "|이수구분|수강년도/학기|한글코드|과목코드|과목명|학점|등급|중복|공통교양|2019년 2학기|교필137|KMA02137|4차산업혁명시대의진로선택|2|P|공통교양|2022년 동계계절|교필104|KMA02104|글쓰기|3|C0|공통교양|2020년 1학기|교필122|KMA02122|기독교와문화|2|B0|공통교양|2019년 2학기|교필127|KMA00101|성서와인간이해|2|B+|공통교양|2019년 하계계절|교필106|KMA02106|영어1|2|B+|2|공통교양|2019년 2학기|교필107|KMA02107|영어2|2|B+|공통교양|2022년 동계계절|교필108|KMA02108|영어회화1|1|B+|3|공통교양|2023년 1학기|교필109|KMA02109|영어회화2|1|A0|공통교양|2020년 1학기|교필101|KMA02101|채플|0.5|P|공통교양|2020년 2학기|교필101|KMA02101|채플|0.5|P|공통교양|2022년 2학기|교필101|KMA02101|채플|0.5|P|공통교양|2023년 1학기|교필101|KMA02101|채플|0.5|P|핵심교양|2022년 2학기|교선130|KMA02130|고전으로읽는인문학|3|A0|핵심교양|2019년 2학기|교선113|KMA02113|세계화와사회변화|3|B+|핵심교양|2018년 1학기|교선135|KMA02135|우주,생명,마음|3|C+|핵심교양|2020년 2학기|교선111|KMA02111|한국근현대사의이해|3|A+|학문기초교양|2019년 1학기|기사133|KMD02133|ICT비즈니스와경영|3|B+|학문기초교양|2022년 2학기|기사123|KMD02123|경제학원론|3|A+|학문기초교양|2022년 2학기|기사103|KMD02103|대중문화와매스컴|3|A0|학문기초교양|2019년 1학기|기자107|KME02107|선형대수학개론|3|B0|6|학문기초교양|2019년 하계계절|기인107|KMB02107|인간심리의이해|3|B+|5|학문기초교양|2020년 2학기|기자106|KME02106|통계학개론|3|A+|일반교양|2022년 2학기|균여111|KMO02111|교양볼링|2|B+|일반교양|2020년 1학기|기컴118|KMI02118|엑셀기초및실무활용|3|B+|4|전공1단계|2019년 1학기|데테202|HED01202|R통계분석|3|A0|전공1단계|2022년 2학기|데테314|HED01314|게임프로그래밍|3|A+|전공1단계|2020년 1학기|데테316|HED01316|고급웹프로그래밍|3|A0|전공1단계|2019년 2학기|데테206|HED01206|기초웹프로그래밍|3|B+|전공1단계|2019년 1학기|융소102|HEB01102|기초프로그래밍|3|B+|1|전공1단계|2019년 2학기|융소105|HEB01105|기초프로그래밍2|3|C+|전공1단계|2019년 2학기|데테318|HED01203|데이터베이스|3|A0|전공1단계|2023년 1학기|데테317|HED01317|데이터베이스프로젝트|3|A+|전공1단계|2023년 1학기|데테407|HED01407|딥러닝|3|B+|전공1단계|2023년 1학기|데테319|HED01318|모바일컴퓨팅|3|A+|전공1단계|2020년 2학기|데테403|HED01403|블록체인기초|3|A+|전공1단계|2023년 1학기|데테404|HED01404|빅데이터기술특론1|3|B0|전공1단계|2022년 2학기|데테306|HED01306|빅데이터프로그래밍|3|A0|전공1단계|2020년 1학기|데테301|HED01301|소프트웨어공학|3|A+|전공1단계|2020년 2학기|데테209|HED01307|알고리즘|3|A+|전공1단계|2020년 2학기|데테303|HED01303|운영체제|3|A+|전공1단계|2020년 1학기|데테315|HED01315|인공지능|3|B+|전공1단계|2019년 1학기|데테201|HED01201|자료구조|3|A0|전공1단계|2023년 1학기|데테413|HED01413|캡스톤디자인|3|A+|전공1단계|2020년 1학기|데테309|HED01309|컴퓨터아키텍쳐|3|A0|전공1단계|2020년 2학기|데테313|HED01313|컴퓨터통신|3|A+|자유선택|2023년 1학기|교선136|KMA02136|SW프로그래밍입문|3|A+|공통교양|2019년 2학기|교필101|KMA02101|채플|0.5|N|공통교양|2018년 1학기|교필106|KMA02106|영어1|0|R|2|공통교양|2018년 1학기|교필108|KMA02108|영어회화1|0|R|3|공통교양|2020년 1학기|교필108|KMA02108|영어회화1|0|R|3|학문기초교양|2018년 1학기|기자107|KME02107|선형대수학개론|0|R|6|학문기초교양|2018년 1학기|기인107|KMB02107|인간심리의이해|0|R|5|일반교양|2018년 1학기|기컴118|KMI02118|엑셀기초및실무활용|0|R|4|전공1단계|2018년 1학기|융소102|HEB01102|기초프로그래밍|0|R|1|"; - //when + //when ParsingInformation parsingInformation = ParsingInformation.parsing(parsingText); //then assertThat(parsingInformation) - .extracting("studentName", "studentNumber", "major", "subMajor", "associatedMajor", "studentCategory") + .extracting("studentName", "studentNumber", "major", "subMajor", "associatedMajor", + "studentCategory") .contains("정지환", "60181666", "데이터테크놀로지전공", null, null, StudentCategory.NORMAL); - assertThat(parsingInformation.getTakenLectureInformation()).hasSize(46); + assertThat(parsingInformation.getTakenLectureInformation()).hasSize(46); } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTextHistoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTextHistoryTest.java index 4990e511..e3c4256b 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTextHistoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/domain/ParsingTextHistoryTest.java @@ -2,21 +2,20 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class ParsingTextHistoryTest { @DisplayName("success 메서드 호출시 ParsingResult는 SUCCESS이다.") @Test void success() { - //given + //given User user = UserFixture.경영학과_19학번_ENG34(); String text = "text"; - //when + //when ParsingTextHistory parsingTextHistory = ParsingTextHistory.success(user, text); //then assertThat(parsingTextHistory) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/ParsingTextHistoryAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/ParsingTextHistoryAdapterTest.java index e668d1df..c0e7ab2b 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/ParsingTextHistoryAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/ParsingTextHistoryAdapterTest.java @@ -2,12 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.Optional; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingResult; import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingTextHistory; import com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.entity.ParsingTextHistoryJpaEntity; @@ -16,6 +10,10 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; +import java.util.Optional; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class ParsingTextHistoryAdapterTest extends PersistenceTestSupport { @@ -61,7 +59,7 @@ void saveParsingTextHistory() { @DisplayName("유저의 ParsingHistory를 삭제한다.") @Test void deleteUserParsingTextHistory() { - //given + //given UserJpaEntity userJpaEntity = userRepository.save(UserJpaEntity.builder() .studentNumber("test") .authId("test") @@ -83,7 +81,7 @@ void deleteUserParsingTextHistory() { //when parsingTextHistoryAdapter.deleteUserParsingTextHistory(user); - //then + //then assertThat(parsingTextRepository.findAll()).isEmpty(); } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/mapper/ParsingTextHistoryMapperTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/mapper/ParsingTextHistoryMapperTest.java index 180cbc4d..b95e0fe2 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/mapper/ParsingTextHistoryMapperTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/parsing/infrastructure/adapter/persistence/mapper/ParsingTextHistoryMapperTest.java @@ -2,17 +2,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; -import com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.entity.ParsingTextHistoryJpaEntity; import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingResult; import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingTextHistory; -import com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.mapper.ParsingTextHistoryMapper; +import com.plzgraduate.myongjigraduatebe.parsing.infrastructure.adapter.persistence.entity.ParsingTextHistoryJpaEntity; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class ParsingTextHistoryMapperTest extends PersistenceTestSupport { diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/support/PersistenceTestSupport.java b/src/test/java/com/plzgraduate/myongjigraduatebe/support/PersistenceTestSupport.java index 66926bf2..da39fff4 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/support/PersistenceTestSupport.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/support/PersistenceTestSupport.java @@ -1,17 +1,14 @@ package com.plzgraduate.myongjigraduatebe.support; +import com.plzgraduate.myongjigraduatebe.core.config.JpaAuditingConfig; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; - -import org.junit.jupiter.api.AfterEach; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; -import com.plzgraduate.myongjigraduatebe.core.config.JpaAuditingConfig; - @ActiveProfiles("test") @SpringBootTest @Transactional diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/support/WebAdaptorTestSupport.java b/src/test/java/com/plzgraduate/myongjigraduatebe/support/WebAdaptorTestSupport.java index a1ed6a4d..b842e590 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/support/WebAdaptorTestSupport.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/support/WebAdaptorTestSupport.java @@ -1,17 +1,6 @@ package com.plzgraduate.myongjigraduatebe.support; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*; - -import org.junit.jupiter.api.BeforeEach; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import com.fasterxml.jackson.databind.ObjectMapper; import com.plzgraduate.myongjigraduatebe.auth.api.signin.SignInController; @@ -51,11 +40,22 @@ import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpUseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.validate.ValidateUserUseCase; import com.plzgraduate.myongjigraduatebe.user.application.usecase.withdraw.WithDrawUserUseCase; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; @ActiveProfiles("test") @ComponentScan( basePackageClasses = {SecurityConfig.class, TokenProvider.class}, - excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {QuerydslConfig.class, + excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { + QuerydslConfig.class, JpaAuditingConfig.class}) ) @WebMvcTest(controllers = { @@ -75,74 +75,52 @@ }) public abstract class WebAdaptorTestSupport { - @Autowired - private WebApplicationContext context; - @Autowired protected MockMvc mockMvc; - @Autowired protected ObjectMapper objectMapper; - @MockBean protected FindUserUseCase findUserUseCase; - @MockBean protected SignInUseCase signInUseCase; - @MockBean protected TokenUseCase tokenUseCase; - @MockBean protected CalculateGraduationUseCase calculateGraduationUseCase; - @MockBean protected SearchLectureUseCase searchLectureUseCase; - @MockBean protected DeleteTakenLectureUseCase deleteTakenLectureUseCase; - @MockBean protected GenerateCustomizedTakenLectureUseCase generateCustomizedTakenLectureUseCase; - @MockBean protected FindTakenLectureUseCase findTakenLectureUseCase; - @MockBean protected FindUserInformationUseCase findUserInformationUseCase; - @MockBean protected FindUserAuthIdUseCase findUserAuthIdUseCase; - @MockBean protected ValidateUserUseCase validateUserUseCase; - @MockBean protected ResetPasswordUseCase resetPasswordUseCase; - @MockBean protected WithDrawUserUseCase withDrawUserUseCase; - @MockBean protected ParsingTextUseCase parsingTextUseCase; - @MockBean protected ParsingTextHistoryUseCase parsingTextHistoryUseCase; - @MockBean protected SignUpUseCase signUpUseCase; - @MockBean protected CheckAuthIdDuplicationUseCase checkAuthIdDuplicationUseCase; - @MockBean protected CheckStudentNumberDuplicationUseCase checkStudentNumberDuplicationUseCase; - @MockBean protected FindCompletedCreditUseCase findCompletedCreditUseCase; - @MockBean protected CalculateSingleDetailGraduationUseCase calculateSingleDetailGraduationUseCase; + @Autowired + private WebApplicationContext context; @BeforeEach void setUp() { diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/support/WithMockAuthenticationUser.java b/src/test/java/com/plzgraduate/myongjigraduatebe/support/WithMockAuthenticationUser.java index d5f1aa2b..e6628b17 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/support/WithMockAuthenticationUser.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/support/WithMockAuthenticationUser.java @@ -2,12 +2,12 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; - import org.springframework.security.test.context.support.WithSecurityContext; @Retention(RetentionPolicy.RUNTIME) @WithSecurityContext(factory = WithMockAuthenticationUserSecurityContext.class) public @interface WithMockAuthenticationUser { + long id() default 1L; String authId() default "tester00"; diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/support/WithMockAuthenticationUserSecurityContext.java b/src/test/java/com/plzgraduate/myongjigraduatebe/support/WithMockAuthenticationUserSecurityContext.java index 0bec6bca..0835bcbb 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/support/WithMockAuthenticationUserSecurityContext.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/support/WithMockAuthenticationUserSecurityContext.java @@ -1,15 +1,15 @@ package com.plzgraduate.myongjigraduatebe.support; +import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationToken; import java.util.Collections; - import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.test.context.support.WithSecurityContextFactory; -import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationToken; public class WithMockAuthenticationUserSecurityContext implements WithSecurityContextFactory { + @Override public SecurityContext createSecurityContext(WithMockAuthenticationUser annotation) { SecurityContext context = SecurityContextHolder.createEmptyContext(); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/find/FindTakenLectureControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/find/FindTakenLectureControllerTest.java index 56dbe7cd..aaf4e097 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/find/FindTakenLectureControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/find/FindTakenLectureControllerTest.java @@ -7,18 +7,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; import com.plzgraduate.myongjigraduatebe.support.WithMockAuthenticationUser; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import java.util.HashSet; +import java.util.Set; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class FindTakenLectureControllerTest extends WebAdaptorTestSupport { @@ -31,29 +29,36 @@ void getTakenLectures() throws Exception { TakenLecture.builder() .lecture(Lecture.builder() .lectureCode("KMA") - .credit(4).build()) + .credit(4) + .build()) .year(2020) - .semester(Semester.FIRST).build(), + .semester(Semester.FIRST) + .build(), TakenLecture.builder() .lecture(Lecture.builder() .lectureCode("KMB") - .credit(3).build()) + .credit(3) + .build()) .year(2020) - .semester(Semester.SECOND).build(), + .semester(Semester.SECOND) + .build(), TakenLecture.builder() .lecture(Lecture.builder() .lectureCode("KMC") - .credit(3).build()) + .credit(3) + .build()) .year(2021) - .semester(Semester.FIRST).build() + .semester(Semester.FIRST) + .build() )); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - given(findTakenLectureUseCase.findTakenLectures(anyLong())).willReturn(takenLectureInventory); + given(findTakenLectureUseCase.findTakenLectures(anyLong())).willReturn( + takenLectureInventory); //when //when mockMvc.perform( - get("/api/v1/taken-lectures") - ) + get("/api/v1/taken-lectures") + ) .andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.totalCredit").value(10)) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/update/UpdateTakenLectureControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/update/UpdateTakenLectureControllerTest.java index 99245006..bfdf8bdb 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/update/UpdateTakenLectureControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/api/update/UpdateTakenLectureControllerTest.java @@ -1,17 +1,17 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.api.update; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.http.MediaType; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; import com.plzgraduate.myongjigraduatebe.support.WithMockAuthenticationUser; import com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.request.GenerateCustomizedTakenLectureRequest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; class UpdateTakenLectureControllerTest extends WebAdaptorTestSupport { diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/delete/DeleteTakenLectureServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/delete/DeleteTakenLectureServiceTest.java index 978caf20..99b8e2f9 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/delete/DeleteTakenLectureServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/delete/DeleteTakenLectureServiceTest.java @@ -1,7 +1,12 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.service.delete; -import static org.mockito.BDDMockito.*; +import static org.mockito.BDDMockito.eq; +import static org.mockito.BDDMockito.then; +import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase; +import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.DeleteTakenLecturePort; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -9,11 +14,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase; -import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.DeleteTakenLecturePort; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class DeleteTakenLectureServiceTest { @@ -40,19 +40,22 @@ void deleteTakenLecture() { deleteTakenLectureService.deleteTakenLecture(userId, deletedTakenLectureId); //then - then(deleteTakenLecturePort).should().deleteTakenLectureById(102L); + then(deleteTakenLecturePort).should() + .deleteTakenLectureById(102L); } @DisplayName("사용자의 모든 수강과목을 삭제한다.") @Test void deleteAllTakenLecturesByUser() { //given - User user = User.builder().build(); + User user = User.builder() + .build(); //when deleteTakenLectureService.deleteAllTakenLecturesByUser(user); //then - then(deleteTakenLecturePort).should().deleteAllTakenLecturesByUser(eq(user)); + then(deleteTakenLecturePort).should() + .deleteAllTakenLecturesByUser(eq(user)); } -} \ No newline at end of file +} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/find/FindTakenLectureServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/find/FindTakenLectureServiceTest.java index 1578f4ae..bafe95e1 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/find/FindTakenLectureServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/find/FindTakenLectureServiceTest.java @@ -6,10 +6,16 @@ import static org.mockito.BDDMockito.anyLong; import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.FindTakenLecturePort; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.time.Instant; import java.util.ArrayList; import java.util.List; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -17,14 +23,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.FindTakenLecturePort; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class FindTakenLectureServiceTest { @@ -39,7 +37,9 @@ class FindTakenLectureServiceTest { @Test void findTakenLectures() { //given - User user = User.builder().id(1L).build(); + User user = User.builder() + .id(1L) + .build(); Lecture 채플 = createLecture(1L, "KMA02101", "채플", 0); Lecture 영어1 = createLecture(2L, "KMA02106", "영어1", 2); Lecture 영어2 = createLecture(3L, "KMA02107", "영어2", 2); @@ -63,7 +63,8 @@ void findTakenLectures() { )); given(findUserUseCase.findUserById(anyLong())).willReturn(user); - given(findTakenLecturePort.findTakenLecturesByUser(any(User.class))).willReturn(takenLectures); + given(findTakenLecturePort.findTakenLecturesByUser(any(User.class))).willReturn( + takenLectures); //when TakenLectureInventory foundTakenLectures = findTakenLectureService.findTakenLectures(1L); @@ -89,7 +90,9 @@ void findTakenLectures() { @Test void addTwoPointIfChapelCountIsOver4() { //given - User user = User.builder().id(1L).build(); + User user = User.builder() + .id(1L) + .build(); Lecture 채플 = createLecture(1L, "KMA02101", "채플", 0); Lecture 영어1 = createLecture(2L, "KMA02106", "영어1", 2); Lecture 영어2 = createLecture(3L, "KMA02107", "영어2", 2); @@ -115,7 +118,8 @@ void addTwoPointIfChapelCountIsOver4() { )); given(findUserUseCase.findUserById(anyLong())).willReturn(user); - given(findTakenLecturePort.findTakenLecturesByUser(any(User.class))).willReturn(takenLectures); + given(findTakenLecturePort.findTakenLecturesByUser(any(User.class))).willReturn( + takenLectures); //when TakenLectureInventory foundTakenLectures = findTakenLectureService.findTakenLectures(1L); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/GenerateTakenLectureServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/GenerateTakenLectureServiceTest.java index a07ec064..7828c9eb 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/GenerateTakenLectureServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/GenerateTakenLectureServiceTest.java @@ -1,14 +1,7 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.application.service.save; -import static org.mockito.BDDMockito.*; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort; @@ -17,9 +10,17 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class GenerateTakenLectureServiceTest { + @Mock private FindUserUseCase findUserUseCase; @Mock @@ -35,19 +36,23 @@ class GenerateTakenLectureServiceTest { @Test void saveTakenLecture() { //given - User user = User.builder().id(1L).build(); + User user = User.builder() + .id(1L) + .build(); Lecture lecture = createLecture(1L); given(findLecturePort.findLectureById(1L)) .willReturn(lecture); - ArgumentCaptor takenLectureCaptor = ArgumentCaptor.forClass(TakenLecture.class); + ArgumentCaptor takenLectureCaptor = ArgumentCaptor.forClass( + TakenLecture.class); //when generateTakenLectureService.generateCustomizedTakenLecture(user.getId(), 1L); generateOrModifyCompletedCreditUseCase.generateOrModifyCompletedCredit(user); //then - then(saveTakenLecturePort).should().saveTakenLecture(takenLectureCaptor.capture()); + then(saveTakenLecturePort).should() + .saveTakenLecture(takenLectureCaptor.capture()); } private Lecture createLecture(Long id) { diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/SaveTakenLectureFromParsingTextServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/SaveTakenLectureFromParsingTextServiceTest.java index a934d1e0..51d3dd60 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/SaveTakenLectureFromParsingTextServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/application/service/save/SaveTakenLectureFromParsingTextServiceTest.java @@ -7,9 +7,15 @@ import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; +import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.FindLecturesUseCase; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.SaveTakenLecturePort; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInformation; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.util.ArrayList; import java.util.List; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -18,14 +24,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.FindLecturesUseCase; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.SaveTakenLecturePort; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInformation; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class SaveTakenLectureFromParsingTextServiceTest { @@ -40,7 +38,9 @@ class SaveTakenLectureFromParsingTextServiceTest { @Test void saveTakenLectures() { //given - User user = User.builder().id(1L).build(); + User user = User.builder() + .id(1L) + .build(); List takenLectureInformationList = new ArrayList<>(List.of( createTakenLectureInformation("KMA02122", 2022), createTakenLectureInformation("KMA02135", 2023) @@ -49,13 +49,15 @@ void saveTakenLectures() { Lecture lecture2 = createLecture("KMA02135"); given(findLecturesUseCase.findLecturesByLectureCodes(List.of("KMA02122", "KMA02135"))) .willReturn(List.of(lecture1, lecture2)); - ArgumentCaptor> takenLectureListCaptor = ArgumentCaptor.forClass(List.class); + ArgumentCaptor> takenLectureListCaptor = ArgumentCaptor.forClass( + List.class); //when saveTakenLectureFromParsingTextService.saveTakenLectures(user, takenLectureInformationList); //then - then(saveTakenLecturePort).should().saveTakenLectures(takenLectureListCaptor.capture()); + then(saveTakenLecturePort).should() + .saveTakenLectures(takenLectureListCaptor.capture()); List capturesTakenLectures = takenLectureListCaptor.getValue(); assertThat(capturesTakenLectures) .hasSize(2) @@ -70,7 +72,9 @@ void saveTakenLectures() { @Test void lectureDoesNotExist() { //given - User user = User.builder().id(1L).build(); + User user = User.builder() + .id(1L) + .build(); List takenLectureInformationList = new ArrayList<>(List.of( createTakenLectureInformation("KMA02122", 2022), createTakenLectureInformation("KMA02135", 2023) @@ -81,7 +85,8 @@ void lectureDoesNotExist() { //when //then assertThatThrownBy( - () -> saveTakenLectureFromParsingTextService.saveTakenLectures(user, takenLectureInformationList)) + () -> saveTakenLectureFromParsingTextService.saveTakenLectures(user, + takenLectureInformationList)) .isInstanceOf(IllegalArgumentException.class) .hasMessage(NON_EXISTED_LECTURE.toString()); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventoryTest.java index 36aa4e6c..4d78a421 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventoryTest.java @@ -2,18 +2,16 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; +import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.util.HashSet; import java.util.Map; import java.util.Set; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; -import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - class TakenLectureInventoryTest { private final User user = UserFixture.경영학과_19학번_ENG34(); @@ -27,7 +25,8 @@ void getTakenCultureLectures() { Set cultureLectures = takenLectureInventory.getCultureLectures(); //then - assertThat(cultureLectures).hasSize(takenLectureInventory.getTakenLectures().size()); + assertThat(cultureLectures).hasSize(takenLectureInventory.getTakenLectures() + .size()); } @DisplayName("수강과목 목록에서 처리 완료된 수강과목들을 제거한다.") @@ -35,7 +34,8 @@ void getTakenCultureLectures() { void handleFinishedTakenLectures() { //given TakenLectureInventory takenLectureInventory = getTakenLectureInventory(); - int beforeHandleSize = takenLectureInventory.getTakenLectures().size(); + int beforeHandleSize = takenLectureInventory.getTakenLectures() + .size(); Set finishedTakenLecture = new HashSet<>(Set.of( TakenLecture.of(user, mockLectureMap.get("KMA00101"), 2019, Semester.FIRST), TakenLecture.of(user, mockLectureMap.get("KMA02102"), 2019, Semester.FIRST), @@ -77,7 +77,8 @@ void calculateTotalCredit() { void sync() { //given TakenLectureInventory takenLectureInventory = getTakenLectureInventory(); - int beforeHandleSize = takenLectureInventory.getTakenLectures().size(); + int beforeHandleSize = takenLectureInventory.getTakenLectures() + .size(); Set finishedLectures = new HashSet<>(Set.of( mockLectureMap.get("KMA00101"), mockLectureMap.get("KMA02102") diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureTest.java index 5d7cfdc4..5e2a5aca 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureTest.java @@ -1,19 +1,17 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.domain.model; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; +import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.util.HashSet; import java.util.Map; import java.util.Set; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; -import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - class TakenLectureTest { private static final Map mockLectureMap = LectureFixture.getMockLectureMap(); @@ -21,10 +19,12 @@ class TakenLectureTest { @DisplayName("수강과목은 과목, 수강 년도, 수강 학기 모두 같으면 같은 것으로 인정된다.") @Test void lectureEqualsTest() { - //given + //given User user = UserFixture.국제통상학과_19학번(); - TakenLecture takenLectureA = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, Semester.FIRST); - TakenLecture takenLectureB = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, Semester.FIRST); + TakenLecture takenLectureA = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, + Semester.FIRST); + TakenLecture takenLectureB = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, + Semester.FIRST); //when boolean equalsResult = takenLectureA.equals(takenLectureB); @@ -42,9 +42,12 @@ void lectureEqualsTest() { void lectureUnEqualsTest() { //given User user = UserFixture.국제통상학과_19학번(); - TakenLecture takenLectureA = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, Semester.FIRST); - TakenLecture takenLectureB = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2018, Semester.SECOND); - TakenLecture takenLectureC = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, Semester.SECOND); + TakenLecture takenLectureA = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, + Semester.FIRST); + TakenLecture takenLectureB = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2018, + Semester.SECOND); + TakenLecture takenLectureC = TakenLecture.of(user, mockLectureMap.get("HBX01128"), 2019, + Semester.SECOND); //when Set takenLectureSet = new HashSet<>(); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLecturePersistenceAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLecturePersistenceAdapterTest.java index 87817d8c..fd9691a2 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLecturePersistenceAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/TakenLecturePersistenceAdapterTest.java @@ -1,18 +1,16 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; +import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; import java.util.Optional; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; -import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; - class TakenLecturePersistenceAdapterTest extends PersistenceTestSupport { @Autowired @@ -33,14 +31,16 @@ void afterEach() { @Test public void deleteTakenLectureById() throws Exception { // given - TakenLectureJpaEntity takenLectureJpaEntity = createTakenLectureJpaEntity(2099, Semester.FIRST); + TakenLectureJpaEntity takenLectureJpaEntity = createTakenLectureJpaEntity(2099, + Semester.FIRST); takenLectureRepository.save(takenLectureJpaEntity); // when takenLecturePersistenceAdapter.deleteTakenLectureById(takenLectureJpaEntity.getId()); // then - Optional result = takenLectureRepository.findById(takenLectureJpaEntity.getId()); + Optional result = takenLectureRepository.findById( + takenLectureJpaEntity.getId()); assertThat(result.isPresent()).isFalse(); } @@ -50,4 +50,4 @@ private TakenLectureJpaEntity createTakenLectureJpaEntity(Integer year, Semester .semester(semester) .build(); } -} \ No newline at end of file +} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/mapper/TakenLectureMapperTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/mapper/TakenLectureMapperTest.java index e3aa00b7..a6353c54 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/mapper/TakenLectureMapperTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/mapper/TakenLectureMapperTest.java @@ -2,21 +2,19 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; -import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.mapper.TakenLectureMapper; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class TakenLectureMapperTest extends PersistenceTestSupport { @@ -27,10 +25,13 @@ class TakenLectureMapperTest extends PersistenceTestSupport { @Test void mapToDomainEntity() { //given - UserJpaEntity userJpaEntity = createUserJpaEntity(1L, "mju1000", "mju1000!", EnglishLevel.ENG12, "김명지", + UserJpaEntity userJpaEntity = createUserJpaEntity(1L, "mju1000", "mju1000!", + EnglishLevel.ENG12, "김명지", "60211111", 21, "경영학과", null, StudentCategory.NORMAL); - LectureJpaEntity lectureJpaEntity = createLectureJpaEntity(1L, "HEB01102", "기초프로그래밍", 3, 0, null); - TakenLectureJpaEntity takenLectureJpaEntity = createTakenLectureJpaEntity(1L, userJpaEntity, lectureJpaEntity, + LectureJpaEntity lectureJpaEntity = createLectureJpaEntity(1L, "HEB01102", "기초프로그래밍", 3, 0, + null); + TakenLectureJpaEntity takenLectureJpaEntity = createTakenLectureJpaEntity(1L, userJpaEntity, + lectureJpaEntity, 2020, Semester.FIRST); //when @@ -53,7 +54,8 @@ void mapToJpaEntity() { TakenLecture takenLecture = createTakenLecture(null, user, lecture, 2020, Semester.FIRST); //when - TakenLectureJpaEntity takenLectureJpaEntity = takenLectureMapper.mapToJpaEntity(takenLecture); + TakenLectureJpaEntity takenLectureJpaEntity = takenLectureMapper.mapToJpaEntity( + takenLecture); //then assertThat(takenLectureJpaEntity) @@ -79,7 +81,8 @@ void mapToUserJpaEntity() { "60211111", 21, "경영학과", null, StudentCategory.NORMAL); } - private TakenLecture createTakenLecture(Long id, User user, Lecture lecture, int year, Semester semester) { + private TakenLecture createTakenLecture(Long id, User user, Lecture lecture, int year, + Semester semester) { return TakenLecture.builder() .id(id) .user(user) @@ -89,7 +92,8 @@ private TakenLecture createTakenLecture(Long id, User user, Lecture lecture, int .build(); } - private TakenLectureJpaEntity createTakenLectureJpaEntity(Long id, UserJpaEntity user, LectureJpaEntity lecture, int year, Semester semester) { + private TakenLectureJpaEntity createTakenLectureJpaEntity(Long id, UserJpaEntity user, + LectureJpaEntity lecture, int year, Semester semester) { return TakenLectureJpaEntity.builder() .id(id) .user(user) @@ -99,8 +103,10 @@ private TakenLectureJpaEntity createTakenLectureJpaEntity(Long id, UserJpaEntity .build(); } - private User createUser(Long id, String authId, String password, EnglishLevel englishLevel, String name, - String studentNumber, int entryYear, String major, String subMajor, StudentCategory studentCategory) { + private User createUser(Long id, String authId, String password, EnglishLevel englishLevel, + String name, + String studentNumber, int entryYear, String major, String subMajor, + StudentCategory studentCategory) { return User.builder() .id(id) .authId(authId) @@ -115,8 +121,10 @@ private User createUser(Long id, String authId, String password, EnglishLevel en .build(); } - private UserJpaEntity createUserJpaEntity(Long id, String authId, String password, EnglishLevel englishLevel, String name, - String studentNumber, int entryYear, String major, String subMajor, StudentCategory studentCategory) { + private UserJpaEntity createUserJpaEntity(Long id, String authId, String password, + EnglishLevel englishLevel, String name, + String studentNumber, int entryYear, String major, String subMajor, + StudentCategory studentCategory) { return UserJpaEntity.builder() .id(id) .authId(authId) @@ -131,7 +139,8 @@ private UserJpaEntity createUserJpaEntity(Long id, String authId, String passwor .build(); } - private Lecture createLecture(Long id, String lectureCode, String name, int credit, int isRevoked, String duplicateCode) { + private Lecture createLecture(Long id, String lectureCode, String name, int credit, + int isRevoked, String duplicateCode) { return Lecture.builder() .id(id) .lectureCode(lectureCode) @@ -142,7 +151,8 @@ private Lecture createLecture(Long id, String lectureCode, String name, int cred .build(); } - private LectureJpaEntity createLectureJpaEntity(Long id, String lectureCode, String name, int credit, int isRevoked, String duplicateCode) { + private LectureJpaEntity createLectureJpaEntity(Long id, String lectureCode, String name, + int credit, int isRevoked, String duplicateCode) { return LectureJpaEntity.builder() .id(id) .lectureCode(lectureCode) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/respository/TakenLectureRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/respository/TakenLectureRepositoryTest.java index 9090d92a..f0b118d6 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/respository/TakenLectureRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/infrastructure/adapter/persistence/respository/TakenLectureRepositoryTest.java @@ -2,19 +2,17 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity; import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository; import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; -import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.TakenLectureRepository; +import com.plzgraduate.myongjigraduatebe.takenlecture.infrastructure.adapter.persistence.entity.TakenLectureJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class TakenLectureRepositoryTest extends PersistenceTestSupport { @@ -32,11 +30,13 @@ void findByUser() { UserJpaEntity user = UserJpaEntity.builder() .authId("abc") .password("12345153") - .studentNumber("60191656").build(); + .studentNumber("60191656") + .build(); userRepository.save(user); LectureJpaEntity lecture = LectureJpaEntity.builder() - .lectureCode("KMA02105").build(); + .lectureCode("KMA02105") + .build(); lectureRepository.save(lecture); TakenLectureJpaEntity takenLectureA = TakenLectureJpaEntity.builder() diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdControllerTest.java index 8dec43c6..c83c255f 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/findauthid/FindAuthIdControllerTest.java @@ -9,11 +9,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; - class FindAuthIdControllerTest extends WebAdaptorTestSupport { @DisplayName("학번으로 해당 학생의 아이디를 조회한다.") diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationControllerTest.java index 579af681..64257b4f 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/finduserinformation/FindUserInformationControllerTest.java @@ -6,13 +6,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; import com.plzgraduate.myongjigraduatebe.support.WithMockAuthenticationUser; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class FindUserInformationControllerTest extends WebAdaptorTestSupport { @@ -34,7 +33,8 @@ void getUserInformation() throws Exception { .studentCategory(StudentCategory.NORMAL) .totalCredit(134) .takenCredit(130.0) - .graduated(false).build(); + .graduated(false) + .build(); given(findUserInformationUseCase.findUserInformation(userId)).willReturn(user); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordControllerTest.java index 890555ab..0109b37e 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/resetpassword/ResetPasswordControllerTest.java @@ -10,14 +10,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; +import com.plzgraduate.myongjigraduatebe.user.api.resetpassword.dto.request.ResetPasswordRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.ResultActions; -import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; -import com.plzgraduate.myongjigraduatebe.user.api.resetpassword.dto.request.ResetPasswordRequest; - class ResetPasswordControllerTest extends WebAdaptorTestSupport { @DisplayName("학번으로 유저 정보 조회 후 로그인 이아디와 일치하는지 확인한다.") @@ -43,7 +42,8 @@ void resetPassword() throws Exception { ResetPasswordRequest request = ResetPasswordRequest.builder() .authId("authId") .newPassword("abcd1234@") - .passwordCheck("abcd1234@").build(); + .passwordCheck("abcd1234@") + .build(); //when ResultActions actions = mockMvc.perform( @@ -64,7 +64,8 @@ void resetPasswordWithNonAuthId() throws Exception { //given ResetPasswordRequest request = ResetPasswordRequest.builder() .newPassword("abcd1234@") - .passwordCheck("abcd1234@").build(); + .passwordCheck("abcd1234@") + .build(); //when ResultActions actions = mockMvc.perform( @@ -87,7 +88,8 @@ void resetPasswordWithUnSuitableNewPassword() throws Exception { ResetPasswordRequest request = ResetPasswordRequest.builder() .authId("authId") .newPassword("abcd1234") - .passwordCheck("abcd1234@").build(); + .passwordCheck("abcd1234@") + .build(); //when ResultActions actions = mockMvc.perform( @@ -110,7 +112,8 @@ void resetPasswordWithUnSuitableCheckPassword() throws Exception { ResetPasswordRequest request = ResetPasswordRequest.builder() .authId("authId") .newPassword("abcd123@") - .passwordCheck("abcd1234").build(); + .passwordCheck("abcd1234") + .build(); //when ResultActions actions = mockMvc.perform( diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpControllerTest.java index 72110a8f..0c1dc206 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/signup/SignUpControllerTest.java @@ -1,6 +1,7 @@ package com.plzgraduate.myongjigraduatebe.user.api.signup; -import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.INVALIDATED_AUTHID_TYPE; +import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.INVALIDATED_PASSWORD_TYPE; import static org.mockito.BDDMockito.given; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -9,16 +10,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.ResultActions; - -import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.request.SignUpRequest; import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.AuthIdDuplicationResponse; import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.StudentNumberDuplicationResponse; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; class SignUpControllerTest extends WebAdaptorTestSupport { @@ -118,8 +117,10 @@ void checkAuthIdDuplication() throws Exception { boolean notDuplicated = true; AuthIdDuplicationResponse authIdDuplicationResponse = AuthIdDuplicationResponse.builder() .authId(authId) - .notDuplicated(notDuplicated).build(); - given(checkAuthIdDuplicationUseCase.checkAuthIdDuplication(authId)).willReturn(authIdDuplicationResponse); + .notDuplicated(notDuplicated) + .build(); + given(checkAuthIdDuplicationUseCase.checkAuthIdDuplication(authId)).willReturn( + authIdDuplicationResponse); //when //then mockMvc.perform( @@ -140,8 +141,10 @@ void checkStudentNumberDuplication() throws Exception { boolean notDuplicated = true; StudentNumberDuplicationResponse studentNumberDuplicationResponse = StudentNumberDuplicationResponse.builder() .studentNumber(studentNumber) - .notDuplicated(notDuplicated).build(); - given(checkStudentNumberDuplicationUseCase.checkStudentNumberDuplication(studentNumber)).willReturn( + .notDuplicated(notDuplicated) + .build(); + given(checkStudentNumberDuplicationUseCase.checkStudentNumberDuplication( + studentNumber)).willReturn( studentNumberDuplicationResponse); //when //then diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawControllerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawControllerTest.java index 61f897ca..8c8fd3e0 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawControllerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/api/withdraw/WithDrawControllerTest.java @@ -6,15 +6,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; +import com.plzgraduate.myongjigraduatebe.support.WithMockAuthenticationUser; +import com.plzgraduate.myongjigraduatebe.user.api.withdraw.dto.request.WithDrawRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.ResultActions; -import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; -import com.plzgraduate.myongjigraduatebe.support.WithMockAuthenticationUser; -import com.plzgraduate.myongjigraduatebe.user.api.withdraw.dto.request.WithDrawRequest; - class WithDrawControllerTest extends WebAdaptorTestSupport { @WithMockAuthenticationUser @@ -23,7 +22,8 @@ class WithDrawControllerTest extends WebAdaptorTestSupport { void withDraw() throws Exception { //given WithDrawRequest request = WithDrawRequest.builder() - .password("abcd1234!").build(); + .password("abcd1234!") + .build(); //when ResultActions actions = mockMvc.perform( @@ -32,7 +32,8 @@ void withDraw() throws Exception { .contentType(MediaType.APPLICATION_JSON)); //then - then(withDrawUserUseCase).should().withDraw(any(), any(String.class)); + then(withDrawUserUseCase).should() + .withDraw(any(), any(String.class)); actions. andDo(print()) .andExpect(status().isOk()); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckAuthIdDuplicationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckAuthIdDuplicationServiceTest.java index d7105761..68398ac8 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckAuthIdDuplicationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckAuthIdDuplicationServiceTest.java @@ -1,8 +1,10 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.check; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.AuthIdDuplicationResponse; +import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -10,9 +12,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.AuthIdDuplicationResponse; -import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; - @ExtendWith(MockitoExtension.class) class CheckAuthIdDuplicationServiceTest { @@ -25,12 +24,12 @@ class CheckAuthIdDuplicationServiceTest { @DisplayName("로그인 아이디의 중복 여부를 확인한다.") @Test void checkAuthIdDuplication() { - //given + //given String authId = "testAuthId"; boolean authIdDuplication = true; given(checkUserPort.checkDuplicateAuthId(authId)).willReturn(authIdDuplication); - //when + //when AuthIdDuplicationResponse authIdDuplicationResponse = checkAuthIdDuplicationService.checkAuthIdDuplication( authId); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckStudentNumberDuplicationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckStudentNumberDuplicationServiceTest.java index 930f93ba..9a48696a 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckStudentNumberDuplicationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/check/CheckStudentNumberDuplicationServiceTest.java @@ -1,8 +1,10 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.check; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.StudentNumberDuplicationResponse; +import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -10,9 +12,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.user.api.signup.dto.response.StudentNumberDuplicationResponse; -import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; - @ExtendWith(MockitoExtension.class) class CheckStudentNumberDuplicationServiceTest { @@ -28,7 +27,8 @@ void checkStudentNumberDuplication() { //given String studentNumber = "60191656"; boolean studentNumberDuplication = true; - given(checkUserPort.checkDuplicateStudentNumber(studentNumber)).willReturn(studentNumberDuplication); + given(checkUserPort.checkDuplicateStudentNumber(studentNumber)).willReturn( + studentNumberDuplication); //when StudentNumberDuplicationResponse studentNumberDuplicationResponse = checkStudentNumberDuplicationService.checkStudentNumberDuplication( diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserAuthIdServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserAuthIdServiceTest.java index 7ec4d1cb..87d60bf7 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserAuthIdServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserAuthIdServiceTest.java @@ -5,6 +5,8 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -12,9 +14,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class FindUserAuthIdServiceTest { diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserInformationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserInformationServiceTest.java index c17e998a..8ce5ab9d 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserInformationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserInformationServiceTest.java @@ -3,6 +3,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -10,9 +12,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class FindUserInformationServiceTest { @@ -25,7 +24,7 @@ class FindUserInformationServiceTest { @DisplayName("학생 정보결과를 반환한다.") @Test void findUserInformation() { - //given + //given Long userId = 1L; String studentName = "testUser"; String studentNumber = "11111111"; @@ -35,11 +34,12 @@ void findUserInformation() { .id(userId) .name(studentName) .studentNumber(studentNumber) - .primaryMajor(major).build(); + .primaryMajor(major) + .build(); given(findUserUseCase.findUserById(userId)).willReturn(foundUser); - //when + //when User user = findUserInformationService.findUserInformation(userId); //then diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserServiceTest.java index eeb7082d..457dfeb4 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/find/FindUserServiceTest.java @@ -5,8 +5,9 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.user.application.port.FindUserPort; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import java.util.Optional; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -15,11 +16,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.user.application.port.FindUserPort; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class FindUserServiceTest { + @Mock private FindUserPort findUserPort; @@ -110,10 +109,12 @@ void findUserByStudentNumber() { @Test void findNonUserByStudentNumber() { //given - given(findUserPort.findUserByStudentNumber("")).willThrow(new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); + given(findUserPort.findUserByStudentNumber("")).willThrow( + new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); //when //then - assertThatThrownBy(() -> findUserService.findUserByStudentNumber("")).isInstanceOf(IllegalArgumentException.class) + assertThatThrownBy(() -> findUserService.findUserByStudentNumber("")).isInstanceOf( + IllegalArgumentException.class) .hasMessage("해당 사용자를 찾을 수 없습니다."); } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/resetpassword/ResetPasswordServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/resetpassword/ResetPasswordServiceTest.java index 5c3fd1a8..379dd0f3 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/resetpassword/ResetPasswordServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/resetpassword/ResetPasswordServiceTest.java @@ -5,6 +5,9 @@ import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; +import com.plzgraduate.myongjigraduatebe.user.application.port.UpdateUserPort; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -13,10 +16,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.security.crypto.password.PasswordEncoder; -import com.plzgraduate.myongjigraduatebe.user.application.port.UpdateUserPort; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class ResetPasswordServiceTest { @@ -37,15 +36,18 @@ void resetPassword() { String authId = "test"; String newPassword = "testPassword"; String passwordCheck = "testPassword"; - User user = User.builder().build(); + User user = User.builder() + .build(); given(findUserUseCase.findUserByAuthId(authId)).willReturn(user); //when resetPasswordService.resetPassword(authId, newPassword, passwordCheck); //then - then(passwordEncoder).should().encode(newPassword); - then(updateUserPort).should().updateUser(user); + then(passwordEncoder).should() + .encode(newPassword); + then(updateUserPort).should() + .updateUser(user); } @DisplayName("변경 비밀번호와 비밀번호 확인이 일치하지 않을 경우 예외가 발생한다.") @@ -57,7 +59,8 @@ void resetPasswordWithDifferentPasswordCheck() { String passwordCheck = "differentPassword"; //when //then - assertThatThrownBy(() -> resetPasswordService.resetPassword(authId, newPassword, passwordCheck)) + assertThatThrownBy( + () -> resetPasswordService.resetPassword(authId, newPassword, passwordCheck)) .isInstanceOf(IllegalArgumentException.class) .hasMessage(MISMATCHED_PASSWORD.toString()); } @@ -73,7 +76,8 @@ void resetPasswordNonUser() { new IllegalArgumentException("존재하지 않는 아이디입니다.")); //when //then - assertThatThrownBy(() -> resetPasswordService.resetPassword(authId, newPassword, passwordCheck)) + assertThatThrownBy( + () -> resetPasswordService.resetPassword(authId, newPassword, passwordCheck)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("존재하지 않는 아이디입니다."); } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/signup/SignUpServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/signup/SignUpServiceTest.java index b6ac15b8..9cd8c62e 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/signup/SignUpServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/signup/SignUpServiceTest.java @@ -10,6 +10,11 @@ import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.times; +import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; +import com.plzgraduate.myongjigraduatebe.user.application.port.SaveUserPort; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpCommand; +import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -18,14 +23,9 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.security.crypto.password.PasswordEncoder; -import com.plzgraduate.myongjigraduatebe.user.application.port.CheckUserPort; -import com.plzgraduate.myongjigraduatebe.user.application.port.SaveUserPort; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.signup.SignUpCommand; -import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class SignUpServiceTest { + @Mock private SaveUserPort saveUserPort; @Mock @@ -51,8 +51,10 @@ void signUp() { signUpService.signUp(command); //then - then(passwordEncoder).should().encode("1q2w3e4r!"); - then(saveUserPort).should().saveUser(any(User.class)); + then(passwordEncoder).should() + .encode("1q2w3e4r!"); + then(saveUserPort).should() + .saveUser(any(User.class)); } @DisplayName("가입하려는 아이디가 이미 존재한다.") @@ -73,9 +75,12 @@ void signUp() { .isInstanceOf(IllegalArgumentException.class) .hasMessage(DUPLICATED_AUTHID.toString()); - then(checkUserPort).should(times(1)).checkDuplicateAuthId(authId); - then(checkUserPort).should(never()).checkDuplicateStudentNumber(anyString()); - then(saveUserPort).should(never()).saveUser(any(User.class)); + then(checkUserPort).should(times(1)) + .checkDuplicateAuthId(authId); + then(checkUserPort).should(never()) + .checkDuplicateStudentNumber(anyString()); + then(saveUserPort).should(never()) + .saveUser(any(User.class)); } @DisplayName("가입하려는 학번이 이미 존재한다.") @@ -97,9 +102,12 @@ void signUp() { .isInstanceOf(IllegalArgumentException.class) .hasMessage(DUPLICATED_STUDENT_NUMBER.toString()); - then(checkUserPort).should(times(1)).checkDuplicateAuthId(anyString()); - then(checkUserPort).should(times(1)).checkDuplicateStudentNumber(studentNumber); - then(saveUserPort).should(never()).saveUser(any(User.class)); + then(checkUserPort).should(times(1)) + .checkDuplicateAuthId(anyString()); + then(checkUserPort).should(times(1)) + .checkDuplicateStudentNumber(studentNumber); + then(saveUserPort).should(never()) + .saveUser(any(User.class)); } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/update/UpdateStudentInformationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/update/UpdateStudentInformationServiceTest.java index aca83573..ddec714e 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/update/UpdateStudentInformationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/update/UpdateStudentInformationServiceTest.java @@ -1,7 +1,11 @@ package com.plzgraduate.myongjigraduatebe.user.application.service.update; -import static org.mockito.BDDMockito.*; +import static org.mockito.BDDMockito.then; +import com.plzgraduate.myongjigraduatebe.user.application.port.UpdateUserPort; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationCommand; +import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -9,11 +13,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationCommand; -import com.plzgraduate.myongjigraduatebe.user.application.port.UpdateUserPort; -import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class UpdateStudentInformationServiceTest { @@ -40,6 +39,7 @@ void updateUser() { updateStudentInformationService.updateUser(command); //then - then(updateUserPort).should().updateUser(user); + then(updateUserPort).should() + .updateUser(user); } } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/validate/ValidateUserServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/validate/ValidateUserServiceTest.java index 7f419af2..0c310005 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/validate/ValidateUserServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/validate/ValidateUserServiceTest.java @@ -3,6 +3,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -10,9 +12,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class ValidateUserServiceTest { @@ -25,14 +24,15 @@ class ValidateUserServiceTest { @DisplayName("성공: 학번으로 유저를 조회 후 로그인 아이디가 맞는지 검증한다.") @Test void validatePassedUser() { - //given + //given String studentNumber = "60191656"; String authId = "testAuthId"; User user = User.builder() - .authId(authId).build(); + .authId(authId) + .build(); given(findUserUseCase.findUserByStudentNumber(studentNumber)).willReturn(user); - //when + //when boolean validated = validateUserService.validateUser(studentNumber, authId); //then @@ -46,7 +46,8 @@ void validateNonPassedUser() { String studentNumber = "60191656"; String authId = "testAuthId"; User user = User.builder() - .authId("userAuthId").build(); + .authId("userAuthId") + .build(); given(findUserUseCase.findUserByStudentNumber(studentNumber)).willReturn(user); //when diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/withdraw/WithDrawUserServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/withdraw/WithDrawUserServiceTest.java index 0cc8d492..b8a62185 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/withdraw/WithDrawUserServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/application/service/withdraw/WithDrawUserServiceTest.java @@ -6,6 +6,12 @@ import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; +import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.DeleteCompletedCreditPort; +import com.plzgraduate.myongjigraduatebe.parsing.application.port.DeleteParsingTextHistoryPort; +import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase; +import com.plzgraduate.myongjigraduatebe.user.application.port.DeleteUserPort; +import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -15,13 +21,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; -import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.DeleteCompletedCreditPort; -import com.plzgraduate.myongjigraduatebe.parsing.application.port.DeleteParsingTextHistoryPort; -import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase; -import com.plzgraduate.myongjigraduatebe.user.application.port.DeleteUserPort; -import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - @ExtendWith(MockitoExtension.class) class WithDrawUserServiceTest { @@ -44,21 +43,26 @@ class WithDrawUserServiceTest { @DisplayName("유저 정보를 삭제한다.") @Test void withDraw() { - //given + //given String password = "abcd1234!"; PasswordEncoder encoder = new BCryptPasswordEncoder(); User user = User.builder() .id(1L) - .password(encoder.encode(password)).build(); + .password(encoder.encode(password)) + .build(); given(findUserUseCase.findUserById(user.getId())).willReturn(user); given(passwordEncoder.matches(anyString(), anyString())).willReturn(true); //when //then - withDrawUserService.withDraw(user.getId(), password); - then(deleteTakenLectureByUserUseCase).should().deleteAllTakenLecturesByUser(user); - then(deleteParsingTextHistoryPort).should().deleteUserParsingTextHistory(user); - then(deleteCompletedCreditPort).should().deleteAllCompletedCredits(user); - then(deleteUserPort).should().deleteUser(user); + withDrawUserService.withDraw(user.getId(), password); + then(deleteTakenLectureByUserUseCase).should() + .deleteAllTakenLecturesByUser(user); + then(deleteParsingTextHistoryPort).should() + .deleteUserParsingTextHistory(user); + then(deleteCompletedCreditPort).should() + .deleteAllCompletedCredits(user); + then(deleteUserPort).should() + .deleteUser(user); } @DisplayName("잘못된 비밀번호를 입력하면 예외가 발생한다.") @@ -69,7 +73,8 @@ void withDrawWithUnValidationPassword() { PasswordEncoder encoder = new BCryptPasswordEncoder(); User user = User.builder() .id(1L) - .password(encoder.encode(password)).build(); + .password(encoder.encode(password)) + .build(); given(findUserUseCase.findUserById(user.getId())).willReturn(user); given(passwordEncoder.matches(anyString(), anyString())).willReturn(false); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/DefaultGraduationRequirementTypeTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/DefaultGraduationRequirementTypeTest.java index b9c9ea6c..ca6c8f43 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/DefaultGraduationRequirementTypeTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/DefaultGraduationRequirementTypeTest.java @@ -1,19 +1,18 @@ package com.plzgraduate.myongjigraduatebe.user.domain.model; -import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.*; -import static org.assertj.core.api.Assertions.*; +import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.ENGLISH; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DefaultGraduationRequirementType; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; import java.util.NoSuchElementException; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DefaultGraduationRequirementType; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; - class DefaultGraduationRequirementTypeTest { @DisplayName("학생의 소속 단과대와 입학년도로 기본졸업요건을 결정한다.") @@ -23,15 +22,18 @@ void determineGraduationRequirement(int entryYear) { //given College ict = College.ICT; User user = User.builder() - .entryYear(entryYear).build(); + .entryYear(entryYear) + .build(); //when - DefaultGraduationRequirementType graduationRequirement = DefaultGraduationRequirementType.determineGraduationRequirement(ict, + DefaultGraduationRequirementType graduationRequirement = DefaultGraduationRequirementType.determineGraduationRequirement( + ict, user); //then assertThat(graduationRequirement.getCollageName()).isEqualTo(ict.getName()); - assertThat(graduationRequirement.getStartEntryYear()).isLessThanOrEqualTo(user.getEntryYear()); + assertThat(graduationRequirement.getStartEntryYear()).isLessThanOrEqualTo( + user.getEntryYear()); assertThat(graduationRequirement.getEndEntryYear()).isGreaterThan(user.getEntryYear()); } @@ -42,10 +44,12 @@ void determineGraduationRequirementWithIllegalUser(int entryYear) { //given College ict = College.ICT; User user = User.builder() - .entryYear(entryYear).build(); + .entryYear(entryYear) + .build(); //when //then - assertThatThrownBy(() -> DefaultGraduationRequirementType.determineGraduationRequirement(ict, user)) + assertThatThrownBy( + () -> DefaultGraduationRequirementType.determineGraduationRequirement(ict, user)) .isInstanceOf(NoSuchElementException.class) .hasMessage("일치하는 졸업 요건이 존재하지 않습니다."); } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategoryTest.java index ee39298e..1d73497f 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategoryTest.java @@ -2,13 +2,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; +import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; - class StudentCategoryTest { @DisplayName("학생 이수구분 카테고리에 포함되는 졸업 카테고리인지 검증한다.") @@ -18,12 +17,14 @@ class StudentCategoryTest { void validateGraduationCategoryInclusion(String graduationCategoryName) { //given User user = User.builder() - .studentCategory(StudentCategory.NORMAL).build(); + .studentCategory(StudentCategory.NORMAL) + .build(); GraduationCategory graduationCategory = GraduationCategory.valueOf(graduationCategoryName); //when //then assertThatThrownBy( - () -> user.getStudentCategory().validateGraduationCategoryInclusion(graduationCategory)) + () -> user.getStudentCategory() + .validateGraduationCategoryInclusion(graduationCategory)) .isInstanceOf(IllegalArgumentException.class) .hasMessage(ErrorCode.UNFITTED_GRADUATION_CATEGORY.toString()); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/UserTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/UserTest.java index 163caafd..80dffa26 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/UserTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/UserTest.java @@ -1,9 +1,10 @@ package com.plzgraduate.myongjigraduatebe.user.domain.model; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.BDDMockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; import static org.mockito.MockitoAnnotations.openMocks; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -12,8 +13,6 @@ import org.mockito.Mock; import org.springframework.security.crypto.password.PasswordEncoder; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; - class UserTest { @Mock @@ -110,7 +109,8 @@ void getEncryptedAuthId() { //given String authId = "testAuthId"; User user = User.builder() - .authId(authId).build(); + .authId(authId) + .build(); //when String encryptedAuthId = user.getEncryptedAuthId(); @@ -129,7 +129,8 @@ void resetPassword() { String beforePassword = "before"; String afterPassword = "after"; User user = User.builder() - .password(beforePassword).build(); + .password(beforePassword) + .build(); //when user.resetPassword(afterPassword); @@ -144,7 +145,8 @@ void isMyAuthId() { //given String authId = "testAuthId"; User user = User.builder() - .authId(authId).build(); + .authId(authId) + .build(); //when boolean result = user.isMyAuthId(authId); @@ -159,7 +161,8 @@ void isNotMyAuthId() { //given String authId = "testAuthId"; User user = User.builder() - .authId("userAuthId").build(); + .authId("userAuthId") + .build(); //when boolean result = user.isMyAuthId(authId); @@ -173,7 +176,12 @@ void isNotMyAuthId() { @ParameterizedTest void getMajorByMajorType(MajorType majorType, String major) { //given - User dualMajorUser = User.builder().id(1L).primaryMajor("융합소프트웨어부").dualMajor("경영학과").subMajor("영문학과").build(); + User dualMajorUser = User.builder() + .id(1L) + .primaryMajor("융합소프트웨어부") + .dualMajor("경영학과") + .subMajor("영문학과") + .build(); //when String majorByMajorType = dualMajorUser.getMajorByMajorType(majorType); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapterTest.java index eba95a81..b135bc4e 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapterTest.java @@ -2,18 +2,15 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; import java.util.Optional; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.UserPersistenceAdapter; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - class UserPersistenceAdapterTest extends PersistenceTestSupport { @Autowired @@ -24,11 +21,11 @@ class UserPersistenceAdapterTest extends PersistenceTestSupport { @DisplayName("사용자를 저장한다.") @Test void 사용자_저장() { - //given + //given User user = createUser("mju1001", "1q2w3e4r!", "60181666"); - //when + //when userPersistenceAdapter.saveUser(user); - //then + //then assertThat(userRepository.findByAuthId("mju1001")).isPresent(); } @@ -44,7 +41,8 @@ class UserPersistenceAdapterTest extends PersistenceTestSupport { //then assertThat(user).isPresent(); - assertThat(user.get().getAuthId()).isEqualTo(authId); + assertThat(user.get() + .getAuthId()).isEqualTo(authId); } @DisplayName("학번으로 사용자를 조회한다.") @@ -60,7 +58,8 @@ void findUserByStudentNumber() { //then assertThat(user).isPresent(); - assertThat(user.get().getStudentNumber()).isEqualTo(studentNumber); + assertThat(user.get() + .getStudentNumber()).isEqualTo(studentNumber); } @DisplayName("아이디가 이미 존재하는지 확인한다.") @@ -71,7 +70,7 @@ void findUserByStudentNumber() { UserJpaEntity user = createUserEntity(authId, "1q2w3e4r!", "60181666"); userRepository.save(user); //when - boolean check= userPersistenceAdapter.checkDuplicateAuthId(authId); + boolean check = userPersistenceAdapter.checkDuplicateAuthId(authId); //then assertThat(check).isTrue(); @@ -85,7 +84,7 @@ void findUserByStudentNumber() { UserJpaEntity user = createUserEntity("mju1001", "1q2w3e4r!", studentNumber); userRepository.save(user); //when - boolean check= userPersistenceAdapter.checkDuplicateStudentNumber(studentNumber); + boolean check = userPersistenceAdapter.checkDuplicateStudentNumber(studentNumber); //then assertThat(check).isTrue(); @@ -94,17 +93,18 @@ void findUserByStudentNumber() { @DisplayName("유저 데이터를 삭제한다.") @Test void deleteUser() { - //given + //given String authId = "mju1000"; UserJpaEntity userJpaEntity = createUserEntity(authId, "1q2w3e4r!", "60181666"); UserJpaEntity savedUserJpaEntity = userRepository.save(userJpaEntity); User user = User.builder() - .id(savedUserJpaEntity.getId()).build(); + .id(savedUserJpaEntity.getId()) + .build(); //when userPersistenceAdapter.deleteUser(user); - //then + //then Optional foundUser = userPersistenceAdapter.findUserByAuthId(authId); assertThat(foundUser.isPresent()).isFalse(); } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/mapper/UserMapperTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/mapper/UserMapperTest.java index 261890a4..5bede63c 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/mapper/UserMapperTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/mapper/UserMapperTest.java @@ -2,15 +2,14 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; class UserMapperTest extends PersistenceTestSupport { @@ -28,8 +27,10 @@ void mapToDomainEntityTest() { //then assertThat(user) - .extracting("id", "authId", "password", "englishLevel", "name", "studentNumber", "entryYear", - "primaryMajor", "subMajor", "studentCategory", "totalCredit", "takenCredit", "graduated") + .extracting("id", "authId", "password", "englishLevel", "name", "studentNumber", + "entryYear", + "primaryMajor", "subMajor", "studentCategory", "totalCredit", "takenCredit", + "graduated") .contains(1L, "mju1000", "mju1000!", EnglishLevel.ENG12, "김명지", "60211111", 21, "경영", null, StudentCategory.NORMAL, 100, 40.0, false); } @@ -45,7 +46,8 @@ void mapToJpaEntityTest() { //then assertThat(userJpaEntity) - .extracting("id", "authId", "password", "englishLevel", "name", "studentNumber", "entryYear", "major", + .extracting("id", "authId", "password", "englishLevel", "name", "studentNumber", + "entryYear", "major", "subMajor", "studentCategory", "totalCredit", "takenCredit", "graduated") .contains(1L, "mju1000", "mju1000!", EnglishLevel.ENG12, "김명지", "60211111", 21, "경영", null, StudentCategory.NORMAL, 100, 40.0, false); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/repository/UserRepositoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/repository/UserRepositoryTest.java index 782c7f87..daf5806a 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/repository/UserRepositoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/repository/UserRepositoryTest.java @@ -1,18 +1,15 @@ package com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; +import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; import java.util.List; import java.util.Optional; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import com.plzgraduate.myongjigraduatebe.support.PersistenceTestSupport; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.entity.UserJpaEntity; -import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.repository.UserRepository; - class UserRepositoryTest extends PersistenceTestSupport { @Autowired @@ -31,7 +28,8 @@ class UserRepositoryTest extends PersistenceTestSupport { //then assertThat(user).isPresent(); - assertThat(user.get().getAuthId()).isEqualTo("mju1001"); + assertThat(user.get() + .getAuthId()).isEqualTo("mju1001"); } @DisplayName("학번을 통해 유저를 조회한다.") @@ -47,7 +45,8 @@ void findByStudentNumber() { //then assertThat(user).isPresent(); - assertThat(user.get().getStudentNumber()).isEqualTo(studentNumber); + assertThat(user.get() + .getStudentNumber()).isEqualTo(studentNumber); } @DisplayName("아이디가 이미 존재하는지 확인한다.") @@ -59,7 +58,7 @@ void findByStudentNumber() { userRepository.save(user); //when - boolean check= userRepository.existsByAuthId(authId); + boolean check = userRepository.existsByAuthId(authId); //then assertThat(check).isTrue(); @@ -74,7 +73,7 @@ void findByStudentNumber() { userRepository.save(user); //when - boolean check= userRepository.existsByStudentNumber(studentNumber); + boolean check = userRepository.existsByStudentNumber(studentNumber); //then assertThat(check).isTrue(); diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index 83ef7a1a..aba0b1a5 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -1,16 +1,16 @@ - - - - %d{HH:mm:ss.SSS} %-5level %logger - %msg%n - - + + + + %d{HH:mm:ss.SSS} %-5level %logger - %msg%n + + - - - + - + + +