-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDemoShopRepository.swift
More file actions
71 lines (59 loc) · 1.69 KB
/
Copy pathDemoShopRepository.swift
File metadata and controls
71 lines (59 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// DemoShopRepository.swift
// NativeAppTemplate
//
import Foundation
@testable import NativeAppTemplate
@MainActor
final class DemoShopRepository: ShopRepositoryProtocol {
var shops: [Shop] = []
var state: DataState = .initial
var limitCount: Int = 10
var createdShopsCount: Int = 0
var isEmpty: Bool {
shops.isEmpty
}
required init(shopsService: ShopsService) {}
func findBy(id: String) -> Shop {
shops.first { $0.id == id }!
}
func reload() {
state = .loading
shops = [
mockShop(id: "1", name: "Shop 1"),
mockShop(id: "2", name: "Shop 2"),
mockShop(id: "3", name: "Shop 3"),
mockShop(id: "4", name: "Shop 4"),
mockShop(id: "5", name: "Shop 5")
]
createdShopsCount = shops.count
state = .hasData
}
func fetchDetail(id: String) async throws -> Shop {
shops.first { $0.id == id }!
}
func create(shop: Shop) async throws -> Shop {
shops.append(shop)
createdShopsCount += 1
return shop
}
func update(id: String, shop: Shop) async throws -> Shop {
let index = shops.firstIndex { $0.id == id }!
shops[index] = shop
return shop
}
func destroy(id: String) async throws {
shops.removeAll { $0.id == id }
}
// MARK: - Helpers
private func mockShop(id: String = UUID().uuidString, name: String = "Mock Shop") -> Shop {
Shop(
id: id,
name: name,
description: "This is a mock shop for testing",
timeZone: "Tokyo",
itemTagsCount: 10,
completedItemTagsCount: 3
)
}
}