Skip to content

Commit

Permalink
style: ktlint style 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
GGHDMS committed Mar 21, 2024
1 parent cfdfc6c commit 833cdbe
Show file tree
Hide file tree
Showing 45 changed files with 496 additions and 400 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.7.3"
id("io.spring.dependency-management") version "1.0.15.RELEASE"
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
id("org.jlleitschuh.gradle.ktlint").version("11.0.0")
id("com.google.osdetector") version "1.7.1"
kotlin("jvm") version "1.6.21"
kotlin("plugin.spring") version "1.6.21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class JwtConfig(
private val jwtProvider: JwtProvider,
private val blackTokenService: BlackTokenService,
) : SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity>() {

override fun configure(http: HttpSecurity) {
http.addFilterBefore(
JwtFilter(jwtProvider, blackTokenService),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ class LoggingInterceptor(
val cachingRequest: ContentCachingRequestWrapper = request
val cachingResponse: ContentCachingResponseWrapper = response

val excludedURIs = listOf(
"/logs",
"/v3/api-docs",
"/swagger-resources",
"/swagger-ui",
"/webjars",
"/swagger",
"/favicon",
"/oauth"
)
val excludedURIs =
listOf(
"/logs",
"/v3/api-docs",
"/swagger-resources",
"/swagger-ui",
"/webjars",
"/swagger",
"/favicon",
"/oauth",
)

if (!excludedURIs.any { request.requestURI.startsWith(it) }) {
accessLogRepository.save(
Expand All @@ -51,7 +52,7 @@ class LoggingInterceptor(
requestBody = objectMapper.readTree(cachingRequest.contentAsByteArray).toString(),
responseBody = objectMapper.readTree(cachingResponse.contentAsByteArray).toString(),
createdAt = LocalDateTime.now(),
)
),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.springframework.data.redis.serializer.StringRedisSerializer

@Configuration
class RedisConfig {

@Value("\${spring.redis.host}")
private var redisHost: String = ""

Expand Down
109 changes: 57 additions & 52 deletions src/main/kotlin/com/yourssu/ssudateserver/config/SecurityConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,38 @@ class SecurityConfig(
private val oauthCacheService: OauthCacheService,
private val blackTokenService: BlackTokenService,
) {

@Bean
fun filterChain(
http: HttpSecurity,
oAuth2UserService: OAuth2UserService<OAuth2UserRequest, OAuth2User>,
): SecurityFilterChain = http
.formLogin { it.disable() }
.logout { it.disable() }
.csrf { it.disable() }
.headers { it.frameOptions().disable() }
.cors {}
.sessionManagement { it.sessionCreationPolicy(SessionCreationPolicy.STATELESS) }
.authorizeRequests {
it
.antMatchers("/search/contact", "/users/my").authenticated()
.antMatchers("/register/**", "/v2/api-docs", "/v3/**", "/swagger-resources/**", "/search/**")
.permitAll()
.antMatchers(HttpMethod.GET, "/**").permitAll()
.anyRequest().authenticated()
.and()
.apply(JwtConfig(jwtProvider, blackTokenService))
.and()
.exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint)
}
.oauth2Login {
it.userInfoEndpoint { userInfo ->
userInfo.userService(oAuth2UserService)
): SecurityFilterChain =
http
.formLogin { it.disable() }
.logout { it.disable() }
.csrf { it.disable() }
.headers { it.frameOptions().disable() }
.cors {}
.sessionManagement { it.sessionCreationPolicy(SessionCreationPolicy.STATELESS) }
.authorizeRequests {
it
.antMatchers("/search/contact", "/users/my").authenticated()
.antMatchers("/register/**", "/v2/api-docs", "/v3/**", "/swagger-resources/**", "/search/**")
.permitAll()
.antMatchers(HttpMethod.GET, "/**").permitAll()
.anyRequest().authenticated()
.and()
.apply(JwtConfig(jwtProvider, blackTokenService))
.and()
.exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint)
}
it.successHandler(oAuth2SuccessHandler())
}
.build()
.oauth2Login {
it.userInfoEndpoint { userInfo ->
userInfo.userService(oAuth2UserService)
}
it.successHandler(oAuth2SuccessHandler())
}
.build()

@Bean
fun oAuth2UserService(): OAuth2UserService<OAuth2UserRequest, OAuth2User> =
Expand All @@ -91,40 +91,45 @@ class SecurityConfig(
}

@Bean
fun oAuth2SuccessHandler() = object : SimpleUrlAuthenticationSuccessHandler() {
@Throws(IOException::class, ServletException::class)
override fun onAuthenticationSuccess(
request: HttpServletRequest,
response: HttpServletResponse,
authentication: Authentication,
) {
val oAuth2User = authentication.principal as OAuth2User
fun oAuth2SuccessHandler() =
object : SimpleUrlAuthenticationSuccessHandler() {
@Throws(IOException::class, ServletException::class)
override fun onAuthenticationSuccess(
request: HttpServletRequest,
response: HttpServletResponse,
authentication: Authentication,
) {
val oAuth2User = authentication.principal as OAuth2User

if (oAuth2User.authorities.any { it.authority == "ROLE_GUEST" }) {
val oauthName = oAuth2User.name
if (oAuth2User.authorities.any { it.authority == "ROLE_GUEST" }) {
val oauthName = oAuth2User.name

oauthCacheService.saveOauthName(oauthName)
oauthCacheService.saveOauthName(oauthName)

val targetUrl =
buildRedirectUrl(frontProperties.url + "/kakao-redirect", mapOf("oauthName" to oauthName))
val targetUrl =
buildRedirectUrl(frontProperties.url + "/kakao-redirect", mapOf("oauthName" to oauthName))

redirectStrategy.sendRedirect(request, response, targetUrl)
} else {
val accessToken = jwtGenerator.generateAccessToken(oAuth2User.name)
val refreshToken = jwtGenerator.generateRefreshToken(oAuth2User.name)
redirectStrategy.sendRedirect(request, response, targetUrl)
} else {
val accessToken = jwtGenerator.generateAccessToken(oAuth2User.name)
val refreshToken = jwtGenerator.generateRefreshToken(oAuth2User.name)

refreshTokenService.saveTokenInfo(oauthName = oAuth2User.name, refreshToken = refreshToken)
refreshTokenService.saveTokenInfo(oauthName = oAuth2User.name, refreshToken = refreshToken)

val targetUrl = buildRedirectUrl(
frontProperties.url + "/kakao-redirect",
mapOf("accessToken" to accessToken, "refreshToken" to refreshToken)
)
redirectStrategy.sendRedirect(request, response, targetUrl)
val targetUrl =
buildRedirectUrl(
frontProperties.url + "/kakao-redirect",
mapOf("accessToken" to accessToken, "refreshToken" to refreshToken),
)
redirectStrategy.sendRedirect(request, response, targetUrl)
}
}
}
}

private fun buildRedirectUrl(baseUri: String, queryParams: Map<String, String>): String =
private fun buildRedirectUrl(
baseUri: String,
queryParams: Map<String, String>,
): String =
UriComponentsBuilder.fromUriString(baseUri).apply {
queryParams.forEach { (key, value) -> queryParam(key, value) }
}.build().encode(StandardCharsets.UTF_8).toUriString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import javax.validation.Valid
class SSUDateController(
private val ssuDateService: SSUDateService,
) {

@GetMapping("/search/recent")
fun searchRecent(): List<SearchResponseDto> {
return ssuDateService.recentSearch()
Expand Down Expand Up @@ -55,7 +54,6 @@ class SSUDateController(
contactRequestDto: ContactRequestDto,
@AuthenticationPrincipal userPrincipal: UserPrincipal,
): ContactResponseDto {

return ssuDateService.contact(userPrincipal.name, contactRequestDto.nickName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ import javax.validation.Valid
class UserController(
private val userService: UserService,
) {

@PostMapping("/register/male")
fun registerMale(
@Valid @RequestBody
registerRequestDto: RegisterMaleRequestDto,
): RegisterResponseDto {

if (registerRequestDto.animals == MaleAnimals.ALL) {
throw AllCanNotRegisterException("ALL은 등록불가능 합니다.")
}
Expand Down Expand Up @@ -83,7 +81,9 @@ class UserController(
}

@GetMapping("/users/my")
fun getMyInfo(@AuthenticationPrincipal userPrincipal: UserPrincipal): UserInfoResponseDto {
fun getMyInfo(
@AuthenticationPrincipal userPrincipal: UserPrincipal,
): UserInfoResponseDto {
return userService.getMyInfo(oauthName = userPrincipal.name)
}

Expand All @@ -92,13 +92,12 @@ class UserController(
@RequestBody updateRequestDto: UpdateRequestDto,
@AuthenticationPrincipal userPrincipal: UserPrincipal,
): UpdateResponseDto {

return userService.updateUserInfo(
updateRequestDto.nickName,
updateRequestDto.mbti,
updateRequestDto.introduce,
updateRequestDto.contact,
userPrincipal.name
userPrincipal.name,
)
}

Expand Down
7 changes: 0 additions & 7 deletions src/main/kotlin/com/yourssu/ssudateserver/entity/AccessLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,17 @@ class AccessLog(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,

val ip: String?,

@Column(columnDefinition = "TEXT", name = "os")
val os: String?,

@Column(columnDefinition = "TEXT", name = "request_url")
val requestURL: String,

@Column(name = "method")
val method: String,

@Column(columnDefinition = "TEXT", name = "request_body")
val requestBody: String?,

@Column(columnDefinition = "TEXT", name = "response_body")
val responseBody: String?,

@Column(name = "created_at")
val createdAt: LocalDateTime,
)
4 changes: 0 additions & 4 deletions src/main/kotlin/com/yourssu/ssudateserver/entity/Code.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ class Code(
@field:Id
@field:GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,

@field:Column(name = "from_code")
val fromCode: String,

@field:Column(name = "to_code")
val toCode: String,

@field:Column(name = "created_at")
val createdAt: LocalDateTime,

)
4 changes: 0 additions & 4 deletions src/main/kotlin/com/yourssu/ssudateserver/entity/Follow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ import javax.persistence.Table
@Entity
@Table(name = "follow")
class Follow(

@field:Id
@field:GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,

@field:Column(name = "from_user_id")
val fromUserId: Long,

@field:Column(name = "to_user_id")
val toUserId: Long,

@field:Column(name = "created_at")
val createdAt: LocalDateTime,
)
13 changes: 0 additions & 13 deletions src/main/kotlin/com/yourssu/ssudateserver/entity/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,34 @@ class User(
@field:Id
@field:GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,

@field:Column(name = "animals")
@field:Enumerated(EnumType.STRING)
val animals: Animals,

@field:Column(name = "mbti")
@field:Enumerated(EnumType.STRING)
var mbti: MBTI,

@field:Column(name = "nick_name", unique = true)
var nickName: String,

@field:Column(name = "o_auth_name", unique = true)
val oauthName: String,

@field:Column(name = "introduction", length = 100)
var introduce: String,

@field:Column(name = "contact")
var contact: String,

@field:Column(name = "weight")
var weight: Int = 0,

@field:Column(name = "ticket")
var ticket: Int = 2,

@field:Column(name = "gender")
@field:Enumerated(EnumType.STRING)
val gender: Gender,

@field:Column(name = "role")
@field:Enumerated(EnumType.STRING)
val role: RoleType,

@field:Column(name = "code")
var code: String,

@field:Column(name = "code_input_chance")
var codeInputChance: Int = 1,

@field:Column(name = "created_at")
val createdAt: LocalDateTime,
) {
Expand Down
11 changes: 10 additions & 1 deletion src/main/kotlin/com/yourssu/ssudateserver/enums/Animals.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package com.yourssu.ssudateserver.enums

enum class Animals {
ALL, DOG, CAT, RABBIT, FOX, HAMSTER, BEAR, WOLF, DINO, PUSSUNG
ALL,
DOG,
CAT,
RABBIT,
FOX,
HAMSTER,
BEAR,
WOLF,
DINO,
PUSSUNG,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ import io.swagger.annotations.ApiModel

@ApiModel
enum class FemaleAnimals {
ALL, DOG, CAT, RABBIT, FOX, HAMSTER, PUSSUNG
ALL,
DOG,
CAT,
RABBIT,
FOX,
HAMSTER,
PUSSUNG,
}
3 changes: 2 additions & 1 deletion src/main/kotlin/com/yourssu/ssudateserver/enums/Gender.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yourssu.ssudateserver.enums

enum class Gender {
MALE, FEMALE
MALE,
FEMALE,
}
Loading

0 comments on commit 833cdbe

Please sign in to comment.