rename planned_event to event
This commit is contained in:
@ -8,14 +8,14 @@ use serde::Serialize;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::model::{
|
||||
planned_event::{self, PlannedEvent},
|
||||
event::{self, Event},
|
||||
tripdetails::{TripDetails, TripDetailsToAdd},
|
||||
user::PlannedEventUser,
|
||||
user::EventUser,
|
||||
};
|
||||
|
||||
//TODO: add constraints (e.g. planned_amount_cox > 0)
|
||||
#[derive(FromForm, Serialize)]
|
||||
struct AddPlannedEventForm<'r> {
|
||||
struct AddEventForm<'r> {
|
||||
name: &'r str,
|
||||
planned_amount_cox: i32,
|
||||
tripdetails: TripDetailsToAdd<'r>,
|
||||
@ -24,8 +24,8 @@ struct AddPlannedEventForm<'r> {
|
||||
#[post("/planned-event", data = "<data>")]
|
||||
async fn create(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<AddPlannedEventForm<'_>>,
|
||||
_admin: PlannedEventUser,
|
||||
data: Form<AddEventForm<'_>>,
|
||||
_admin: EventUser,
|
||||
) -> Flash<Redirect> {
|
||||
let data = data.into_inner();
|
||||
|
||||
@ -34,14 +34,14 @@ async fn create(
|
||||
//just created
|
||||
//the object
|
||||
|
||||
PlannedEvent::create(db, data.name, data.planned_amount_cox, trip_details).await;
|
||||
Event::create(db, data.name, data.planned_amount_cox, trip_details).await;
|
||||
|
||||
Flash::success(Redirect::to("/planned"), "Event hinzugefügt")
|
||||
}
|
||||
|
||||
//TODO: add constraints (e.g. planned_amount_cox > 0)
|
||||
#[derive(FromForm)]
|
||||
struct UpdatePlannedEventForm<'r> {
|
||||
struct UpdateEventForm<'r> {
|
||||
id: i64,
|
||||
name: &'r str,
|
||||
planned_amount_cox: i32,
|
||||
@ -54,10 +54,10 @@ struct UpdatePlannedEventForm<'r> {
|
||||
#[put("/planned-event", data = "<data>")]
|
||||
async fn update(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<UpdatePlannedEventForm<'_>>,
|
||||
_admin: PlannedEventUser,
|
||||
data: Form<UpdateEventForm<'_>>,
|
||||
_admin: EventUser,
|
||||
) -> Flash<Redirect> {
|
||||
let update = planned_event::EventUpdate {
|
||||
let update = event::EventUpdate {
|
||||
name: data.name,
|
||||
planned_amount_cox: data.planned_amount_cox,
|
||||
max_people: data.max_people,
|
||||
@ -65,7 +65,7 @@ async fn update(
|
||||
always_show: data.always_show,
|
||||
is_locked: data.is_locked,
|
||||
};
|
||||
match PlannedEvent::find_by_id(db, data.id).await {
|
||||
match Event::find_by_id(db, data.id).await {
|
||||
Some(planned_event) => {
|
||||
planned_event.update(db, &update).await;
|
||||
Flash::success(Redirect::to("/planned"), "Event erfolgreich bearbeitet")
|
||||
@ -75,9 +75,9 @@ async fn update(
|
||||
}
|
||||
|
||||
#[get("/planned-event/<id>/delete")]
|
||||
async fn delete(db: &State<SqlitePool>, id: i64, _admin: PlannedEventUser) -> Flash<Redirect> {
|
||||
let Some(event) = PlannedEvent::find_by_id(db, id).await else {
|
||||
return Flash::error(Redirect::to("/planned"), "PlannedEvent does not exist");
|
||||
async fn delete(db: &State<SqlitePool>, id: i64, _admin: EventUser) -> Flash<Redirect> {
|
||||
let Some(event) = Event::find_by_id(db, id).await else {
|
||||
return Flash::error(Redirect::to("/planned"), "Event does not exist");
|
||||
};
|
||||
|
||||
match event.delete(db).await {
|
||||
@ -105,7 +105,7 @@ mod test {
|
||||
fn test_delete() {
|
||||
let db = testdb!();
|
||||
|
||||
let _ = PlannedEvent::find_by_id(&db, 1).await.unwrap();
|
||||
let _ = Event::find_by_id(&db, 1).await.unwrap();
|
||||
|
||||
let rocket = rocket::build().manage(db.clone());
|
||||
let rocket = crate::tera::config(rocket);
|
||||
@ -130,7 +130,7 @@ mod test {
|
||||
|
||||
assert_eq!(flash_cookie.value(), "7:successEvent gelöscht");
|
||||
|
||||
let event = PlannedEvent::find_by_id(&db, 1).await;
|
||||
let event = Event::find_by_id(&db, 1).await;
|
||||
assert_eq!(event, None);
|
||||
}
|
||||
|
||||
@ -159,16 +159,16 @@ mod test {
|
||||
.get("_flash")
|
||||
.expect("Expected flash cookie");
|
||||
|
||||
assert_eq!(flash_cookie.value(), "5:errorPlannedEvent does not exist");
|
||||
assert_eq!(flash_cookie.value(), "5:errorEvent does not exist");
|
||||
|
||||
let _ = PlannedEvent::find_by_id(&db, 1).await.unwrap();
|
||||
let _ = Event::find_by_id(&db, 1).await.unwrap();
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_update() {
|
||||
let db = testdb!();
|
||||
|
||||
let event = PlannedEvent::find_by_id(&db, 1).await.unwrap();
|
||||
let event = Event::find_by_id(&db, 1).await.unwrap();
|
||||
assert_eq!(event.notes, Some("trip_details for a planned event".into()));
|
||||
|
||||
let rocket = rocket::build().manage(db.clone());
|
||||
@ -200,7 +200,7 @@ mod test {
|
||||
"7:successEvent erfolgreich bearbeitet"
|
||||
);
|
||||
|
||||
let event = PlannedEvent::find_by_id(&db, 1).await.unwrap();
|
||||
let event = Event::find_by_id(&db, 1).await.unwrap();
|
||||
assert_eq!(event.notes, Some("new-planned-event-text".into()));
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ mod test {
|
||||
|
||||
assert_eq!(flash_cookie.value(), "7:successEvent hinzugefügt");
|
||||
|
||||
let event = PlannedEvent::find_by_id(&db, 2).await.unwrap();
|
||||
let event = Event::find_by_id(&db, 2).await.unwrap();
|
||||
assert_eq!(event.name, "my-cool-new-event");
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ use rocket::{
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::model::{
|
||||
event::Event,
|
||||
log::Log,
|
||||
planned_event::PlannedEvent,
|
||||
trip::{self, CoxHelpError, Trip, TripDeleteError, TripHelpDeleteError, TripUpdateError},
|
||||
tripdetails::{TripDetails, TripDetailsToAdd},
|
||||
user::CoxUser,
|
||||
@ -82,7 +82,7 @@ async fn update(
|
||||
|
||||
#[get("/join/<planned_event_id>")]
|
||||
async fn join(db: &State<SqlitePool>, planned_event_id: i64, cox: CoxUser) -> Flash<Redirect> {
|
||||
if let Some(planned_event) = PlannedEvent::find_by_id(db, planned_event_id).await {
|
||||
if let Some(planned_event) = Event::find_by_id(db, planned_event_id).await {
|
||||
match Trip::new_join(db, &cox, &planned_event).await {
|
||||
Ok(_) => {
|
||||
Log::create(
|
||||
@ -137,7 +137,7 @@ async fn remove_trip(db: &State<SqlitePool>, trip_id: i64, cox: CoxUser) -> Flas
|
||||
|
||||
#[get("/remove/<planned_event_id>")]
|
||||
async fn remove(db: &State<SqlitePool>, planned_event_id: i64, cox: CoxUser) -> Flash<Redirect> {
|
||||
if let Some(planned_event) = PlannedEvent::find_by_id(db, planned_event_id).await {
|
||||
if let Some(planned_event) = Event::find_by_id(db, planned_event_id).await {
|
||||
match Trip::delete_by_planned_event(db, &cox, &planned_event).await {
|
||||
Ok(_) => {
|
||||
Log::create(
|
||||
|
@ -1,12 +1,12 @@
|
||||
use rocket::{get, http::ContentType, routes, Route, State};
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::model::planned_event::PlannedEvent;
|
||||
use crate::model::event::Event;
|
||||
|
||||
#[get("/cal")]
|
||||
async fn cal(db: &State<SqlitePool>) -> (ContentType, String) {
|
||||
//TODO: add unit test once proper functionality is there
|
||||
(ContentType::Calendar, PlannedEvent::get_ics_feed(db).await)
|
||||
(ContentType::Calendar, Event::get_ics_feed(db).await)
|
||||
}
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
|
Reference in New Issue
Block a user