-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/Onboarding/10' of https://github.com/PyeonHaeng…
…/PyeonHaeng-iOS into feature/Onboarding/10
- Loading branch information
Showing
239 changed files
with
4,535 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// HomeService.swift | ||
// | ||
// | ||
// Created by 홍승현 on 1/31/24. | ||
// | ||
|
||
import Entity | ||
import Foundation | ||
import Network | ||
|
||
// MARK: - HomeServiceRepresentable | ||
|
||
public protocol HomeServiceRepresentable { | ||
func fetchProductList(request: ProductRequest) async throws -> [Product] | ||
func fetchProductCount(request: ProductCountRequest) async throws -> Int | ||
} | ||
|
||
// MARK: - HomeService | ||
|
||
public struct HomeService { | ||
private let network: Networking | ||
|
||
public init(network: Networking) { | ||
self.network = network | ||
} | ||
} | ||
|
||
// MARK: HomeServiceRepresentable | ||
|
||
extension HomeService: HomeServiceRepresentable { | ||
public func fetchProductList(request: ProductRequest) async throws -> [Product] { | ||
let products: [ProductResponse] = try await network.request(with: HomeEndPoint.fetchProducts(request)) | ||
return products.map(Product.init) | ||
} | ||
|
||
public func fetchProductCount(request: ProductCountRequest) async throws -> Int { | ||
let countResponse: ProductCountResponse = try await network.request(with: HomeEndPoint.fetchCount(request)) | ||
return countResponse.count | ||
} | ||
} | ||
|
||
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
17
APIService/Sources/HomeAPI/Requests/ProductCountRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// ProductCountRequest.swift | ||
// | ||
// | ||
// Created by 홍승현 on 2/2/24. | ||
// | ||
|
||
import Entity | ||
import Foundation | ||
|
||
public struct ProductCountRequest: Encodable { | ||
public let convenienceStore: ConvenienceStore | ||
|
||
public init(convenienceStore: ConvenienceStore) { | ||
self.convenienceStore = convenienceStore | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// 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 | ||
|
||
public init(store: ConvenienceStore, promotion: Promotion, order: Order, pageSize: Int, offset: Int) { | ||
self.store = store | ||
self.promotion = promotion | ||
self.order = order | ||
self.pageSize = pageSize | ||
self.offset = offset | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
APIService/Sources/HomeAPI/Responses/ProductCountResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// ProductCountResponse.swift | ||
// | ||
// | ||
// Created by 홍승현 on 2/2/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ProductCountResponse: Decodable { | ||
let count: Int | ||
} |
27 changes: 27 additions & 0 deletions
27
APIService/Sources/HomeAPI/Responses/ProductResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
struct ProductResponse: 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 | ||
} | ||
} |
85 changes: 0 additions & 85 deletions
85
APIService/Sources/HomeAPISupport/HomeProductResponse.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
APIService/Sources/HomeAPISupport/Mocks/HomeProductCountResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"count": 24 | ||
} |
Oops, something went wrong.