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

서비스 이름을 가져오는 API추가 #40

Merged
merged 2 commits into from
Nov 26, 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 @@ -4,12 +4,7 @@ import com.msg.gauth.domain.auth.presentation.dto.request.SignUpDto
import com.msg.gauth.domain.auth.presentation.dto.request.SigninRequestDto
import com.msg.gauth.domain.auth.presentation.dto.response.RefreshResponseDto
import com.msg.gauth.domain.auth.presentation.dto.response.SigninResponseDto
import com.msg.gauth.domain.auth.services.LogoutService
import com.msg.gauth.domain.auth.services.RefreshService
import com.msg.gauth.domain.auth.services.SignUpService
import com.msg.gauth.domain.auth.services.SignInService
import com.msg.gauth.global.annotation.logger.log4k
import org.slf4j.Logger
import com.msg.gauth.domain.auth.services.*
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
Expand All @@ -21,7 +16,7 @@ class AuthController(
private val refreshService: RefreshService,
private val logoutService: LogoutService,
private val signInService: SignInService,
private val signUpService: SignUpService
private val signUpService: SignUpService,
) {
@PatchMapping
fun refresh(@RequestHeader("RefreshToken") refreshToken: String): ResponseEntity<RefreshResponseDto> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ package com.msg.gauth.domain.oauth.presentation
import com.msg.gauth.domain.oauth.presentation.dto.request.OauthCodeRequestDto
import com.msg.gauth.domain.oauth.presentation.dto.request.UserTokenRequestDto
import com.msg.gauth.domain.oauth.presentation.dto.response.OauthCodeResponseDto
import com.msg.gauth.domain.oauth.presentation.dto.response.ServiceNameResponseDto
import com.msg.gauth.domain.oauth.presentation.dto.response.UserTokenResponseDto
import com.msg.gauth.domain.oauth.services.GetServiceNameService
import com.msg.gauth.domain.oauth.services.OauthCodeService
import com.msg.gauth.domain.oauth.services.OauthRefreshService
import com.msg.gauth.domain.oauth.services.OauthTokenService
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*
import javax.validation.Valid

@RestController
@RequestMapping("/oauth")
class OauthController(
val oauthCodeService: OauthCodeService,
val oauthTokenService: OauthTokenService,
val oauthRefreshService: OauthRefreshService,
private val oauthCodeService: OauthCodeService,
private val oauthTokenService: OauthTokenService,
private val oauthRefreshService: OauthRefreshService,
private val getServiceNameService: GetServiceNameService,
){
@PostMapping("/code")
fun generateOauthCode(@Valid @RequestBody oauthCodeRequestDto : OauthCodeRequestDto): ResponseEntity<OauthCodeResponseDto> =
Expand All @@ -33,4 +32,8 @@ class OauthController(
@PostMapping("/refresh")
fun refreshOauthToken(@RequestHeader refreshToken: String): ResponseEntity<UserTokenResponseDto> =
ResponseEntity.ok(oauthRefreshService.execute(refreshToken))

@GetMapping("/{clientId}")
fun getServiceName(@PathVariable clientId: String): ResponseEntity<ServiceNameResponseDto> =
ResponseEntity.ok(getServiceNameService.execute(clientId))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.msg.gauth.domain.oauth.presentation.dto.response

class ServiceNameResponseDto(
val serviceName: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.msg.gauth.domain.oauth.services

import com.msg.gauth.domain.oauth.presentation.dto.response.ServiceNameResponseDto
import com.msg.gauth.domain.client.exception.ClientNotFindException
import com.msg.gauth.domain.client.repository.ClientRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class GetServiceNameService(
private val clientRepository: ClientRepository,
){
@Transactional(readOnly = true, rollbackFor = [Exception::class])
fun execute(clientId: String): ServiceNameResponseDto {
val client = (clientRepository.findByClientId(clientId)
?: throw ClientNotFindException())
return ServiceNameResponseDto(
client.serviceName
)
}
}