Skip to content

Commit

Permalink
🔀 �[ProductInfo] 테스트 네트워킹 작업 (#46)
Browse files Browse the repository at this point in the history
* 🌱 ViewModelRepresentable 프로토콜 구현

* 💄 LineGraph UI에 '이전 행사 정보' 레이블 UI 추가

* 👔 ProductInfoViewModel 구현

* 🌱 DTO관련 서버에 맞게 대폭 수정 및 연관된 코드 수정

* 💄 편의점 이미지만 반환 할 수 있는 있는 convenienceStoreImage(_:) 메서드 구현

* 🌱 ProductInfoDependency 구현

* 💄 자잘한 코드 수정

* 🎨 포맷 재설정

* 🎨 포맷 재설정

* 🔥 문제가 되는 코드 삭제

- 문제가 되는 코드 삭제

* 🔥 요청 사항 수정
- productID 프로퍼티 삭제

* 🔥 요청 사항 수정
  • Loading branch information
eung7 authored Feb 19, 2024
1 parent 0568570 commit 0bbb4fb
Show file tree
Hide file tree
Showing 16 changed files with 368 additions and 127 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ProductInfoAPI"
BuildableName = "ProductInfoAPI"
BlueprintName = "ProductInfoAPI"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ProductInfoAPI"
BuildableName = "ProductInfoAPI"
BlueprintName = "ProductInfoAPI"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
36 changes: 17 additions & 19 deletions APIService/Sources/ProductInfoAPI/ProductInfoService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,49 @@ import Network
// MARK: - ProductInfoServiceRepresentable

public protocol ProductInfoServiceRepresentable {
func fetchProduct(productID: Int) async throws -> ProductDetail
func fetchProductPrice(productID: Int) async throws -> [ProductPrice]
func fetchProduct() async throws -> ProductDetail
func fetchProductPrice() async throws -> [ProductDetail]
}

// MARK: - ProductInfoService

public struct ProductInfoService {
private let network: Networking
private let productID: Int

public init(network: Networking) {
public init(productID: Int, network: Networking) {
self.productID = productID
self.network = network
}
}

// MARK: ProductInfoServiceRepresentable

extension ProductInfoService: ProductInfoServiceRepresentable {
public func fetchProduct(productID _: Int) async throws -> ProductDetail {
let productResponse: ProductDetailResponse = try await network.request(with: ProductInfoEndPoint.fetchProduct(0))
return ProductDetail(dto: productResponse)
}

public func fetchProductPrice(productID _: Int) async throws -> [ProductPrice] {
let productPrice: [ProductPriceResponse] = try await network.request(
with: ProductInfoEndPoint.fetchPrices(0)
public func fetchProduct() async throws -> ProductDetail {
let response: ProductDetailResponse = try await network.request(
with: ProductInfoEndPoint.fetchProduct(productID)
)
return productPrice.map(ProductPrice.init)
return ProductDetail(dto: response)
}
}

private extension ProductPrice {
init(dto: ProductPriceResponse) {
self.init(date: dto.date, price: dto.price)
public func fetchProductPrice() async throws -> [ProductDetail] {
let response: [ProductDetailResponse] = try await network.request(
with: ProductInfoEndPoint.fetchPrices(productID)
)
return response.map(ProductDetail.init(dto:))
}
}

private extension ProductDetail {
init(dto: ProductDetailResponse) {
self.init(
id: dto.id,
imageURL: dto.imageURL,
imageURL: dto.img,
price: dto.price,
name: dto.name,
promotion: dto.promotion,
convenienceStore: dto.convenienceStore
promotion: dto.tag,
convenienceStore: dto.store
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@ import Entity
import Foundation

struct ProductDetailResponse: Decodable {
let id: Int
let imageURL: URL
let price: Int
let name: String
let promotion: Promotion
let convenienceStore: ConvenienceStore

enum CodingKeys: String, CodingKey {
case id
case imageURL = "image_url"
case price
case name
case promotion
case convenienceStore
}
let img: URL
let price: Int
let store: ConvenienceStore
let tag: Promotion
let proinfo: Int
let id: Int
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"name": "힛더티)슈퍼말차초코콘150ML",
"img": "https://image.woodongs.com/imgsvr/item/GD_8809490180818_002.jpg",
"price": 2500,
"store": "GS25",
"tag": "2+1",
"proinfo": 0,
"date": "2023-06-01",
"id": 33580
},
{
"name": "힛더티)슈퍼말차초코콘150ML",
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
"price": 2500,
"store": "GS25",
"tag": "2+1",
"proinfo": 0,
"date": "2023-05-01",
"id": 28766
},
{
"name": "힛더티)슈퍼말차초코콘150ML",
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
"price": 2500,
"store": "GS25",
"tag": "2+1",
"proinfo": 0,
"date": "2023-03-01",
"id": 17993
},
{
"name": "힛더티)슈퍼말차초코콘150ML",
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
"price": 2500,
"store": "GS25",
"tag": "2+1",
"proinfo": 0,
"date": "2023-02-01",
"id": 13602
},
{
"name": "힛더티)슈퍼말차초코콘150ML",
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
"price": 2500,
"store": "GS25",
"tag": "2+1",
"proinfo": 0,
"date": "2023-01-01",
"id": 9644
},
{
"name": "힛더티)슈퍼말차초코콘150ML",
"img": "http://gs25appimg.gsretail.com/imgsvr/item/GD_8809490180818_001.jpg",
"price": 2500,
"store": "GS25",
"tag": "2+1",
"proinfo": 0,
"date": "2022-11-01",
"id": 2792
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "힛더티)슈퍼말차초코콘150ML",
"img": "https://image.woodongs.com/imgsvr/item/GD_8809490180818_002.jpg",
"price": 2500,
"store": "GS25",
"tag": "2+1",
"proinfo": 0,
"date": "2023-06-01",
"id": 33580
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
//

import Foundation
import Log
import Network
import ProductInfoAPI

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

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

override public func stopLoading() {}

private func loadMockData(fileName: String) -> Data? {
guard let url = Bundle.module.url(forResource: fileName, withExtension: "json")
else {
Expand Down
3 changes: 2 additions & 1 deletion Entity/Sources/Entity/ConvenienceStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//

import Foundation
import SwiftUI

public enum ConvenienceStore: String, Codable {
case cu = "CU"
case gs25 = "GS25"
case _7Eleven = "7-Eleven"
case _7Eleven = "7-ElEVEN"
case emart24
case ministop = "MINISTOP"
}
4 changes: 2 additions & 2 deletions Entity/Sources/Entity/ProductDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct ProductDetail: Identifiable {
public let id: Int

/// 이미지 URL
public let imageURL: URL
public let imageURL: URL?

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

public init(
id: Int,
imageURL: URL,
imageURL: URL?,
price: Int,
name: String,
promotion: Promotion,
Expand Down
Loading

0 comments on commit 0bbb4fb

Please sign in to comment.