diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/user/controller/UserController.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/user/controller/UserController.kt new file mode 100644 index 00000000..06340f4a --- /dev/null +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/user/controller/UserController.kt @@ -0,0 +1,25 @@ +package team.themoment.gsmNetworking.domain.user.controller + +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import team.themoment.gsmNetworking.common.manager.AuthenticatedUserManager +import team.themoment.gsmNetworking.domain.user.service.ProfileUrlRegistrationService + +@RestController +@RequestMapping("/api/v1/user") +class UserController( + private val authenticatedUserManager: AuthenticatedUserManager, + private val profileUrlRegistrationService: ProfileUrlRegistrationService +) { + + @PostMapping("/profile/{profileUrl}") + fun profileUrlRegistration(@PathVariable profileUrl: String): ResponseEntity { + val authenticationId = authenticatedUserManager.getName() + profileUrlRegistrationService.execute(authenticationId, profileUrl) + return ResponseEntity.status(HttpStatus.CREATED).build() + } +} diff --git a/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/ProfileUrlRegistrationService.kt b/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/ProfileUrlRegistrationService.kt new file mode 100644 index 00000000..dba2253f --- /dev/null +++ b/src/main/kotlin/team/themoment/gsmNetworking/domain/user/service/ProfileUrlRegistrationService.kt @@ -0,0 +1,37 @@ +package team.themoment.gsmNetworking.domain.user.service + +import org.springframework.http.HttpStatus +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import team.themoment.gsmNetworking.common.exception.ExpectedException +import team.themoment.gsmNetworking.domain.user.domain.User +import team.themoment.gsmNetworking.domain.user.repository.UserRepository + +@Service +@Transactional(rollbackFor = [Exception::class]) +class ProfileUrlRegistrationService( + private val userRepository: UserRepository +) { + + fun execute(authenticationId: Long, profileUrl: String) { + val user = userRepository.findByAuthenticationId(authenticationId) + ?: throw ExpectedException("user를 찾을 수 없습니다.", HttpStatus.NOT_FOUND) + + profileUrlRegistered(user, profileUrl) + } + + fun profileUrlRegistered(user: User, profileUrl: String) { + val userUpdatedProfileUrl = User( + user.userId, + user.authenticationId, + user.name, + user.generation, + user.email, + user.phoneNumber, + user.snsUrl, + profileUrl + ) + + userRepository.save(userUpdatedProfileUrl) + } +} diff --git a/src/main/kotlin/team/themoment/gsmNetworking/global/security/SecurityConfig.kt b/src/main/kotlin/team/themoment/gsmNetworking/global/security/SecurityConfig.kt index 8533d80a..03ff1ece 100644 --- a/src/main/kotlin/team/themoment/gsmNetworking/global/security/SecurityConfig.kt +++ b/src/main/kotlin/team/themoment/gsmNetworking/global/security/SecurityConfig.kt @@ -92,6 +92,10 @@ class SecurityConfig( .mvcMatchers(HttpMethod.POST, "/api/v1/mentee").hasAnyRole( Authority.UNAUTHENTICATED.name ) + // /user + .mvcMatchers("/api/v1/user/**").hasAnyRole( + Authority.USER.name + ) // /file .mvcMatchers("/api/v1/file").hasAnyRole( Authority.USER.name