Skip to content

Commit 9893843

Browse files
Update README.md
1 parent 352e77a commit 9893843

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

README.md

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,51 @@ The `Item` must be shared between the client and the [Breeze Lambda API](https:/
2929
import Foundation
3030
import BreezeLambdaAPIClient
3131

32-
struct Item: Codable {
33-
var key: String?
34-
var name: String
35-
var description: String
36-
var createdAt: Date?
37-
var updatedAt: Date?
32+
protocol ItemServing {
33+
func create(item: Item) async throws -> Item
34+
func read(key: String) async throws -> Item
35+
func update(item: Item) async throws -> Item
36+
func delete(item: Item) async throws
37+
func list(startKey: String?, limit: Int?) async throws -> [Item]
3838
}
3939

40-
struct APIService {
40+
struct ItemService: ItemServing {
4141

4242
private let apiClient: BreezeLambdaAPIClient<Item>
4343

44-
private var token: String?
44+
private let session: SessionService
45+
46+
private var token: String? {
47+
session.userSession?.jwtToken
48+
}
4549

4650
init(session: SessionService) {
4751
guard var env = try? APIEnvironment.dev() else {
4852
fatalError("Invalid Environment")
4953
}
5054
env.logger = Logger()
5155
self.session = session
52-
self.apiClient = BreezeLambdaAPIClient<Item>(env: env, path: "forms", additionalHeaders: [:])
56+
self.apiClient = BreezeLambdaAPIClient<Item>(env: env, path: "items", additionalHeaders: [:])
5357
}
5458

55-
func create(form: Item) async throws -> Item {
56-
try await apiClient.create(token: token, item: form)
59+
func create(item: Item) async throws -> Item {
60+
try await apiClient.create(token: token, item: item)
5761
}
5862

5963
func read(key: String) async throws -> Item {
6064
try await apiClient.read(token: token, key: key)
6165
}
6266

63-
func update(form: Item) async throws -> Item {
64-
try await apiClient.update(token: token, item: form)
67+
func update(item: Item) async throws -> Item {
68+
try await apiClient.update(token: token, item: item)
6569
}
6670

67-
func delete(form: Item) async throws {
68-
guard let updatedAt = form.updatedAt,
69-
let createdAt = form.createdAt else {
70-
throw FormServiceError.invalidForm
71+
func delete(item: Item) async throws {
72+
guard let updatedAt = item.updatedAt,
73+
let createdAt = item.createdAt else {
74+
throw ItemServiceError.invalidItem
7175
}
72-
try await apiClient.delete(token: token, key: form.key, createdAt: createdAt, updatedAt: updatedAt)
76+
try await apiClient.delete(token: token, key: item.key, createdAt: createdAt, updatedAt: updatedAt)
7377
}
7478

7579
func list(startKey: String?, limit: Int?) async throws -> [Item] {
@@ -97,7 +101,14 @@ struct Logger: APIClientLogging {
97101
}
98102
}
99103

100-
enum FormServiceError: Error {
101-
case invalidForm
104+
enum ItemServiceError: Error {
105+
case invalidItem
102106
}
103-
```
107+
```
108+
109+
Note:
110+
The SessionService is used to get the JWT token. The session is not part of this package.
111+
112+
# Contributing
113+
114+
Contributions are more than welcome! Follow this [guide](https://github.com/swift-sprinter/BreezeLambdaAPIClient/blob/main/CONTRIBUTING.md) to contribute.

0 commit comments

Comments
 (0)