Move main.rs to bin/ and stub some message stuff.

This commit is contained in:
Bill Thiede 2023-11-06 18:41:12 -08:00
parent 035508f3ad
commit da15ef0f15
5 changed files with 30 additions and 3 deletions

View File

@ -2,6 +2,7 @@
name = "server"
version = "0.1.0"
edition = "2021"
default-bin = "server"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -13,6 +13,8 @@ use rocket::{
Response, State,
};
use rocket_cors::{AllowedHeaders, AllowedOrigins};
use server::{error::ServerError, nm::threadset_to_messages};
use shared::Message;
#[get("/")]
fn hello() -> &'static str {
@ -56,9 +58,9 @@ async fn search(
async fn show_pretty(
nm: &State<Notmuch>,
query: &str,
) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
let query = urlencoding::decode(query).map_err(NotmuchError::from)?;
let res = nm.show(&query)?;
) -> Result<Json<Vec<Message>>, Debug<ServerError>> {
let query = urlencoding::decode(query).map_err(|e| ServerError::from(NotmuchError::from(e)))?;
let res = threadset_to_messages(nm.show(&query).map_err(ServerError::from)?)?;
Ok(Json(res))
}

9
server/src/error.rs Normal file
View File

@ -0,0 +1,9 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ServerError {
#[error("notmuch")]
NotmuchError(#[from] notmuch::NotmuchError),
#[error("flatten")]
FlattenError,
}

2
server/src/lib.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod error;
pub mod nm;

13
server/src/nm.rs Normal file
View File

@ -0,0 +1,13 @@
use shared::Message;
use crate::error;
// TODO(wathiede): decide good error type
pub fn threadset_to_messages(
thread_set: notmuch::ThreadSet,
) -> Result<Vec<Message>, error::ServerError> {
for t in thread_set.0 {
for tn in t.0 {}
}
Ok(Vec::new())
}