Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User 엔티티의 profileUrl 등록 로직 구현 #73

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<Void> {
val authenticationId = authenticatedUserManager.getName()
profileUrlRegistrationService.execute(authenticationId, profileUrl)
return ResponseEntity.status(HttpStatus.CREATED).build()
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down