Remove API
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.
This commit is contained in:
parent
1195287bc8
commit
c8bc885919
|
@ -1,11 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
||||
//
|
||||
// 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));
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
||||
//
|
||||
// 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<PgPool>,
|
||||
new_item: web::Json<NewItem>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>, path: web::Path<Uuid>) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>,
|
||||
path: web::Path<Uuid>,
|
||||
new_item: web::Json<NewItem>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>,
|
||||
path: web::Path<Uuid>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>,
|
||||
path: web::Path<Uuid>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let id = path.into_inner();
|
||||
|
||||
let parents = manage::item::get_parents(&pool, id)
|
||||
.await
|
||||
.map_err(error::ErrorInternalServerError)?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(parents))
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
||||
//
|
||||
// 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<PgPool>,
|
||||
new_item_class: web::Json<NewItemClass>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>, path: web::Path<Uuid>) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>,
|
||||
path: web::Path<Uuid>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>,
|
||||
path: web::Path<Uuid>,
|
||||
new_item_class: web::Json<NewItemClass>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
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<PgPool>,
|
||||
path: web::Path<Uuid>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let id = path.into_inner();
|
||||
|
||||
manage::item_class::delete(&pool, id)
|
||||
.await
|
||||
.map_err(error::ErrorInternalServerError)?;
|
||||
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
||||
//
|
||||
// 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<PgPool>,
|
||||
params: web::Query<QueryParams>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
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::<Result<Vec<Uuid>, 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()))
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
||||
//
|
||||
// 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);
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
pub mod api;
|
||||
pub mod frontend;
|
||||
pub mod label;
|
||||
pub mod manage;
|
||||
|
|
|
@ -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<String>| async {
|
||||
|
|
Loading…
Reference in a new issue