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