Skip to content

Commit

Permalink
feat: alamofire 삭제 (#76))
Browse files Browse the repository at this point in the history
etc: 아카이빙하면서 생긴 에러 삭제 (#76)
  • Loading branch information
hryeong66 committed Sep 30, 2024
1 parent c71105a commit f349cd7
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 81 deletions.
33 changes: 3 additions & 30 deletions Projects/Core/PPACData/Sources/Endpoint/MemeEditEndPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

}
}
}
3 changes: 1 addition & 2 deletions Projects/Core/PPACNetwork/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ let project = Project(
sources: "Sources/**",
resources: "Resources/**",
dependencies: [
.Core.PPACUtil,
.ThirdParty.Alamofire
.Core.PPACUtil
]
)
]
Expand Down
2 changes: 0 additions & 2 deletions Projects/Core/PPACNetwork/Sources/MultipartRequestable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
//

import Foundation
import Alamofire

public protocol MultipartRequestable: Requestable {
var formData: MultipartFormData { get }
var multipartFormData: Alamofire.MultipartFormData { get }
}
42 changes: 1 addition & 41 deletions Projects/Core/PPACNetwork/Sources/NetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import Alamofire

final public class NetworkService: NetworkServiceable {

Expand All @@ -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")
Expand Down Expand Up @@ -54,44 +51,7 @@ final public class NetworkService: NetworkServiceable {
return .failure(.invalidResponse)
}
}

private func excuteAFUploadRequest<T: Decodable>(_ request: MultipartRequestable, dataType: T.Type) async -> Result<T, NetworkError> {
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<T: Decodable>(_ response: URLResponse, data: Data, dataType: T.Type) -> Result<T, NetworkError> {
guard let httpResponse = response as? HTTPURLResponse else {
NetworkLogger.logError(.invalidResponse)
Expand Down
1 change: 0 additions & 1 deletion Projects/Features/MyPage/Sources/MyPageRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import DesignSystem

import MemeDetail
import Setting
import MemeEditor


public final class MyPageRouter: Router, MyPageRouting {
Expand Down
6 changes: 2 additions & 4 deletions Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import PackageDescription
"Lottie": .framework,
"Kingfisher": .framework,
"PopupView": .framework,
"SkeletonUI": .framework,
"Alamofire": .framework
"SkeletonUI": .framework
]
)
#endif
Expand All @@ -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")
]
)
1 change: 0 additions & 1 deletion Tuist/ProjectDescriptionHelpers/TargetDependency+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f349cd7

Please sign in to comment.