Skip to content

Commit ca7a76f

Browse files
authored
Merge branch 'main' into feature/productinfo/48
2 parents 11a6f66 + d615750 commit ca7a76f

File tree

13 files changed

+379
-134
lines changed

13 files changed

+379
-134
lines changed

APIService/Sources/HomeAPI/HomeService.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Network
1212
// MARK: - HomeServiceRepresentable
1313

1414
public protocol HomeServiceRepresentable {
15-
func fetchProductList(request: ProductRequest) async throws -> [Product]
15+
func fetchProductList(request: ProductRequest) async throws -> Paginated<Product>
1616
func fetchProductCount(request: ProductCountRequest) async throws -> Int
1717
}
1818

@@ -29,9 +29,9 @@ public struct HomeService {
2929
// MARK: HomeServiceRepresentable
3030

3131
extension HomeService: HomeServiceRepresentable {
32-
public func fetchProductList(request: ProductRequest) async throws -> [Product] {
33-
let products: [ProductResponse] = try await network.request(with: HomeEndPoint.fetchProducts(request))
34-
return products.map(Product.init)
32+
public func fetchProductList(request: ProductRequest) async throws -> Paginated<Product> {
33+
let response: ProductResponse = try await network.request(with: HomeEndPoint.fetchProducts(request))
34+
return Paginated<Product>(dto: response)
3535
}
3636

3737
public func fetchProductCount(request: ProductCountRequest) async throws -> Int {
@@ -40,8 +40,18 @@ extension HomeService: HomeServiceRepresentable {
4040
}
4141
}
4242

43-
private extension Product {
43+
private extension Paginated where Model == Product {
4444
init(dto: ProductResponse) {
45+
self.init(
46+
count: dto.count,
47+
hasMore: dto.hasMore,
48+
results: dto.results.map(Product.init)
49+
)
50+
}
51+
}
52+
53+
private extension Product {
54+
init(dto: ProductItemResponse) {
4555
self.init(
4656
id: dto.id,
4757
imageURL: dto.imageURL,

APIService/Sources/HomeAPI/Responses/ProductResponse.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,37 @@ import Foundation
1010

1111
// MARK: - ProductResponse
1212

13-
struct ProductResponse: Decodable {
13+
struct ProductResponse: Decodable, Paginatable {
14+
let count: Int
15+
let hasMore: Bool
16+
17+
let results: [ProductItemResponse]
18+
19+
enum CodingKeys: String, CodingKey {
20+
case count
21+
case hasMore = "has_more"
22+
case results
23+
}
24+
}
25+
26+
// MARK: - ProductItemResponse
27+
28+
struct ProductItemResponse: Decodable {
1429
let id: Int
1530
let imageURL: URL
31+
let date: Date
1632
let price: Int
1733
let name: String
1834
let promotion: Promotion
1935
let convenienceStore: ConvenienceStore
2036

2137
enum CodingKeys: String, CodingKey {
2238
case id
23-
case imageURL = "image_url"
39+
case imageURL = "img"
2440
case price
41+
case date
2542
case name
26-
case promotion
27-
case convenienceStore
43+
case promotion = "tag"
44+
case convenienceStore = "store"
2845
}
2946
}
Lines changed: 36 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,36 @@
1-
[
2-
{
3-
"id": 1,
4-
"date": "2024:01",
5-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809288634967_001.jpg",
6-
"price": 2500,
7-
"name": "BR)레인보우샤베트과즙워터500ML",
8-
"promotion": "1+1",
9-
"convenienceStore": "GS25"
10-
},
11-
{
12-
"id": 2,
13-
"date": "2024:01",
14-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809288635315_003.jpg",
15-
"price": 2500,
16-
"name": "BR)망고탱고과즙워터500ML",
17-
"promotion": "1+1",
18-
"convenienceStore": "GS25"
19-
},
20-
{
21-
"id": 3,
22-
"date": "2024:01",
23-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809288634974_001.jpg",
24-
"price": 2500,
25-
"name": "BR)피치요거트과즙워터500ML",
26-
"promotion": "1+1",
27-
"convenienceStore": "GS25"
28-
},
29-
{
30-
"id": 4,
31-
"date": "2024:01",
32-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8806002010861_865.jpg",
33-
"price": 5000,
34-
"name": "광동)헛개파워100ML",
35-
"promotion": "1+1",
36-
"convenienceStore": "GS25"
37-
},
38-
{
39-
"id": 5,
40-
"date": "2024:01",
41-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8806011416005_001.JPG",
42-
"price": 5000,
43-
"name": "동아)모닝케어D100ML",
44-
"promotion": "1+1",
45-
"convenienceStore": "GS25"
46-
},
47-
{
48-
"id": 6,
49-
"date": "2024:01",
50-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8806011415992_001.JPG",
51-
"price": 5000,
52-
"name": "동아)모닝케어H100ML",
53-
"promotion": "1+1",
54-
"convenienceStore": "GS25"
55-
},
56-
{
57-
"id": 7,
58-
"date": "2024:01",
59-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809556566891_001.jpg",
60-
"price": 5000,
61-
"name": "서영)모닝이즈백100ML",
62-
"promotion": "1+1",
63-
"convenienceStore": "GS25"
64-
},
65-
{
66-
"id": 8,
67-
"date": "2024:01",
68-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809125061857_002.jpg",
69-
"price": 5000,
70-
"name": "종근당)헛개땡큐골드100ML",
71-
"promotion": "1+1",
72-
"convenienceStore": "GS25"
73-
},
74-
{
75-
"id": 9,
76-
"date": "2024:01",
77-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8809329050015_018.jpg",
78-
"price": 5000,
79-
"name": "천지개벽)숙취해소음료100ML",
80-
"promotion": "1+1",
81-
"convenienceStore": "GS25"
82-
},
83-
{
84-
"id": 10,
85-
"date": "2024:01",
86-
"image_url": "https://image.woodongs.com/imgsvr/item/GD_8801013777260_001.jpg",
87-
"price": 5000,
88-
"name": "큐원)상쾌환부스터100ML",
89-
"promotion": "1+1",
90-
"convenienceStore": "GS25"
91-
}
92-
]
1+
{
2+
"count": 3,
3+
"has_more": true,
4+
"results": [
5+
{
6+
"name": "MDS)베이컨까르보나라파스타",
7+
"img": "https://www.7-eleven.co.kr/upload/product/8805684/009026.1.jpg",
8+
"price": 4100,
9+
"store": "7-ELEVEn",
10+
"tag": "2+1",
11+
"proinfo": 0,
12+
"date": "2024-02-01T10:11:47Z",
13+
"id": 84683
14+
},
15+
{
16+
"name": "MDS)투움바파스타230g",
17+
"img": "https://www.7-eleven.co.kr/upload/product/8805684/003307.1.jpg",
18+
"price": 4100,
19+
"store": "7-ELEVEn",
20+
"tag": "2+1",
21+
"proinfo": 0,
22+
"date": "2024-02-01T10:11:47Z",
23+
"id": 84684
24+
},
25+
{
26+
"name": "MDS)미트파스타230g",
27+
"img": "https://www.7-eleven.co.kr/upload/product/8805684/005813.1.jpg",
28+
"price": 4100,
29+
"store": "7-ELEVEn",
30+
"tag": "2+1",
31+
"proinfo": 0,
32+
"date": "2024-02-01T10:11:47Z",
33+
"id": 84685
34+
}
35+
]
36+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Paginatable.swift
3+
//
4+
//
5+
// Created by 홍승현 on 2/23/24.
6+
//
7+
8+
public protocol Paginatable {
9+
associatedtype Model
10+
var count: Int { get }
11+
var hasMore: Bool { get }
12+
13+
var results: [Model] { get }
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Paginated.swift
3+
//
4+
//
5+
// Created by 홍승현 on 2/23/24.
6+
//
7+
8+
/// 페이징 처리가 들어가는 모델의 경우 해당 모델을 사용합니다.
9+
public struct Paginated<Model>: Paginatable {
10+
public let count: Int
11+
public let hasMore: Bool
12+
public let results: [Model]
13+
14+
public init(count: Int, hasMore: Bool, results: [Model]) {
15+
self.count = count
16+
self.hasMore = hasMore
17+
self.results = results
18+
}
19+
}

Entity/Sources/Entity/ConvenienceStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import Foundation
99
import SwiftUI
1010

11-
public enum ConvenienceStore: String, Codable {
11+
public enum ConvenienceStore: String, Codable, CaseIterable {
1212
case cu = "CU"
1313
case gs25 = "GS25"
14-
case _7Eleven = "7-ElEVEN"
14+
case _7Eleven = "7-ELEVEn"
1515
case emart24
1616
case ministop = "MINISTOP"
1717
}

PyeonHaeng-iOS.xcodeproj/project.pbxproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
BA28F1A42B61572A0052855E /* Pretendard-ExtraBold.otf in Resources */ = {isa = PBXBuildFile; fileRef = BA28F19A2B61572A0052855E /* Pretendard-ExtraBold.otf */; };
3131
BA28F1A52B61572A0052855E /* Pretendard-Light.otf in Resources */ = {isa = PBXBuildFile; fileRef = BA28F19B2B61572A0052855E /* Pretendard-Light.otf */; };
3232
BA28F1A62B61572A0052855E /* Pretendard-Black.otf in Resources */ = {isa = PBXBuildFile; fileRef = BA28F19C2B61572A0052855E /* Pretendard-Black.otf */; };
33+
BA402F7E2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA402F7D2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift */; };
3334
BA4EA3602B6A37E10003DCE7 /* Entity in Frameworks */ = {isa = PBXBuildFile; productRef = BA4EA35F2B6A37E10003DCE7 /* Entity */; };
3435
BAA4D9AD2B5A1795005999F8 /* PyeonHaengApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAA4D9AC2B5A1795005999F8 /* PyeonHaengApp.swift */; };
3536
BAA4D9AF2B5A1795005999F8 /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAA4D9AE2B5A1795005999F8 /* SplashView.swift */; };
@@ -87,6 +88,7 @@
8788
BA28F19B2B61572A0052855E /* Pretendard-Light.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-Light.otf"; sourceTree = "<group>"; };
8889
BA28F19C2B61572A0052855E /* Pretendard-Black.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-Black.otf"; sourceTree = "<group>"; };
8990
BA28F1A72B6157E90052855E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
91+
BA402F7D2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvenienceSelectBottomSheetView.swift; sourceTree = "<group>"; };
9092
BA4EA35A2B6A00F70003DCE7 /* Entity */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Entity; sourceTree = "<group>"; };
9193
BAA4D9A92B5A1795005999F8 /* PyeonHaeng-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PyeonHaeng-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
9294
BAA4D9AC2B5A1795005999F8 /* PyeonHaengApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PyeonHaengApp.swift; sourceTree = "<group>"; };
@@ -218,6 +220,7 @@
218220
BA28F1862B61558C0052855E /* HomeScene */ = {
219221
isa = PBXGroup;
220222
children = (
223+
BA402F7C2B85E2DE00E86AAD /* BottomSheet */,
221224
BA28F1872B6155910052855E /* HomeView.swift */,
222225
BAB5CF262B6B7CF3008B24BF /* HomeViewModel.swift */,
223226
BAE159D72B65FA6F002DCF94 /* HomeProductDetailSelectionView.swift */,
@@ -271,6 +274,14 @@
271274
path = Fonts;
272275
sourceTree = "<group>";
273276
};
277+
BA402F7C2B85E2DE00E86AAD /* BottomSheet */ = {
278+
isa = PBXGroup;
279+
children = (
280+
BA402F7D2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift */,
281+
);
282+
path = BottomSheet;
283+
sourceTree = "<group>";
284+
};
274285
BAA4D9A02B5A1795005999F8 = {
275286
isa = PBXGroup;
276287
children = (
@@ -505,6 +516,8 @@
505516
files = (
506517
BAE159DA2B65FC35002DCF94 /* HomeProductListView.swift in Sources */,
507518
E5F2EC402B637D4A00EE0838 /* ProductInfoDetailView.swift in Sources */,
519+
E5F2EC402B637D4A00EE0838 /* ProductInfoHeader.swift in Sources */,
520+
BA402F7E2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift in Sources */,
508521
BA28F1852B6155810052855E /* OnboardingView.swift in Sources */,
509522
BAB5CF272B6B7CF3008B24BF /* HomeViewModel.swift in Sources */,
510523
BA28F1882B6155910052855E /* HomeView.swift in Sources */,

0 commit comments

Comments
 (0)