// // app.rs // Copyright (C) 2022 veypi // 2022-07-09 03:10 // Distributed under terms of the Apache license. // // use actix_web::{delete, get, post, web, Responder}; use proc::access_read; use serde::{Deserialize, Serialize}; use crate::{models, Error, Result, CONFIG}; use chrono::NaiveDateTime; #[get("/app/{id}")] #[access_read("app")] pub async fn get(id: web::Path) -> Result { let n = id.into_inner(); if !n.is_empty() { let s = sqlx::query_as::<_, models::App>("select * from app where id = ?") .bind(n) .fetch_one(CONFIG.db()) .await?; Ok(web::Json(s)) } else { Err(Error::Missing("id".to_string())) } } #[derive(Debug, Serialize, Deserialize, sqlx::FromRow)] pub struct App { pub id: String, pub created: Option, pub updated: Option, pub name: Option, pub des: Option, pub icon: Option, pub user_count: i64, pub hide: bool, pub join_method: models::AppJoin, pub role_id: Option, pub redirect: Option, pub status: i64, pub u_status: i64, } #[get("/app/")] #[access_read("app")] pub async fn list() -> Result { let result = sqlx::query_as::<_, App>( "select app.id,app.created, app.updated, app.icon, app.name, app.des, app.user_count, app.hide,app.join_method, app.role_id, app.redirect, app.status, app_user.status as u_status from app left join app_user on app_user.user_id = ? && app_user.app_id = app.id", ).bind(_auth_token.id) .fetch_all(CONFIG.db()) .await?; Ok(web::Json(result)) } #[post("/app/")] pub async fn create() -> Result { Ok("") } #[delete("/app/{id}")] pub async fn del(id: web::Path) -> Result { Ok("") }