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

๐Ÿ”€ :: Client ๋„๋ฉ”์ธ refactoring #29

Merged
merged 1 commit into from
Oct 9, 2022
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
Expand Up @@ -2,11 +2,11 @@ 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.ClientOneResDto
import com.msg.gauth.domain.client.persentation.dto.response.SingleClientResDto
import com.msg.gauth.domain.client.persentation.dto.response.ClientDetailResDto
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.GetMyAllClientsService
import com.msg.gauth.domain.client.services.GetMyDetailClientService
import com.msg.gauth.domain.client.services.RegisterClientService
import com.msg.gauth.domain.client.services.UpdateClientService
import org.springframework.http.ResponseEntity
Expand All @@ -21,27 +21,27 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/client")
class ClientController(
private val getAllClientsService: GetAllClientsService,
private val getMyAllClientsService: GetMyAllClientsService,
private val updateClientService: UpdateClientService,
private val getOneClientService: GetOneClientService,
private val getMyDetailClientService: GetMyDetailClientService,
private val registerClientService: RegisterClientService,
) {

@PostMapping
fun registerClient(@RequestBody clientRegisterReqDto: ClientRegisterReqDto):ResponseEntity<ClientRegisterResDto>{
fun registerClient(@RequestBody clientRegisterReqDto: ClientRegisterReqDto): ResponseEntity<ClientRegisterResDto>{
val clientRegisterResDto = registerClientService.execute(clientRegisterReqDto)
return ResponseEntity.ok(clientRegisterResDto)
}

@GetMapping
fun getMyAllClients(): ResponseEntity<List<ClientOneResDto>>{
val result = getAllClientsService.execute()
fun getMyAllClients(): ResponseEntity<List<SingleClientResDto>>{
val result = getMyAllClientsService.execute()
return ResponseEntity.ok(result)
}

@GetMapping("/{id}")
fun getMyOneClient(@PathVariable id: Long): ResponseEntity<ClientDetailResDto>{
val clientOneResDto = getOneClientService.execute(id)
fun getMyDetailClient(@PathVariable id: Long): ResponseEntity<ClientDetailResDto>{
val clientOneResDto = getMyDetailClientService.execute(id)
return ResponseEntity.ok(clientOneResDto)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.msg.gauth.domain.client.persentation.dto.response

import com.msg.gauth.domain.client.Client

data class ClientOneResDto(
data class SingleClientResDto(
val clientId: String,
val serviceName: String,
val serviceUri: String,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.msg.gauth.domain.client.services

import com.msg.gauth.domain.client.persentation.dto.response.SingleClientResDto
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
class GetMyAllClientsService(
private val clientRepository: ClientRepository,
private val userUtil: UserUtil,
) {
fun execute(): List<SingleClientResDto> =
clientRepository.findAllByCreatedBy(userUtil.fetchCurrentUser())
.map { SingleClientResDto(it) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package com.msg.gauth.domain.client.services
import com.msg.gauth.domain.client.exception.ClientNotFindException
import com.msg.gauth.domain.client.persentation.dto.response.ClientDetailResDto
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.global.util.CurrentUserUtil
import com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
class GetOneClientService(
class GetMyDetailClientService(
private val clientRepository: ClientRepository,
private val currentUserUtil: CurrentUserUtil,
private val userUtil: UserUtil
) {
fun execute(id: Long): ClientDetailResDto{
val client = clientRepository.findByIdAndCreatedBy(id, currentUserUtil.getCurrentUser()) ?: throw ClientNotFindException()
val client = clientRepository.findByIdAndCreatedBy(id, userUtil.fetchCurrentUser()) ?: throw ClientNotFindException()
return ClientDetailResDto(client)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ 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 com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.UUID

@Service
class RegisterClientService(
private val clientRepository: ClientRepository,
private val currentUserUtil: CurrentUserUtil,
private val userUtil: UserUtil
) {
@Transactional
fun execute(clientRegisterDto: ClientRegisterReqDto): ClientRegisterResDto {
val clientSecret = createUUID()
val clientId = createUUID()
val user = currentUserUtil.getCurrentUser()
val user = userUtil.fetchCurrentUser()
val client = clientRegisterDto.toEntity(user, clientSecret, clientId)
return ClientRegisterResDto(clientRepository.save(client))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package com.msg.gauth.domain.client.services
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
import com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class UpdateClientService(
private val clientRepository: ClientRepository,
private val currentUserUtil: CurrentUserUtil,
private val userUtil: UserUtil
) {
@Transactional
fun updateClient(id: Long, clientUpdateReqDto: ClientUpdateReqDto){
val client = clientRepository.findByIdAndCreatedBy(id, currentUserUtil.getCurrentUser()) ?: throw ClientNotFindException()
val client = clientRepository.findByIdAndCreatedBy(id, userUtil.fetchCurrentUser()) ?: throw ClientNotFindException()
client.update(clientUpdateReqDto)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class SecurityConfig(
.antMatchers(HttpMethod.POST, "/email").permitAll()
.antMatchers(HttpMethod.GET, "/email/authentication").permitAll()

// Client
.antMatchers(HttpMethod.GET, "/client").authenticated()
.antMatchers(HttpMethod.POST, "/client").authenticated()
.antMatchers(HttpMethod.GET, "/client/{id}").authenticated()
.antMatchers(HttpMethod.PATCH, "/client/{id}").authenticated()

.anyRequest().denyAll()
.and()
.exceptionHandling()
Expand Down
28 changes: 0 additions & 28 deletions src/main/kotlin/com/msg/gauth/global/util/CurrentUserUtil.kt

This file was deleted.