Skip to content

Commit

Permalink
Merge branch 'main' into feature/productinfo/48
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteHyun authored Feb 25, 2024
2 parents 11a6f66 + d615750 commit ca7a76f
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 134 deletions.
20 changes: 15 additions & 5 deletions APIService/Sources/HomeAPI/HomeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Network
// MARK: - HomeServiceRepresentable

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

Expand All @@ -29,9 +29,9 @@ public struct HomeService {
// 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 fetchProductList(request: ProductRequest) async throws -> Paginated<Product> {
let response: ProductResponse = try await network.request(with: HomeEndPoint.fetchProducts(request))
return Paginated<Product>(dto: response)
}

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

private extension Product {
private extension Paginated where Model == Product {
init(dto: ProductResponse) {
self.init(
count: dto.count,
hasMore: dto.hasMore,
results: dto.results.map(Product.init)
)
}
}

private extension Product {
init(dto: ProductItemResponse) {
self.init(
id: dto.id,
imageURL: dto.imageURL,
Expand Down
25 changes: 21 additions & 4 deletions APIService/Sources/HomeAPI/Responses/ProductResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,37 @@ import Foundation

// MARK: - ProductResponse

struct ProductResponse: Decodable {
struct ProductResponse: Decodable, Paginatable {
let count: Int
let hasMore: Bool

let results: [ProductItemResponse]

enum CodingKeys: String, CodingKey {
case count
case hasMore = "has_more"
case results
}
}

// MARK: - ProductItemResponse

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

enum CodingKeys: String, CodingKey {
case id
case imageURL = "image_url"
case imageURL = "img"
case price
case date
case name
case promotion
case convenienceStore
case promotion = "tag"
case convenienceStore = "store"
}
}
128 changes: 36 additions & 92 deletions APIService/Sources/HomeAPISupport/Mocks/HomeProductResponse.json
Original file line number Diff line number Diff line change
@@ -1,92 +1,36 @@
[
{
"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"
}
]
{
"count": 3,
"has_more": true,
"results": [
{
"name": "MDS)베이컨까르보나라파스타",
"img": "https://www.7-eleven.co.kr/upload/product/8805684/009026.1.jpg",
"price": 4100,
"store": "7-ELEVEn",
"tag": "2+1",
"proinfo": 0,
"date": "2024-02-01T10:11:47Z",
"id": 84683
},
{
"name": "MDS)투움바파스타230g",
"img": "https://www.7-eleven.co.kr/upload/product/8805684/003307.1.jpg",
"price": 4100,
"store": "7-ELEVEn",
"tag": "2+1",
"proinfo": 0,
"date": "2024-02-01T10:11:47Z",
"id": 84684
},
{
"name": "MDS)미트파스타230g",
"img": "https://www.7-eleven.co.kr/upload/product/8805684/005813.1.jpg",
"price": 4100,
"store": "7-ELEVEn",
"tag": "2+1",
"proinfo": 0,
"date": "2024-02-01T10:11:47Z",
"id": 84685
}
]
}
14 changes: 14 additions & 0 deletions Entity/Sources/Entity/Common/Paginatable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Paginatable.swift
//
//
// Created by 홍승현 on 2/23/24.
//

public protocol Paginatable {
associatedtype Model
var count: Int { get }
var hasMore: Bool { get }

var results: [Model] { get }
}
19 changes: 19 additions & 0 deletions Entity/Sources/Entity/Common/Paginated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Paginated.swift
//
//
// Created by 홍승현 on 2/23/24.
//

/// 페이징 처리가 들어가는 모델의 경우 해당 모델을 사용합니다.
public struct Paginated<Model>: Paginatable {
public let count: Int
public let hasMore: Bool
public let results: [Model]

public init(count: Int, hasMore: Bool, results: [Model]) {
self.count = count
self.hasMore = hasMore
self.results = results
}
}
4 changes: 2 additions & 2 deletions Entity/Sources/Entity/ConvenienceStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import Foundation
import SwiftUI

public enum ConvenienceStore: String, Codable {
public enum ConvenienceStore: String, Codable, CaseIterable {
case cu = "CU"
case gs25 = "GS25"
case _7Eleven = "7-ElEVEN"
case _7Eleven = "7-ELEVEn"
case emart24
case ministop = "MINISTOP"
}
13 changes: 13 additions & 0 deletions PyeonHaeng-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
BA28F1A42B61572A0052855E /* Pretendard-ExtraBold.otf in Resources */ = {isa = PBXBuildFile; fileRef = BA28F19A2B61572A0052855E /* Pretendard-ExtraBold.otf */; };
BA28F1A52B61572A0052855E /* Pretendard-Light.otf in Resources */ = {isa = PBXBuildFile; fileRef = BA28F19B2B61572A0052855E /* Pretendard-Light.otf */; };
BA28F1A62B61572A0052855E /* Pretendard-Black.otf in Resources */ = {isa = PBXBuildFile; fileRef = BA28F19C2B61572A0052855E /* Pretendard-Black.otf */; };
BA402F7E2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA402F7D2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift */; };
BA4EA3602B6A37E10003DCE7 /* Entity in Frameworks */ = {isa = PBXBuildFile; productRef = BA4EA35F2B6A37E10003DCE7 /* Entity */; };
BAA4D9AD2B5A1795005999F8 /* PyeonHaengApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAA4D9AC2B5A1795005999F8 /* PyeonHaengApp.swift */; };
BAA4D9AF2B5A1795005999F8 /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAA4D9AE2B5A1795005999F8 /* SplashView.swift */; };
Expand Down Expand Up @@ -87,6 +88,7 @@
BA28F19B2B61572A0052855E /* Pretendard-Light.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-Light.otf"; sourceTree = "<group>"; };
BA28F19C2B61572A0052855E /* Pretendard-Black.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-Black.otf"; sourceTree = "<group>"; };
BA28F1A72B6157E90052855E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BA402F7D2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvenienceSelectBottomSheetView.swift; sourceTree = "<group>"; };
BA4EA35A2B6A00F70003DCE7 /* Entity */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Entity; sourceTree = "<group>"; };
BAA4D9A92B5A1795005999F8 /* PyeonHaeng-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PyeonHaeng-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
BAA4D9AC2B5A1795005999F8 /* PyeonHaengApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PyeonHaengApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -218,6 +220,7 @@
BA28F1862B61558C0052855E /* HomeScene */ = {
isa = PBXGroup;
children = (
BA402F7C2B85E2DE00E86AAD /* BottomSheet */,
BA28F1872B6155910052855E /* HomeView.swift */,
BAB5CF262B6B7CF3008B24BF /* HomeViewModel.swift */,
BAE159D72B65FA6F002DCF94 /* HomeProductDetailSelectionView.swift */,
Expand Down Expand Up @@ -271,6 +274,14 @@
path = Fonts;
sourceTree = "<group>";
};
BA402F7C2B85E2DE00E86AAD /* BottomSheet */ = {
isa = PBXGroup;
children = (
BA402F7D2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift */,
);
path = BottomSheet;
sourceTree = "<group>";
};
BAA4D9A02B5A1795005999F8 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -505,6 +516,8 @@
files = (
BAE159DA2B65FC35002DCF94 /* HomeProductListView.swift in Sources */,
E5F2EC402B637D4A00EE0838 /* ProductInfoDetailView.swift in Sources */,
E5F2EC402B637D4A00EE0838 /* ProductInfoHeader.swift in Sources */,
BA402F7E2B85E31800E86AAD /* ConvenienceSelectBottomSheetView.swift in Sources */,
BA28F1852B6155810052855E /* OnboardingView.swift in Sources */,
BAB5CF272B6B7CF3008B24BF /* HomeViewModel.swift in Sources */,
BA28F1882B6155910052855E /* HomeView.swift in Sources */,
Expand Down
Loading

0 comments on commit ca7a76f

Please sign in to comment.