More smoothing, as they say

This commit is contained in:
Dave
2026-02-16 16:35:25 +00:00
parent 5923165fcf
commit f76376b203
10 changed files with 256 additions and 265 deletions

View File

@@ -1,24 +1,38 @@
use crate::http::context::{AppContext, OpenApiResult, bad_request};
use crate::http::payloads::PathPayload;
use crate::io::fs;
use poem_openapi::payload::Json;
use poem_openapi::{Object, OpenApi, payload::Json};
use serde::Deserialize;
use std::sync::Arc;
pub async fn get_current_project(ctx: &AppContext) -> OpenApiResult<Json<Option<String>>> {
let result = fs::get_current_project(&ctx.state, ctx.store.as_ref()).map_err(bad_request)?;
Ok(Json(result))
#[derive(Deserialize, Object)]
struct PathPayload {
path: String,
}
pub async fn open_project(
payload: Json<PathPayload>,
ctx: &AppContext,
) -> OpenApiResult<Json<String>> {
let confirmed = fs::open_project(payload.0.path, &ctx.state, ctx.store.as_ref())
.await
.map_err(bad_request)?;
Ok(Json(confirmed))
pub struct ProjectApi {
pub ctx: Arc<AppContext>,
}
pub async fn close_project(ctx: &AppContext) -> OpenApiResult<Json<bool>> {
fs::close_project(&ctx.state, ctx.store.as_ref()).map_err(bad_request)?;
Ok(Json(true))
#[OpenApi]
impl ProjectApi {
#[oai(path = "/project", method = "get")]
async fn get_current_project(&self) -> OpenApiResult<Json<Option<String>>> {
let result = fs::get_current_project(&self.ctx.state, self.ctx.store.as_ref())
.map_err(bad_request)?;
Ok(Json(result))
}
#[oai(path = "/project", method = "post")]
async fn open_project(&self, payload: Json<PathPayload>) -> OpenApiResult<Json<String>> {
let confirmed = fs::open_project(payload.0.path, &self.ctx.state, self.ctx.store.as_ref())
.await
.map_err(bad_request)?;
Ok(Json(confirmed))
}
#[oai(path = "/project", method = "delete")]
async fn close_project(&self) -> OpenApiResult<Json<bool>> {
fs::close_project(&self.ctx.state, self.ctx.store.as_ref()).map_err(bad_request)?;
Ok(Json(true))
}
}