Skip to content

Commit

Permalink
[FEATURE] 인증 과정 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
Goraniieee committed Aug 24, 2023
1 parent a3a8817 commit 2706489
Show file tree
Hide file tree
Showing 96 changed files with 2,460 additions and 2,070 deletions.
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")

// Database
runtimeOnly("com.mysql:mysql-connector-j")
Expand Down Expand Up @@ -91,6 +91,10 @@ tasks {
inputs.dir(snippetsDir)
configurations(asciidoctorExt.name)
dependsOn(test)
baseDirFollowsSourceFile()
sources {
include("**/index.adoc")
}
doFirst {
delete("src/main/resources/static/docs")
}
Expand Down
52 changes: 0 additions & 52 deletions src/docs/asciidoc/Letter-API.adoc

This file was deleted.

17 changes: 0 additions & 17 deletions src/docs/asciidoc/User-API.adoc

This file was deleted.

27 changes: 27 additions & 0 deletions src/docs/asciidoc/api-auth.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[Auth-API]]
== 인증 관련 API

[[GGZZ-Signup]]
=== 끄적 회원가입

operation::auth/ggzz-signup[snippets='http-request,request-fields,http-response']

[[GGZZ-Signin]]
=== 끄적 로그인

operation::auth/ggzz-signup[snippets='http-request,request-fields,http-response']

[[GGZZ-Refresh]]
=== JWT 토큰 재발급

operation::auth/ggzz-refresh[snippets='http-request,request-headers,http-response']

[[Provider-Signup]]
=== 소셜 회원가입

operation::auth/provider-signup[snippets='http-request,request-fields,http-response']

[[Provider-Signin]]
=== 소셜 로그인

operation::auth/provider-signin[snippets='http-request,request-fields,http-response']
13 changes: 13 additions & 0 deletions src/docs/asciidoc/api-letter-interaction.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[Letter-Interaction-API]]
== 끄적 상호작용 API

[[Letter-Interaction-Like]]
=== 끄적 좋아요하기

operation::letter-interaction/like[snippets='http-request,path-parameters,http-response']

[[Letter-Interaction-Delete-Like]]
=== 끄적 좋아요 취소하기

operation::letter-interaction/delete-like[snippets='http-request,path-parameters,http-response']

7 changes: 7 additions & 0 deletions src/docs/asciidoc/api-letter-me.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[My-Letter-API]]
== 내 끄적 API

[[My-Letter-List]]
=== 내 끄적 목록 조회하기

operation::my-letter/list[snippets='http-request,http-response']
22 changes: 22 additions & 0 deletions src/docs/asciidoc/api-letter.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[[Letter-API]]
== 끄적 기본 API

[[Letter-Create]]
=== 끄적 생성하기

operation::letter/create[snippets='http-request,request-parts,http-response']

[[Letter-List]]
=== 끄적 목록 가져오기

operation::letter/list[snippets='http-request,query-parameters,http-response']

[[Letter-Detail]]
=== 끄적 상세 가져오기

operation::letter/detail[snippets='http-request,query-parameters,http-response']

[[Letter-Delete]]
=== 끄적 삭제하기

operation::letter/delete[snippets='http-request,path-parameters,http-response']
7 changes: 7 additions & 0 deletions src/docs/asciidoc/api-user.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[User-API]]
== 회원 API

[[User-Me]]
=== 내 정보 조회하기

operation::user/me[snippets='http-request,http-response']
10 changes: 6 additions & 4 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
:includedir: src/docs/asciidoc

= 끄적 API Documentation
:doctype: book
:icons: font
Expand All @@ -8,7 +6,11 @@
:toclevels: 2
:sectlinks:

include::{includedir}/User-API.adoc[]
include::api-auth.adoc[]

include::api-letter.adoc[]
include::api-letter-interaction.adoc[]
include::api-letter-me.adoc[]

include::{includedir}/Letter-API.adoc[]
include::api-user.adoc[]

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.wafflestudio.ggzz.domain.auth.controller

