|
|
|
@ -16,15 +16,19 @@ use forms::{
|
|
|
|
|
NewUserForm,
|
|
|
|
|
NewListForm,
|
|
|
|
|
PermsForm,
|
|
|
|
|
NewNoteForm,
|
|
|
|
|
};
|
|
|
|
|
use db::{
|
|
|
|
|
List,
|
|
|
|
|
Notes,
|
|
|
|
|
Note,
|
|
|
|
|
Result,
|
|
|
|
|
add_permission,
|
|
|
|
|
get_user_from_email,
|
|
|
|
|
get_user_lists,
|
|
|
|
|
get_user_lists_from_perms,
|
|
|
|
|
get_notes_from_list,
|
|
|
|
|
add_note_to_list,
|
|
|
|
|
User,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -45,6 +49,7 @@ use rocket::{
|
|
|
|
|
http::{
|
|
|
|
|
Cookie,
|
|
|
|
|
CookieJar,
|
|
|
|
|
RawStr,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -133,6 +138,23 @@ async fn new_list_form(_user: User) -> Template {
|
|
|
|
|
async fn new_list_form_not_logged_in() -> Redirect {
|
|
|
|
|
Redirect::to(uri!(home))
|
|
|
|
|
}
|
|
|
|
|
#[get("/new/note/<list_uuid>")]
|
|
|
|
|
async fn new_note_form(mut db: Connection<Notes>, user: User, list_uuid: String) -> Result<Template> {
|
|
|
|
|
Ok(Template::render("new_note_form", context!{
|
|
|
|
|
list_uuid: list_uuid
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
#[post("/note", data="<note>")]
|
|
|
|
|
async fn new_note(mut db: Connection<Notes>, user: User, note: Form<NewNoteForm<'_>>) -> Result<String> {
|
|
|
|
|
let list = match List::from_uuid(note.list_uuid.to_string(), &mut *db).await? {
|
|
|
|
|
Some(l) => l,
|
|
|
|
|
None => return Ok(format!("List not found!")),
|
|
|
|
|
};
|
|
|
|
|
match add_note_to_list(&mut *db, list.id, note.content.to_string(), user.id).await {
|
|
|
|
|
Ok(_) => Ok(format!("Added note!")),
|
|
|
|
|
Err(_) => Ok(format!("Error!"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[post("/perms", data="<perms>")]
|
|
|
|
|
async fn new_perms(perms: Form<PermsForm<'_>>, user: User, mut db: Connection<Notes>) -> Result<String> {
|
|
|
|
@ -181,6 +203,17 @@ async fn logout(mut db: Connection<Notes>, cookies: &CookieJar<'_>) -> Result<St
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[get("/notes/<list_uuid>")]
|
|
|
|
|
async fn show_notes(user: User, mut db: Connection<Notes>, list_uuid: String) -> Result<Template> {
|
|
|
|
|
let list = match List::from_uuid(list_uuid, &mut *db).await? {
|
|
|
|
|
Some(list) => list,
|
|
|
|
|
None => panic!("LOL!"),
|
|
|
|
|
};
|
|
|
|
|
Ok(Template::render("show_notes", context!{
|
|
|
|
|
notes: get_notes_from_list(list.id, &mut *db).await?
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[launch]
|
|
|
|
|
fn rocket() -> _ {
|
|
|
|
|
rocket::build()
|
|
|
|
@ -197,12 +230,15 @@ fn rocket() -> _ {
|
|
|
|
|
.mount("/new", routes![
|
|
|
|
|
new_list, new_list_not_logged_in,
|
|
|
|
|
new_perms, new_perms_not_logged_in,
|
|
|
|
|
new_note, //new_note_not_logged_in,
|
|
|
|
|
])
|
|
|
|
|
.mount("/show", routes![
|
|
|
|
|
show_list, show_list_not_logged_in
|
|
|
|
|
show_list, show_list_not_logged_in,
|
|
|
|
|
show_notes,
|
|
|
|
|
])
|
|
|
|
|
.mount("/forms", routes![
|
|
|
|
|
add_perms_form, add_perms_form_not_logged_in,
|
|
|
|
|
new_list_form, new_list_form_not_logged_in
|
|
|
|
|
new_list_form, new_list_form_not_logged_in,
|
|
|
|
|
new_note_form,
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|