From 29cfeca2fb64a00805c3048ac4f91533da758f74 Mon Sep 17 00:00:00 2001 From: jeayoung Date: Wed, 21 Sep 2022 15:15:03 +0900 Subject: [PATCH 01/10] add clientService --- .../com/msg/gauth/domain/client/Client.kt | 15 ++++++++--- .../exception/MemberNotSameException.kt | 6 +++++ .../dto/request/ClientRegisterReqDto.kt | 21 +++++++++++++++ .../dto/request/ClientUpdateReqDto.kt | 8 ++++++ .../dto/response/ClientAllResDto.kt | 15 +++++++++++ .../dto/response/ClientOneResDto.kt | 19 +++++++++++++ .../dto/response/ClientRegisterResDto.kt | 19 +++++++++++++ .../client/repository/ClientRepository.kt | 10 +++++++ .../client/services/GetAllClientsService.kt | 21 +++++++++++++++ .../client/services/GetOneClientService.kt | 20 ++++++++++++++ .../client/services/RegisterClientService.kt | 22 +++++++++++++++ .../client/services/UpdateClientService.kt | 22 +++++++++++++++ .../msg/gauth/global/exception/ErrorCode.kt | 2 ++ .../msg/gauth/global/util/CurrentUserUtil.kt | 27 +++++++++++++++++++ 14 files changed, 223 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/exception/MemberNotSameException.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientRegisterReqDto.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientUpdateReqDto.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientOneResDto.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientRegisterResDto.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/repository/ClientRepository.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt create mode 100644 src/main/kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt diff --git a/src/main/kotlin/com/msg/gauth/domain/client/Client.kt b/src/main/kotlin/com/msg/gauth/domain/client/Client.kt index 8461ebc5..b7151416 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/Client.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/Client.kt @@ -1,5 +1,6 @@ package com.msg.gauth.domain.client +import com.msg.gauth.domain.client.persentation.dto.request.ClientUpdateReqDto import com.msg.gauth.domain.user.User import com.msg.gauth.global.entity.BaseIdEntity import javax.persistence.* @@ -8,11 +9,17 @@ import javax.persistence.* class Client( val clientId: String, val clientSecret: String, - val redirectUri: String, - val serviceName: String, - val serviceUri: String, + var redirectUri: String, + var serviceName: String, + var serviceUri: String, @ManyToOne @JoinColumn(name = "user_id", nullable = false) val createdBy: User -): BaseIdEntity() \ No newline at end of file +): BaseIdEntity(){ + fun update(clientUpdateReqDto: ClientUpdateReqDto){ + this.redirectUri = clientUpdateReqDto.redirectUri + this.serviceName = clientUpdateReqDto.serviceName + this.serviceUri = clientUpdateReqDto.serviceUri + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/exception/MemberNotSameException.kt b/src/main/kotlin/com/msg/gauth/domain/client/exception/MemberNotSameException.kt new file mode 100644 index 00000000..c7f025d9 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/exception/MemberNotSameException.kt @@ -0,0 +1,6 @@ +package com.msg.gauth.domain.client.exception + +import com.msg.gauth.global.exception.ErrorCode +import com.msg.gauth.global.exception.exceptions.BasicException + +class UserNotSameException: BasicException(ErrorCode.USER_NOT_SAME){} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientRegisterReqDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientRegisterReqDto.kt new file mode 100644 index 00000000..9752021f --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientRegisterReqDto.kt @@ -0,0 +1,21 @@ +package com.msg.gauth.domain.client.persentation.dto.request + +import com.msg.gauth.domain.client.Client +import com.msg.gauth.domain.user.User + +class ClientRegisterReqDto( + private val serviceName: String, + private val serviceUri: String, + private val redirectUri: String, +){ + fun toEntity(user: User, clientSecret: String, clientId: String):Client{ + return Client( + clientId=clientId, + clientSecret = clientSecret, + serviceName = serviceName, + serviceUri = serviceUri, + redirectUri = redirectUri, + createdBy = user, + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientUpdateReqDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientUpdateReqDto.kt new file mode 100644 index 00000000..fc101897 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientUpdateReqDto.kt @@ -0,0 +1,8 @@ +package com.msg.gauth.domain.client.persentation.dto.request + +class ClientUpdateReqDto( + val serviceName: String, + val serviceUri: String, + val redirectUri: String, +) { +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt new file mode 100644 index 00000000..a96fd251 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt @@ -0,0 +1,15 @@ +package com.msg.gauth.domain.client.persentation.dto.response + +import com.msg.gauth.domain.client.Client + +class ClientAllResDto( + val clientId: String, + val serviceName: String, + val serviceUri: String, +){ + constructor(client:Client) : this( + clientId = client.clientId, + serviceName = client.serviceName, + serviceUri = client.serviceUri, + ) +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientOneResDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientOneResDto.kt new file mode 100644 index 00000000..9db4c116 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientOneResDto.kt @@ -0,0 +1,19 @@ +package com.msg.gauth.domain.client.persentation.dto.response + +import com.msg.gauth.domain.client.Client + +class ClientOneResDto( + val clientId: String, + val clientSecret: String, + val redirectUri: String, + val serviceName: String, + val serviceUri: String, +){ + constructor(client: Client) : this( + clientId = client.clientId, + clientSecret = client.clientSecret, + redirectUri = client.redirectUri, + serviceName = client.serviceName, + serviceUri = client.serviceUri, + ) +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientRegisterResDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientRegisterResDto.kt new file mode 100644 index 00000000..bbce602d --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientRegisterResDto.kt @@ -0,0 +1,19 @@ +package com.msg.gauth.domain.client.persentation.dto.response + +import com.msg.gauth.domain.client.Client + +class ClientRegisterResDto( + val clientId: String, + val clientSecret: String, + val redirectUri: String, + val serviceName: String, + val serviceUri: String, +){ + constructor(client: Client) : this( + clientId = client.clientId, + clientSecret = client.clientSecret, + redirectUri = client.redirectUri, + serviceName = client.serviceName, + serviceUri = client.serviceUri, + ) +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/repository/ClientRepository.kt b/src/main/kotlin/com/msg/gauth/domain/client/repository/ClientRepository.kt new file mode 100644 index 00000000..63b06a07 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/repository/ClientRepository.kt @@ -0,0 +1,10 @@ +package com.msg.gauth.domain.client.repository + +import com.msg.gauth.domain.client.Client +import com.msg.gauth.domain.user.User +import org.springframework.data.jpa.repository.JpaRepository + +interface ClientRepository: JpaRepository { + fun findAllByCreatedBy(createdBy: User): List + fun findClientByClientId(clientId: String): Client? +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt new file mode 100644 index 00000000..9ff7be66 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt @@ -0,0 +1,21 @@ +package com.msg.gauth.domain.client.services + +import com.msg.gauth.domain.client.persentation.dto.response.ClientAllResDto +import com.msg.gauth.domain.client.repository.ClientRepository +import com.msg.gauth.global.util.CurrentUserUtil +import org.springframework.stereotype.Service + +@Service +class GetAllClientsService( + val clientRepository: ClientRepository, + val currentUserUtil: CurrentUserUtil, +){ + fun execute():List{ + val findAllByCreatedBy = clientRepository.findAllByCreatedBy(currentUserUtil.getCurrentUser()) + val list = mutableListOf() + findAllByCreatedBy.forEach { + list.add(ClientAllResDto(it)) + } + return list + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt new file mode 100644 index 00000000..9d2e2862 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt @@ -0,0 +1,20 @@ +package com.msg.gauth.domain.client.services + +import com.msg.gauth.domain.client.exception.UserNotSameException +import com.msg.gauth.domain.client.persentation.dto.response.ClientOneResDto +import com.msg.gauth.domain.client.repository.ClientRepository +import com.msg.gauth.global.util.CurrentUserUtil +import org.springframework.stereotype.Service + +@Service +class GetOneClientService( + val clientRepository: ClientRepository, + val currentUserUtil: CurrentUserUtil, +){ + fun execute(clientId: String): ClientOneResDto{ + val client = clientRepository.findClientByClientId(clientId)!! + if(client.createdBy != currentUserUtil.getCurrentUser()) + throw UserNotSameException() + return ClientOneResDto(client) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt new file mode 100644 index 00000000..ec87fb57 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt @@ -0,0 +1,22 @@ +package com.msg.gauth.domain.client.services + +import com.msg.gauth.domain.client.persentation.dto.request.ClientRegisterReqDto +import com.msg.gauth.domain.client.persentation.dto.response.ClientRegisterResDto +import com.msg.gauth.domain.client.repository.ClientRepository +import com.msg.gauth.global.util.CurrentUserUtil +import org.springframework.stereotype.Service +import java.util.UUID + +@Service +class RegisterClientService( + val clientRepository: ClientRepository, + val currentUserUtil: CurrentUserUtil, +){ + fun execute(clientRegisterDto: ClientRegisterReqDto): ClientRegisterResDto { + val clientSecret = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID().toString().replace("-", "") + val user = currentUserUtil.getCurrentUser() + val client = clientRegisterDto.toEntity(user, clientSecret, "") + clientRepository.save(client) + return ClientRegisterResDto(client) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt new file mode 100644 index 00000000..9ca954a7 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt @@ -0,0 +1,22 @@ +package com.msg.gauth.domain.client.services + +import com.msg.gauth.domain.client.exception.UserNotSameException +import com.msg.gauth.domain.client.persentation.dto.request.ClientUpdateReqDto +import com.msg.gauth.domain.client.repository.ClientRepository +import com.msg.gauth.global.util.CurrentUserUtil +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class UpdateClientService( + val clientRepository: ClientRepository, + val currentUserUtil: CurrentUserUtil, +){ + @Transactional + fun updateClient(clientId: String, clientUpdateReqDto: ClientUpdateReqDto){ + val client = clientRepository.findClientByClientId(clientId)!! + if(client.createdBy != currentUserUtil.getCurrentUser()) + throw UserNotSameException() + client.update(clientUpdateReqDto) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/global/exception/ErrorCode.kt b/src/main/kotlin/com/msg/gauth/global/exception/ErrorCode.kt index 74100625..6458fa80 100644 --- a/src/main/kotlin/com/msg/gauth/global/exception/ErrorCode.kt +++ b/src/main/kotlin/com/msg/gauth/global/exception/ErrorCode.kt @@ -14,6 +14,7 @@ enum class ErrorCode( EXPIRED_REFRESH_TOKEN("리프레시 토큰이 만료되었습니다", 401), INVALID_REFRESH_TOKEN("리프레시 토큰이 변질되었습니다", 401), EMAIL_NOT_VERIFIED("인증된 이메일이 아닙니다.", 401), + USER_NOT_SAME("유저가 일치하지 않습니다", 401), NOT_FOUND("리소스를 찾을수 없음", 404), USER_NOT_FOUND("해당 유저를 찾을 수 없습니다.", 404), @@ -24,5 +25,6 @@ enum class ErrorCode( MAIL_SEND_FAIL("메일을 보내는데 실패했습니다.", 500), INTERNAL_SERVER_ERROR("서버 내부 에러", 500) + ; } \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt b/src/main/kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt new file mode 100644 index 00000000..83cf03d4 --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt @@ -0,0 +1,27 @@ +package com.msg.gauth.global.util + +import com.msg.gauth.domain.user.User +import com.msg.gauth.domain.user.repository.UserRepository +import com.msg.gauth.global.security.auth.AuthDetails +import org.springframework.security.core.context.SecurityContextHolder +import org.springframework.security.core.userdetails.UserDetails +import org.springframework.stereotype.Component + +@Component +class CurrentUserUtil( + private val userRepository: UserRepository +){ + private fun getCurrentEmail():String{ + val principal = SecurityContextHolder.getContext().authentication.principal + val email: String = + if(principal is UserDetails){ + (principal as AuthDetails).username + }else{ + principal.toString() + } + return email + } + + fun getCurrentUser(): User = + userRepository.findByEmail(getCurrentEmail())!! +} \ No newline at end of file From 07f374601c158aeeac3f4ed5507fe9f12864e8bc Mon Sep 17 00:00:00 2001 From: jeayoung Date: Wed, 21 Sep 2022 16:00:24 +0900 Subject: [PATCH 02/10] =?UTF-8?q?Service=20=EB=A9=A4=EB=B2=84=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=EB=A5=BC=20private=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msg/gauth/domain/client/services/GetAllClientsService.kt | 4 ++-- .../msg/gauth/domain/client/services/GetOneClientService.kt | 4 ++-- .../msg/gauth/domain/client/services/RegisterClientService.kt | 4 ++-- .../msg/gauth/domain/client/services/UpdateClientService.kt | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt index 9ff7be66..609f5461 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt @@ -7,8 +7,8 @@ import org.springframework.stereotype.Service @Service class GetAllClientsService( - val clientRepository: ClientRepository, - val currentUserUtil: CurrentUserUtil, + private val clientRepository: ClientRepository, + private val currentUserUtil: CurrentUserUtil, ){ fun execute():List{ val findAllByCreatedBy = clientRepository.findAllByCreatedBy(currentUserUtil.getCurrentUser()) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt index 9d2e2862..da9d658a 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt @@ -8,8 +8,8 @@ import org.springframework.stereotype.Service @Service class GetOneClientService( - val clientRepository: ClientRepository, - val currentUserUtil: CurrentUserUtil, + private val clientRepository: ClientRepository, + private val currentUserUtil: CurrentUserUtil, ){ fun execute(clientId: String): ClientOneResDto{ val client = clientRepository.findClientByClientId(clientId)!! diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt index ec87fb57..f272d098 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt @@ -9,8 +9,8 @@ import java.util.UUID @Service class RegisterClientService( - val clientRepository: ClientRepository, - val currentUserUtil: CurrentUserUtil, + private val clientRepository: ClientRepository, + private val currentUserUtil: CurrentUserUtil, ){ fun execute(clientRegisterDto: ClientRegisterReqDto): ClientRegisterResDto { val clientSecret = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID().toString().replace("-", "") diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt index 9ca954a7..1425cd2f 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt @@ -9,8 +9,8 @@ import org.springframework.transaction.annotation.Transactional @Service class UpdateClientService( - val clientRepository: ClientRepository, - val currentUserUtil: CurrentUserUtil, + private val clientRepository: ClientRepository, + private val currentUserUtil: CurrentUserUtil, ){ @Transactional fun updateClient(clientId: String, clientUpdateReqDto: ClientUpdateReqDto){ From aade2c70f38136fa38c6b949e7a3d8996b775c3e Mon Sep 17 00:00:00 2001 From: jeayoung Date: Wed, 21 Sep 2022 16:00:52 +0900 Subject: [PATCH 03/10] add ClientController --- .../client/persentation/ClientController.kt | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt new file mode 100644 index 00000000..ac1a25bb --- /dev/null +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt @@ -0,0 +1,53 @@ +package com.msg.gauth.domain.client.persentation + +import com.msg.gauth.domain.client.persentation.dto.request.ClientRegisterReqDto +import com.msg.gauth.domain.client.persentation.dto.request.ClientUpdateReqDto +import com.msg.gauth.domain.client.persentation.dto.response.ClientAllResDto +import com.msg.gauth.domain.client.persentation.dto.response.ClientOneResDto +import com.msg.gauth.domain.client.persentation.dto.response.ClientRegisterResDto +import com.msg.gauth.domain.client.services.GetAllClientsService +import com.msg.gauth.domain.client.services.GetOneClientService +import com.msg.gauth.domain.client.services.RegisterClientService +import com.msg.gauth.domain.client.services.UpdateClientService +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PatchMapping +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 org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/client") +class ClientController( + private val getAllClientsService: GetAllClientsService, + private val updateClientService: UpdateClientService, + private val getOneClientService: GetOneClientService, + private val registerClientService: RegisterClientService, +){ + + @PostMapping + fun registerClient(@RequestBody clientRegisterReqDto: ClientRegisterReqDto):ResponseEntity{ + val clientRegisterResDto = registerClientService.execute(clientRegisterReqDto) + return ResponseEntity.ok(clientRegisterResDto) + } + + @GetMapping + fun getAllClients(): ResponseEntity>{ + val result = getAllClientsService.execute() + return ResponseEntity.ok(result) + } + + @GetMapping("/{id}") + fun getOneClient(@PathVariable id:String): ResponseEntity{ + val clientOneResDto = getOneClientService.execute(id) + return ResponseEntity.ok(clientOneResDto) + } + + @PatchMapping("/{id}") + fun updateClient(@PathVariable id:String, @RequestBody clientUpdateDto: ClientUpdateReqDto): ResponseEntity{ + updateClientService.updateClient(id, clientUpdateDto) + return ResponseEntity.ok().build() + } +} \ No newline at end of file From 7db27e5885c3465f9768a08f4f1d22b580a9ec3b Mon Sep 17 00:00:00 2001 From: jeayoung Date: Wed, 21 Sep 2022 16:06:01 +0900 Subject: [PATCH 04/10] add ClientId logic --- .../msg/gauth/domain/client/services/RegisterClientService.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt index f272d098..0f2568f0 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt @@ -14,8 +14,9 @@ class RegisterClientService( ){ fun execute(clientRegisterDto: ClientRegisterReqDto): ClientRegisterResDto { val clientSecret = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID().toString().replace("-", "") + val clientId = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID().toString().replace("-", "") val user = currentUserUtil.getCurrentUser() - val client = clientRegisterDto.toEntity(user, clientSecret, "") + val client = clientRegisterDto.toEntity(user, clientSecret, clientId) clientRepository.save(client) return ClientRegisterResDto(client) } From 9db17213936b3743546d25f40a6d05f10da7d898 Mon Sep 17 00:00:00 2001 From: baegteun Date: Wed, 21 Sep 2022 16:08:41 +0900 Subject: [PATCH 05/10] =?UTF-8?q?:recycle:=20=20::=20=EC=9E=90=EB=B0=94?= =?UTF-8?q?=EA=B0=99=EC=9D=80=20class=EB=93=A4=20=EB=8D=94=20kotling=20?= =?UTF-8?q?=EC=8A=A4=EB=9F=BD=EA=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/ClientRegisterReqDto.kt | 15 +++++++-------- .../dto/request/ClientUpdateReqDto.kt | 5 ++--- .../persentation/dto/response/ClientAllResDto.kt | 6 +++--- .../persentation/dto/response/ClientOneResDto.kt | 4 ++-- .../dto/response/ClientRegisterResDto.kt | 6 +++--- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientRegisterReqDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientRegisterReqDto.kt index 9752021f..0f85d37a 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientRegisterReqDto.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientRegisterReqDto.kt @@ -3,19 +3,18 @@ package com.msg.gauth.domain.client.persentation.dto.request import com.msg.gauth.domain.client.Client import com.msg.gauth.domain.user.User -class ClientRegisterReqDto( - private val serviceName: String, - private val serviceUri: String, - private val redirectUri: String, +data class ClientRegisterReqDto( + val serviceName: String, + val serviceUri: String, + val redirectUri: String, ){ - fun toEntity(user: User, clientSecret: String, clientId: String):Client{ - return Client( - clientId=clientId, + fun toEntity(user: User, clientSecret: String, clientId: String): Client = + Client( + clientId = clientId, clientSecret = clientSecret, serviceName = serviceName, serviceUri = serviceUri, redirectUri = redirectUri, createdBy = user, ) - } } \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientUpdateReqDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientUpdateReqDto.kt index fc101897..7192d6a3 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientUpdateReqDto.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/request/ClientUpdateReqDto.kt @@ -1,8 +1,7 @@ package com.msg.gauth.domain.client.persentation.dto.request -class ClientUpdateReqDto( +data class ClientUpdateReqDto( val serviceName: String, val serviceUri: String, val redirectUri: String, -) { -} \ No newline at end of file +) \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt index a96fd251..c78952ba 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt @@ -2,12 +2,12 @@ package com.msg.gauth.domain.client.persentation.dto.response import com.msg.gauth.domain.client.Client -class ClientAllResDto( +data class ClientAllResDto( val clientId: String, val serviceName: String, val serviceUri: String, -){ - constructor(client:Client) : this( +) { + constructor(client:Client): this( clientId = client.clientId, serviceName = client.serviceName, serviceUri = client.serviceUri, diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientOneResDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientOneResDto.kt index 9db4c116..a9908b55 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientOneResDto.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientOneResDto.kt @@ -2,14 +2,14 @@ package com.msg.gauth.domain.client.persentation.dto.response import com.msg.gauth.domain.client.Client -class ClientOneResDto( +data class ClientOneResDto( val clientId: String, val clientSecret: String, val redirectUri: String, val serviceName: String, val serviceUri: String, ){ - constructor(client: Client) : this( + constructor(client: Client): this( clientId = client.clientId, clientSecret = client.clientSecret, redirectUri = client.redirectUri, diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientRegisterResDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientRegisterResDto.kt index bbce602d..08f3f5de 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientRegisterResDto.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientRegisterResDto.kt @@ -2,14 +2,14 @@ package com.msg.gauth.domain.client.persentation.dto.response import com.msg.gauth.domain.client.Client -class ClientRegisterResDto( +data class ClientRegisterResDto( val clientId: String, val clientSecret: String, val redirectUri: String, val serviceName: String, val serviceUri: String, -){ - constructor(client: Client) : this( +) { + constructor(client: Client): this( clientId = client.clientId, clientSecret = client.clientSecret, redirectUri = client.redirectUri, From eac967a67e66f82fd7564526a3ba9f3ab588cfda Mon Sep 17 00:00:00 2001 From: baegteun Date: Wed, 21 Sep 2022 16:11:57 +0900 Subject: [PATCH 06/10] =?UTF-8?q?:recycle:=20=20::=20GetAllClientsService?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/msg/gauth/domain/client/Client.kt | 2 +- .../domain/client/services/GetAllClientsService.kt | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/Client.kt b/src/main/kotlin/com/msg/gauth/domain/client/Client.kt index b7151416..3ba493b4 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/Client.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/Client.kt @@ -16,7 +16,7 @@ class Client( @ManyToOne @JoinColumn(name = "user_id", nullable = false) val createdBy: User -): BaseIdEntity(){ +): BaseIdEntity() { fun update(clientUpdateReqDto: ClientUpdateReqDto){ this.redirectUri = clientUpdateReqDto.redirectUri this.serviceName = clientUpdateReqDto.serviceName diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt index 609f5461..8d6a1f13 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt @@ -10,12 +10,7 @@ class GetAllClientsService( private val clientRepository: ClientRepository, private val currentUserUtil: CurrentUserUtil, ){ - fun execute():List{ - val findAllByCreatedBy = clientRepository.findAllByCreatedBy(currentUserUtil.getCurrentUser()) - val list = mutableListOf() - findAllByCreatedBy.forEach { - list.add(ClientAllResDto(it)) - } - return list - } + fun execute(): List = + clientRepository.findAllByCreatedBy(currentUserUtil.getCurrentUser()) + .map { ClientAllResDto(it) } } \ No newline at end of file From 654bb25f684ddfa69a722f69c6690fb9cece6ada Mon Sep 17 00:00:00 2001 From: jeayoung Date: Wed, 21 Sep 2022 16:43:35 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=EB=A6=AC=ED=8E=99=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...{MemberNotSameException.kt => ClientNotFindException.kt} | 3 ++- .../msg/gauth/domain/client/repository/ClientRepository.kt | 2 +- .../msg/gauth/domain/client/services/GetOneClientService.kt | 6 ++---- .../gauth/domain/client/services/RegisterClientService.kt | 3 +-- .../msg/gauth/domain/client/services/UpdateClientService.kt | 6 ++---- src/main/kotlin/com/msg/gauth/global/exception/ErrorCode.kt | 1 + 6 files changed, 9 insertions(+), 12 deletions(-) rename src/main/kotlin/com/msg/gauth/domain/client/exception/{MemberNotSameException.kt => ClientNotFindException.kt} (67%) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/exception/MemberNotSameException.kt b/src/main/kotlin/com/msg/gauth/domain/client/exception/ClientNotFindException.kt similarity index 67% rename from src/main/kotlin/com/msg/gauth/domain/client/exception/MemberNotSameException.kt rename to src/main/kotlin/com/msg/gauth/domain/client/exception/ClientNotFindException.kt index c7f025d9..5814565c 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/exception/MemberNotSameException.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/exception/ClientNotFindException.kt @@ -3,4 +3,5 @@ package com.msg.gauth.domain.client.exception import com.msg.gauth.global.exception.ErrorCode import com.msg.gauth.global.exception.exceptions.BasicException -class UserNotSameException: BasicException(ErrorCode.USER_NOT_SAME){} \ No newline at end of file +class ClientNotFindException: BasicException(ErrorCode.CLIENT_NOT_FOUND) { +} \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/repository/ClientRepository.kt b/src/main/kotlin/com/msg/gauth/domain/client/repository/ClientRepository.kt index 63b06a07..60197dce 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/repository/ClientRepository.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/repository/ClientRepository.kt @@ -6,5 +6,5 @@ import org.springframework.data.jpa.repository.JpaRepository interface ClientRepository: JpaRepository { fun findAllByCreatedBy(createdBy: User): List - fun findClientByClientId(clientId: String): Client? + fun findByClientIdAndCreatedBy(clientId: String, createdBy: User): Client? } \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt index da9d658a..d41e1ab9 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt @@ -1,6 +1,6 @@ package com.msg.gauth.domain.client.services -import com.msg.gauth.domain.client.exception.UserNotSameException +import com.msg.gauth.domain.client.exception.ClientNotFindException import com.msg.gauth.domain.client.persentation.dto.response.ClientOneResDto import com.msg.gauth.domain.client.repository.ClientRepository import com.msg.gauth.global.util.CurrentUserUtil @@ -12,9 +12,7 @@ class GetOneClientService( private val currentUserUtil: CurrentUserUtil, ){ fun execute(clientId: String): ClientOneResDto{ - val client = clientRepository.findClientByClientId(clientId)!! - if(client.createdBy != currentUserUtil.getCurrentUser()) - throw UserNotSameException() + val client = clientRepository.findByClientIdAndCreatedBy(clientId, currentUserUtil.getCurrentUser()) ?: throw ClientNotFindException() return ClientOneResDto(client) } } \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt index 0f2568f0..6671eaa2 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt @@ -17,7 +17,6 @@ class RegisterClientService( val clientId = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID().toString().replace("-", "") val user = currentUserUtil.getCurrentUser() val client = clientRegisterDto.toEntity(user, clientSecret, clientId) - clientRepository.save(client) - return ClientRegisterResDto(client) + return ClientRegisterResDto(clientRepository.save(client)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt index 1425cd2f..7ade7c0a 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt @@ -1,6 +1,6 @@ package com.msg.gauth.domain.client.services -import com.msg.gauth.domain.client.exception.UserNotSameException +import com.msg.gauth.domain.client.exception.ClientNotFindException import com.msg.gauth.domain.client.persentation.dto.request.ClientUpdateReqDto import com.msg.gauth.domain.client.repository.ClientRepository import com.msg.gauth.global.util.CurrentUserUtil @@ -14,9 +14,7 @@ class UpdateClientService( ){ @Transactional fun updateClient(clientId: String, clientUpdateReqDto: ClientUpdateReqDto){ - val client = clientRepository.findClientByClientId(clientId)!! - if(client.createdBy != currentUserUtil.getCurrentUser()) - throw UserNotSameException() + val client = clientRepository.findByClientIdAndCreatedBy(clientId, currentUserUtil.getCurrentUser()) ?: throw ClientNotFindException() client.update(clientUpdateReqDto) } } \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/global/exception/ErrorCode.kt b/src/main/kotlin/com/msg/gauth/global/exception/ErrorCode.kt index 6458fa80..aad611f8 100644 --- a/src/main/kotlin/com/msg/gauth/global/exception/ErrorCode.kt +++ b/src/main/kotlin/com/msg/gauth/global/exception/ErrorCode.kt @@ -18,6 +18,7 @@ enum class ErrorCode( NOT_FOUND("리소스를 찾을수 없음", 404), USER_NOT_FOUND("해당 유저를 찾을 수 없습니다.", 404), + CLIENT_NOT_FOUND("해당 클라이언트를 찾을 수 없습니다.", 404), DUPLICATE_EMAIL("중복되는 이메일입니다.", 409), From 60c161b036b98ebd204034964b9cd96a0cc00a15 Mon Sep 17 00:00:00 2001 From: jeayoung Date: Wed, 21 Sep 2022 17:41:28 +0900 Subject: [PATCH 08/10] =?UTF-8?q?=EB=A6=AC=ED=8E=99=ED=86=A0=EB=A7=812?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gauth/domain/client/exception/ClientNotFindException.kt | 3 +-- .../gauth/domain/client/persentation/ClientController.kt | 4 ++-- .../gauth/domain/client/services/GetAllClientsService.kt | 2 ++ .../msg/gauth/domain/client/services/GetOneClientService.kt | 2 ++ .../gauth/domain/client/services/RegisterClientService.kt | 6 ++++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/exception/ClientNotFindException.kt b/src/main/kotlin/com/msg/gauth/domain/client/exception/ClientNotFindException.kt index 5814565c..bc73572f 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/exception/ClientNotFindException.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/exception/ClientNotFindException.kt @@ -3,5 +3,4 @@ package com.msg.gauth.domain.client.exception import com.msg.gauth.global.exception.ErrorCode import com.msg.gauth.global.exception.exceptions.BasicException -class ClientNotFindException: BasicException(ErrorCode.CLIENT_NOT_FOUND) { -} \ No newline at end of file +class ClientNotFindException: BasicException(ErrorCode.CLIENT_NOT_FOUND) \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt index ac1a25bb..b47b8ddd 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt @@ -34,13 +34,13 @@ class ClientController( } @GetMapping - fun getAllClients(): ResponseEntity>{ + fun getMyAllClients(): ResponseEntity>{ val result = getAllClientsService.execute() return ResponseEntity.ok(result) } @GetMapping("/{id}") - fun getOneClient(@PathVariable id:String): ResponseEntity{ + fun getMyOneClient(@PathVariable id:String): ResponseEntity{ val clientOneResDto = getOneClientService.execute(id) return ResponseEntity.ok(clientOneResDto) } diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt index 8d6a1f13..0774381a 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt @@ -4,8 +4,10 @@ import com.msg.gauth.domain.client.persentation.dto.response.ClientAllResDto import com.msg.gauth.domain.client.repository.ClientRepository import com.msg.gauth.global.util.CurrentUserUtil import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional @Service +@Transactional(readOnly = true) class GetAllClientsService( private val clientRepository: ClientRepository, private val currentUserUtil: CurrentUserUtil, diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt index d41e1ab9..f88d45c0 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt @@ -5,8 +5,10 @@ import com.msg.gauth.domain.client.persentation.dto.response.ClientOneResDto import com.msg.gauth.domain.client.repository.ClientRepository import com.msg.gauth.global.util.CurrentUserUtil import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional @Service +@Transactional(readOnly = true) class GetOneClientService( private val clientRepository: ClientRepository, private val currentUserUtil: CurrentUserUtil, diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt index 6671eaa2..7279f6fa 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt @@ -13,10 +13,12 @@ class RegisterClientService( private val currentUserUtil: CurrentUserUtil, ){ fun execute(clientRegisterDto: ClientRegisterReqDto): ClientRegisterResDto { - val clientSecret = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID().toString().replace("-", "") - val clientId = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID().toString().replace("-", "") + val clientSecret = createUUID() + val clientId = createUUID() val user = currentUserUtil.getCurrentUser() val client = clientRegisterDto.toEntity(user, clientSecret, clientId) return ClientRegisterResDto(clientRepository.save(client)) } + + private fun createUUID() = (UUID.randomUUID().toString() + UUID.randomUUID().toString()).replace("-", "") } \ No newline at end of file From 9aaa560737eb104d140db7ccd13f38ab55a08ca0 Mon Sep 17 00:00:00 2001 From: jeayoung Date: Wed, 21 Sep 2022 17:50:46 +0900 Subject: [PATCH 09/10] =?UTF-8?q?=EC=95=84=EC=9E=87=20=EC=B5=9C=ED=98=95?= =?UTF-8?q?=EC=9A=B0=20=EC=82=AC=EC=86=8C=ED=95=9C=EA=B1=B4=EB=8D=B0....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msg/gauth/domain/client/persentation/ClientController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt index b47b8ddd..362c8d0e 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt @@ -34,7 +34,7 @@ class ClientController( } @GetMapping - fun getMyAllClients(): ResponseEntity>{ + fun getMyAllClients(): ResponseEntity>{ val result = getAllClientsService.execute() return ResponseEntity.ok(result) } From e55a89b09852345c0c154aed63a28c8a176b4349 Mon Sep 17 00:00:00 2001 From: jeayoung Date: Wed, 21 Sep 2022 18:16:20 +0900 Subject: [PATCH 10/10] =?UTF-8?q?=EB=9D=84=EC=96=B4=EC=93=B0=EA=B8=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=A6=AC=ED=8E=99=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gauth/domain/client/persentation/ClientController.kt | 8 ++++---- .../client/persentation/dto/response/ClientAllResDto.kt | 2 +- .../gauth/domain/client/services/GetAllClientsService.kt | 2 +- .../gauth/domain/client/services/GetOneClientService.kt | 2 +- .../gauth/domain/client/services/RegisterClientService.kt | 2 +- .../gauth/domain/client/services/UpdateClientService.kt | 2 +- .../kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt | 7 ++++--- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt index 362c8d0e..e84b7123 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/ClientController.kt @@ -25,7 +25,7 @@ class ClientController( private val updateClientService: UpdateClientService, private val getOneClientService: GetOneClientService, private val registerClientService: RegisterClientService, -){ +) { @PostMapping fun registerClient(@RequestBody clientRegisterReqDto: ClientRegisterReqDto):ResponseEntity{ @@ -40,14 +40,14 @@ class ClientController( } @GetMapping("/{id}") - fun getMyOneClient(@PathVariable id:String): ResponseEntity{ + fun getMyOneClient(@PathVariable id: String): ResponseEntity{ val clientOneResDto = getOneClientService.execute(id) return ResponseEntity.ok(clientOneResDto) } @PatchMapping("/{id}") - fun updateClient(@PathVariable id:String, @RequestBody clientUpdateDto: ClientUpdateReqDto): ResponseEntity{ + fun updateClient(@PathVariable id: String, @RequestBody clientUpdateDto: ClientUpdateReqDto): ResponseEntity{ updateClientService.updateClient(id, clientUpdateDto) - return ResponseEntity.ok().build() + return ResponseEntity.noContent().build() } } \ No newline at end of file diff --git a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt index c78952ba..371599cc 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/persentation/dto/response/ClientAllResDto.kt @@ -7,7 +7,7 @@ data class ClientAllResDto( val serviceName: String, val serviceUri: String, ) { - constructor(client:Client): this( + constructor(client: Client): this( clientId = client.clientId, serviceName = client.serviceName, serviceUri = client.serviceUri, diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt index 0774381a..d5dbf399 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetAllClientsService.kt @@ -11,7 +11,7 @@ import org.springframework.transaction.annotation.Transactional class GetAllClientsService( private val clientRepository: ClientRepository, private val currentUserUtil: CurrentUserUtil, -){ +) { fun execute(): List = clientRepository.findAllByCreatedBy(currentUserUtil.getCurrentUser()) .map { ClientAllResDto(it) } diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt index f88d45c0..d89e3732 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/GetOneClientService.kt @@ -12,7 +12,7 @@ import org.springframework.transaction.annotation.Transactional class GetOneClientService( private val clientRepository: ClientRepository, private val currentUserUtil: CurrentUserUtil, -){ +) { fun execute(clientId: String): ClientOneResDto{ val client = clientRepository.findByClientIdAndCreatedBy(clientId, currentUserUtil.getCurrentUser()) ?: throw ClientNotFindException() return ClientOneResDto(client) diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt index 7279f6fa..9c03e7eb 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/RegisterClientService.kt @@ -11,7 +11,7 @@ import java.util.UUID class RegisterClientService( private val clientRepository: ClientRepository, private val currentUserUtil: CurrentUserUtil, -){ +) { fun execute(clientRegisterDto: ClientRegisterReqDto): ClientRegisterResDto { val clientSecret = createUUID() val clientId = createUUID() diff --git a/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt b/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt index 7ade7c0a..892371d1 100644 --- a/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt +++ b/src/main/kotlin/com/msg/gauth/domain/client/services/UpdateClientService.kt @@ -11,7 +11,7 @@ import org.springframework.transaction.annotation.Transactional class UpdateClientService( private val clientRepository: ClientRepository, private val currentUserUtil: CurrentUserUtil, -){ +) { @Transactional fun updateClient(clientId: String, clientUpdateReqDto: ClientUpdateReqDto){ val client = clientRepository.findByClientIdAndCreatedBy(clientId, currentUserUtil.getCurrentUser()) ?: throw ClientNotFindException() diff --git a/src/main/kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt b/src/main/kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt index 83cf03d4..0601681f 100644 --- a/src/main/kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt +++ b/src/main/kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt @@ -1,6 +1,7 @@ package com.msg.gauth.global.util import com.msg.gauth.domain.user.User +import com.msg.gauth.domain.user.exception.UserNotFoundException import com.msg.gauth.domain.user.repository.UserRepository import com.msg.gauth.global.security.auth.AuthDetails import org.springframework.security.core.context.SecurityContextHolder @@ -10,8 +11,8 @@ import org.springframework.stereotype.Component @Component class CurrentUserUtil( private val userRepository: UserRepository -){ - private fun getCurrentEmail():String{ +) { + private fun getCurrentEmail(): String{ val principal = SecurityContextHolder.getContext().authentication.principal val email: String = if(principal is UserDetails){ @@ -23,5 +24,5 @@ class CurrentUserUtil( } fun getCurrentUser(): User = - userRepository.findByEmail(getCurrentEmail())!! + userRepository.findByEmail(getCurrentEmail())?: throw UserNotFoundException() } \ No newline at end of file