From b6a169c3e7e4c23437dcdb06ecda9c26c867e640 Mon Sep 17 00:00:00 2001 From: squall7011 Date: Mon, 20 Nov 2023 08:30:13 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=9F=20::?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/AnalysisController.kt | 4 ++-- .../analysis/service/AnalysisServiceImpl.kt | 4 ++-- .../auth/presentation/AuthController.kt | 9 ++++++++ .../request/OAuthSignInWithAndroidRequest.kt | 12 ++++++++++ .../domain/auth/service/GoogleAuthService.kt | 3 +++ .../auth/service/GoogleAuthServiceImpl.kt | 23 +++++++++++++++++++ 6 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/com/example/onui/domain/auth/presentation/dto/request/OAuthSignInWithAndroidRequest.kt diff --git a/src/main/kotlin/com/example/onui/domain/analysis/presentation/AnalysisController.kt b/src/main/kotlin/com/example/onui/domain/analysis/presentation/AnalysisController.kt index dddf038..ed39bbf 100644 --- a/src/main/kotlin/com/example/onui/domain/analysis/presentation/AnalysisController.kt +++ b/src/main/kotlin/com/example/onui/domain/analysis/presentation/AnalysisController.kt @@ -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() } \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/domain/analysis/service/AnalysisServiceImpl.kt b/src/main/kotlin/com/example/onui/domain/analysis/service/AnalysisServiceImpl.kt index c7db35c..e7ed7ea 100644 --- a/src/main/kotlin/com/example/onui/domain/analysis/service/AnalysisServiceImpl.kt +++ b/src/main/kotlin/com/example/onui/domain/analysis/service/AnalysisServiceImpl.kt @@ -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) diff --git a/src/main/kotlin/com/example/onui/domain/auth/presentation/AuthController.kt b/src/main/kotlin/com/example/onui/domain/auth/presentation/AuthController.kt index b8bdf80..13e9e10 100644 --- a/src/main/kotlin/com/example/onui/domain/auth/presentation/AuthController.kt +++ b/src/main/kotlin/com/example/onui/domain/auth/presentation/AuthController.kt @@ -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 @@ -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 @@ -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) diff --git a/src/main/kotlin/com/example/onui/domain/auth/presentation/dto/request/OAuthSignInWithAndroidRequest.kt b/src/main/kotlin/com/example/onui/domain/auth/presentation/dto/request/OAuthSignInWithAndroidRequest.kt new file mode 100644 index 0000000..8f36db6 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/auth/presentation/dto/request/OAuthSignInWithAndroidRequest.kt @@ -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? +) diff --git a/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthService.kt b/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthService.kt index 4a4e68b..ab47c86 100644 --- a/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthService.kt +++ b/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthService.kt @@ -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 } \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthServiceImpl.kt b/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthServiceImpl.kt index c6e3ea6..a46ad93 100644 --- a/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthServiceImpl.kt +++ b/src/main/kotlin/com/example/onui/domain/auth/service/GoogleAuthServiceImpl.kt @@ -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 @@ -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 + } } \ No newline at end of file