Fix merge issues
This commit is contained in:
parent
dc8a5db7f9
commit
417875300f
|
|
@ -53,12 +53,18 @@ async fn main() {
|
||||||
// build our application with some routes
|
// build our application with some routes
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/dashboard", get(dashboard))
|
.route("/dashboard", get(dashboard))
|
||||||
.route("/cottagecalendar", get(cottagecalendar))
|
|
||||||
|
// User
|
||||||
.route("/profile", get(profile))
|
.route("/profile", get(profile))
|
||||||
.route("/useradmin", get(useradmin))
|
.route("/useradmin", get(useradmin))
|
||||||
.route("/users/:user_id", get(user_profile))
|
.route("/users/:user_id", get(user_profile))
|
||||||
.route("/roles/:user_id/:role_id/add", get(add_user_role))
|
.route("/roles/:user_id/:role_id/add", get(add_user_role))
|
||||||
.route("/roles/:user_id/:user_role_id/delete", get(delete_user_role))
|
.route("/roles/:user_id/:user_role_id/delete", get(delete_user_role))
|
||||||
|
|
||||||
|
// Calendar
|
||||||
|
.route("/cottagecalendar", get(cottagecalendar))
|
||||||
|
|
||||||
|
// Wishlist
|
||||||
.route("/wishlists", get(wishlists))
|
.route("/wishlists", get(wishlists))
|
||||||
.route("/userwishlist/:user_id", get(user_wishlist))
|
.route("/userwishlist/:user_id", get(user_wishlist))
|
||||||
.route("/userwishlist/add/:user_id", get(user_wishlist_add).post(user_wishlist_add_item))
|
.route("/userwishlist/add/:user_id", get(user_wishlist_add).post(user_wishlist_add_item))
|
||||||
|
|
@ -67,8 +73,11 @@ async fn main() {
|
||||||
.route("/userwishlist/received/:user_id", get(user_wishlist_received_item))
|
.route("/userwishlist/received/:user_id", get(user_wishlist_received_item))
|
||||||
.route("/userwishlist/delete/:item_id", get(user_wishlist_delete_item))
|
.route("/userwishlist/delete/:item_id", get(user_wishlist_delete_item))
|
||||||
.route("/userwishlist/returned/:item_id", get(user_wishlist_returned_item))
|
.route("/userwishlist/returned/:item_id", get(user_wishlist_returned_item))
|
||||||
.route("/giftexchanges", get(giftexchanges))
|
|
||||||
.route("/giftexchange/:giftexchange_id", get(giftexchange).post(giftexchange_save))
|
// Secret Gift Exchange - Not ready for public use yet
|
||||||
|
//.route("/giftexchanges", get(giftexchanges))
|
||||||
|
//.route("/giftexchange/:giftexchange_id", get(giftexchange).post(giftexchange_save))
|
||||||
|
|
||||||
.nest_service("/assets", ServeDir::new("templates/assets")
|
.nest_service("/assets", ServeDir::new("templates/assets")
|
||||||
.fallback(get_service(ServeDir::new("templates/assets"))))
|
.fallback(get_service(ServeDir::new("templates/assets"))))
|
||||||
.route("/", get(index))
|
.route("/", get(index))
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ pub async fn index(
|
||||||
if logged_in {
|
if logged_in {
|
||||||
// Extract the user data.
|
// Extract the user data.
|
||||||
let user = user_data.as_ref().unwrap().clone();
|
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("/dashboard", user_data, db_pool).await {
|
if is_authorized("/dashboard", user_data, db_pool).await {
|
||||||
Redirect::to("/dashboard").into_response()
|
Redirect::to("/dashboard").into_response()
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ struct GiftExchange {
|
||||||
#[template(path = "giftexchanges.html")]
|
#[template(path = "giftexchanges.html")]
|
||||||
struct GiftExchangesTemplate {
|
struct GiftExchangesTemplate {
|
||||||
logged_in: bool,
|
logged_in: bool,
|
||||||
name: String,
|
user: UserData,
|
||||||
user_roles: Vec<crate::user::UserRolesDisplay>,
|
user_roles: Vec<crate::user::UserRolesDisplay>,
|
||||||
giftexchanges: Vec<GiftExchange>,
|
giftexchanges: Vec<GiftExchange>,
|
||||||
}
|
}
|
||||||
|
|
@ -101,28 +101,33 @@ pub async fn giftexchanges(
|
||||||
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 giftexchanges = sqlx::query_as::<_, GiftExchange>("SELECT * FROM gift_exchange")
|
if logged_in {
|
||||||
.fetch_all(&db_pool)
|
// Extract the user data.
|
||||||
.await
|
let user = user_data.as_ref().unwrap().clone();
|
||||||
.unwrap();
|
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
||||||
|
|
||||||
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
let giftexchanges = sqlx::query_as::<_, GiftExchange>("SELECT * FROM gift_exchange")
|
||||||
|
.fetch_all(&db_pool)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
if is_authorized("/giftexchange", user_data, db_pool.clone()).await {
|
if is_authorized("/giftexchange", user_data, db_pool.clone()).await {
|
||||||
// Get user roles
|
// Get user roles
|
||||||
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
||||||
|
|
||||||
let template = GiftExchangesTemplate {
|
let template = GiftExchangesTemplate {
|
||||||
logged_in,
|
logged_in,
|
||||||
name,
|
user,
|
||||||
user_roles,
|
user_roles,
|
||||||
giftexchanges,
|
giftexchanges,
|
||||||
};
|
};
|
||||||
HtmlTemplate(template).into_response()
|
HtmlTemplate(template).into_response()
|
||||||
|
} else {
|
||||||
|
Redirect::to("/").into_response()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Redirect::to("/").into_response()
|
Redirect::to("/").into_response()
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +149,7 @@ struct GiftExchangeParticipant {
|
||||||
#[template(path = "giftexchange.html")]
|
#[template(path = "giftexchange.html")]
|
||||||
struct GiftExchangeTemplate {
|
struct GiftExchangeTemplate {
|
||||||
logged_in: bool,
|
logged_in: bool,
|
||||||
name: String,
|
user: UserData,
|
||||||
user_roles: Vec<crate::user::UserRolesDisplay>,
|
user_roles: Vec<crate::user::UserRolesDisplay>,
|
||||||
giftexchange: GiftExchange,
|
giftexchange: GiftExchange,
|
||||||
participants: Vec<UserData>,
|
participants: Vec<UserData>,
|
||||||
|
|
@ -156,30 +161,33 @@ pub async fn giftexchange(
|
||||||
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 userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
|
||||||
|
|
||||||
if is_authorized("/giftexchange", user_data, db_pool.clone()).await {
|
if logged_in {
|
||||||
// Get user roles
|
// Extract the user data.
|
||||||
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
let user = user_data.as_ref().unwrap().clone();
|
||||||
|
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
||||||
|
|
||||||
// Get gift exchange
|
if is_authorized("/giftexchange", user_data, db_pool.clone()).await {
|
||||||
let giftexchange = match sqlx::query_as!(
|
// Get user roles
|
||||||
GiftExchange,
|
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
||||||
"SELECT * FROM gift_exchange WHERE id = ?",
|
|
||||||
exchange_id
|
|
||||||
)
|
|
||||||
.fetch_one(&db_pool)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(giftexchange) => giftexchange,
|
|
||||||
Err(_) => GiftExchange::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get participants
|
// Get gift exchange
|
||||||
let participants = sqlx::query_as::<_, UserData>(
|
let giftexchange = match sqlx::query_as!(
|
||||||
|
GiftExchange,
|
||||||
|
"SELECT * FROM gift_exchange WHERE id = ?",
|
||||||
|
exchange_id
|
||||||
|
)
|
||||||
|
.fetch_one(&db_pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(giftexchange) => giftexchange,
|
||||||
|
Err(_) => GiftExchange::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get participants
|
||||||
|
let participants = sqlx::query_as::<_, UserData>(
|
||||||
"select * from users where users.id in (select participant_id from gift_exchange_participants where exchange_id = ?)",
|
"select * from users where users.id in (select participant_id from gift_exchange_participants where exchange_id = ?)",
|
||||||
)
|
)
|
||||||
.bind(exchange_id)
|
.bind(exchange_id)
|
||||||
|
|
@ -187,8 +195,8 @@ pub async fn giftexchange(
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Get non participants
|
// Get non participants
|
||||||
let non_participants = sqlx::query_as::<_, UserData>(
|
let non_participants = sqlx::query_as::<_, UserData>(
|
||||||
"select * from users where users.id not in (select participant_id from gift_exchange_participants where exchange_id = ?)",
|
"select * from users where users.id not in (select participant_id from gift_exchange_participants where exchange_id = ?)",
|
||||||
)
|
)
|
||||||
.bind(exchange_id)
|
.bind(exchange_id)
|
||||||
|
|
@ -196,15 +204,18 @@ pub async fn giftexchange(
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let template = GiftExchangeTemplate {
|
let template = GiftExchangeTemplate {
|
||||||
logged_in,
|
logged_in,
|
||||||
name,
|
user,
|
||||||
user_roles,
|
user_roles,
|
||||||
giftexchange,
|
giftexchange,
|
||||||
participants,
|
participants,
|
||||||
non_participants,
|
non_participants,
|
||||||
};
|
};
|
||||||
HtmlTemplate(template).into_response()
|
HtmlTemplate(template).into_response()
|
||||||
|
} else {
|
||||||
|
Redirect::to("/").into_response()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Redirect::to("/").into_response()
|
Redirect::to("/").into_response()
|
||||||
}
|
}
|
||||||
|
|
@ -240,7 +251,7 @@ pub async fn giftexchange_save(
|
||||||
}
|
}
|
||||||
} */
|
} */
|
||||||
let (req_parts, map_request_body) = request.into_parts();
|
let (req_parts, map_request_body) = request.into_parts();
|
||||||
let bytes = match body::to_bytes(map_request_body,usize::MAX).await {
|
let bytes = match body::to_bytes(map_request_body, usize::MAX).await {
|
||||||
Ok(bytes) => bytes,
|
Ok(bytes) => bytes,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Err((
|
return Err((
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
use askama_axum::{IntoResponse, Response, Template};
|
use askama_axum::{IntoResponse, Response, Template};
|
||||||
use axum::{
|
use axum::{
|
||||||
|
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
|
|
||||||
response::Redirect,
|
response::Redirect,
|
||||||
|
|
||||||
Extension, Form,
|
Extension, Form,
|
||||||
,
|
|
||||||
};
|
};
|
||||||
use axum_extra::response::Html;
|
use axum_extra::response::Html;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
|
@ -15,14 +11,11 @@ use serde::Deserialize;
|
||||||
use sqlx::{Row, SqlitePool};
|
use sqlx::{Row, SqlitePool};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
||||||
middlewares::is_authorized,
|
middlewares::is_authorized,
|
||||||
|
|
||||||
user::{
|
user::{
|
||||||
get_user_roles_display, get_user_wishlist_item_by_id, get_user_wishlist_items, UserData,
|
get_user_roles_display, get_user_wishlist_item_by_id, get_user_wishlist_items, UserData,
|
||||||
UserWishlistItem,
|
UserWishlistItem,
|
||||||
},
|
},
|
||||||
,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HtmlTemplate<T>(T);
|
struct HtmlTemplate<T>(T);
|
||||||
|
|
@ -210,7 +203,6 @@ pub async fn user_wishlist_add_item(
|
||||||
State(db_pool): State<SqlitePool>,
|
State(db_pool): State<SqlitePool>,
|
||||||
Extension(user_data): Extension<Option<UserData>>,
|
Extension(user_data): Extension<Option<UserData>>,
|
||||||
Form(item_form): Form<ItemForm>,
|
Form(item_form): Form<ItemForm>,
|
||||||
Form(item_form): Form<ItemForm>,
|
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await {
|
if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await {
|
||||||
// Insert new item to database
|
// Insert new item to database
|
||||||
|
|
@ -257,8 +249,6 @@ pub async fn user_wishlist_edit_item(
|
||||||
let user = user_data.as_ref().unwrap().clone();
|
let user = user_data.as_ref().unwrap().clone();
|
||||||
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default();
|
||||||
|
|
||||||
// Extract the user data.
|
|
||||||
|
|
||||||
if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await {
|
if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await {
|
||||||
// Get user roles
|
// Get user roles
|
||||||
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
let user_roles = get_user_roles_display(userid, &db_pool.clone()).await;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue