Skip to content

Commit 0bbb4fb

Browse files
authored
🔀 �[ProductInfo] 테스트 네트워킹 작업 (#46)
* 🌱 ViewModelRepresentable 프로토콜 구현 * 💄 LineGraph UI에 '이전 행사 정보' 레이블 UI 추가 * 👔 ProductInfoViewModel 구현 * 🌱 DTO관련 서버에 맞게 대폭 수정 및 연관된 코드 수정 * 💄 편의점 이미지만 반환 할 수 있는 있는 convenienceStoreImage(_:) 메서드 구현 * 🌱 ProductInfoDependency 구현 * 💄 자잘한 코드 수정 * 🎨 포맷 재설정 * 🎨 포맷 재설정 * 🔥 문제가 되는 코드 삭제 - 문제가 되는 코드 삭제 * 🔥 요청 사항 수정 - productID 프로퍼티 삭제 * 🔥 요청 사항 수정
1 parent 0568570 commit 0bbb4fb

File tree

16 files changed

+368
-127
lines changed

16 files changed

+368
-127
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1520"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "ProductInfoAPI"
18+
BuildableName = "ProductInfoAPI"
19+
BlueprintName = "ProductInfoAPI"
20+
ReferencedContainer = "container:">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
shouldAutocreateTestPlan = "YES">
31+
</TestAction>
32+
<LaunchAction
33+
buildConfiguration = "Debug"
34+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
35+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
36+
launchStyle = "0"
37+
useCustomWorkingDirectory = "NO"
38+
ignoresPersistentStateOnLaunch = "NO"
39+
debugDocumentVersioning = "YES"
40+
debugServiceExtension = "internal"
41+
allowLocationSimulation = "YES">
42+
</LaunchAction>
43+
<ProfileAction
44+
buildConfiguration = "Release"
45+
shouldUseLaunchSchemeArgsEnv = "YES"
46+
savedToolIdentifier = ""
47+
useCustomWorkingDirectory = "NO"
48+
debugDocumentVersioning = "YES">
49+
<MacroExpansion>
50+
<BuildableReference
51+
BuildableIdentifier = "primary"
52+
BlueprintIdentifier = "ProductInfoAPI"
53+
BuildableName = "ProductInfoAPI"
54+
BlueprintName = "ProductInfoAPI"
55+
ReferencedContainer = "container:">
56+
</BuildableReference>
57+
</MacroExpansion>
58+
</ProfileAction>
59+
<AnalyzeAction
60+
buildConfiguration = "Debug">
61+
</AnalyzeAction>
62+
<ArchiveAction
63+
buildConfiguration = "Release"
64+
revealArchiveInOrganizer = "YES">
65+
</ArchiveAction>
66+
</Scheme>

APIService/Sources/ProductInfoAPI/ProductInfoService.swift

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,49 @@ import Network
1212
// MARK: - ProductInfoServiceRepresentable
1313

1414
public protocol ProductInfoServiceRepresentable {
15-
func fetchProduct(productID: Int) async throws -> ProductDetail
16-
func fetchProductPrice(productID: Int) async throws -> [ProductPrice]
15+
func fetchProduct() async throws -> ProductDetail
16+
func fetchProductPrice() async throws -> [ProductDetail]
1717
}
1818

1919
// MARK: - ProductInfoService
2020

2121
public struct ProductInfoService {
2222
private let network: Networking
23+
private let productID: Int
2324

24-
public init(network: Networking) {
25+
public init(productID: Int, network: Networking) {
26+
self.productID = productID
2527
self.network = network
2628
}
2729
}
2830

2931
// MARK: ProductInfoServiceRepresentable
3032

3133
extension ProductInfoService: ProductInfoServiceRepresentable {
32-
public func fetchProduct(productID _: Int) async throws -> ProductDetail {
33-
let productResponse: ProductDetailResponse = try await network.request(with: ProductInfoEndPoint.fetchProduct(0))
34-
return ProductDetail(dto: productResponse)
35-
}
36-
37-
public func fetchProductPrice(productID _: Int) async throws -> [ProductPrice] {
38-
let productPrice: [ProductPriceResponse] = try await network.request(
39-
with: ProductInfoEndPoint.fetchPrices(0)
34+
public func fetchProduct() async throws -> ProductDetail {
35+
let response: ProductDetailResponse = try await network.request(
36+
with: ProductInfoEndPoint.fetchProduct(productID)
4037
)
41-
return productPrice.map(ProductPrice.init)
38+
return ProductDetail(dto: response)
4239
}
43-
}
4440

45-
private extension ProductPrice {
46-
init(dto: ProductPriceResponse) {
47-
self.init(date: dto.date, price: dto.price)
41+
public func fetchProductPrice() async throws -> [ProductDetail] {
42+
let response: [ProductDetailResponse] = try await network.request(
43+
with: ProductInfoEndPoint.fetchPrices(productID)
44+
)
45+
return response.map(ProductDetail.init(dto:))
4846
}
4947
}
5048

5149
private extension ProductDetail {
5250
init(dto: ProductDetailResponse) {
5351
self.init(
5452
id: dto.id,
55-
imageURL: dto.imageURL,
53+
imageURL: dto.img,
5654
price: dto.price,
5755
name: dto.name,
58-
promotion: dto.promotion,
59-
convenienceStore: dto.convenienceStore
56+
promotion: dto.tag,
57+
convenienceStore: dto.store
6058
)
6159
}
6260
}

APIService/Sources/ProductInfoAPI/Responses/ProductDetailResponse.swift

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@ import Entity
99
import Foundation
1010

1111
struct ProductDetailResponse: Decodable {
12-
let id: Int
13-
let imageURL: URL
14-
let price: Int
1512
let name: String
16-
let promotion: Promotion
17-
let convenienceStore: ConvenienceStore
18-
19-
enum CodingKeys: String, CodingKey {
20-
case id
21-
case imageURL = "image_url"
22-
case price
23-
case name
24-
case promotion
25-
case convenienceStore
26-
}
13+
let img: URL
14+
let price: Int
15+
let store: ConvenienceStore
16+
let tag: Promotion
17+
let proinfo: Int
18+
let id: Int
2719
}

APIService/Sources/ProductInfoAPI/Responses/ProductPriceResponse.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"name": "힛더티)슈퍼말차초코콘150ML",
4+
"img": "https://image.woodongs.com/imgsvr/item/GD_8809490180818_002.jpg",
5+
"price": 2500,
6+
"store": "GS25",
7+
"tag": "2+1",
8+
"proinfo": 0,
9+
"date": "2023-06-01",
10+
"id": 33580
11+
},
12+
{
13+
"name": "힛더티)슈퍼말차초코콘150ML",
14+
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
15+
"price": 2500,
16+
"store": "GS25",
17+
"tag": "2+1",
18+
"proinfo": 0,
19+
"date": "2023-05-01",
20+
"id": 28766
21+
},
22+
{
23+
"name": "힛더티)슈퍼말차초코콘150ML",
24+
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
25+
"price": 2500,
26+
"store": "GS25",
27+
"tag": "2+1",
28+
"proinfo": 0,
29+
"date": "2023-03-01",
30+
"id": 17993
31+
},
32+
{
33+
"name": "힛더티)슈퍼말차초코콘150ML",
34+
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
35+
"price": 2500,
36+
"store": "GS25",
37+
"tag": "2+1",
38+
"proinfo": 0,
39+
"date": "2023-02-01",
40+
"id": 13602
41+
},
42+
{
43+
"name": "힛더티)슈퍼말차초코콘150ML",
44+
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
45+
"price": 2500,
46+
"store": "GS25",
47+
"tag": "2+1",
48+
"proinfo": 0,
49+
"date": "2023-01-01",
50+
"id": 9644
51+
},
52+
{
53+
"name": "힛더티)슈퍼말차초코콘150ML",
54+
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
55+
"price": 2500,
56+
"store": "GS25",
57+
"tag": "2+1",
58+
"proinfo": 0,
59+
"date": "2022-11-01",
60+
"id": 2792
61+
}
62+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "힛더티)슈퍼말차초코콘150ML",
3+
"img": "https://image.woodongs.com/imgsvr/item/GD_8809490180818_002.jpg",
4+
"price": 2500,
5+
"store": "GS25",
6+
"tag": "2+1",
7+
"proinfo": 0,
8+
"date": "2023-06-01",
9+
"id": 33580
10+
}

APIService/Sources/ProductInfoAPISupport/Mocks/ProductPriceResponse.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

APIService/Sources/ProductInfoAPISupport/ProductInfoURLProtocol.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
//
77

88
import Foundation
9+
import Log
910
import Network
1011
import ProductInfoAPI
1112

1213
public final class ProductInfoURLProtocol: URLProtocol {
1314
private lazy var mockData: [String: Data?] = [
14-
ProductInfoEndPoint.fetchProduct(0).path: loadMockData(fileName: "HomeProductResponse"),
15-
ProductInfoEndPoint.fetchPrices(0).path: loadMockData(fileName: "ProductPriceResponse"),
15+
ProductInfoEndPoint.fetchProduct(-1).path: loadMockData(fileName: "ProductInfoProductResponse"),
16+
ProductInfoEndPoint.fetchPrices(-1).path: loadMockData(fileName: "ProductInfoPriceResponse"),
1617
]
1718

1819
override public class func canInit(with _: URLRequest) -> Bool {
@@ -36,6 +37,8 @@ public final class ProductInfoURLProtocol: URLProtocol {
3637
}
3738
}
3839

40+
override public func stopLoading() {}
41+
3942
private func loadMockData(fileName: String) -> Data? {
4043
guard let url = Bundle.module.url(forResource: fileName, withExtension: "json")
4144
else {

Entity/Sources/Entity/ConvenienceStore.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
//
77

88
import Foundation
9+
import SwiftUI
910

1011
public enum ConvenienceStore: String, Codable {
1112
case cu = "CU"
1213
case gs25 = "GS25"
13-
case _7Eleven = "7-Eleven"
14+
case _7Eleven = "7-ElEVEN"
1415
case emart24
1516
case ministop = "MINISTOP"
1617
}

Entity/Sources/Entity/ProductDetail.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct ProductDetail: Identifiable {
1313
public let id: Int
1414

1515
/// 이미지 URL
16-
public let imageURL: URL
16+
public let imageURL: URL?
1717

1818
/// 제품 가격
1919
public let price: Int
@@ -31,7 +31,7 @@ public struct ProductDetail: Identifiable {
3131

3232
public init(
3333
id: Int,
34-
imageURL: URL,
34+
imageURL: URL?,
3535
price: Int,
3636
name: String,
3737
promotion: Promotion,

0 commit comments

Comments
 (0)