-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUser.swift
36 lines (31 loc) · 965 Bytes
/
User.swift
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
import Foundation
public extension Client {
func user(_ ident: String) async throws(ClientError) -> User {
let res = try await request("/api/v2/users/\(ident)", method: .get)
guard res.resp.statusCode == 200 else {
throw responseAsError(res)
}
return try decode(User.self, from: res.data)
}
}
public struct User: Encodable, Decodable, Equatable, Sendable {
public let id: UUID
public let username: String
public init(
id: UUID,
username: String
) {
self.id = id
self.username = username
}
}
public struct Role: Encodable, Decodable, Equatable, Sendable {
public let name: String
public let display_name: String
public let organization_id: UUID?
public init(name: String, display_name: String, organization_id: UUID?) {
self.name = name
self.display_name = display_name
self.organization_id = organization_id
}
}