apps: get all with filter, serde
This commit is contained in:
parent
842be36a1b
commit
42d88cc2dd
9 changed files with 259 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -52,6 +52,7 @@ dependencies = [
|
||||||
"hash",
|
"hash",
|
||||||
"id",
|
"id",
|
||||||
"openid",
|
"openid",
|
||||||
|
"serde",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ edition = "2021"
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
url = { workspace = true }
|
url = { workspace = true }
|
||||||
|
serde = { workspace = true }
|
||||||
|
|
||||||
# local crates
|
# local crates
|
||||||
id = { path = "../id" }
|
id = { path = "../id" }
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,17 @@ impl From<DatabaseApps> for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
pub async fn get_all(
|
||||||
|
conn: impl SqliteExecutor<'_>,
|
||||||
|
filter_get_archived: Option<bool>,
|
||||||
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
Ok(DatabaseApps::get_all(conn, filter_get_archived)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(Self::from)
|
||||||
|
.collect::<Vec<_>>())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
conn: impl SqliteExecutor<'_>,
|
conn: impl SqliteExecutor<'_>,
|
||||||
id: &AppID,
|
id: &AppID,
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@ mod get_valid;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use id::AppID;
|
use id::AppID;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
pub use crate::error::Error;
|
pub use crate::error::Error;
|
||||||
pub use get_valid::Error as GetValidError;
|
pub use get_valid::Error as GetValidError;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Serialize, Debug, Clone)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
id: AppID,
|
id: AppID,
|
||||||
created_at: DateTime<Utc>,
|
created_at: DateTime<Utc>,
|
||||||
|
|
|
||||||
11
crates/database/queries/apps/get_all.sql
Normal file
11
crates/database/queries/apps/get_all.sql
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
select id,
|
||||||
|
created_at as "created_at: DateTime<Utc>",
|
||||||
|
updated_at as "updated_at: DateTime<Utc>",
|
||||||
|
label,
|
||||||
|
redirect_uri,
|
||||||
|
secret,
|
||||||
|
is_confidential as "is_confidential: bool",
|
||||||
|
is_archived as "is_archived: bool"
|
||||||
|
from apps
|
||||||
|
|
||||||
|
order by created_at desc
|
||||||
12
crates/database/queries/apps/get_all_active.sql
Normal file
12
crates/database/queries/apps/get_all_active.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
select id,
|
||||||
|
created_at as "created_at: DateTime<Utc>",
|
||||||
|
updated_at as "updated_at: DateTime<Utc>",
|
||||||
|
label,
|
||||||
|
redirect_uri,
|
||||||
|
secret,
|
||||||
|
is_confidential as "is_confidential: bool",
|
||||||
|
is_archived as "is_archived: bool"
|
||||||
|
from apps
|
||||||
|
|
||||||
|
where is_archived is 0
|
||||||
|
order by created_at desc
|
||||||
12
crates/database/queries/apps/get_all_archived.sql
Normal file
12
crates/database/queries/apps/get_all_archived.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
select id,
|
||||||
|
created_at as "created_at: DateTime<Utc>",
|
||||||
|
updated_at as "updated_at: DateTime<Utc>",
|
||||||
|
label,
|
||||||
|
redirect_uri,
|
||||||
|
secret,
|
||||||
|
is_confidential as "is_confidential: bool",
|
||||||
|
is_archived as "is_archived: bool"
|
||||||
|
from apps
|
||||||
|
|
||||||
|
where is_archived is 1
|
||||||
|
order by created_at desc
|
||||||
|
|
@ -20,6 +20,66 @@
|
||||||
},
|
},
|
||||||
"query": "update settings\n\nset business_name = ?\n\nwhere id is 0\n"
|
"query": "update settings\n\nset business_name = ?\n\nwhere id is 0\n"
|
||||||
},
|
},
|
||||||
|
"13c26aaf556d259535afb95f5c53b4c594f373084c73000bc7865a280df74fdd": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "created_at: DateTime<Utc>",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "updated_at: DateTime<Utc>",
|
||||||
|
"ordinal": 2,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "label",
|
||||||
|
"ordinal": 3,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "redirect_uri",
|
||||||
|
"ordinal": 4,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "secret",
|
||||||
|
"ordinal": 5,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "is_confidential: bool",
|
||||||
|
"ordinal": 6,
|
||||||
|
"type_info": "Int64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "is_archived: bool",
|
||||||
|
"ordinal": 7,
|
||||||
|
"type_info": "Int64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n updated_at as \"updated_at: DateTime<Utc>\",\n label,\n redirect_uri,\n secret,\n is_confidential as \"is_confidential: bool\",\n is_archived as \"is_archived: bool\"\nfrom apps\n\nwhere is_archived is 0\norder by created_at desc"
|
||||||
|
},
|
||||||
"3c8e31ffa5cbfd4dded8a272777cb320fb51fd2e53ed25054d24e9801df0c358": {
|
"3c8e31ffa5cbfd4dded8a272777cb320fb51fd2e53ed25054d24e9801df0c358": {
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
|
|
@ -728,6 +788,66 @@
|
||||||
},
|
},
|
||||||
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n revoked_at as \"revoked_at: DateTime<Utc>\",\n private_der,\n public_der\n\nfrom keys\nwhere revoked_at is null\norder by created_at desc\n"
|
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n revoked_at as \"revoked_at: DateTime<Utc>\",\n private_der,\n public_der\n\nfrom keys\nwhere revoked_at is null\norder by created_at desc\n"
|
||||||
},
|
},
|
||||||
|
"d8517e5faa5292da25d21a85fcb2f676dce0f67275466566d5bbedf0f4b7f4f5": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "created_at: DateTime<Utc>",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "updated_at: DateTime<Utc>",
|
||||||
|
"ordinal": 2,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "label",
|
||||||
|
"ordinal": 3,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "redirect_uri",
|
||||||
|
"ordinal": 4,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "secret",
|
||||||
|
"ordinal": 5,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "is_confidential: bool",
|
||||||
|
"ordinal": 6,
|
||||||
|
"type_info": "Int64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "is_archived: bool",
|
||||||
|
"ordinal": 7,
|
||||||
|
"type_info": "Int64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n updated_at as \"updated_at: DateTime<Utc>\",\n label,\n redirect_uri,\n secret,\n is_confidential as \"is_confidential: bool\",\n is_archived as \"is_archived: bool\"\nfrom apps\n\nwhere is_archived is 1\norder by created_at desc"
|
||||||
|
},
|
||||||
"e22ba816faac0c17ca9f2c31fd1b4a5f13a09cece9ec78e0b6e018950c91facb": {
|
"e22ba816faac0c17ca9f2c31fd1b4a5f13a09cece9ec78e0b6e018950c91facb": {
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
|
|
@ -1093,5 +1213,65 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"query": "select u.id,\n u.created_at as \"created_at: DateTime<Utc>\",\n u.updated_at as \"updated_at: DateTime<Utc>\",\n u.is_admin as \"is_admin: bool\",\n u.username,\n u.name,\n u.email,\n u.password,\n u.password_recover,\n u.paper_key,\n u.is_archived as \"is_archived: bool\"\nfrom users u\n\n inner join authorization_codes ac on u.id = ac.user\n\nwhere ac.code is ?"
|
"query": "select u.id,\n u.created_at as \"created_at: DateTime<Utc>\",\n u.updated_at as \"updated_at: DateTime<Utc>\",\n u.is_admin as \"is_admin: bool\",\n u.username,\n u.name,\n u.email,\n u.password,\n u.password_recover,\n u.paper_key,\n u.is_archived as \"is_archived: bool\"\nfrom users u\n\n inner join authorization_codes ac on u.id = ac.user\n\nwhere ac.code is ?"
|
||||||
|
},
|
||||||
|
"fb35faa6eb7349f783d0053509225216693532c7233a3bf61674b64c2fb3dad7": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "created_at: DateTime<Utc>",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "updated_at: DateTime<Utc>",
|
||||||
|
"ordinal": 2,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "label",
|
||||||
|
"ordinal": 3,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "redirect_uri",
|
||||||
|
"ordinal": 4,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "secret",
|
||||||
|
"ordinal": 5,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "is_confidential: bool",
|
||||||
|
"ordinal": 6,
|
||||||
|
"type_info": "Int64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "is_archived: bool",
|
||||||
|
"ordinal": 7,
|
||||||
|
"type_info": "Int64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n updated_at as \"updated_at: DateTime<Utc>\",\n label,\n redirect_uri,\n secret,\n is_confidential as \"is_confidential: bool\",\n is_archived as \"is_archived: bool\"\nfrom apps\n\norder by created_at desc\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,35 @@ pub struct Apps {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Apps {
|
impl Apps {
|
||||||
|
pub async fn get_all(
|
||||||
|
conn: impl SqliteExecutor<'_>,
|
||||||
|
filter_get_archived: Option<bool>,
|
||||||
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
match filter_get_archived {
|
||||||
|
Some(true) => {
|
||||||
|
// Get all archived apps
|
||||||
|
sqlx::query_file_as!(Self, "queries/apps/get_all_archived.sql")
|
||||||
|
.fetch_all(conn)
|
||||||
|
.await
|
||||||
|
.map_err(handle_error)
|
||||||
|
}
|
||||||
|
Some(false) => {
|
||||||
|
// Get all active apps
|
||||||
|
sqlx::query_file_as!(Self, "queries/apps/get_all_active.sql")
|
||||||
|
.fetch_all(conn)
|
||||||
|
.await
|
||||||
|
.map_err(handle_error)
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
// Get all apps
|
||||||
|
sqlx::query_file_as!(Self, "queries/apps/get_all.sql")
|
||||||
|
.fetch_all(conn)
|
||||||
|
.await
|
||||||
|
.map_err(handle_error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
conn: impl SqliteExecutor<'_>,
|
conn: impl SqliteExecutor<'_>,
|
||||||
id: &str,
|
id: &str,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue