Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Home] Mock JSON으로 제품 리스트 가져오는 흐름 구현 #29

Merged
merged 16 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion APIService/Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

Expand All @@ -18,12 +17,14 @@ let package = Package(
],
dependencies: [
.package(path: "../Core"),
.package(path: "../Entity"),
],
targets: [
.target(
name: "HomeAPI",
dependencies: [
.product(name: "Network", package: "Core"),
.product(name: "Entity", package: "Entity"),
]
),
.target(
Expand Down
8 changes: 4 additions & 4 deletions APIService/Sources/HomeAPI/HomeEndPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import Foundation
import Network

struct HomeEndPoint: EndPoint {
var method: HTTPMethod
let method: HTTPMethod = .get

var path: String
let path: String = "v2/products"

var parameters: Network.HTTPParameter
let parameters: HTTPParameter = .plain

var headers: [String: String]
let headers: [String: String] = ["Content-Type": "application/json"]
}
48 changes: 48 additions & 0 deletions APIService/Sources/HomeAPI/HomeService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// HomeService.swift
//
//
// Created by 홍승현 on 1/31/24.
//

import Entity
import Foundation
import Network

// MARK: - HomeServiceRepresentable

public protocol HomeServiceRepresentable {
func fetchProductList() async throws -> [Product]
}

// MARK: - HomeService

public struct HomeService {
private let network: Networking

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

// MARK: HomeServiceRepresentable
eung7 marked this conversation as resolved.
Show resolved Hide resolved

extension HomeService: HomeServiceRepresentable {
public func fetchProductList() async throws -> [Product] {
let products: [ProductResponse] = try await network.request(with: HomeEndPoint())
return products.map(Product.init)
}
}

private extension Product {
init(dto: ProductResponse) {
self.init(
id: dto.id,
imageURL: dto.imageURL,
price: dto.price,
name: dto.name,
promotion: dto.promotion,
convenienceStore: dto.convenienceStore
)
}
}
17 changes: 17 additions & 0 deletions APIService/Sources/HomeAPI/Requests/ProductRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ProductRequest.swift
//
//
// Created by 홍승현 on 1/31/24.
//

import Entity
import Foundation

public struct ProductRequest: Encodable {
public let store: ConvenienceStore
public let promotion: Promotion
public let order: Order
public let pageSize: Int
public let offset: Int
}
27 changes: 27 additions & 0 deletions APIService/Sources/HomeAPI/Responses/ProductResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ProductResponse.swift
//
//
// Created by 홍승현 on 1/31/24.
//

import Entity
import Foundation

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

public enum CodingKeys: String, CodingKey {
case id
case imageURL = "image_url"
case price
case name
case promotion
case convenienceStore
}
}
177 changes: 92 additions & 85 deletions APIService/Sources/HomeAPISupport/HomeProductResponse.json
Original file line number Diff line number Diff line change
@@ -1,85 +1,92 @@
{
"count": 10,
"products": [
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8809288634967_001.jpg",
"price": 2500,
"name": "BR)레인보우샤베트과즙워터500ML",
"tag": "1+1",
"store": "GS25"
},
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8809288635315_003.jpg",
"price": 2500,
"name": "BR)망고탱고과즙워터500ML",
"tag": "1+1",
"store": "GS25"
},
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8809288634974_001.jpg",
"price": 2500,
"name": "BR)피치요거트과즙워터500ML",
"tag": "1+1",
"store": "GS25"
},
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8806002010861_865.jpg",
"price": 5000,
"name": "광동)헛개파워100ML",
"tag": "1+1",
"store": "GS25"
},
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8806011416005_001.JPG",
"price": 5000,
"name": "동아)모닝케어D100ML",
"tag": "1+1",
"store": "GS25"
},
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8806011415992_001.JPG",
"price": 5000,
"name": "동아)모닝케어H100ML",
"tag": "1+1",
"store": "GS25"
},
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8809556566891_001.jpg",
"price": 5000,
"name": "서영)모닝이즈백100ML",
"tag": "1+1",
"store": "GS25"
},
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8809125061857_002.jpg",
"price": 5000,
"name": "종근당)헛개땡큐골드100ML",
"tag": "1+1",
"store": "GS25"
},
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8809329050015_018.jpg",
"price": 5000,
"name": "천지개벽)숙취해소음료100ML",
"tag": "1+1",
"store": "GS25"
},
{
"date": "2024:01",
"img": "https://image.woodongs.com/imgsvr/item/GD_8801013777260_001.jpg",
"price": 5000,
"name": "큐원)상쾌환부스터100ML",
"tag": "1+1",
"store": "GS25"
}
]
}
[
{
"id": 1,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809288634967_001.jpg",
"price": 2500,
"name": "BR)레인보우샤베트과즙워터500ML",
"promotion": "1+1",
"convenienceStore": "GS25"
},
{
"id": 2,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809288635315_003.jpg",
"price": 2500,
"name": "BR)망고탱고과즙워터500ML",
"promotion": "1+1",
"convenienceStore": "GS25"
},
{
"id": 3,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809288634974_001.jpg",
"price": 2500,
"name": "BR)피치요거트과즙워터500ML",
"promotion": "1+1",
"convenienceStore": "GS25"
},
{
"id": 4,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8806002010861_865.jpg",
"price": 5000,
"name": "광동)헛개파워100ML",
"promotion": "1+1",
"convenienceStore": "GS25"
},
{
"id": 5,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8806011416005_001.JPG",
"price": 5000,
"name": "동아)모닝케어D100ML",
"promotion": "1+1",
"convenienceStore": "GS25"
},
{
"id": 6,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8806011415992_001.JPG",
"price": 5000,
"name": "동아)모닝케어H100ML",
"promotion": "1+1",
"convenienceStore": "GS25"
},
{
"id": 7,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809556566891_001.jpg",
"price": 5000,
"name": "서영)모닝이즈백100ML",
"promotion": "1+1",
"convenienceStore": "GS25"
},
{
"id": 8,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809125061857_002.jpg",
"price": 5000,
"name": "종근당)헛개땡큐골드100ML",
"promotion": "1+1",
"convenienceStore": "GS25"
},
{
"id": 9,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809329050015_018.jpg",
"price": 5000,
"name": "천지개벽)숙취해소음료100ML",
"promotion": "1+1",
"convenienceStore": "GS25"
},
{
"id": 10,
"date": "2024:01",
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8801013777260_001.jpg",
"price": 5000,
"name": "큐원)상쾌환부스터100ML",
"promotion": "1+1",
"convenienceStore": "GS25"
}
]
8 changes: 8 additions & 0 deletions Entity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
18 changes: 18 additions & 0 deletions Entity/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// swift-tools-version: 5.9

import PackageDescription

let package = Package(
name: "Entity",
products: [
.library(
name: "Entity",
targets: ["Entity"]
),
],
targets: [
.target(
name: "Entity"
),
]
)
16 changes: 16 additions & 0 deletions Entity/Sources/Entity/ConvenienceStore.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ConvenienceStore.swift
//
//
// Created by 홍승현 on 1/31/24.
//

import Foundation

public enum ConvenienceStore: String, Codable {
case cu = "CU"
case gs25 = "GS25"
case _7Eleven = "7-Eleven"
case emart24
case ministop = "MINISTOP"
}
14 changes: 14 additions & 0 deletions Entity/Sources/Entity/Order.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Order.swift
//
//
// Created by 홍승현 on 1/31/24.
//

import Foundation

public enum Order: String, Codable {
case normal
case ascending = "asc"
case descending = "desc"
}
Loading