diff --git a/Project_Timer.xcodeproj/project.pbxproj b/Project_Timer.xcodeproj/project.pbxproj index 8987f7ee..56fef71d 100644 --- a/Project_Timer.xcodeproj/project.pbxproj +++ b/Project_Timer.xcodeproj/project.pbxproj @@ -47,7 +47,7 @@ 8706C3302AEF881500F7C842 /* TTSignupTextFieldWarning.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8706C32F2AEF881500F7C842 /* TTSignupTextFieldWarning.swift */; }; 8706C3322AEF8A0300F7C842 /* TTSignupNextButtonForMac.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8706C3312AEF8A0300F7C842 /* TTSignupNextButtonForMac.swift */; }; 870800502B2C38F900830B39 /* ServerURLNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8708004F2B2C38F900830B39 /* ServerURLNetwork.swift */; }; - 870800522B2C3A0800830B39 /* ServerURLDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870800512B2C3A0800830B39 /* ServerURLDTO.swift */; }; + 870800522B2C3A0800830B39 /* ServerURLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870800512B2C3A0800830B39 /* ServerURLResponse.swift */; }; 870800542B2C3A5400830B39 /* ServerURLRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870800532B2C3A5400830B39 /* ServerURLRepository.swift */; }; 870800562B2C3AC600830B39 /* ServerURLRepositoryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870800552B2C3AC600830B39 /* ServerURLRepositoryInterface.swift */; }; 870800582B2C3B0C00830B39 /* GetServerURLUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870800572B2C3B0C00830B39 /* GetServerURLUseCase.swift */; }; @@ -318,6 +318,7 @@ 87B90B3A2BF4AEF600D6886E /* FirebaseRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87B90B392BF4AEF600D6886E /* FirebaseRepository.swift */; }; 87B90B3C2BF4B13D00D6886E /* AppVersionResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87B90B3B2BF4B13D00D6886E /* AppVersionResponse.swift */; }; 87B90B3F2BF4BC6D00D6886E /* ErrorResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87B90B3E2BF4BC6D00D6886E /* ErrorResponse.swift */; }; + 87B90B412BF4BFEE00D6886E /* TTProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87B90B402BF4BFEE00D6886E /* TTProvider.swift */; }; 87BE88E72AD425BE0010A84A /* SigninTextFieldView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87BE88E62AD425BE0010A84A /* SigninTextFieldView.swift */; }; 87BEBEE9281C17000095CD29 /* RecordsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87BEBEE8281C17000095CD29 /* RecordsManager.swift */; }; 87BEBEEB281C19CA0095CD29 /* StopwatchVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87BEBEEA281C19CA0095CD29 /* StopwatchVM.swift */; }; @@ -482,7 +483,7 @@ 8706C32F2AEF881500F7C842 /* TTSignupTextFieldWarning.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TTSignupTextFieldWarning.swift; sourceTree = ""; }; 8706C3312AEF8A0300F7C842 /* TTSignupNextButtonForMac.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TTSignupNextButtonForMac.swift; sourceTree = ""; }; 8708004F2B2C38F900830B39 /* ServerURLNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerURLNetwork.swift; sourceTree = ""; }; - 870800512B2C3A0800830B39 /* ServerURLDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerURLDTO.swift; sourceTree = ""; }; + 870800512B2C3A0800830B39 /* ServerURLResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerURLResponse.swift; sourceTree = ""; }; 870800532B2C3A5400830B39 /* ServerURLRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerURLRepository.swift; sourceTree = ""; }; 870800552B2C3AC600830B39 /* ServerURLRepositoryInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerURLRepositoryInterface.swift; sourceTree = ""; }; 870800572B2C3B0C00830B39 /* GetServerURLUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetServerURLUseCase.swift; sourceTree = ""; }; @@ -736,6 +737,7 @@ 87B90B392BF4AEF600D6886E /* FirebaseRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseRepository.swift; sourceTree = ""; }; 87B90B3B2BF4B13D00D6886E /* AppVersionResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppVersionResponse.swift; sourceTree = ""; }; 87B90B3E2BF4BC6D00D6886E /* ErrorResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorResponse.swift; sourceTree = ""; }; + 87B90B402BF4BFEE00D6886E /* TTProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TTProvider.swift; sourceTree = ""; }; 87BE88E62AD425BE0010A84A /* SigninTextFieldView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SigninTextFieldView.swift; sourceTree = ""; }; 87BEBEE8281C17000095CD29 /* RecordsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordsManager.swift; sourceTree = ""; }; 87BEBEEA281C19CA0095CD29 /* StopwatchVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StopwatchVM.swift; sourceTree = ""; }; @@ -1151,7 +1153,6 @@ 875FAE222B1C653A008F19D2 /* DTO */ = { isa = PBXGroup; children = ( - 870800512B2C3A0800830B39 /* ServerURLDTO.swift */, 8708005E2B2C5F5F00830B39 /* AuthDTO.swift */, 8708006E2B2CA92C00830B39 /* DailyDTO.swift */, 87F10938284C589A002E31EA /* FunctionInfo.swift */, @@ -1728,8 +1729,9 @@ children = ( 8708005D2B2C5DF400830B39 /* FirebaseValue */, 87D4DCCE2BA5492700BB5AAB /* SimpleResponse.swift */, - 87B90B3B2BF4B13D00D6886E /* AppVersionResponse.swift */, 87B90B3E2BF4BC6D00D6886E /* ErrorResponse.swift */, + 87B90B3B2BF4B13D00D6886E /* AppVersionResponse.swift */, + 870800512B2C3A0800830B39 /* ServerURLResponse.swift */, ); path = Response; sourceTree = ""; @@ -1936,6 +1938,7 @@ 87F778DC2B196E8F00909511 /* Data */ = { isa = PBXGroup; children = ( + 87B90B402BF4BFEE00D6886E /* TTProvider.swift */, 87B90B3D2BF4BC0100D6886E /* Error */, 87D4DCCD2BA548E300BB5AAB /* Response */, 87D4DCCA2BA5476900BB5AAB /* Request */, @@ -2437,6 +2440,7 @@ 87A8CD292AF0C5CB00D4C1D7 /* OverlayRemoveButtonForTextFieldView.swift in Sources */, 8751C6F628472133007FAFC4 /* SettingCellInfo.swift in Sources */, 87D4DCC72BA52F3800BB5AAB /* ResetPasswordInfo.swift in Sources */, + 87B90B412BF4BFEE00D6886E /* TTProvider.swift in Sources */, 8750082D2905998200E27B4A /* TargetTimeSettingPopupVC.swift in Sources */, 8760FCB929541BE3000BCCD1 /* KeyChain.swift in Sources */, 87D5E65328C7477100D53F8D /* MonthTime.swift in Sources */, @@ -2460,7 +2464,7 @@ 8706C32E2AEF878D00F7C842 /* TTSignupTextFieldUnderlineView.swift in Sources */, 87199F442882BC430017D01A /* StandardDailyGraphView.swift in Sources */, 93B08521248DDF2F00E215BD /* AppDelegate.swift in Sources */, - 870800522B2C3A0800830B39 /* ServerURLDTO.swift in Sources */, + 870800522B2C3A0800830B39 /* ServerURLResponse.swift in Sources */, 8791C1F227DCD050000D6BA9 /* Notification+Extension.swift in Sources */, 87F771BF2984101700BF1907 /* Todolist.swift in Sources */, 878BF7EF2955E73C0044C079 /* SyncLog.swift in Sources */, diff --git a/Project_Timer/Data/Repository/FirebaseRepository.swift b/Project_Timer/Data/Repository/FirebaseRepository.swift index 34e26604..8068f6bd 100644 --- a/Project_Timer/Data/Repository/FirebaseRepository.swift +++ b/Project_Timer/Data/Repository/FirebaseRepository.swift @@ -12,9 +12,9 @@ import RxSwift import RxMoya final class FirebaseRepository { - private let api: MoyaProvider + private let api: TTProvider - init(api: MoyaProvider) { + init(api: TTProvider) { self.api = api } @@ -23,15 +23,15 @@ final class FirebaseRepository { .map(AppVersionResponse.self) .map { $0.toDomain() } .catch { error in - if let moyaError = error as? MoyaError { - switch moyaError { - case .statusCode(let response): - return Single.error(NetworkError.serverError(statusCode: response.statusCode)) - default: - return Single.error(NetworkError.FAIL) - } - } - + return Single.error(NetworkError.DECODEERROR) + } + } + + func getServerURL() -> Single { + return self.api.rx.request(.getServerURL) + .map(ServerURLResponse.self) + .map { $0.base.value } + .catch { error in return Single.error(NetworkError.DECODEERROR) } } diff --git a/Project_Timer/Data/Repository/lagacy/ServerURLRepository.swift b/Project_Timer/Data/Repository/lagacy/ServerURLRepository.swift index e819daa4..cf692f0c 100644 --- a/Project_Timer/Data/Repository/lagacy/ServerURLRepository.swift +++ b/Project_Timer/Data/Repository/lagacy/ServerURLRepository.swift @@ -16,7 +16,7 @@ final class ServerURLRepository: ServerURLRepositoryInterface { switch result.status { case .SUCCESS: guard let data = result.data, - let dto = try? JSONDecoder().decode(ServerURLDTO.self, from: data) else { + let dto = try? JSONDecoder().decode(ServerURLResponse.self, from: data) else { completion(.failure(.DECODEERROR)) return } diff --git a/Project_Timer/Data/DTO/ServerURLDTO.swift b/Project_Timer/Data/Response/ServerURLResponse.swift similarity index 75% rename from Project_Timer/Data/DTO/ServerURLDTO.swift rename to Project_Timer/Data/Response/ServerURLResponse.swift index 147046f1..1fc92d5f 100644 --- a/Project_Timer/Data/DTO/ServerURLDTO.swift +++ b/Project_Timer/Data/Response/ServerURLResponse.swift @@ -1,14 +1,15 @@ // -// ServerURLDTO.swift +// ServerURLResponse.swift // Project_Timer // -// Created by Kang Minsang on 2023/12/15. -// Copyright © 2023 FDEE. All rights reserved. +// Created by Kang Minsang on 2024/05/15. +// Copyright © 2024 FDEE. All rights reserved. // import Foundation -struct ServerURLDTO: Decodable { +/// TiTi 서버 URL 정보 +struct ServerURLResponse: Decodable { let base: FirebaseStringValue private enum RootKey: String, CodingKey { diff --git a/Project_Timer/Data/TTProvider.swift b/Project_Timer/Data/TTProvider.swift new file mode 100644 index 00000000..b812674d --- /dev/null +++ b/Project_Timer/Data/TTProvider.swift @@ -0,0 +1,34 @@ +// +// TTProvider.swift +// Project_Timer +// +// Created by Kang Minsang on 2024/05/15. +// Copyright © 2024 FDEE. All rights reserved. +// + +import Foundation +import RxSwift +import Moya +import RxMoya + +/// 공통적인 에러를 반환하는 Provider +final class TTProvider: MoyaProvider { + func request(_ token: T) -> Single { + return super.rx.request(token) + .catch { error in + self.handleError(error) + } + } + + private func handleError(_ error: Error) -> Single { + if let moyaError = error as? MoyaError { + switch moyaError { + case .statusCode(let response): + return Single.error(NetworkError.serverError(statusCode: response.statusCode)) + default: + return Single.error(NetworkError.FAIL) + } + } + return Single.error(NetworkError.FAIL) + } +}