grafbase_local_backend/api/
types.rs1use super::{errors::LoginApiError, graphql};
2use serde::{Deserialize, Serialize};
3use std::fmt::{self, Display};
4
5pub enum LoginMessage {
6 CallbackUrl(String),
7 Done,
8 Error(LoginApiError),
9}
10
11#[derive(Debug)]
12pub struct Account {
13 pub id: String,
14 pub name: String,
15 pub slug: String,
16 pub personal: bool,
17}
18
19#[derive(Debug)]
20pub struct AccountWithProjects {
21 pub id: String,
22 pub name: String,
23 pub slug: String,
24 pub personal: bool,
25 pub projects: Vec<Project>,
26}
27
28#[derive(Debug)]
29pub struct Project {
30 pub id: String,
31 pub slug: String,
32}
33
34#[derive(Serialize, Deserialize)]
35#[serde(rename_all = "camelCase")]
36pub struct Credentials<'a> {
37 pub access_token: &'a str,
38}
39
40impl<'a> ToString for Credentials<'a> {
41 fn to_string(&self) -> String {
42 serde_json::to_string(&self).expect("must parse")
43 }
44}
45
46#[derive(Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct ProjectMetadata {
49 pub account_id: String,
50 pub project_id: String,
51}
52
53impl ToString for ProjectMetadata {
54 fn to_string(&self) -> String {
55 serde_json::to_string(&self).expect("must parse")
56 }
57}
58
59#[derive(Clone)]
60pub struct DatabaseRegion {
61 pub name: String,
62 pub city: String,
63}
64
65impl Display for DatabaseRegion {
66 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
67 formatter.write_str(&self.name)
68 }
69}
70
71impl From<graphql::queries::viewer_and_regions::DatabaseRegion> for DatabaseRegion {
72 fn from(api_region: graphql::queries::viewer_and_regions::DatabaseRegion) -> Self {
73 Self {
74 name: api_region.name,
75 city: api_region.city,
76 }
77 }
78}