From f349cd79e45cf0ef24ff4777f60c71c23211f41b Mon Sep 17 00:00:00 2001 From: hryeong66 Date: Mon, 30 Sep 2024 18:42:23 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20alamofire=20=EC=82=AD=EC=A0=9C=20(#76))?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit etc: 아카이빙하면서 생긴 에러 삭제 (#76) --- .../Sources/Endpoint/MemeEditEndPoint.swift | 33 ++------------- Projects/Core/PPACNetwork/Project.swift | 3 +- .../Sources/MultipartRequestable.swift | 2 - .../PPACNetwork/Sources/NetworkService.swift | 42 +------------------ .../MyPage/Sources/MyPageRouter.swift | 1 - Tuist/Package.swift | 6 +-- .../TargetDependency+.swift | 1 - 7 files changed, 7 insertions(+), 81 deletions(-) diff --git a/Projects/Core/PPACData/Sources/Endpoint/MemeEditEndPoint.swift b/Projects/Core/PPACData/Sources/Endpoint/MemeEditEndPoint.swift index 016670b..8fe7859 100644 --- a/Projects/Core/PPACData/Sources/Endpoint/MemeEditEndPoint.swift +++ b/Projects/Core/PPACData/Sources/Endpoint/MemeEditEndPoint.swift @@ -8,12 +8,11 @@ import Foundation import PPACNetwork import UIKit -import Alamofire enum MemeEditEndPoint: MultipartRequestable { case registerMeme(formData: FormData, title: String, source: String, keywordIds: [String]) - var httpMethod: PPACNetwork.HTTPMethod { + var httpMethod: HTTPMethod { switch self { case .registerMeme: return .post @@ -35,13 +34,13 @@ enum MemeEditEndPoint: MultipartRequestable { return nil } - var formData: PPACNetwork.MultipartFormData { + var formData: MultipartFormData { switch self { case .registerMeme(let formData, let title, let source, let keywordIds): let formFields: [String : String] = ["title" : title, "source": source] print("=============== MultipartFormData ===============\n") - var multipartFormData = PPACNetwork.MultipartFormData() + var multipartFormData = MultipartFormData() formFields.forEach { key, value in multipartFormData.appendTextField(named: key, value: value) @@ -58,30 +57,4 @@ enum MemeEditEndPoint: MultipartRequestable { } } - var multipartFormData: Alamofire.MultipartFormData { - switch self { - case .registerMeme(let formData, let title, let source, let keywordIds): - - let formFields: [String : String] = ["title" : title, - "source": source] - let multipartFormData = Alamofire.MultipartFormData() - - formFields.forEach { key, value in - if let data = "\(value)".data(using: .utf8) { - multipartFormData.append(data, withName: key) - } - } - - keywordIds.forEach { keywordId in - if let data = "\(keywordId)".data(using: .utf8) { - multipartFormData.append(data, withName: "keywordIds[]") - } - } - - multipartFormData.append(formData.fileData, withName: formData.fieldName, fileName: formData.fileName, mimeType: formData.mimeType) - - return multipartFormData - - } - } } diff --git a/Projects/Core/PPACNetwork/Project.swift b/Projects/Core/PPACNetwork/Project.swift index 8fa85c0..e7eedc7 100644 --- a/Projects/Core/PPACNetwork/Project.swift +++ b/Projects/Core/PPACNetwork/Project.swift @@ -20,8 +20,7 @@ let project = Project( sources: "Sources/**", resources: "Resources/**", dependencies: [ - .Core.PPACUtil, - .ThirdParty.Alamofire + .Core.PPACUtil ] ) ] diff --git a/Projects/Core/PPACNetwork/Sources/MultipartRequestable.swift b/Projects/Core/PPACNetwork/Sources/MultipartRequestable.swift index 20f63a6..147732c 100644 --- a/Projects/Core/PPACNetwork/Sources/MultipartRequestable.swift +++ b/Projects/Core/PPACNetwork/Sources/MultipartRequestable.swift @@ -6,9 +6,7 @@ // import Foundation -import Alamofire public protocol MultipartRequestable: Requestable { var formData: MultipartFormData { get } - var multipartFormData: Alamofire.MultipartFormData { get } } diff --git a/Projects/Core/PPACNetwork/Sources/NetworkService.swift b/Projects/Core/PPACNetwork/Sources/NetworkService.swift index ecb682d..15387e9 100644 --- a/Projects/Core/PPACNetwork/Sources/NetworkService.swift +++ b/Projects/Core/PPACNetwork/Sources/NetworkService.swift @@ -6,7 +6,6 @@ // import Foundation -import Alamofire final public class NetworkService: NetworkServiceable { @@ -22,8 +21,6 @@ final public class NetworkService: NetworkServiceable { if let multipartRequest = request as? MultipartRequestable { - let result = await self.excuteAFUploadRequest(multipartRequest, dataType: dataType) - print("result = \(result)") let multipartFormData = multipartRequest.formData urlRequest.setValue("*/*", forHTTPHeaderField: "Accept") urlRequest.setValue(multipartFormData.contentType, forHTTPHeaderField: "Content-Type") @@ -54,44 +51,7 @@ final public class NetworkService: NetworkServiceable { return .failure(.invalidResponse) } } - - private func excuteAFUploadRequest(_ request: MultipartRequestable, dataType: T.Type) async -> Result { - guard let url = request.makeURL() else { - NetworkLogger.logError(.urlEncodingError) - return .failure(.urlEncodingError) - } - - var urlRequest = request.buildURLRequest(with: url) - urlRequest.setValue("*/*", forHTTPHeaderField: "Accept") - urlRequest.setValue("multipart/form-data", forHTTPHeaderField: "Content-Type") - let headers = urlRequest.allHTTPHeaderFields ?? [:] - do { - return try await withCheckedThrowingContinuation { continuation in - AF.upload( - multipartFormData: request.multipartFormData, - to: url, - method: .post, - headers: HTTPHeaders(headers)) - .responseJSON { response in - switch response.result { - case .success(let data): - do { - guard let responseData = response.data else { return } - let decodedData = try JSONDecoder().decode(T.self, from: responseData) - continuation.resume(returning: .success(decodedData)) - } catch { - continuation.resume(returning: .failure(.dataDecodingError)) - } - case .failure(let error): - continuation.resume(returning: .failure(NetworkError.serverError(statusCode: error.responseCode ?? -1 , message: error.errorDescription))) - } - } - } - } catch { - return .failure(.invalidResponse) - } - } - + private func handleResponse(_ response: URLResponse, data: Data, dataType: T.Type) -> Result { guard let httpResponse = response as? HTTPURLResponse else { NetworkLogger.logError(.invalidResponse) diff --git a/Projects/Features/MyPage/Sources/MyPageRouter.swift b/Projects/Features/MyPage/Sources/MyPageRouter.swift index 6ccfda4..975dd19 100644 --- a/Projects/Features/MyPage/Sources/MyPageRouter.swift +++ b/Projects/Features/MyPage/Sources/MyPageRouter.swift @@ -18,7 +18,6 @@ import DesignSystem import MemeDetail import Setting -import MemeEditor public final class MyPageRouter: Router, MyPageRouting { diff --git a/Tuist/Package.swift b/Tuist/Package.swift index 5ca9fa6..47a03cf 100644 --- a/Tuist/Package.swift +++ b/Tuist/Package.swift @@ -10,8 +10,7 @@ import PackageDescription "Lottie": .framework, "Kingfisher": .framework, "PopupView": .framework, - "SkeletonUI": .framework, - "Alamofire": .framework + "SkeletonUI": .framework ] ) #endif @@ -25,7 +24,6 @@ let package = Package( .package(url: "https://github.com/exyte/PopupView.git", from: "3.0.4"), .package(url: "https://github.com/CSolanaM/SkeletonUI.git", from: "2.0.2"), .package(url: "https://github.com/AppsFlyerSDK/AppsFlyerFramework-Dynamic", from: "6.15.1"), - .package(url: "https://github.com/firebase/firebase-ios-sdk", from: "10.27.0"), - .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.9.1") + .package(url: "https://github.com/firebase/firebase-ios-sdk", from: "10.27.0") ] ) diff --git a/Tuist/ProjectDescriptionHelpers/TargetDependency+.swift b/Tuist/ProjectDescriptionHelpers/TargetDependency+.swift index f2e33df..a75b457 100644 --- a/Tuist/ProjectDescriptionHelpers/TargetDependency+.swift +++ b/Tuist/ProjectDescriptionHelpers/TargetDependency+.swift @@ -39,7 +39,6 @@ extension TargetDependency { public static let FirebaseCrashlytics = TargetDependency.external(name: "FirebaseCrashlytics") public static let SkeletonUI = TargetDependency.external(name: "SkeletonUI") public static let AppsFlyerLib = TargetDependency.external(name: "AppsFlyerLib-Dynamic") - public static let Alamofire = TargetDependency.external(name: "Alamofire") } public static let ResourceKit = TargetDependency.project(