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_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)
|
||||
)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ where
|
|||
#[template(path = "cottagecalendar.html")]
|
||||
struct CottageCalendarTemplate {
|
||||
logged_in: bool,
|
||||
name: String,
|
||||
user: UserData,
|
||||
user_roles: Vec<crate::user::UserRolesDisplay>,
|
||||
}
|
||||
|
||||
|
|
@ -43,22 +43,27 @@ pub async fn cottagecalendar(
|
|||
Extension(user_data): Extension<Option<UserData>>,
|
||||
State(db_pool): State<SqlitePool>,
|
||||
) -> 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<String> {
|
|||
.fetch_one(db_pool)
|
||||
.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 user;
|
||||
mod wishlist;
|
||||
mod email;
|
||||
mod secret_gift_exchange;
|
||||
|
||||
use error_handling::AppError;
|
||||
|
|
|
|||
Loading…
Reference in New Issue