-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUser.swift
73 lines (68 loc) · 2.09 KB
/
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
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
72
73
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)
}
do {
return try Client.decoder.decode(User.self, from: res.data)
} catch {
throw .unexpectedResponse(res.data.prefix(1024))
}
}
}
public struct User: Encodable, Decodable, Equatable, Sendable {
public let id: UUID
public let username: String
public let avatar_url: String
public let name: String
public let email: String
public let created_at: Date
public let updated_at: Date
public let last_seen_at: Date
public let status: String
public let login_type: String
public let theme_preference: String
public let organization_ids: [UUID]
public let roles: [Role]
public init(
id: UUID,
username: String,
avatar_url: String,
name: String,
email: String,
created_at: Date,
updated_at: Date,
last_seen_at: Date,
status: String,
login_type: String,
theme_preference: String,
organization_ids: [UUID],
roles: [Role]
) {
self.id = id
self.username = username
self.avatar_url = avatar_url
self.name = name
self.email = email
self.created_at = created_at
self.updated_at = updated_at
self.last_seen_at = last_seen_at
self.status = status
self.login_type = login_type
self.theme_preference = theme_preference
self.organization_ids = organization_ids
self.roles = roles
}
}
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
}
}