From 5a5ced748ae8fdf277b3ef585363a1dba4073bad Mon Sep 17 00:00:00 2001 From: yeahzxnn Date: Fri, 31 May 2024 19:10:19 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat=20:=20KAKAO=20LOGIN=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RollTheDice.xcodeproj/project.pbxproj | 61 ++++++++++++++++--- .../RollTheDice/Resources/Support/Info.plist | 16 +++++ .../RollTheDice/RollTheDiceApp.swift | 8 +++ .../Source/View/Authentication/AuthAPI.swift | 46 ++++++++++++++ .../Authentication/AuthenticatedView.swift | 16 ++++- .../AuthenticationViewModel.swift | 52 ++++++++++++++++ .../View/News/NewsCard/NewsListView.swift | 2 +- .../Source/View/News/NewsCard/NewsView.swift | 28 ++++----- 8 files changed, 205 insertions(+), 24 deletions(-) create mode 100644 iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthAPI.swift diff --git a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj index efb496c1..e53a4885 100644 --- a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj +++ b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj @@ -9,6 +9,12 @@ /* Begin PBXBuildFile section */ 357666102BBD4BF6002C226A /* ReportListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3576660F2BBD4BF6002C226A /* ReportListView.swift */; }; 357666132BBD54AA002C226A /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357666122BBD54AA002C226A /* SplashView.swift */; }; + 3576993A2C09C1EB00AD2DA4 /* KakaoSDK in Frameworks */ = {isa = PBXBuildFile; productRef = 357699392C09C1EB00AD2DA4 /* KakaoSDK */; }; + 3576993C2C09C1EB00AD2DA4 /* KakaoSDKAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 3576993B2C09C1EB00AD2DA4 /* KakaoSDKAuth */; }; + 3576993E2C09C1EB00AD2DA4 /* KakaoSDKCert in Frameworks */ = {isa = PBXBuildFile; productRef = 3576993D2C09C1EB00AD2DA4 /* KakaoSDKCert */; }; + 357699402C09C1EB00AD2DA4 /* KakaoSDKCertCore in Frameworks */ = {isa = PBXBuildFile; productRef = 3576993F2C09C1EB00AD2DA4 /* KakaoSDKCertCore */; }; + 357699422C09C1EB00AD2DA4 /* KakaoSDKCommon in Frameworks */ = {isa = PBXBuildFile; productRef = 357699412C09C1EB00AD2DA4 /* KakaoSDKCommon */; }; + 357699442C09C7B900AD2DA4 /* AuthAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357699432C09C7B900AD2DA4 /* AuthAPI.swift */; }; 357FC6EA2BCE866B00AD8915 /* DetailCardNews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357FC6E92BCE866B00AD8915 /* DetailCardNews.swift */; }; 35C71BF22B79F39900F777D1 /* ExyteChat in Frameworks */ = {isa = PBXBuildFile; productRef = 35C71BF12B79F39900F777D1 /* ExyteChat */; }; 6C32379F2B7C376D00B699AB /* Bookmark.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C32379E2B7C376D00B699AB /* Bookmark.swift */; }; @@ -93,6 +99,7 @@ /* Begin PBXFileReference section */ 3576660F2BBD4BF6002C226A /* ReportListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportListView.swift; sourceTree = ""; }; 357666122BBD54AA002C226A /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = ""; }; + 357699432C09C7B900AD2DA4 /* AuthAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthAPI.swift; sourceTree = ""; }; 357FC6E92BCE866B00AD8915 /* DetailCardNews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailCardNews.swift; sourceTree = ""; }; 6C32379E2B7C376D00B699AB /* Bookmark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bookmark.swift; sourceTree = ""; }; 6C3237A02B7C377600B699AB /* BookmarkViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkViewModel.swift; sourceTree = ""; }; @@ -176,12 +183,17 @@ buildActionMask = 2147483647; files = ( 6CF130BB2BAB74FD00A437B6 /* RxMoya in Frameworks */, + 3576993A2C09C1EB00AD2DA4 /* KakaoSDK in Frameworks */, 35C71BF22B79F39900F777D1 /* ExyteChat in Frameworks */, 6CF130B72BAB74FD00A437B6 /* Moya in Frameworks */, + 357699422C09C1EB00AD2DA4 /* KakaoSDKCommon in Frameworks */, 6CF130B92BAB74FD00A437B6 /* ReactiveMoya in Frameworks */, 6CE2AC1B2BD444BB00416A02 /* OpenAI in Frameworks */, 6C7651422BF37F5C00196536 /* OSLog.framework in Frameworks */, 6CF130B52BAB74FD00A437B6 /* CombineMoya in Frameworks */, + 3576993C2C09C1EB00AD2DA4 /* KakaoSDKAuth in Frameworks */, + 357699402C09C1EB00AD2DA4 /* KakaoSDKCertCore in Frameworks */, + 3576993E2C09C1EB00AD2DA4 /* KakaoSDKCert in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -248,13 +260,6 @@ path = ChatList; sourceTree = ""; }; - 6C41B8DD2BE116A200274FA4 /* Social */ = { - isa = PBXGroup; - children = ( - ); - path = Social; - sourceTree = ""; - }; 6C454A762B9DA62C006FD9D0 /* SignUp */ = { isa = PBXGroup; children = ( @@ -343,7 +348,6 @@ 6C7704862B722618001B17CB /* Source */ = { isa = PBXGroup; children = ( - 6C41B8DD2BE116A200274FA4 /* Social */, 6C454A852B9DB429006FD9D0 /* General */, 6C7704882B722647001B17CB /* View */, 6C454A7F2B9DAF21006FD9D0 /* Model */, @@ -565,6 +569,7 @@ children = ( 6CF130AC2BAB0C4400A437B6 /* AuthenticationViewModel.swift */, 6CF130AE2BAB0C4F00A437B6 /* AuthenticatedView.swift */, + 357699432C09C7B900AD2DA4 /* AuthAPI.swift */, ); path = Authentication; sourceTree = ""; @@ -638,6 +643,11 @@ 6CF130B82BAB74FD00A437B6 /* ReactiveMoya */, 6CF130BA2BAB74FD00A437B6 /* RxMoya */, 6CE2AC1A2BD444BB00416A02 /* OpenAI */, + 357699392C09C1EB00AD2DA4 /* KakaoSDK */, + 3576993B2C09C1EB00AD2DA4 /* KakaoSDKAuth */, + 3576993D2C09C1EB00AD2DA4 /* KakaoSDKCert */, + 3576993F2C09C1EB00AD2DA4 /* KakaoSDKCertCore */, + 357699412C09C1EB00AD2DA4 /* KakaoSDKCommon */, ); productName = RollTheDice; productReference = 6CC4DDC32B5574670080E7E8 /* RollTheDice.app */; @@ -671,6 +681,7 @@ 35C71BF02B79F39900F777D1 /* XCRemoteSwiftPackageReference "Chat" */, 6CDB2A002BAA085A0081037B /* XCRemoteSwiftPackageReference "OpenAI" */, 6CF130B32BAB74FD00A437B6 /* XCRemoteSwiftPackageReference "Moya" */, + 357699382C09C1EB00AD2DA4 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */, ); productRefGroup = 6CC4DDC42B5574670080E7E8 /* Products */; projectDirPath = ""; @@ -711,6 +722,7 @@ files = ( 6C454A882B9DB6C2006FD9D0 /* CustomNavigationBar.swift in Sources */, 6CF130BF2BAB783300A437B6 /* APIConstants.swift in Sources */, + 357699442C09C7B900AD2DA4 /* AuthAPI.swift in Sources */, 6C76513C2BF37ED300196536 /* Extension+Log.swift in Sources */, 6CE103102BD56A5B00498AA4 /* TypeReportViewModel.swift in Sources */, 6CF130C52BAB79DE00A437B6 /* ScoopAPI.swift in Sources */, @@ -979,6 +991,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + 357699382C09C1EB00AD2DA4 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/kakao/kakao-ios-sdk"; + requirement = { + branch = master; + kind = branch; + }; + }; 35C71BF02B79F39900F777D1 /* XCRemoteSwiftPackageReference "Chat" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/exyte/Chat.git"; @@ -1006,6 +1026,31 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 357699392C09C1EB00AD2DA4 /* KakaoSDK */ = { + isa = XCSwiftPackageProductDependency; + package = 357699382C09C1EB00AD2DA4 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDK; + }; + 3576993B2C09C1EB00AD2DA4 /* KakaoSDKAuth */ = { + isa = XCSwiftPackageProductDependency; + package = 357699382C09C1EB00AD2DA4 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKAuth; + }; + 3576993D2C09C1EB00AD2DA4 /* KakaoSDKCert */ = { + isa = XCSwiftPackageProductDependency; + package = 357699382C09C1EB00AD2DA4 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKCert; + }; + 3576993F2C09C1EB00AD2DA4 /* KakaoSDKCertCore */ = { + isa = XCSwiftPackageProductDependency; + package = 357699382C09C1EB00AD2DA4 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKCertCore; + }; + 357699412C09C1EB00AD2DA4 /* KakaoSDKCommon */ = { + isa = XCSwiftPackageProductDependency; + package = 357699382C09C1EB00AD2DA4 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKCommon; + }; 35C71BF12B79F39900F777D1 /* ExyteChat */ = { isa = XCSwiftPackageProductDependency; package = 35C71BF02B79F39900F777D1 /* XCRemoteSwiftPackageReference "Chat" */; diff --git a/iOS/RollTheDice/RollTheDice/Resources/Support/Info.plist b/iOS/RollTheDice/RollTheDice/Resources/Support/Info.plist index 01a3db65..f00932c0 100644 --- a/iOS/RollTheDice/RollTheDice/Resources/Support/Info.plist +++ b/iOS/RollTheDice/RollTheDice/Resources/Support/Info.plist @@ -2,6 +2,22 @@ + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + kakaoc88865e8a0481b67b98073d22cef6b248 + + + + LSApplicationQueriesSchemes + + kakaokompassauth + kakaolink + NSAppTransportSecurity NSAllowsArbitraryLoads diff --git a/iOS/RollTheDice/RollTheDice/RollTheDiceApp.swift b/iOS/RollTheDice/RollTheDice/RollTheDiceApp.swift index 22480d6d..7d7af40e 100644 --- a/iOS/RollTheDice/RollTheDice/RollTheDiceApp.swift +++ b/iOS/RollTheDice/RollTheDice/RollTheDiceApp.swift @@ -6,6 +6,9 @@ // import SwiftUI +import KakaoSDKCommon +import KakaoSDKAuth +import KakaoSDKUser @main struct RollTheDiceApp: App { @@ -19,6 +22,10 @@ struct RollTheDiceApp: App { var newsListViewModel = NewsListViewModel() @StateObject var bookmarkListViewModel = BookmarkListViewModel() + init() { + KakaoSDK.initSDK(appKey: "88865e8a0481b67b98073d22cef6b248") + } + var body: some Scene { WindowGroup { @@ -26,6 +33,7 @@ struct RollTheDiceApp: App { case .unauthenticated: AuthenticatedView() .environmentObject(authViewModel) + case .authenticated: SignUpQuestionView() .environmentObject(authViewModel) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthAPI.swift b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthAPI.swift new file mode 100644 index 00000000..fa0335f6 --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthAPI.swift @@ -0,0 +1,46 @@ +// +// AuthAPI.swift +// RollTheDice +// +// Created by 신예진 on 5/31/24. +// + +import Foundation +import Moya + +struct AuthProvider { + static let provider = MoyaProvider() +} + +enum AuthTarget: TargetType { + case login(token: String) + + var baseURL: URL { + return URL(string: "http://ec2-13-124-191-244.ap-northeast-2.compute.amazonaws.com:8080")! + } + + var path: String { + switch self { + case .login: + return "/login" + } + } + + var method: Moya.Method { + switch self { + case .login: + return .post + } + } + + var task: Task { + switch self { + case .login(let token): + return .requestParameters(parameters: ["accessToken": token], encoding: JSONEncoding.default) + } + } + + var headers: [String: String]? { + return ["Content-Type": "application/json"] + } +} diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift index 2acdef2b..f84992ac 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift @@ -6,10 +6,13 @@ // import SwiftUI +import KakaoSDKUser +import KakaoSDKAuth +import KakaoSDKCommon struct AuthenticatedView: View { @EnvironmentObject var authViewModel: AuthenticationViewModel -// @EnvironmentObject var pathModel: PathModel + @EnvironmentObject var pathModel: PathModel var totalDuration = 10.0 @@ -120,6 +123,17 @@ struct AuthenticatedView: View { } Button { + if (UserApi.isKakaoTalkLoginAvailable()) { + UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in + print(oauthToken) + print(error) + } + } else { + UserApi.shared.loginWithKakaoAccount {(oauthToken, error) in + print(oauthToken) + print(error) + } + } } label: { Image(.kakaoSignInBtn01) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticationViewModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticationViewModel.swift index af2bb8d7..521d3965 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticationViewModel.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticationViewModel.swift @@ -6,6 +6,9 @@ // import Foundation +import KakaoSDKAuth +import KakaoSDKUser + enum AuthenticationState { case unauthenticated // Kakao & Apple 로그인 전 @@ -18,3 +21,52 @@ enum AuthenticationState { var authenticationState: AuthenticationState = .unauthenticated var isLoading = false } + +extension AuthenticationViewModel { + func loginWithKakao() { + if (UserApi.isKakaoTalkLoginAvailable()) { + UserApi.shared.loginWithKakaoTalk { (oauthToken, error) in + if let error = error { + print("Kakao login error: \(error)") + self.authenticationState = .unauthenticated + } else { + // 로그인 성공 시 사용자 정보 가져오기 + UserApi.shared.me { (user, error) in + if let error = error { + print("Kakao user info error: \(error)") + self.authenticationState = .unauthenticated + } else { + // 사용자 정보 처리 + self.authenticationState = .authenticated + } + } + } + } + } else { + // Kakao 계정으로 로그인할 수 없는 경우 처리 + self.authenticationState = .unauthenticated + } + } +} + +extension AuthenticationViewModel { + func loginToBackend(with token: String) { + AuthProvider.provider.request(.login(token: token)) { result in + switch result { + case .success(let response): + do { + let json = try response.mapJSON() + print("Login response: \(json)") + self.authenticationState = .completedSignUp + } catch { + print("Login error: \(error)") + self.authenticationState = .unauthenticated + } + case .failure(let error): + print("Login error: \(error)") + self.authenticationState = .unauthenticated + } + } + } +} + diff --git a/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsListView.swift b/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsListView.swift index edb29969..faf04761 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsListView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsListView.swift @@ -33,7 +33,7 @@ struct NewsListView: View { fileprivate var body: some View { GeometryReader { proxy in ScrollView(.horizontal, showsIndicators: false) { - LazyHStack(spacing: -234567876455aa0) { + LazyHStack(spacing: -234567876455) { ForEach(newsList) { news in NewsView(news: news) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsView.swift b/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsView.swift index 859b4230..81e81d9d 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsView.swift @@ -43,20 +43,20 @@ struct NewsView: View { .frame(width: 322, height: 160) .clipShape(RoundedRectangle(cornerRadius: 8)) .shadow(color: .black.opacity(0.25), radius: 2, x: 0, y: 0) - case .empty: - Image(.exampleNews) - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: 322, height: 160) - .clipShape(RoundedRectangle(cornerRadius: 8)) - .shadow(color: .black.opacity(0.25), radius: 2, x: 0, y: 0) - case .failure(_): - Image(.exampleNews) - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: 322, height: 160) - .clipShape(RoundedRectangle(cornerRadius: 8)) - .shadow(color: .black.opacity(0.25), radius: 2, x: 0, y: 0) +// case .empty: +// Image(.exampleNews) +// .resizable() +// .aspectRatio(contentMode: .fill) +// .frame(width: 322, height: 160) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// .shadow(color: .black.opacity(0.25), radius: 2, x: 0, y: 0) +// case .failure(_): +// Image(.exampleNews) +// .resizable() +// .aspectRatio(contentMode: .fill) +// .frame(width: 322, height: 160) +// .clipShape(RoundedRectangle(cornerRadius: 8)) +// .shadow(color: .black.opacity(0.25), radius: 2, x: 0, y: 0) @unknown default: Text(""); } From bc12cc8ecb99e6ae1076dd184ecd25fbb00a4c21 Mon Sep 17 00:00:00 2001 From: yeahzxnn Date: Fri, 31 May 2024 19:46:49 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat=20:=20KAKAO=20LOGIN=20-=20MAINTAB=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Authentication/AuthenticatedView.swift | 49 ++++++++++++++----- .../Source/View/MainTab/MainTabView.swift | 2 + 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift index f84992ac..07434669 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift @@ -13,7 +13,7 @@ import KakaoSDKCommon struct AuthenticatedView: View { @EnvironmentObject var authViewModel: AuthenticationViewModel @EnvironmentObject var pathModel: PathModel - + var totalDuration = 10.0 var body: some View { @@ -122,25 +122,50 @@ struct AuthenticatedView: View { .frame(height: 50) } +// Button { +// if (UserApi.isKakaoTalkLoginAvailable()) { +// UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in +// print(oauthToken) +// print(error) +// } +// } else { +// UserApi.shared.loginWithKakaoAccount {(oauthToken, error) in +// print(oauthToken) +// print(error) +// } +// } +// +// } label: { +// Image(.kakaoSignInBtn01) +// .resizable() +// .aspectRatio(contentMode: .fit) +// .frame(height: 50) +// } Button { - if (UserApi.isKakaoTalkLoginAvailable()) { - UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in - print(oauthToken) - print(error) - } - } else { - UserApi.shared.loginWithKakaoAccount {(oauthToken, error) in - print(oauthToken) - print(error) - } + if UserApi.isKakaoTalkLoginAvailable() { + UserApi.shared.loginWithKakaoTalk { (oauthToken, error) in + if let error = error { + print("Kakao Login Error: \(error)") + } else if let oauthToken = oauthToken { + print("Kakao Login Success: \(oauthToken)") + authViewModel.authenticationState = .completedSignUp } } - + } else { + UserApi.shared.loginWithKakaoAccount { (oauthToken, error) in + if let error = error { + print("Kakao Login Error: \(error)") + } else if let oauthToken = oauthToken { + print("Kakao Login Success: \(oauthToken)") + authViewModel.authenticationState = .completedSignUp } + } + } } label: { Image(.kakaoSignInBtn01) .resizable() .aspectRatio(contentMode: .fit) .frame(height: 50) } + } } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/MainTab/MainTabView.swift b/iOS/RollTheDice/RollTheDice/Source/View/MainTab/MainTabView.swift index 037c040a..242bc53b 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/MainTab/MainTabView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/MainTab/MainTabView.swift @@ -11,6 +11,8 @@ struct MainTabView: View { @EnvironmentObject private var pathModel: PathModel var newsListViewModel: NewsListViewModel + @EnvironmentObject var authViewModel: AuthenticationViewModel + @StateObject var mainTabViewModel = MainTabViewModel() From ad266534dea458b9e8aa730dce706766accdc039 Mon Sep 17 00:00:00 2001 From: yeahzxnn Date: Fri, 14 Jun 2024 15:33:18 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat=20:=20kakao=20accesstoken=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RollTheDice.xcodeproj/project.pbxproj | 4 +++ .../Source/Domain/API/TokenManager.swift | 26 +++++++++++++++++++ .../Source/View/Authentication/AuthAPI.swift | 12 +++++++-- .../Authentication/AuthenticatedView.swift | 2 ++ .../News/NewsCard/DetailNewsViewModel.swift | 7 ++++- .../News/NewsCard/NewsListViewModel.swift | 7 ++++- 6 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 iOS/RollTheDice/RollTheDice/Source/Domain/API/TokenManager.swift diff --git a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj index e53a4885..43967286 100644 --- a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj +++ b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 3509091A2C1C1248007D76A1 /* TokenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 350909192C1C1248007D76A1 /* TokenManager.swift */; }; 357666102BBD4BF6002C226A /* ReportListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3576660F2BBD4BF6002C226A /* ReportListView.swift */; }; 357666132BBD54AA002C226A /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357666122BBD54AA002C226A /* SplashView.swift */; }; 3576993A2C09C1EB00AD2DA4 /* KakaoSDK in Frameworks */ = {isa = PBXBuildFile; productRef = 357699392C09C1EB00AD2DA4 /* KakaoSDK */; }; @@ -97,6 +98,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 350909192C1C1248007D76A1 /* TokenManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenManager.swift; sourceTree = ""; }; 3576660F2BBD4BF6002C226A /* ReportListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportListView.swift; sourceTree = ""; }; 357666122BBD54AA002C226A /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = ""; }; 357699432C09C7B900AD2DA4 /* AuthAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthAPI.swift; sourceTree = ""; }; @@ -607,6 +609,7 @@ isa = PBXGroup; children = ( 6CF130C12BAB786600A437B6 /* APIHeaderManager.swift */, + 350909192C1C1248007D76A1 /* TokenManager.swift */, ); path = API; sourceTree = ""; @@ -775,6 +778,7 @@ 6C7704992B722A20001B17CB /* MainTabViewModel.swift in Sources */, 6C454A7C2B9DA71C006FD9D0 /* SignUpView.swift in Sources */, 6C41B8DA2BE104A800274FA4 /* RecentNewsCardView.swift in Sources */, + 3509091A2C1C1248007D76A1 /* TokenManager.swift in Sources */, 6CF130C72BAB7B9800A437B6 /* ScoopAPINews.swift in Sources */, 6C7651402BF37F3400196536 /* Log.swift in Sources */, 6CE1031A2BD57A2500498AA4 /* DebateSummaryView.swift in Sources */, diff --git a/iOS/RollTheDice/RollTheDice/Source/Domain/API/TokenManager.swift b/iOS/RollTheDice/RollTheDice/Source/Domain/API/TokenManager.swift new file mode 100644 index 00000000..e5c00e6e --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/Domain/API/TokenManager.swift @@ -0,0 +1,26 @@ +// +// TokenManager.swift +// RollTheDice +// +// Created by 신예진 on 6/14/24. +// + +import Foundation +import SwiftUI + +class TokenManager { + static let shared = TokenManager() + + private init() { } + + private let accessTokenKey = "accessToken" + + var accessToken: String? { + get { + return UserDefaults.standard.string(forKey: accessTokenKey) + } + set { + UserDefaults.standard.setValue(newValue, forKey: accessTokenKey) + } + } +} diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthAPI.swift b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthAPI.swift index fa0335f6..54af7c2c 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthAPI.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthAPI.swift @@ -40,7 +40,15 @@ enum AuthTarget: TargetType { } } +// var headers: [String: String]? { +// return ["Content-Type": "application/json"] +// } + var headers: [String: String]? { - return ["Content-Type": "application/json"] - } + var headers = [String: String]() + if let token = TokenManager.shared.accessToken { + headers["Authorization"] = "Bearer \(token)" + } + return headers + } } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift index 07434669..72eb4ff6 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Authentication/AuthenticatedView.swift @@ -148,6 +148,7 @@ struct AuthenticatedView: View { print("Kakao Login Error: \(error)") } else if let oauthToken = oauthToken { print("Kakao Login Success: \(oauthToken)") + TokenManager.shared.accessToken = oauthToken.accessToken authViewModel.authenticationState = .completedSignUp } } } else { @@ -156,6 +157,7 @@ struct AuthenticatedView: View { print("Kakao Login Error: \(error)") } else if let oauthToken = oauthToken { print("Kakao Login Success: \(oauthToken)") + TokenManager.shared.accessToken = oauthToken.accessToken authViewModel.authenticationState = .completedSignUp } } } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/DetailNewsViewModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/DetailNewsViewModel.swift index 427140cd..d48adfc6 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/DetailNewsViewModel.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/DetailNewsViewModel.swift @@ -28,7 +28,12 @@ import SwiftUI extension DetailNewsViewModel { public func getNewsDetail(newsId: Int) { - let accessToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBY2Nlc3NUb2tlbiIsImV4cCI6MTcxNjMwMzYwMiwiZW1haWwiOiJjaGVueWVvbmp5QGRhdW0ubmV0In0.UmW0VdDtxsI7L2WSBrpUaAof5zikQ8JWdp_DIsXIlFwPaFBRUrfhgJ0aYljVcosOkQrk4b2NwOhme5lR13aEgw" +// let accessToken = "" + // TokenManager에서 accessToken 가져오기 + guard let accessToken = TokenManager.shared.accessToken else { + print("Access token 사용 불가능...") + return + } if let cancellable = newsCancellable { cancellable.cancel() diff --git a/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsListViewModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsListViewModel.swift index 5afaa6b5..2b9cbfbb 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsListViewModel.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/News/NewsCard/NewsListViewModel.swift @@ -31,7 +31,12 @@ import SwiftUI extension NewsListViewModel { public func getAllNewsData(page: Int, size: Int) { - let accessToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBY2Nlc3NUb2tlbiIsImV4cCI6MTcxNjMwMzYwMiwiZW1haWwiOiJjaGVueWVvbmp5QGRhdW0ubmV0In0.UmW0VdDtxsI7L2WSBrpUaAof5zikQ8JWdp_DIsXIlFwPaFBRUrfhgJ0aYljVcosOkQrk4b2NwOhme5lR13aEgw" +// let accessToken = "" + // TokenManager에서 accessToken 가져오기 + guard let accessToken = TokenManager.shared.accessToken else { + print("Access token 사용 불가능...") + return + } if let cancellable = newsCancellable { cancellable.cancel() From bf08269779709f38d6d0f5ed592fe90abfcdb308 Mon Sep 17 00:00:00 2001 From: yeahzxnn Date: Tue, 18 Jun 2024 14:17:53 +0900 Subject: [PATCH 4/9] =?UTF-8?q?fix=20:=20=EC=B9=B4=EC=B9=B4=EC=98=A4?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=95=B1=20=ED=82=A4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/RollTheDice/.DS_Store | Bin 6148 -> 6148 bytes .../RollTheDice/Resources/Support/Info.plist | 2 +- .../RollTheDice/RollTheDiceApp.swift | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iOS/RollTheDice/.DS_Store b/iOS/RollTheDice/.DS_Store index ea989d1d857d4e2b2c2c3e0d7e467d2c854ffd53..0ed7ed287d10ca2ba122648fa0235e0d173b019d 100644 GIT binary patch delta 63 zcmZoMXffE}&cw{j>OT1#liuVCCLVUv784atzGIWmGU-p=g~GRCVh-3W$o!3EVguV| Ic8R%>V!Z delta 63 zcmZoMXffE}&cw{f?K$}zliuVCCLZ=B?^pa2+Editor CFBundleURLSchemes - kakaoc88865e8a0481b67b98073d22cef6b248 + kakaoff09b3d83873ed4e320f0d6bc90759d6 diff --git a/iOS/RollTheDice/RollTheDice/RollTheDiceApp.swift b/iOS/RollTheDice/RollTheDice/RollTheDiceApp.swift index 7d7af40e..3e61f628 100644 --- a/iOS/RollTheDice/RollTheDice/RollTheDiceApp.swift +++ b/iOS/RollTheDice/RollTheDice/RollTheDiceApp.swift @@ -23,7 +23,7 @@ struct RollTheDiceApp: App { @StateObject var bookmarkListViewModel = BookmarkListViewModel() init() { - KakaoSDK.initSDK(appKey: "88865e8a0481b67b98073d22cef6b248") + KakaoSDK.initSDK(appKey: "ff09b3d83873ed4e320f0d6bc90759d6") } var body: some Scene { From 38799213086525708d2d3a87535ce9ea19a98a09 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 18 Jun 2024 20:12:21 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat:=20=ED=86=A0=ED=81=B0=20=EB=B0=94?= =?UTF-8?q?=EB=94=94=EC=97=90=20=EB=8B=B4=EC=95=84=EC=84=9C=20=EB=B3=B4?= =?UTF-8?q?=EB=82=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/jwt/dto/TokenResponse.java | 14 +++++++++++++ .../security/jwt/service/JwtService.java | 21 ++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/global/security/jwt/dto/TokenResponse.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/security/jwt/dto/TokenResponse.java b/backend/core/src/main/java/com/rollthedice/backend/global/security/jwt/dto/TokenResponse.java new file mode 100644 index 00000000..8294fd43 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/global/security/jwt/dto/TokenResponse.java @@ -0,0 +1,14 @@ +package com.rollthedice.backend.global.security.jwt.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Schema(description = "AccessToken, RefreshToken 반환 포맷") +public class TokenResponse { + private String accessToken; + private String refreshToken; +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/security/jwt/service/JwtService.java b/backend/core/src/main/java/com/rollthedice/backend/global/security/jwt/service/JwtService.java index ed9abc12..a7228879 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/security/jwt/service/JwtService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/security/jwt/service/JwtService.java @@ -3,7 +3,10 @@ import com.auth0.jwt.JWT; import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.exceptions.JWTVerificationException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.rollthedice.backend.domain.member.repository.MemberRepository; +import com.rollthedice.backend.global.security.jwt.dto.TokenResponse; import com.rollthedice.backend.global.security.jwt.refresh.service.RefreshTokenService; import com.rollthedice.backend.global.security.jwt.exception.NotFoundEmailException; import com.rollthedice.backend.global.security.jwt.exception.NotFoundTokenException; @@ -15,6 +18,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.io.IOException; import java.util.Date; import java.util.Optional; @@ -30,6 +34,7 @@ public class JwtService { private final MemberRepository memberRepository; private final RefreshTokenService refreshTokenService; + private final ObjectMapper objectMapper; @Value("${jwt.secret-key}") private String secretKey; @@ -43,12 +48,22 @@ public class JwtService { private String refreshHeader; public void sendAccessAndRefreshToken(HttpServletResponse response, String email) { - setTokenHeader(response, accessHeader, createAccessToken(email)); - + String accessToken = createAccessToken(email); String refreshToken = createRefreshToken(); + + try { + String token = objectMapper.writeValueAsString(TokenResponse.builder() + .accessToken(accessToken) + .refreshToken(refreshToken) + .build()); + response.getWriter().write(token); + } catch (IOException e) { + throw new RuntimeException(e); + } + + setTokenHeader(response, accessHeader, accessToken); setTokenHeader(response, refreshHeader, refreshToken); refreshTokenService.updateToken(email, refreshToken); - log.info("Access Token, Refresh Token 헤더 설정 완료"); } public String createAccessToken(String email) { From 8105c84da020a10e7d1bb9212c0aa5a77d134b34 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 18 Jun 2024 20:12:43 +0900 Subject: [PATCH 6/9] =?UTF-8?q?feat:=20AuthApi=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/oauth2/api/AuthApi.java | 43 +++++++++++++++++++ .../{controller => api}/AuthController.java | 6 ++- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthApi.java rename backend/core/src/main/java/com/rollthedice/backend/global/oauth2/{controller => api}/AuthController.java (91%) diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthApi.java b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthApi.java new file mode 100644 index 00000000..b8528389 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthApi.java @@ -0,0 +1,43 @@ +package com.rollthedice.backend.global.oauth2.api; + +import com.rollthedice.backend.domain.member.dto.MemberUpdateDto; +import com.rollthedice.backend.global.oauth2.dto.LoginRequest; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; + +public interface AuthApi { + @Operation( + summary = "소셜 로그인", + description = "소셜 로그인을 합니다. 회원가입이 되어있지 않은 회원일 경우, 회원가입이 진행됩니다.", + security = {@SecurityRequirement(name = "access_token")}, + tags = {"인증"} + ) + @ApiResponse( + responseCode = "201", + description = "Created" + ) + ResponseEntity login( + @RequestBody LoginRequest request, + HttpServletResponse response + ); + + @Operation( + summary = "닉네임 입력", + description = "닉네임을 입력합니다. 해당 로직이 진행되어야 회원가입이 완료됩니다.", + security = {@SecurityRequirement(name = "access_token")}, + tags = {"인증"} + ) + @ApiResponse( + responseCode = "201", + description = "Created" + ) + ResponseEntity updateMember( + String email, + @RequestBody MemberUpdateDto memberUpdateDto + ); +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/controller/AuthController.java b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthController.java similarity index 91% rename from backend/core/src/main/java/com/rollthedice/backend/global/oauth2/controller/AuthController.java rename to backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthController.java index 5a38e5b1..dad5b0f7 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/controller/AuthController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/api/AuthController.java @@ -1,4 +1,4 @@ -package com.rollthedice.backend.global.oauth2.controller; +package com.rollthedice.backend.global.oauth2.api; import com.rollthedice.backend.domain.member.dto.MemberUpdateDto; import com.rollthedice.backend.domain.member.service.MemberService; @@ -17,17 +17,19 @@ @Slf4j @RestController @RequiredArgsConstructor -public class AuthController { +public class AuthController implements AuthApi { private final AuthService authService; private final MemberService memberService; @PostMapping("/login") + @Override public ResponseEntity login(@RequestBody LoginRequest request, HttpServletResponse response) { authService.authenticateOrRegisterUser(request, response); return new ResponseEntity<>(HttpStatus.OK); } @PostMapping("/oauth2/sign-up") + @Override public ResponseEntity updateMember(@LoginMemberEmail String email, @RequestBody MemberUpdateDto memberUpdateDto) { memberService.update(memberUpdateDto); From ab6f665f21740a343ad16c75850edc6a885b0429 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 18 Jun 2024 20:14:24 +0900 Subject: [PATCH 7/9] =?UTF-8?q?feat:=20DebateRoom=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EC=8B=9C,=20=ED=86=A0=EB=A1=A0=EB=B0=A9=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/api/DebateApi.java | 3 ++- .../domain/debate/api/DebateController.java | 5 +++-- .../dto/response/DebateRoomSaveResponse.java | 22 +++++++++++++++++++ .../debate/service/DebateRoomService.java | 7 ++++-- 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomSaveResponse.java diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java index 9fe8eec2..f70a4d3b 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateApi.java @@ -4,6 +4,7 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; +import com.rollthedice.backend.domain.debate.dto.response.DebateRoomSaveResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -29,7 +30,7 @@ public interface DebateApi { responseCode = "201", description = "Created" ) - void saveDebateRoom(@RequestBody DebateRoomRequest request); + DebateRoomSaveResponse saveDebateRoom(@RequestBody DebateRoomRequest request); @Operation( summary = "토론방 전체 조회", diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java index 4e802ef3..9c5863aa 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/api/DebateController.java @@ -4,6 +4,7 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; +import com.rollthedice.backend.domain.debate.dto.response.DebateRoomSaveResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; import com.rollthedice.backend.domain.debate.service.DebateMessageService; import com.rollthedice.backend.domain.debate.service.DebateRoomService; @@ -25,8 +26,8 @@ public class DebateController implements DebateApi { @ResponseStatus(HttpStatus.CREATED) @PostMapping("") @Override - public void saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) { - debateRoomService.saveDebateRoom(request); + public DebateRoomSaveResponse saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) { + return debateRoomService.saveDebateRoom(request); } @ResponseStatus(HttpStatus.OK) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomSaveResponse.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomSaveResponse.java new file mode 100644 index 00000000..3dda3cf8 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomSaveResponse.java @@ -0,0 +1,22 @@ +package com.rollthedice.backend.domain.debate.dto.response; + +import com.rollthedice.backend.domain.debate.entity.DebateRoom; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@Schema(description = "토론방 생성 결과") +public class DebateRoomSaveResponse { + @Schema(description = "토론방의 ID입니다.") + private Long id; + + @Schema(description = "토론 주제입니다.") + private String topic; + + @Builder + public DebateRoomSaveResponse(DebateRoom debateRoom) { + this.id = debateRoom.getId(); + this.topic = debateRoom.getTopic(); + } +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java index 595359ed..469e0729 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateRoomService.java @@ -2,6 +2,7 @@ import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest; import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse; +import com.rollthedice.backend.domain.debate.dto.response.DebateRoomSaveResponse; import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse; import com.rollthedice.backend.domain.debate.entity.DebateRoom; import com.rollthedice.backend.domain.debate.exception.DebateRoomNotFoundException; @@ -28,9 +29,11 @@ public class DebateRoomService { @Transactional - public void saveDebateRoom(DebateRoomRequest request) { + public DebateRoomSaveResponse saveDebateRoom(DebateRoomRequest request) { final Member member = authService.getMember(); - debateRoomRepository.save(debateRoomMapper.toEntity(member, request)); + DebateRoom debateRoom = debateRoomRepository + .save(debateRoomMapper.toEntity(member, request)); + return DebateRoomSaveResponse.builder().debateRoom(debateRoom).build(); } @Transactional(readOnly = true) From 71d3b34ba94c0d4f7153bfca8c3d697e276b474b Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 18 Jun 2024 20:15:37 +0900 Subject: [PATCH 8/9] =?UTF-8?q?docs:=20Swagger=20=EC=84=A4=EB=AA=85=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/bookmark/dto/response/BookmarkResponse.java | 2 ++ .../domain/debate/dto/request/DebateMessageRequest.java | 2 ++ .../domain/debate/dto/request/DebateRoomRequest.java | 3 ++- .../domain/debate/dto/response/DebateMessageResponse.java | 5 +++++ .../domain/debate/dto/response/DebateRoomResponse.java | 7 +++++++ .../domain/debate/dto/response/DebateSummaryResponse.java | 1 + .../backend/domain/statistics/api/StatisticsApi.java | 4 ++-- 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/dto/response/BookmarkResponse.java b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/dto/response/BookmarkResponse.java index cd5ed0d4..61ea52b7 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/dto/response/BookmarkResponse.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/bookmark/dto/response/BookmarkResponse.java @@ -1,5 +1,6 @@ package com.rollthedice.backend.domain.bookmark.dto.response; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -9,6 +10,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@Schema(description = "사용자가 북마크했는지 여부") public class BookmarkResponse { private Long id; private Boolean isBookmarked; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java index 405a1d84..698ffb0c 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateMessageRequest.java @@ -3,6 +3,7 @@ import com.rollthedice.backend.domain.debate.entity.DebateMessage; import com.rollthedice.backend.domain.debate.entity.DebateRoom; import com.rollthedice.backend.domain.debate.entity.SenderType; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -12,6 +13,7 @@ @Builder @AllArgsConstructor @NoArgsConstructor +@Schema(description = "토론 메세지 생성") public class DebateMessageRequest { private String message; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java index 92f5bd0a..6a161e50 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/request/DebateRoomRequest.java @@ -1,6 +1,6 @@ package com.rollthedice.backend.domain.debate.dto.request; -import com.rollthedice.backend.domain.debate.entity.DebateRoom; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -10,6 +10,7 @@ @AllArgsConstructor @NoArgsConstructor @Builder +@Schema(description = "토론방 생성") public class DebateRoomRequest { private String topic; } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateMessageResponse.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateMessageResponse.java index 3e5ff3e5..e8347bf2 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateMessageResponse.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateMessageResponse.java @@ -1,6 +1,7 @@ package com.rollthedice.backend.domain.debate.dto.response; import com.rollthedice.backend.domain.debate.entity.SenderType; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -10,7 +11,11 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@Schema(description = "토론 내용 저장") public class DebateMessageResponse { + @Schema(description = "토론 메세지 내용") private String message; + + @Schema(description = "송신자의 타입입니다. (HUMAN, AI)") private SenderType senderType; } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomResponse.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomResponse.java index 27d3d766..3db3309f 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomResponse.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateRoomResponse.java @@ -1,5 +1,6 @@ package com.rollthedice.backend.domain.debate.dto.response; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -9,8 +10,14 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@Schema(description = "토론방 정보") public class DebateRoomResponse { + @Schema(description = "토론방의 ID입니다.") private Long id; + + @Schema(description = "토론 주제입니다.") private String topic; + + @Schema(description = "토론이 종료되었는지 여부입니다.") private Boolean isClosed; } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java index a3a46c11..d79acf50 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/dto/response/DebateSummaryResponse.java @@ -10,6 +10,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@Schema(description = "토론 요약 결과") public class DebateSummaryResponse { Long roomId; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsApi.java index 3f8b53d7..6866c2bb 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/api/StatisticsApi.java @@ -13,7 +13,7 @@ public interface StatisticsApi { summary = "최근 일주일 날짜별 뉴스 조회수 조회", description = "최근 일주일간 날짜별로 뉴스 조회수를 조회합니다.", security = {@SecurityRequirement(name = "access_token")}, - tags = {"Statistics"} + tags = {"통계"} ) @ApiResponse( responseCode = "200", @@ -25,7 +25,7 @@ public interface StatisticsApi { summary = "카테고리별 조회수 조회", description = "카테고리별 조회수를 조회합니다.", security = {@SecurityRequirement(name = "access_token")}, - tags = {"Statistics"} + tags = {"통계"} ) @ApiResponse( responseCode = "200", From 3c9e32d91879f398933362d9896a0d6c80e45000 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 18 Jun 2024 20:16:00 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20@Transactional=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/debate/service/DebateMessageService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java index 76d9b583..3c6a881c 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/debate/service/DebateMessageService.java @@ -28,6 +28,7 @@ public void saveHumanDebateMessage(final Long roomId, DebateMessageRequest reque debateMessageRepository.save(request.toHumanMessageEntity(getDebateRoom(roomId))); } + @Transactional public void saveAIDebateMessage(Long roomId, DebateMessageRequest request) { debateMessageRepository.save(request.toAIMessageEntity(getDebateRoom(roomId))); }