Starting the owner tree module.

This commit is contained in:
Tom Alexander 2023-08-17 03:42:18 -04:00
parent 65aba3c993
commit 40bf188c5a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 27 additions and 8 deletions

View File

@ -1,7 +1,7 @@
#![feature(exit_status_error)]
use axum::{http::StatusCode, routing::post, Json, Router};
use owner_tree::{build_owner_tree, OwnerTree};
use parse::emacs_parse_org_document;
use serde::Serialize;
use tower_http::services::{ServeDir, ServeFile};
mod owner_tree;
@ -18,13 +18,18 @@ async fn main() {
axum::serve(listener, app).await.unwrap();
}
async fn parse_org_mode(body: String) -> Result<(StatusCode, Json<OwnerTree>), (StatusCode, String)> {
let ast = emacs_parse_org_document(&body).await.map_err(|e| (StatusCode::BAD_REQUEST, e.to_string()))?;
let ret = OwnerTree { input_source: body };
Ok((StatusCode::OK, Json(ret)))
async fn parse_org_mode(
body: String,
) -> Result<(StatusCode, Json<OwnerTree>), (StatusCode, String)> {
_parse_org_mode(body)
.await
.map_err(|e| (StatusCode::BAD_REQUEST, e.to_string()))
}
#[derive(Serialize)]
struct OwnerTree {
input_source: String,
async fn _parse_org_mode(
body: String,
) -> Result<(StatusCode, Json<OwnerTree>), Box<dyn std::error::Error>> {
let ast = emacs_parse_org_document(&body).await?;
let owner_tree = build_owner_tree(body)?;
Ok((StatusCode::OK, Json(owner_tree)))
}

View File

@ -1 +1,15 @@
use serde::Serialize;
pub fn build_owner_tree<C>(file_contents: C) -> Result<OwnerTree, Box<dyn std::error::Error>>
where
C: AsRef<str>,
{
Ok(OwnerTree {
input_source: file_contents.as_ref().to_owned(),
})
}
#[derive(Serialize)]
pub struct OwnerTree {
input_source: String,
}