From c8bc8859198e95d3fcf85c1a3f88e77a4e05604b Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sat, 20 Jul 2024 23:09:22 +0200 Subject: [PATCH] Remove API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I didn’t really use it apart from very early testing and I don’t anticipate it getting much use. It might be reintroduced in the future. --- src/api/mod.rs | 11 ----- src/api/v1/item.rs | 94 ---------------------------------------- src/api/v1/item_class.rs | 94 ---------------------------------------- src/api/v1/label.rs | 42 ------------------ src/api/v1/mod.rs | 15 ------- src/lib.rs | 1 - src/main.rs | 5 --- 7 files changed, 262 deletions(-) delete mode 100644 src/api/mod.rs delete mode 100644 src/api/v1/item.rs delete mode 100644 src/api/v1/item_class.rs delete mode 100644 src/api/v1/label.rs delete mode 100644 src/api/v1/mod.rs diff --git a/src/api/mod.rs b/src/api/mod.rs deleted file mode 100644 index 2d58c49..0000000 --- a/src/api/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Simon Bruder -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -pub mod v1; - -use actix_web::web; - -pub fn config(cfg: &mut web::ServiceConfig) { - cfg.service(web::scope("/v1").configure(v1::config)); -} diff --git a/src/api/v1/item.rs b/src/api/v1/item.rs deleted file mode 100644 index f68ce34..0000000 --- a/src/api/v1/item.rs +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Simon Bruder -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -use actix_web::{delete, error, get, post, put, web, HttpResponse, Responder}; -use sqlx::PgPool; -use uuid::Uuid; - -use crate::manage; -use crate::models::*; - -pub fn config(cfg: &mut web::ServiceConfig) { - cfg.service(add) - .service(list) - .service(show) - .service(update) - .service(delete) - .service(parents); -} - -#[put("/item")] -async fn add( - pool: web::Data, - new_item: web::Json, -) -> actix_web::Result { - let item = manage::item::add(&pool, new_item.into_inner()) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(item)) -} - -#[get("/item")] -async fn list(pool: web::Data) -> actix_web::Result { - let items = manage::item::get_all(&pool) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(items)) -} - -#[get("/item/{id}")] -async fn show(pool: web::Data, path: web::Path) -> actix_web::Result { - let id = path.into_inner(); - - let item = manage::item::get(&pool, id) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(item)) -} - -#[post("/item/{id}")] -async fn update( - pool: web::Data, - path: web::Path, - new_item: web::Json, -) -> actix_web::Result { - let id = path.into_inner(); - - let item = manage::item::update(&pool, id, new_item.into_inner()) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(item)) -} - -#[delete("/item/{id}")] -async fn delete( - pool: web::Data, - path: web::Path, -) -> actix_web::Result { - let id = path.into_inner(); - - manage::item::delete(&pool, id) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok()) -} - -#[get("/item/{id}/parents")] -async fn parents( - pool: web::Data, - path: web::Path, -) -> actix_web::Result { - let id = path.into_inner(); - - let parents = manage::item::get_parents(&pool, id) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(parents)) -} diff --git a/src/api/v1/item_class.rs b/src/api/v1/item_class.rs deleted file mode 100644 index fff2764..0000000 --- a/src/api/v1/item_class.rs +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Simon Bruder -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -use actix_web::{delete, error, get, post, put, web, HttpResponse, Responder}; -use sqlx::PgPool; -use uuid::Uuid; - -use crate::manage; -use crate::models::*; - -pub fn config(cfg: &mut web::ServiceConfig) { - cfg.service(add) - .service(list) - .service(show) - .service(items) - .service(update) - .service(delete); -} - -#[put("/item-class")] -async fn add( - pool: web::Data, - new_item_class: web::Json, -) -> actix_web::Result { - let item_class = manage::item_class::add(&pool, new_item_class.into_inner()) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(item_class)) -} - -#[get("/item-class")] -async fn list(pool: web::Data) -> actix_web::Result { - let item_classes = manage::item_class::get_all(&pool) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(item_classes)) -} - -#[get("/item-class/{id}")] -async fn show(pool: web::Data, path: web::Path) -> actix_web::Result { - let id = path.into_inner(); - - let item_class = manage::item_class::get(&pool, id) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(item_class)) -} - -#[get("/item-class/{id}/items")] -async fn items( - pool: web::Data, - path: web::Path, -) -> actix_web::Result { - let id = path.into_inner(); - - let items = manage::item_class::items(&pool, id) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(items)) -} - -#[post("/item-class/{id}")] -async fn update( - pool: web::Data, - path: web::Path, - new_item_class: web::Json, -) -> actix_web::Result { - let id = path.into_inner(); - - let item_class = manage::item_class::update(&pool, id, new_item_class.into_inner()) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok().json(item_class)) -} - -#[delete("/item-class/{id}")] -async fn delete( - pool: web::Data, - path: web::Path, -) -> actix_web::Result { - let id = path.into_inner(); - - manage::item_class::delete(&pool, id) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(HttpResponse::Ok()) -} diff --git a/src/api/v1/label.rs b/src/api/v1/label.rs deleted file mode 100644 index 35a4bc6..0000000 --- a/src/api/v1/label.rs +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Simon Bruder -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -use actix_web::{error, get, web, Responder}; -use serde::Deserialize; -use sqlx::PgPool; -use uuid::Uuid; - -use crate::label::{Label, LabelPreset}; -use crate::manage; - -pub fn config(cfg: &mut web::ServiceConfig) { - cfg.service(items); -} - -#[derive(Debug, Deserialize)] -struct QueryParams { - // FIXME: serde_urlencoded does not support sequences - ids: String, - preset: LabelPreset, -} - -#[get("/label/items")] -async fn items( - pool: web::Data, - params: web::Query, -) -> actix_web::Result { - let ids = params - .ids - .split(',') - .skip_while(|s| s.is_empty()) // to make the empty string parse as an empty iterator - .map(Uuid::try_parse) - .collect::, uuid::Error>>() - .map_err(error::ErrorInternalServerError)?; - - let items = manage::item::get_multiple(&pool, &ids) - .await - .map_err(error::ErrorInternalServerError)?; - - Ok(Label::for_items(&items, params.preset.clone().into())) -} diff --git a/src/api/v1/mod.rs b/src/api/v1/mod.rs deleted file mode 100644 index 581d6bf..0000000 --- a/src/api/v1/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Simon Bruder -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -mod item; -mod item_class; -mod label; - -use actix_web::web; - -pub fn config(cfg: &mut web::ServiceConfig) { - cfg.configure(item::config) - .configure(item_class::config) - .configure(label::config); -} diff --git a/src/lib.rs b/src/lib.rs index 78bda4f..606f212 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later -pub mod api; pub mod frontend; pub mod label; pub mod manage; diff --git a/src/main.rs b/src/main.rs index 7e7fc5d..b483eb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,11 +55,6 @@ async fn main() -> std::io::Result<()> { HttpServer::new(move || { App::new() .app_data(web::Data::new(pool.clone())) - .service( - web::scope("/api") - .wrap(li7y::middleware::ForceIdentity) - .configure(li7y::api::config), - ) .service(web::scope("/static").route( "/{_:.*}", web::get().to(|path: web::Path| async {