remove unneeded type conversion

main
Zynh0722 2023-11-14 16:38:15 -08:00
parent 519ece03b4
commit 0eeb088b24
2 changed files with 3 additions and 20 deletions

View File

@ -79,27 +79,10 @@ async fn close_shift(
render!(crate::templates::home_html, None, !hx) render!(crate::templates::home_html, None, !hx)
} }
#[derive(Deserialize, Debug)]
struct DrinkForm {
shift_id: u32,
price: u32,
quantity: u32,
}
impl From<DrinkForm> for NewDrink {
fn from(value: DrinkForm) -> Self {
NewDrink {
price: value.price,
quantity: value.quantity,
shift: value.shift_id,
}
}
}
async fn add_drink( async fn add_drink(
State(state): State<AppState>, State(state): State<AppState>,
HxRequest(hx): HxRequest, HxRequest(hx): HxRequest,
Form(form): Form<DrinkForm>, Form(form): Form<NewDrink>,
) -> Response { ) -> Response {
let mut conn = state.connection.get().await.unwrap(); let mut conn = state.connection.get().await.unwrap();
@ -129,7 +112,7 @@ async fn add_drink(
use cm_lib::schema::drinks::dsl::*; use cm_lib::schema::drinks::dsl::*;
diesel::insert_into(drinks) diesel::insert_into(drinks)
.values::<NewDrink>(form.into()) .values::<NewDrink>(form)
.execute(&mut conn) .execute(&mut conn)
.await .await
.unwrap() .unwrap()

View File

@ -49,7 +49,7 @@ pub struct Show {
pub end: Option<chrono::NaiveDateTime>, pub end: Option<chrono::NaiveDateTime>,
} }
#[derive(Insertable, Debug)] #[derive(Insertable, Deseralize, Debug)]
#[diesel(table_name = crate::schema::drinks)] #[diesel(table_name = crate::schema::drinks)]
#[diesel(check_for_backend(diesel::mysql::Mysql))] #[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct NewDrink { pub struct NewDrink {