From 49c750abd70b5106a5fdf456674a9e55966723fd Mon Sep 17 00:00:00 2001 From: hajeu Date: Mon, 27 May 2024 20:52:59 +0900 Subject: [PATCH] =?UTF-8?q?feature:=20=EB=A9=98=ED=86=A0=EC=9D=98=20?= =?UTF-8?q?=EC=BB=A4=EB=A6=AC=EC=96=B4=EC=97=90=20=ED=9A=8C=EC=82=AC=20?= =?UTF-8?q?=EC=A3=BC=EC=86=8C=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentor/controller/MentorController.kt | 8 ++++++ .../domain/mentor/domain/Career.kt | 4 +++ .../dto/CompanyAddressRegistrationDto.kt | 6 ++++ .../domain/mentor/dto/MentorCareerDto.kt | 2 ++ .../service/GenerateCompanyAddressUseCase.kt | 8 ++++++ .../mentor/service/impl/MentorService.kt | 19 ++++++++++--- .../user/service/QueryUserByIdUseCase.kt | 8 ++++++ .../domain/user/service/impl/UserService.kt | 28 ++++++++++--------- 8 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/dto/CompanyAddressRegistrationDto.kt create mode 100644 src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/service/GenerateCompanyAddressUseCase.kt create mode 100644 src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/QueryUserByIdUseCase.kt diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/controller/MentorController.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/controller/MentorController.kt index 9635a533..2fce59ec 100644 --- a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/controller/MentorController.kt +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/controller/MentorController.kt @@ -4,6 +4,7 @@ import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody @@ -24,6 +25,7 @@ class MentorController( private val deleteMentorInfoByIdUseCase: DeleteMentorInfoByIdUseCase, private val modifyMentorInfoByIdUseCase: ModifyMentorInfoByIdUseCase, private val authenticatedUserManager: AuthenticatedUserManager, + private val generateCompanyAddressUseCase: GenerateCompanyAddressUseCase ) { @PostMapping @@ -60,4 +62,10 @@ class MentorController( return ResponseEntity.noContent().build() } + @PatchMapping("/career/company-address") + fun companyAddressRegistration(@RequestBody @Valid dto: CompanyAddressRegistrationDto): ResponseEntity { + generateCompanyAddressUseCase.generateCompanyAddress(dto) + return ResponseEntity.status(HttpStatus.CREATED).build() + } + } diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/domain/Career.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/domain/Career.kt index 60e5893e..d4eaf779 100644 --- a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/domain/Career.kt +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/domain/Career.kt @@ -23,6 +23,9 @@ class Career( @Column(nullable = true) val companyUrl: String, + @Column(nullable = true) + var companyAddress: String?, + @Column(nullable = false) val position: String, @@ -43,6 +46,7 @@ class Career( mentor = mentor, companyName = it.companyName, companyUrl = it.companyUrl ?: "", + companyAddress = it.companyAddress ?: "", position = it.position, startDate = it.startDate, endDate = it.endDate, diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/dto/CompanyAddressRegistrationDto.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/dto/CompanyAddressRegistrationDto.kt new file mode 100644 index 00000000..3d5d0ecb --- /dev/null +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/dto/CompanyAddressRegistrationDto.kt @@ -0,0 +1,6 @@ +package team.themoment.gsmNetworking.domain.mentor.dto + +data class CompanyAddressRegistrationDto ( + val id: Long, + val companyAddress: String? +) diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/dto/MentorCareerDto.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/dto/MentorCareerDto.kt index 63657c8c..f85ae4a7 100644 --- a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/dto/MentorCareerDto.kt +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/dto/MentorCareerDto.kt @@ -10,6 +10,8 @@ data class MentorCareerDto( val companyUrl: String?, + val companyAddress: String?, + @field:NotBlank val position: String, diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/service/GenerateCompanyAddressUseCase.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/service/GenerateCompanyAddressUseCase.kt new file mode 100644 index 00000000..e7fd555a --- /dev/null +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/service/GenerateCompanyAddressUseCase.kt @@ -0,0 +1,8 @@ +package team.themoment.gsmNetworking.domain.mentor.service + +import team.themoment.gsmNetworking.domain.mentor.dto.CompanyAddressRegistrationDto + +interface GenerateCompanyAddressUseCase { + + fun generateCompanyAddress(dto: CompanyAddressRegistrationDto) +} \ No newline at end of file diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/service/impl/MentorService.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/service/impl/MentorService.kt index b878c830..222e1f40 100644 --- a/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/service/impl/MentorService.kt +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/mentor/service/impl/MentorService.kt @@ -15,6 +15,8 @@ import team.themoment.gsmNetworking.domain.user.repository.UserRepository import team.themoment.gsmNetworking.domain.user.service.DeleteUserInfoByIdUseCase import team.themoment.gsmNetworking.domain.user.service.GenerateUserUseCase import team.themoment.gsmNetworking.domain.user.service.ModifyUserInfoByIdUseCase +import team.themoment.gsmNetworking.domain.user.service.QueryUserByIdUseCase +import javax.print.PrintService /** * 멘토 관련 로직이 담긴 클래스 입니다. @@ -27,12 +29,14 @@ class MentorService( private val queryAllTempMentorsUseCase: QueryAllTempMentorsUseCase, private val generateUserUseCase: GenerateUserUseCase, private val modifyUserInfoByIdUseCase: ModifyUserInfoByIdUseCase, - private val deleteUserInfoByIdUseCase: DeleteUserInfoByIdUseCase + private val deleteUserInfoByIdUseCase: DeleteUserInfoByIdUseCase, + private val queryUserByIdUseCase: QueryUserByIdUseCase ) : QueryAllMentorsUseCase, MentorRegistrationUseCase, QueryMentorInfoByIdUseCase, DeleteMentorInfoByIdUseCase, - ModifyMentorInfoByIdUseCase { + ModifyMentorInfoByIdUseCase, + GenerateCompanyAddressUseCase{ /** * 모든 멘토 리스트를 가져와서 리턴해주는 메서드 입니다. @@ -73,6 +77,7 @@ class MentorService( mentor = mentor, companyName = it.companyName, companyUrl = it.companyUrl ?: "", + companyAddress = it.companyAddress ?: "", position = it.position, startDate = it.startDate, endDate = it.endDate, @@ -107,8 +112,7 @@ class MentorService( @Transactional override fun modifyMentorInfoById(authenticationId: Long, mentorSaveInfoDto: MentorSaveInfoDto) { - val user = userRepository.findByAuthenticationId(authenticationId) - ?: throw ExpectedException("user를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) + val user = queryUserByIdUseCase.queryUserById(authenticationId) val mentor = mentorRepository.findByUser(user) ?: throw ExpectedException("mentor를 찾을 수 없습니다", HttpStatus.NOT_FOUND) @@ -126,4 +130,11 @@ class MentorService( careerRepository.deleteAllByMentor(mentor) careerRepository.saveAll(updateCareers) } + + @Transactional + override fun generateCompanyAddress( companyAddressRegistrationDto: CompanyAddressRegistrationDto) { + val career = careerRepository.findById(companyAddressRegistrationDto.id) + .orElseThrow { ExpectedException("career를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) } + career.companyAddress = companyAddressRegistrationDto.companyAddress + } } diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/QueryUserByIdUseCase.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/QueryUserByIdUseCase.kt new file mode 100644 index 00000000..64a0888d --- /dev/null +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/QueryUserByIdUseCase.kt @@ -0,0 +1,8 @@ +package team.themoment.gsmNetworking.domain.user.service + +import team.themoment.gsmNetworking.domain.user.domain.User + +interface QueryUserByIdUseCase { + + fun queryUserById(authenticationId: Long): User +} \ No newline at end of file diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/impl/UserService.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/impl/UserService.kt index 3464ac5e..34045491 100644 --- a/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/impl/UserService.kt +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/impl/UserService.kt @@ -25,13 +25,20 @@ class UserService( QueryUserInfoByUserIdUseCase, QueryEmailByUserIdUseCase, QueryUserIsTeacherUsecase, - UpdateUserProfileNumberUseCase { + UpdateUserProfileNumberUseCase, + QueryUserByIdUseCase { + + override fun queryUserById(authenticationId: Long): User { + val user = userRepository.findByAuthenticationId(authenticationId) + ?: throw ExpectedException("user를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) + + return user + } @Transactional override fun generateUser(userSaveInfoDto: UserSaveInfoDto, authenticationId: Long): User { if(userRepository.existsByAuthenticationId(authenticationId)){ - val user = userRepository.findByAuthenticationId(authenticationId) - ?: throw ExpectedException("user를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) + val user = queryUserById(authenticationId) checkExistUserByInfo(userSaveInfoDto, user) @@ -66,8 +73,7 @@ class UserService( @Transactional override fun modifyUserInfoById(authenticationId: Long, userSaveInfoDto: UserSaveInfoDto) { - val user = userRepository.findByAuthenticationId(authenticationId) - ?: throw ExpectedException("user를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) + val user = queryUserById(authenticationId) checkExistUserByInfo(userSaveInfoDto, user) @@ -104,8 +110,7 @@ class UserService( @Transactional override fun generateProfileUrl(authenticationId: Long, dto: ProfileUrlRegistrationDto) { - val user = userRepository.findByAuthenticationId(authenticationId) - ?: throw ExpectedException("user를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) + val user = queryUserById(authenticationId) profileUrlRegistered(user, dto.profileUrl) } @@ -131,8 +136,7 @@ class UserService( @Transactional override fun deleteUserInfoByIdUseCase(authenticationId: Long): User { - val user = userRepository.findByAuthenticationId(authenticationId) - ?: throw ExpectedException("user를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) + val user = queryUserById(authenticationId) userRepository.delete(user) return user @@ -140,8 +144,7 @@ class UserService( @Transactional(readOnly = true) override fun queryUserInfoById(authenticationId: Long): UserInfoDto { - val user = userRepository.findByAuthenticationId(authenticationId) - ?: throw ExpectedException("유저를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) + val user = queryUserById(authenticationId) return UserInfoDto( id = user.id, @@ -189,8 +192,7 @@ class UserService( @Transactional override fun updateUserProfileNumber(userProfileNumberDto: UserProfileNumberDto, authenticationId: Long) { - val user = userRepository.findByAuthenticationId(authenticationId) - ?: throw ExpectedException("유저를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) + val user = queryUserById(authenticationId) user.updateProfileNumber(userProfileNumberDto.profileNumber) userRepository.save(user)