finish day CRU
This commit is contained in:
20
src/main.rs
20
src/main.rs
@ -7,6 +7,7 @@ use std::collections::HashMap;
|
||||
|
||||
use chrono::Duration;
|
||||
use chrono::Local;
|
||||
use rocket::response::Redirect;
|
||||
use rocket::{form::Form, fs::FileServer, State};
|
||||
use rocket_dyn_templates::context;
|
||||
use rocket_dyn_templates::Template;
|
||||
@ -49,17 +50,26 @@ struct DayForm {
|
||||
}
|
||||
|
||||
#[put("/day", data = "<day>")]
|
||||
async fn create(db: &State<DatabaseConnection>, day: Form<DayForm>) -> Template {
|
||||
let day = day::ActiveModel {
|
||||
day: Set(chrono::NaiveDate::parse_from_str(&day.day, "%Y-%m-%d").unwrap()),
|
||||
async fn create(db: &State<DatabaseConnection>, day: Form<DayForm>) -> Redirect {
|
||||
let id = chrono::NaiveDate::parse_from_str(&day.day, "%Y-%m-%d").unwrap();
|
||||
let new_day = day::ActiveModel {
|
||||
day: Set(id),
|
||||
planned_amount_cox: Set(day.planned_amount_cox),
|
||||
planned_starting_time: Set(day.planned_starting_time.clone()),
|
||||
open_registration: Set(day.open_registration),
|
||||
};
|
||||
|
||||
day.insert(db.inner()).await.unwrap(); //TODO: fixme
|
||||
let day: Option<day::Model> = day::Entity::find_by_id(id).one(db.inner()).await.unwrap();
|
||||
match day {
|
||||
Some(_) => {
|
||||
new_day.update(db.inner()).await.unwrap(); //TODO: fixme
|
||||
}
|
||||
None => {
|
||||
new_day.insert(db.inner()).await.unwrap(); //TODO: fixme
|
||||
}
|
||||
}
|
||||
|
||||
Template::render("index", context! {})
|
||||
Redirect::to("/")
|
||||
}
|
||||
|
||||
#[launch]
|
||||
|
Reference in New Issue
Block a user