You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oab/src/api/app.rs

70 lines
1.8 KiB
Rust

3 years ago
//
// app.rs
// Copyright (C) 2022 veypi <i@veypi.com>
// 2022-07-09 03:10
// Distributed under terms of the Apache license.
//
3 years ago
//
use actix_web::{delete, get, post, web, Responder};
3 years ago
use proc::access_read;
use serde::{Deserialize, Serialize};
3 years ago
use crate::{models, Error, Result, CONFIG};
3 years ago
use chrono::NaiveDateTime;
3 years ago
#[get("/app/{id}")]
3 years ago
#[access_read("app")]
3 years ago
pub async fn get(id: web::Path<String>) -> Result<impl Responder> {
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()))
}
}
3 years ago
#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
pub struct App {
pub id: String,
pub created: Option<NaiveDateTime>,
pub updated: Option<NaiveDateTime>,
pub name: Option<String>,
pub des: Option<String>,
pub icon: Option<String>,
pub user_count: i64,
pub hide: bool,
pub join_method: models::AppJoin,
pub role_id: Option<String>,
pub redirect: Option<String>,
pub status: i64,
pub u_status: i64,
}
3 years ago
#[get("/app/")]
3 years ago
#[access_read("app")]
3 years ago
pub async fn list() -> Result<impl Responder> {
3 years ago
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)
3 years ago
.fetch_all(CONFIG.db())
.await?;
3 years ago
3 years ago
Ok(web::Json(result))
}
#[post("/app/")]
pub async fn create() -> Result<impl Responder> {
Ok("")
}
#[delete("/app/{id}")]
pub async fn del(id: web::Path<String>) -> Result<impl Responder> {
Ok("")
}