import com.wafflestudio.ggzz.domain.auth.dto.GgzzAuthResponse
import com.wafflestudio.ggzz.domain.auth.dto.GgzzLoginRequest
import com.wafflestudio.ggzz.domain.auth.dto.GgzzSignupRequest
import com.wafflestudio.ggzz.domain.auth.dto.ProviderLoginRequest
import com.wafflestudio.ggzz.domain.auth.exception.InvalidTokenException
import com.wafflestudio.ggzz.domain.auth.service.AuthService
import com.wafflestudio.ggzz.global.common.utils.JwtUtils
import jakarta.servlet.http.HttpServletRequest
import jakarta.validation.Valid
import org.springframework.http.HttpHeaders
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("/api/v1/auth")
class AuthController(
private val authService: AuthService
) {

@PostMapping("/ggzz/signup")
fun signup(@RequestBody @Valid request: GgzzSignupRequest): GgzzAuthResponse {
return authService.signup(request)
}

@PostMapping("/ggzz/login")
fun login(@RequestBody @Valid request: GgzzLoginRequest): GgzzAuthResponse {
return authService.login(request)
}

@PostMapping("/ggzz/refresh")
fun refresh(request: HttpServletRequest): GgzzAuthResponse {
request.getHeader(HttpHeaders.AUTHORIZATION)?.let {
if (JwtUtils.isBearerToken(it))
return authService.refresh(it)

throw InvalidTokenException()
} ?: throw InvalidTokenException()
}

@PostMapping("/provider/signup")
fun signupWithProvider(@RequestBody @Valid request: ProviderLoginRequest): GgzzAuthResponse {
if (JwtUtils.isBearerToken(request.accessToken!!))
return authService.signupWithProvider(request)

throw InvalidTokenException()
}

@PostMapping("/provider/login")
fun loginWithProvider(@RequestBody @Valid request: ProviderLoginRequest): GgzzAuthResponse {
if (JwtUtils.isBearerToken(request.accessToken!!))
return authService.loginWithProvider(request)

throw InvalidTokenException()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wafflestudio.ggzz.domain.auth.dto

import com.wafflestudio.ggzz.domain.user.dto.UserBasicInfoResponse

data class GgzzAuthResponse(
val accessToken: String,
val user: UserBasicInfoResponse?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wafflestudio.ggzz.domain.auth.dto

import jakarta.validation.constraints.NotBlank

data class GgzzLoginRequest(
@field: NotBlank
val ggzzId: String?,
@field: NotBlank
val password: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.wafflestudio.ggzz.domain.auth.dto

import jakarta.validation.constraints.NotBlank

data class GgzzSignupRequest(
@field: NotBlank
val ggzzId: String?,
@field: NotBlank
val username: String?,
@field: NotBlank
val password: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.wafflestudio.ggzz.domain.auth.dto

import com.wafflestudio.ggzz.domain.auth.model.Provider
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull

data class ProviderLoginRequest(
@field:NotBlank
val accessToken: String?,
@field:NotNull
val provider: Provider?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wafflestudio.ggzz.domain.auth.exception

import com.wafflestudio.ggzz.global.common.exception.CustomException.ConflictException
import com.wafflestudio.ggzz.global.common.exception.ErrorType.Conflict.DUPLICATE_FIREBASE_ID

class DuplicateFirebaseIdException(id: String): ConflictException(DUPLICATE_FIREBASE_ID, "Firebase ID '$id' exists.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wafflestudio.ggzz.domain.auth.exception

import com.wafflestudio.ggzz.global.common.exception.CustomException.ConflictException
import com.wafflestudio.ggzz.global.common.exception.ErrorType.Conflict.DUPLICATE_ID

class DuplicateGgzzIdException(id: String): ConflictException(DUPLICATE_ID, "ID '$id' exists.")
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wafflestudio.ggzz.domain.user.exception
package com.wafflestudio.ggzz.domain.auth.exception

import com.wafflestudio.ggzz.global.common.exception.CustomException.ConflictException
import com.wafflestudio.ggzz.global.common.exception.ErrorType.Conflict.USERNAME_CONFLICT
import com.wafflestudio.ggzz.global.common.exception.ErrorType.Conflict.DUPLICATE_USERNAME

class DuplicateUsernameException(username: String): ConflictException(USERNAME_CONFLICT, "Username '$username' exists.")
class DuplicateUsernameException(username: String): ConflictException(DUPLICATE_USERNAME, "Username '$username' exists.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wafflestudio.ggzz.domain.auth.exception

import com.wafflestudio.ggzz.domain.auth.model.Provider
import com.wafflestudio.ggzz.global.common.exception.CustomException.BadRequestException
import com.wafflestudio.ggzz.global.common.exception.ErrorType.BadRequest.INVALID_PROVIDER

class InvalidProviderException(provider: Provider): BadRequestException(INVALID_PROVIDER, "Invalid provider: $provider")
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wafflestudio.ggzz.global.error
package com.wafflestudio.ggzz.domain.auth.exception

import com.wafflestudio.ggzz.global.common.exception.CustomException.BadRequestException
import com.wafflestudio.ggzz.global.common.exception.ErrorType.BadRequest.INVALID_TOKEN

class InvalidTokenException(type: String): BadRequestException(INVALID_TOKEN, "The $type token is invalid.")
class InvalidTokenException: BadRequestException(INVALID_TOKEN, "Invalid token.")
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wafflestudio.ggzz.domain.user.exception
package com.wafflestudio.ggzz.domain.auth.exception

import com.wafflestudio.ggzz.global.common.exception.CustomException.UnauthorizedException
import com.wafflestudio.ggzz.global.common.exception.ErrorType.Unauthorized.LOGIN_FAIL

class LoginFailedException: UnauthorizedException(LOGIN_FAIL, "Login is failed")
class LoginFailedException: UnauthorizedException(LOGIN_FAIL, "Login failed")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wafflestudio.ggzz.domain.auth.exception

import com.wafflestudio.ggzz.global.common.exception.CustomException
import com.wafflestudio.ggzz.global.common.exception.ErrorType.Unauthorized.NO_TOKEN

class NoTokenException: CustomException.UnauthorizedException(NO_TOKEN, "Token doesn't exist.")
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wafflestudio.ggzz.global.error
package com.wafflestudio.ggzz.domain.auth.exception

import com.wafflestudio.ggzz.global.common.exception.CustomException
import com.wafflestudio.ggzz.global.common.exception.ErrorType.Forbidden.WRONG_API
Expand Down
Loading

0 comments on commit 2706489

Please sign in to comment.