Fix calendar sql up
This commit is contained in:
parent
0cd8f47dd5
commit
567ba5da75
|
|
@ -10,7 +10,7 @@ create table calendar (
|
||||||
updated_at integer null default CURRENT_TIMESTAMP,
|
updated_at integer null default CURRENT_TIMESTAMP,
|
||||||
updated_by integer not null default 0,
|
updated_by integer not null default 0,
|
||||||
name varchar(255) not null
|
name varchar(255) not null
|
||||||
)
|
);
|
||||||
|
|
||||||
-- Event types
|
-- Event types
|
||||||
-- 1 - Rental
|
-- 1 - Rental
|
||||||
|
|
@ -22,7 +22,7 @@ create table calendar_event_types (
|
||||||
updated_at integer null default CURRENT_TIMESTAMP,
|
updated_at integer null default CURRENT_TIMESTAMP,
|
||||||
updated_by integer not null default 0,
|
updated_by integer not null default 0,
|
||||||
name varchar(255) not null
|
name varchar(255) not null
|
||||||
)
|
);
|
||||||
|
|
||||||
create table calendar_events (
|
create table calendar_events (
|
||||||
id integer not null primary key autoincrement,
|
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_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,
|
repeat_interval integer not null default 0,
|
||||||
celebrate boolean 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)
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ where
|
||||||
#[template(path = "cottagecalendar.html")]
|
#[template(path = "cottagecalendar.html")]
|
||||||
struct CottageCalendarTemplate {
|
struct CottageCalendarTemplate {
|
||||||
logged_in: bool,
|
logged_in: bool,
|
||||||
name: String,
|
user: UserData,
|
||||||
user_roles: Vec<crate::user::UserRolesDisplay>,
|
user_roles: Vec<crate::user::UserRolesDisplay>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,22 +43,27 @@ pub async fn cottagecalendar(
|
||||||
Extension(user_data): Extension<Option<UserData>>,
|
Extension(user_data): Extension<Option<UserData>>,
|
||||||
State(db_pool): State<SqlitePool>,
|
State(db_pool): State<SqlitePool>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let user_name = user_data.as_ref().map(|s| s.name.clone());
|
// Is the user logged in?
|
||||||
let logged_in = user_name.is_some();
|
let logged_in = user_data.is_some();
|
||||||
let name = user_name.unwrap_or_default();
|
|
||||||
|
|
||||||
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 {
|
if is_authorized("/cottagecalendar", user_data, db_pool.clone()).await {
|
||||||
// Get user roles
|
// Get user roles
|
||||||
let user_roles = get_user_roles_display(user_id, &db_pool.clone()).await;
|
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
||||||
|
|
||||||
let template = CottageCalendarTemplate {
|
let template = CottageCalendarTemplate {
|
||||||
logged_in,
|
logged_in,
|
||||||
name,
|
user,
|
||||||
user_roles,
|
user_roles,
|
||||||
};
|
};
|
||||||
HtmlTemplate(template).into_response()
|
HtmlTemplate(template).into_response()
|
||||||
|
} else {
|
||||||
|
Redirect::to("/").into_response()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Redirect::to("/").into_response()
|
Redirect::to("/").into_response()
|
||||||
}
|
}
|
||||||
|
|
@ -71,5 +76,5 @@ async fn get_next_event(db_pool: &SqlitePool) -> Option<String> {
|
||||||
.fetch_one(db_pool)
|
.fetch_one(db_pool)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
next_event.map(|(date, title)| format!("{} - {}", date, title))
|
next_event.map(|(date, title)| format!("{} - {}", date, title)).ok()
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,6 @@ mod middlewares;
|
||||||
mod routes;
|
mod routes;
|
||||||
mod user;
|
mod user;
|
||||||
mod wishlist;
|
mod wishlist;
|
||||||
mod email;
|
|
||||||
mod secret_gift_exchange;
|
mod secret_gift_exchange;
|
||||||
|
|
||||||
use error_handling::AppError;
|
use error_handling::AppError;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue