haste_repository/types/
scope.rs1use haste_jwt::scopes::Scopes;
2use sqlx::types::time::OffsetDateTime;
3
4#[derive(Debug, Clone)]
5pub struct ClientId(String);
6impl From<ClientId> for String {
7 fn from(client_id: ClientId) -> Self {
8 client_id.0
9 }
10}
11impl ClientId {
12 #[must_use]
13 pub fn new(id: String) -> Self {
14 ClientId(id)
15 }
16}
17impl AsRef<str> for ClientId {
18 fn as_ref(&self) -> &str {
19 &self.0
20 }
21}
22
23#[derive(Debug, Clone)]
24pub struct UserId(String);
25impl From<UserId> for String {
26 fn from(user_id: UserId) -> Self {
27 user_id.0
28 }
29}
30impl UserId {
31 #[must_use]
32 pub fn new(id: String) -> Self {
33 UserId(id)
34 }
35}
36impl AsRef<str> for UserId {
37 fn as_ref(&self) -> &str {
38 &self.0
39 }
40}
41
42#[derive(sqlx::FromRow, Debug)]
43pub struct Scope {
44 pub client: String,
45 pub user_: String,
46 pub scope: Scopes,
47 pub created_at: OffsetDateTime,
48}
49
50pub struct UpdateScope {
51 pub client: ClientId,
52 pub user_: UserId,
53 pub scope: Scopes,
54}
55
56pub struct ScopeSearchClaims {
57 pub user_: Option<UserId>,
58 pub client: Option<ClientId>,
59}
60
61pub struct CreateScope {
62 pub client: ClientId,
63 pub user_: UserId,
64 pub scope: Scopes,
65}
66
67pub struct ScopeKey(pub ClientId, pub UserId);
68impl ScopeKey {
69 #[must_use]
70 pub fn new(client: ClientId, user_: UserId) -> Self {
71 ScopeKey(client, user_)
72 }
73}