Skip to content

Commit

Permalink
🌟 ::
Browse files Browse the repository at this point in the history
  • Loading branch information
gurdl0525 committed Nov 19, 2023
1 parent 5fa3352 commit b6a169c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class AnalysisController(private val analysisService: AnalysisService) {
@GetMapping("/test")
fun test() = analysisService.test()

@GetMapping("/mood-change")
@GetMapping("/mood")
fun getMoodChange() = analysisService.getMoodeChange()

@GetMapping("/monthly-change")
@GetMapping("/monthly")
fun getMonthlyChange() = analysisService.getMonthlyChange()
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class AnalysisServiceImpl(

val response = moodCount(diaries)

val sigma = getSigma(response)
val sigma = getSigma(response).toInt()

val message = if (sigma < 10) {
"현재 감정은 완만한 편이에요!"
} else {
"표준편차는 ${sigma.toInt()} 이에요! (10이하가 완만하고 안정적인편)"
"표준편차는 $sigma 이에요! (10이하가 완만하고 안정적인편)"
}

return MonthlyChangeResponse.of(diaries.map { it.toResponse() }.toMutableList(), message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.onui.domain.auth.presentation

import com.example.onui.domain.auth.presentation.dto.request.OAuthSignInWithAndroidRequest
import com.example.onui.domain.auth.presentation.dto.response.TokenResponse
import com.example.onui.domain.auth.service.AppleAuthService
import com.example.onui.domain.auth.service.AuthService
Expand All @@ -11,6 +12,7 @@ import org.springframework.http.HttpStatus
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import java.util.*
import javax.validation.Valid

@Validated
@RestController
Expand All @@ -29,6 +31,13 @@ class AuthController(
token: String
): TokenResponse = googleAuthService.oauthGoogleSignIn(token)

@PostMapping("/google/v2")
@ResponseStatus(HttpStatus.CREATED)
fun oauthSignInWithAndroid(
@RequestBody @Valid
req: OAuthSignInWithAndroidRequest
): TokenResponse = googleAuthService.oauthGoogleSignInWith(req)

@PutMapping("/re-issue")
fun reissue(
@RequestParam("token", required = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.onui.domain.auth.presentation.dto.request

import javax.validation.constraints.NotBlank

data class OAuthSignInWithAndroidRequest (

@field:NotBlank
val sub: String?,

@field:NotBlank
val name: String?
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.example.onui.domain.auth.service

import com.example.onui.domain.auth.presentation.dto.request.OAuthSignInWithAndroidRequest
import com.example.onui.domain.auth.presentation.dto.response.TokenResponse

interface GoogleAuthService {

fun oauthGoogleSignIn(token: String): TokenResponse

fun oauthGoogleSignInWith(req: OAuthSignInWithAndroidRequest): TokenResponse
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.onui.domain.auth.service

import com.example.onui.domain.auth.presentation.dto.request.OAuthSignInWithAndroidRequest
import com.example.onui.domain.auth.presentation.dto.response.TokenResponse
import com.example.onui.domain.auth.repository.RefreshTokenRepository
import com.example.onui.domain.mission.entity.MissionType
Expand Down Expand Up @@ -68,4 +69,26 @@ class GoogleAuthServiceImpl(

return tokenResponse
}

@Transactional
override fun oauthGoogleSignInWith(req: OAuthSignInWithAndroidRequest): TokenResponse {
refreshTokenRepository.findBySub(req.sub!!)?.let {
refreshTokenRepository.delete(it)
}

val tokenResponse = tokenProvider.receiveToken(req.sub)

userRepository.findBySub(req.sub) ?: userRepository.save(
User(
req.sub,
req.name!!,
DEFAULT,
themeRepository.findByIdOrNull(DEFAULT_ID)!!
)
).apply {
missionService.assignMission(this, missionRepository.findAllByMissionType(MissionType.RANDOM))
}

return tokenResponse
}
}

0 comments on commit b6a169c

Please sign in to comment.