Move main.rs to bin/ and stub some message stuff.
This commit is contained in:
parent
035508f3ad
commit
da15ef0f15
@ -2,6 +2,7 @@
|
|||||||
name = "server"
|
name = "server"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
default-bin = "server"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,8 @@ use rocket::{
|
|||||||
Response, State,
|
Response, State,
|
||||||
};
|
};
|
||||||
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
||||||
|
use server::{error::ServerError, nm::threadset_to_messages};
|
||||||
|
use shared::Message;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn hello() -> &'static str {
|
fn hello() -> &'static str {
|
||||||
@ -56,9 +58,9 @@ async fn search(
|
|||||||
async fn show_pretty(
|
async fn show_pretty(
|
||||||
nm: &State<Notmuch>,
|
nm: &State<Notmuch>,
|
||||||
query: &str,
|
query: &str,
|
||||||
) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
|
) -> Result<Json<Vec<Message>>, Debug<ServerError>> {
|
||||||
let query = urlencoding::decode(query).map_err(NotmuchError::from)?;
|
let query = urlencoding::decode(query).map_err(|e| ServerError::from(NotmuchError::from(e)))?;
|
||||||
let res = nm.show(&query)?;
|
let res = threadset_to_messages(nm.show(&query).map_err(ServerError::from)?)?;
|
||||||
Ok(Json(res))
|
Ok(Json(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
9
server/src/error.rs
Normal file
9
server/src/error.rs
Normal 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
2
server/src/lib.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod error;
|
||||||
|
pub mod nm;
|
||||||
13
server/src/nm.rs
Normal file
13
server/src/nm.rs
Normal 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())
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user