diff --git a/backend/migrations/20241113203107_calendar_tables.up.sql b/backend/migrations/20241113203107_calendar_tables.up.sql index bd7f1e6..66691e8 100644 --- a/backend/migrations/20241113203107_calendar_tables.up.sql +++ b/backend/migrations/20241113203107_calendar_tables.up.sql @@ -10,7 +10,7 @@ create table calendar ( updated_at integer null default CURRENT_TIMESTAMP, updated_by integer not null default 0, name varchar(255) not null -) +); -- Event types -- 1 - Rental @@ -22,7 +22,7 @@ create table calendar_event_types ( updated_at integer null default CURRENT_TIMESTAMP, updated_by integer not null default 0, name varchar(255) not null -) +); create table calendar_events ( id integer not null primary key autoincrement, @@ -39,7 +39,4 @@ create table calendar_events ( repeat_type integer not null default 0, -- 0 - None, 1 - Daily, 2 - Weekly, 3 - Monthly, 4 - Yearly, 5 - Day of week, 6 - Day of month repeat_interval integer not null default 0, celebrate boolean not null default 0 - - foreign key (calendar_id) references calendar(id), - foreign key (event_type_id) references calendar_event_types(id) -) +); diff --git a/backend/src/calendar.rs b/backend/src/calendar.rs index 5b603dc..2dad967 100644 --- a/backend/src/calendar.rs +++ b/backend/src/calendar.rs @@ -35,7 +35,7 @@ where #[template(path = "cottagecalendar.html")] struct CottageCalendarTemplate { logged_in: bool, - name: String, + user: UserData, user_roles: Vec, } @@ -43,22 +43,27 @@ pub async fn cottagecalendar( Extension(user_data): Extension>, State(db_pool): State, ) -> impl IntoResponse { - let user_name = user_data.as_ref().map(|s| s.name.clone()); - let logged_in = user_name.is_some(); - let name = user_name.unwrap_or_default(); + // Is the user logged in? + let logged_in = user_data.is_some(); - let user_id = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default(); + if logged_in { + // Extract the user data. + let user = user_data.as_ref().unwrap().clone(); + let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default(); - if is_authorized("/cottagecalendar", user_data, db_pool.clone()).await { - // Get user roles - let user_roles = get_user_roles_display(user_id, &db_pool.clone()).await; + if is_authorized("/cottagecalendar", user_data, db_pool.clone()).await { + // Get user roles + let user_roles = get_user_roles_display(userid, &db_pool.clone()).await; - let template = CottageCalendarTemplate { - logged_in, - name, - user_roles, - }; - HtmlTemplate(template).into_response() + let template = CottageCalendarTemplate { + logged_in, + user, + user_roles, + }; + HtmlTemplate(template).into_response() + } else { + Redirect::to("/").into_response() + } } else { Redirect::to("/").into_response() } @@ -71,5 +76,5 @@ async fn get_next_event(db_pool: &SqlitePool) -> Option { .fetch_one(db_pool) .await; - next_event.map(|(date, title)| format!("{} - {}", date, title)) + next_event.map(|(date, title)| format!("{} - {}", date, title)).ok() } \ No newline at end of file diff --git a/backend/src/main.rs b/backend/src/main.rs index 2bbabd6..3b77e12 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -18,7 +18,6 @@ mod middlewares; mod routes; mod user; mod wishlist; -mod email; mod secret_gift_exchange; use error_handling::AppError;