Skip to content

Commit

Permalink
refactor/#178 서버 응답 및 DTO 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hooni0918 committed Jul 15, 2024
1 parent e964d05 commit f8c6356
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 76 deletions.
4 changes: 4 additions & 0 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
78B928782C29402E006D9942 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 78B928762C29402E006D9942 /* LaunchScreen.storyboard */; };
78BD61202C43F557005752FD /* SwiftKeychainWrapper in Frameworks */ = {isa = PBXBuildFile; productRef = 78BD611F2C43F557005752FD /* SwiftKeychainWrapper */; };
78BD61272C446A97005752FD /* LoginService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78BD61262C446A97005752FD /* LoginService.swift */; };
78BD612B2C4550A6005752FD /* Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78BD612A2C4550A6005752FD /* Bundle.swift */; };
A3DD9C3D2C41BAD000E58A13 /* MeetingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C322C41BAD000E58A13 /* MeetingTableViewCell.swift */; };
A3DD9C3E2C41BAD000E58A13 /* MeetingDummyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C342C41BAD000E58A13 /* MeetingDummyModel.swift */; };
A3DD9C3F2C41BAD000E58A13 /* MeetingListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C362C41BAD000E58A13 /* MeetingListView.swift */; };
Expand Down Expand Up @@ -205,6 +206,7 @@
78B928772C29402E006D9942 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
78B928792C29402E006D9942 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
78BD61262C446A97005752FD /* LoginService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginService.swift; sourceTree = "<group>"; };
78BD612A2C4550A6005752FD /* Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = "<group>"; };
A3DD9C322C41BAD000E58A13 /* MeetingTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeetingTableViewCell.swift; sourceTree = "<group>"; };
A3DD9C342C41BAD000E58A13 /* MeetingDummyModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeetingDummyModel.swift; sourceTree = "<group>"; };
A3DD9C362C41BAD000E58A13 /* MeetingListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeetingListView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1053,6 +1055,7 @@
DE254AA62C3118B300A4015E /* Extension */,
DE254AB52C3119BC00A4015E /* Util */,
DE254ABA2C311C3100A4015E /* Font */,
78BD612A2C4550A6005752FD /* Bundle.swift */,
);
path = Resource;
sourceTree = "<group>";
Expand Down Expand Up @@ -1540,6 +1543,7 @@
DD43937B2C412F4500EC1799 /* CreateMeetingViewController.swift in Sources */,
DE8247FD2C36E7C7000601BC /* MoyaLoggingPlugin.swift in Sources */,
DDAF1C842C3D5D19008A37D3 /* ViewModelType.swift in Sources */,
78BD612B2C4550A6005752FD /* Bundle.swift in Sources */,
DD3072262C3C0F0B00416D9F /* TardyInfoModel.swift in Sources */,
DE254AB92C311AB300A4015E /* Screen.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation

struct SocialLoginRequestModel: RequestModelType {
let provider: String?
let provider: String
let fcmToken: String

}
18 changes: 6 additions & 12 deletions KkuMulKum/Network/DTO/Model/Auth/SocialLoginResponseModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@

import Foundation

struct SocialLoginResponseModel: ResponseModelType {
let success: Bool
let data: LoginData?
let error: ErrorData?
}

struct LoginData: Codable {
struct UserData: ResponseModelType {
let name: String?
let jwtTokenDto: JwtTokenDto

enum CodingKeys: String, CodingKey {
case name
case jwtTokenDto // 서버 응답과
}
}

struct JwtTokenDto: Codable {
let accessToken: String
let refreshToken: String
}

struct ErrorData: Codable {
let code: Int
let message: String
}
2 changes: 2 additions & 0 deletions KkuMulKum/Network/DTO/ResponseBody/ResponseBodyDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation

/// 제네릭 ResponseBody 구조체 정의
struct ResponseBodyDTO<T: ResponseModelType>: Codable {
let success: Bool
let data: T?
let error: ErrorResponse?
}
Expand All @@ -18,3 +19,4 @@ struct ErrorResponse: Codable {
let code: Int
let message: String
}

37 changes: 5 additions & 32 deletions KkuMulKum/Network/DTO/TargetType/LoginService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// Created by 이지훈 on 7/15/24.
//

import Foundation
import Moya

Expand All @@ -14,24 +15,15 @@ enum LoginService {

extension LoginService: TargetType {
var baseURL: URL {
print("Attempting to get baseURL")
guard let privacyInfo = Bundle.main.privacyInfo else {
fatalError("PrivacyInfo.plist not found")
}

guard let urlString = privacyInfo["BASE_URL"] as? String else {
fatalError("BASE_URL not found in PrivacyInfo.plist")
}

guard let url = URL(string: urlString) else {
fatalError("Invalid BASE_URL in PrivacyInfo.plist: \(urlString)")
guard let privacyInfo = Bundle.main.privacyInfo,
let urlString = privacyInfo["BASE_URL"] as? String,
let url = URL(string: urlString) else {
fatalError("Invalid BASE_URL in PrivacyInfo.plist")
}

return url
}

var path: String {
print("Getting path: /api/v1/auth/signin")
return "/api/v1/auth/signin"
}

Expand Down Expand Up @@ -63,22 +55,3 @@ extension LoginService: TargetType {
}
}
}

extension Bundle {
var privacyInfo: [String: Any]? {
guard let url = self.url(forResource: "PrivacyInfo", withExtension: "plist") else {
return nil
}
guard let data = try? Data(contentsOf: url) else {
return nil
}
guard let result = try? PropertyListSerialization.propertyList(
from: data,
options: [],
format: nil
) as? [String: Any] else {
return nil
}
return result
}
}
23 changes: 23 additions & 0 deletions KkuMulKum/Resource/Bundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Bundle.swift
// KkuMulKum
//
// Created by 이지훈 on 7/15/24.
//

import Foundation

extension Bundle {
var privacyInfo: [String: Any]? {
guard let url = self.url(forResource: "PrivacyInfo", withExtension: "plist"),
let data = try? Data(contentsOf: url),
let result = try? PropertyListSerialization.propertyList(
from: data,
options: [],
format: nil
) as? [String: Any] else {
return nil
}
return result
}
}
30 changes: 15 additions & 15 deletions KkuMulKum/Source/Onboarding/Login/VIewModel/LoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
//
// Created by 이지훈 on 7/9/24.
//
import UIKit

import UIKit
import AuthenticationServices

import KakaoSDKUser
import KakaoSDKAuth
import Moya
Expand All @@ -21,13 +22,12 @@ class LoginViewModel: NSObject {
var loginState: ObservablePattern<LoginState> = ObservablePattern(.notLoggedIn)
var error: ObservablePattern<String> = ObservablePattern("")

private let provider = MoyaProvider<LoginService>(
plugins: [NetworkLoggerPlugin(
configuration: .init(
logOptions: .verbose
)
)]
)
private let provider: MoyaProvider<LoginService>

init(provider: MoyaProvider<LoginService> = MoyaProvider<LoginService>(plugins: [NetworkLoggerPlugin(configuration: .init(logOptions: .verbose))])) {
self.provider = provider
super.init()
}

func performAppleLogin(presentationAnchor: ASPresentationAnchor) {
print("Performing Apple Login")
Expand Down Expand Up @@ -63,7 +63,7 @@ class LoginViewModel: NSObject {

if let token = oauthToken?.accessToken {
print("Kakao Login Successful, access token: \(token)")
loginToServer(with: .kakaoLogin(accessToken: token, fcmToken: ""))
loginToServer(with: .kakaoLogin(accessToken: token, fcmToken: "dummy_fcm_token"))
} else {
print("Kakao Login Error: No access token")
self.error.value = "No access token received"
Expand All @@ -76,7 +76,7 @@ class LoginViewModel: NSObject {
case .success(let response):
print("Received response from server: \(response)")
do {
let loginResponse = try response.map(SocialLoginResponseModel.self)
let loginResponse = try response.map(ResponseBodyDTO<UserData>.self)
print("Successfully mapped response: \(loginResponse)")
self?.handleLoginResponse(loginResponse)
} catch {
Expand All @@ -91,7 +91,7 @@ class LoginViewModel: NSObject {
}
}

private func handleLoginResponse(_ response: SocialLoginResponseModel) {
private func handleLoginResponse(_ response: ResponseBodyDTO<UserData>) {
print("Handling login response")
if response.success {
if let data = response.data {
Expand All @@ -105,7 +105,7 @@ class LoginViewModel: NSObject {

let tokens = data.jwtTokenDto
print("Received tokens - Access: \(tokens.accessToken), Refresh: \(tokens.refreshToken)")
// TODO: 키체인에 토큰 저장 로직추가 예정
// TODO: 토큰 저장 로직 구현
} else {
print("Warning: No data received in response")
error.value = "No data received"
Expand All @@ -120,10 +120,10 @@ class LoginViewModel: NSObject {
}
}
}

}

extension LoginViewModel: ASAuthorizationControllerDelegate,
ASAuthorizationControllerPresentationContextProviding {
extension LoginViewModel: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
func authorizationController(
controller: ASAuthorizationController,
didCompleteWithAuthorization authorization: ASAuthorization
Expand All @@ -137,7 +137,7 @@ extension LoginViewModel: ASAuthorizationControllerDelegate,
}

print("Apple Login Successful, identity token: \(tokenString)")
loginToServer(with: .appleLogin(identityToken: tokenString, fcmToken: ""))
loginToServer(with: .appleLogin(identityToken: tokenString, fcmToken: "dummy_fcm_token"))
}

func authorizationController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
//

import UIKit

import AuthenticationServices

class LoginViewController: BaseViewController {

private let loginView = LoginView()
private let loginViewModel = LoginViewModel()
private let loginViewModel: LoginViewModel

init(viewModel: LoginViewModel = LoginViewModel()) {
self.loginViewModel = viewModel
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func loadView() {
view = loginView
Expand Down Expand Up @@ -77,32 +85,19 @@ class LoginViewController: BaseViewController {
}

@objc private func dummyNextButtonTapped() {
// _ = NicknameViewController()
// let welcomeViewController = NicknameViewController()
// welcomeViewController.modalPresentationStyle = .fullScreen
// present(welcomeViewController, animated: true, completion: nil)

// TODO: 프로필 설정부터 네비게이션으로 플로우 동작

let viewController = MainTabBarController()

viewController.modalPresentationStyle = .fullScreen

present(viewController, animated: true)
}

private func navigateToMainScreen() {
DispatchQueue.main.async {
let mainTabBarController = MainTabBarController()

let navigationController = UINavigationController(rootViewController: mainTabBarController)

navigationController.isNavigationBarHidden = true
navigationController.modalPresentationStyle = .fullScreen
navigationController.modalTransitionStyle = .crossDissolve

self.present(navigationController, animated: true, completion: nil)

}
}

Expand Down

0 comments on commit f8c6356

Please sign in to comment.