Skip to content

Commit

Permalink
feat: #4- 코드리뷰 반영 - 네이밍 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hryeong66 committed Jun 13, 2024
1 parent b1e342a commit f340e5a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Projects/Core/PPACNetwork/Sources/NetworkError.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// APIServiceError.swift
// NetworkError.swift
// PPACNetwork
//
// Created by 장혜령 on 6/8/24.
Expand Down
2 changes: 1 addition & 1 deletion Projects/Core/PPACNetwork/Sources/NetworkServiceable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import Foundation

public protocol NetworkServiceable {
func request<T: Decodable>(_ request: Requestable) async throws -> T?
func request<T: Decodable>(_ request: Requestable) async -> (data: T?, error: Error?)
}
5 changes: 2 additions & 3 deletions Projects/Core/PPACNetwork/Sources/Requestable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public protocol Requestable {
var url: String { get }
var httpMethod: HTTPMethod { get }
var headers: [String: String]? { get }
var body: Data? { get }
var body: [String: Any]? { get }

func buildURLRequest(with url: URL) -> URLRequest
}
Expand All @@ -28,9 +28,8 @@ extension Requestable {
var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = httpMethod.rawValue.uppercased()
urlRequest.allHTTPHeaderFields = headers ?? [:]
urlRequest.httpBody = body
urlRequest.httpBody = body?.toJsonString()?.data(using: .utf8)
return urlRequest
}
}


27 changes: 17 additions & 10 deletions Projects/Features/Home/Sources/Service/ExampleRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@

import Foundation
import PPACModels
import PPACNetwork

protocol ExampleRepository {
func getExample() -> ExampleVO
func fetchExample() async -> ExampleVO?
func postExample(id: Int) async -> ExampleVO?
}

class ExampleRepositoryImpl: ExampleRepository {

let apiClient: ExampleServiceable
let apiService: NetworkServiceable
init(apiService: NetworkServiceable) {
self.apiService = apiService
}

init(apiClient: ExampleServiceable) {
self.apiClient = apiClient
func fetchExample() async -> ExampleVO? {
let request = ExampleServiceEndpoints.getExample
let (data: ExampleDTO, error) = await self.apiService.request(request)
guard let data, error == nil else { return nil }
return ExampleVO(exampleString: response.exampleString ?? "")
}

func getExample() -> ExampleVO {
Task {
let exampleDTO = await apiClient.fetchExample()
let exampleVO = ExampleVO(exampleString: "")
return exampleVO
}
func postExample(id: Int) async -> ExampleVO? {
let request = ExampleServiceEndpoints.postExmple(id: id)
let (data: ExampleDTO, error) = await self.apiService.request(request)
guard let data, error == nil else { return nil }
return ExampleVO(exampleString: response.exampleString ?? "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import PPACNetwork

enum ExampleServiceEndpoints {
enum ExampleServiceEndpoints: Requestable {
case fetchExample
case postExmple(id: Int)

Expand All @@ -25,7 +25,7 @@ enum ExampleServiceEndpoints {
}
}

var requestBody: [String: String]? {
var body: [String: Any]? {
switch self {
case .postExmple(let id):
return ["id": id]
Expand All @@ -36,7 +36,6 @@ enum ExampleServiceEndpoints {

var url: String {
let baseUrl = ""

switch self {
case .fetchExample:
return "\(baseUrl)/example"
Expand All @@ -45,18 +44,11 @@ enum ExampleServiceEndpoints {
}
}

var headers: [String: String] {
var headers: [String: String]? {
var headers: [String: String] = [:]
headers["Authorization"] = "token"
headers["Content-Type"] = "application/json"
return headers
}

func createRequest() -> NetworkRequest {
return NetworkRequest(url: url,
httpMethod: httpMethod,
headers: headers,
body: requestBody)
}
}

8 changes: 5 additions & 3 deletions Projects/Features/Home/Sources/Service/ExampleUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import PPACModels

protocol ExampleUseCase {
func getExample() -> ExampleVO
func getExample()
}

class ExampleUseCaseImpl: ExampleUseCase {
Expand All @@ -19,7 +19,9 @@ class ExampleUseCaseImpl: ExampleUseCase {
self.repository = repository
}

func getExample() -> ExampleVO {
return self.repository.getExample()
func getExample() {
Task {
let exempleVO = self.repository.fetchExample()
}
}
}
2 changes: 1 addition & 1 deletion Tuist/ProjectDescriptionHelpers/Target+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension Target {
product: product,
// productName: productName,
bundleId: bundleId ?? "\(organizationName).\(name)",
deploymentTargets: .iOS("17.5"),
deploymentTargets: .iOS("17.0"),
infoPlist: infoPlist,
sources: sources,
resources: resources,
Expand Down

0 comments on commit f340e5a

Please sign in to comment.