add flow notes
This commit is contained in:
parent
132aeee971
commit
860508fa29
4 changed files with 84 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use mongod::{vec_to_api, Model, Referencable, ToAPI};
|
||||
use mongod::{reference_of, vec_to_api, Model, Referencable, Sort, ToAPI};
|
||||
use mongodb::bson::doc;
|
||||
use rocket::{get, post, serde::json::Json, State};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -9,7 +9,7 @@ use serde_json::json;
|
|||
use crate::{
|
||||
check_auth,
|
||||
config::Config,
|
||||
flow::{Flow, FlowInfo},
|
||||
flow::{Flow, FlowInfo, FlowNote},
|
||||
json_store::JSONStore,
|
||||
routes::{api_error, FallibleApiResponse, Token},
|
||||
transaction::{Price, Transaction},
|
||||
|
@ -189,3 +189,33 @@ pub async fn continue_flow_route(
|
|||
|
||||
Ok(json!({"uuid": next_flow._id}))
|
||||
}
|
||||
|
||||
#[get("/flow/<id>/notes")]
|
||||
pub async fn flow_notes_route(id: &str) -> FallibleApiResponse {
|
||||
let notes = FlowNote::find(
|
||||
doc! {
|
||||
"on_flow": reference_of!(Flow, id).ok_or_else(|| api_error("No such flow"))?
|
||||
},
|
||||
None,
|
||||
Some(doc! { "timestamp": Sort::Descending }),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Ok(json!(vec_to_api(¬es).await))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NoteAdd {
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
#[post("/flow/<id>/note", data = "<form>")]
|
||||
pub async fn create_flow_note_route(id: &str, form: Json<NoteAdd>) -> FallibleApiResponse {
|
||||
let note = FlowNote::create(
|
||||
&form.content,
|
||||
reference_of!(Flow, id).ok_or_else(|| api_error("No such flow"))?,
|
||||
)
|
||||
.await;
|
||||
Ok(json!({"uuid": note._id }))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue