Skip to content

Commit

Permalink
feature: 멘토의 커리어에 회사 주소를 추가하는 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
hajeu committed May 27, 2024
1 parent 67a58f7 commit 49c750a
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +25,7 @@ class MentorController(
private val deleteMentorInfoByIdUseCase: DeleteMentorInfoByIdUseCase,
private val modifyMentorInfoByIdUseCase: ModifyMentorInfoByIdUseCase,
private val authenticatedUserManager: AuthenticatedUserManager,
private val generateCompanyAddressUseCase: GenerateCompanyAddressUseCase
) {

@PostMapping
Expand Down Expand Up @@ -60,4 +62,10 @@ class MentorController(
return ResponseEntity.noContent().build()
}

@PatchMapping("/career/company-address")
fun companyAddressRegistration(@RequestBody @Valid dto: CompanyAddressRegistrationDto): ResponseEntity<Void> {
generateCompanyAddressUseCase.generateCompanyAddress(dto)
return ResponseEntity.status(HttpStatus.CREATED).build()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class Career(
@Column(nullable = true)
val companyUrl: String,

@Column(nullable = true)
var companyAddress: String?,

@Column(nullable = false)
val position: String,

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package team.themoment.gsmNetworking.domain.mentor.dto

data class CompanyAddressRegistrationDto (
val id: Long,
val companyAddress: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ data class MentorCareerDto(

val companyUrl: String?,

val companyAddress: String?,

@field:NotBlank
val position: String,

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
* 멘토 관련 로직이 담긴 클래스 입니다.
Expand All @@ -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{

/**
* 모든 멘토 리스트를 가져와서 리턴해주는 메서드 입니다.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
Expand All @@ -131,17 +136,15 @@ 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
}

@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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 49c750a

Please sign in to comment.