fix many clones()

This commit is contained in:
2023-05-24 12:11:55 +02:00
parent cf45036642
commit 99296d4060
8 changed files with 54 additions and 71 deletions

View File

@ -10,30 +10,29 @@ use crate::model::{planned_event::PlannedEvent, tripdetails::TripDetails, user::
//TODO: add constraints (e.g. planned_amount_cox > 0)
#[derive(FromForm)]
struct AddPlannedEventForm {
day: String,
name: String,
struct AddPlannedEventForm<'r> {
day: &'r str,
name: &'r str,
planned_amount_cox: i32,
allow_guests: bool,
planned_starting_time: String,
planned_starting_time: &'r str,
max_people: i32,
notes: Option<String>,
notes: Option<&'r str>,
trip_type: Option<i64>,
}
#[post("/planned-event", data = "<data>")]
async fn create(
db: &State<SqlitePool>,
data: Form<AddPlannedEventForm>,
data: Form<AddPlannedEventForm<'_>>,
_admin: AdminUser,
) -> Flash<Redirect> {
//TODO: fix clones()
let trip_details_id = TripDetails::create(
db,
data.planned_starting_time.clone(),
data.planned_starting_time,
data.max_people,
data.day.clone(),
data.notes.clone(),
data.day,
data.notes,
data.allow_guests,
data.trip_type,
)
@ -43,36 +42,30 @@ async fn create(
//just created
//the object
//TODO: fix clone()
PlannedEvent::create(db, data.name.clone(), data.planned_amount_cox, trip_details).await;
PlannedEvent::create(db, data.name, data.planned_amount_cox, trip_details).await;
Flash::success(Redirect::to("/"), "Successfully planned the event")
}
//TODO: add constraints (e.g. planned_amount_cox > 0)
#[derive(FromForm)]
struct UpdatePlannedEventForm {
struct UpdatePlannedEventForm<'r> {
id: i64,
planned_amount_cox: i32,
max_people: i32,
notes: Option<String>,
notes: Option<&'r str>,
}
#[put("/planned-event", data = "<data>")]
async fn update(
db: &State<SqlitePool>,
data: Form<UpdatePlannedEventForm>,
data: Form<UpdatePlannedEventForm<'_>>,
_admin: AdminUser,
) -> Flash<Redirect> {
match PlannedEvent::find_by_id(db, data.id).await {
Some(planned_event) => {
planned_event
.update(
db,
data.planned_amount_cox,
data.max_people,
data.notes.clone(),
)
.update(db, data.planned_amount_cox, data.max_people, data.notes)
.await;
Flash::success(Redirect::to("/"), "Successfully edited the event")
}

View File

@ -86,18 +86,18 @@ async fn update(
}
#[derive(FromForm)]
struct UserAddForm {
name: String,
struct UserAddForm<'r> {
name: &'r str,
is_guest: bool,
}
#[post("/user/new", data = "<data>")]
async fn create(
db: &State<SqlitePool>,
data: Form<UserAddForm>,
data: Form<UserAddForm<'_>>,
_admin: AdminUser,
) -> Flash<Redirect> {
if User::create(db, data.name.clone(), data.is_guest).await {
if User::create(db, data.name, data.is_guest).await {
//TODO: fix clone() above
Flash::success(Redirect::to("/admin/user"), "Successfully created user")
} else {