From a590bf114a8845876623b327a02a61a2f0e5ef5a Mon Sep 17 00:00:00 2001 From: Chris Jean-Marie Date: Tue, 5 Nov 2024 21:35:06 +0000 Subject: [PATCH] Add bootstrap-table --- backend/src/wishlist.rs | 57 ++++++++++++++++------------ backend/templates/authorized.html | 1 + backend/templates/base.html | 14 +++++-- backend/templates/useradmin.html | 6 +-- backend/templates/userwishlist.html | 6 +-- backend/templates/userwishlists.html | 6 +-- 6 files changed, 53 insertions(+), 37 deletions(-) diff --git a/backend/src/wishlist.rs b/backend/src/wishlist.rs index b42fa6c..3e1e2f8 100644 --- a/backend/src/wishlist.rs +++ b/backend/src/wishlist.rs @@ -1,12 +1,19 @@ use askama_axum::{IntoResponse, Response, Template}; -use axum::{extract::{Path, State}, response::Redirect, Extension, Form}; +use axum::{ + extract::{Path, State}, + response::Redirect, + Extension, Form, +}; use axum_extra::response::Html; use chrono::Utc; use http::StatusCode; use serde::Deserialize; -use sqlx::{SqlitePool, Row}; +use sqlx::{Row, SqlitePool}; -use crate::{middlewares::is_authorized, user::{get_user_roles_display, get_user_wishlist_items, UserData, UserWishlistItem}}; +use crate::{ + middlewares::is_authorized, + user::{get_user_roles_display, get_user_wishlist_items, UserData, UserWishlistItem}, +}; struct HtmlTemplate(T); @@ -48,17 +55,17 @@ pub async fn wishlists( .await .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(); - if is_authorized("/userwishlists", user_data, db_pool.clone()).await { - // Get user roles - let user_roles = get_user_roles_display(userid, &db_pool.clone()).await; + if is_authorized("/userwishlists", user_data, db_pool.clone()).await { + // Get user roles + let user_roles = get_user_roles_display(userid, &db_pool.clone()).await; - let template = WishListsTemplate { - logged_in, - name, - users, - user_roles, + let template = WishListsTemplate { + logged_in, + name, + users, + user_roles, }; HtmlTemplate(template).into_response() } else { @@ -97,11 +104,11 @@ pub async fn user_wishlist( .await .unwrap(); - if is_authorized("/wishlist", user_data, db_pool.clone()).await { - // Get user roles - let user_roles = get_user_roles_display(userid, &db_pool.clone()).await; + if is_authorized("/wishlist", user_data, db_pool.clone()).await { + // Get user roles + let user_roles = get_user_roles_display(userid, &db_pool.clone()).await; - // Get user wishlist + // Get user wishlist let user_wishlist_items = get_user_wishlist_items(user_id, &db_pool.clone()).await; // Is viewed and viewing user the same (my wishlist)? @@ -151,10 +158,10 @@ pub async fn user_wishlist_add( let userid = user_data.as_ref().map(|s| s.id.clone()).unwrap_or_default(); if is_authorized("/wishlist", user_data, db_pool.clone()).await { - // Get user roles - let user_roles = get_user_roles_display(userid, &db_pool.clone()).await; + // Get user roles + let user_roles = get_user_roles_display(userid, &db_pool.clone()).await; - // Get user wishlist items + // Get user wishlist items let user_wishlist_items = get_user_wishlist_items(user_id, &db_pool.clone()).await; // Create the wishlist template. @@ -181,7 +188,7 @@ pub async fn user_wishlist_add_item( Path(user_id): Path, State(db_pool): State, Extension(user_data): Extension>, - Form(item_form): Form + Form(item_form): Form, ) -> impl IntoResponse { if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await { // Insert new item to database @@ -209,12 +216,12 @@ pub async fn user_wishlist_add_item( pub async fn user_wishlist_bought_item( Path(user_id): Path, State(db_pool): State, - Extension(user_data): Extension> + Extension(user_data): Extension>, ) -> impl IntoResponse { if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await { // Update item to purchased sqlx::query("update wishlist_items set purchased_by = ? where id = ?") - .bind(user_data.as_ref().unwrap().id)// Created by current user + .bind(user_data.as_ref().unwrap().id) // Created by current user .bind(user_id) .execute(&db_pool) .await @@ -222,7 +229,7 @@ pub async fn user_wishlist_bought_item( // Redirect to user wishlist // Extract the user data. - let row = sqlx::query( "SELECT user_id FROM wishlist_items WHERE id = ?") + let row = sqlx::query("SELECT user_id FROM wishlist_items WHERE id = ?") .bind(user_id) .fetch_one(&db_pool) .await @@ -239,14 +246,14 @@ pub async fn user_wishlist_bought_item( pub async fn user_wishlist_received_item( Path(user_id): Path, State(db_pool): State, - Extension(user_data): Extension> + Extension(user_data): Extension>, ) -> impl IntoResponse { if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await { // Update item received time let now = Utc::now().timestamp(); sqlx::query("update wishlist_items set received_at = ? where id = ?") - .bind(now)// Received now + .bind(now) // Received now .bind(user_id) .execute(&db_pool) .await diff --git a/backend/templates/authorized.html b/backend/templates/authorized.html index 1c8500a..f3429f7 100644 --- a/backend/templates/authorized.html +++ b/backend/templates/authorized.html @@ -9,6 +9,7 @@
  • Web links
  • Cottage Calendar
  • Wish lists
  • +
  • Gift Exchanges
  • {% for user_role in user_roles %} {% if user_role.role_name == "admin" %} diff --git a/backend/templates/base.html b/backend/templates/base.html index 66b687b..2662a1a 100644 --- a/backend/templates/base.html +++ b/backend/templates/base.html @@ -8,10 +8,14 @@ - + - + + + +
    @@ -51,7 +55,11 @@
    - + + + \ No newline at end of file diff --git a/backend/templates/useradmin.html b/backend/templates/useradmin.html index 0418cd4..e252f6c 100644 --- a/backend/templates/useradmin.html +++ b/backend/templates/useradmin.html @@ -2,11 +2,11 @@ {% block title %}User Administration{% endblock %} {% block center %}

    Users

    - +
    - - + + diff --git a/backend/templates/userwishlist.html b/backend/templates/userwishlist.html index 85e76d7..93de39f 100644 --- a/backend/templates/userwishlist.html +++ b/backend/templates/userwishlist.html @@ -12,11 +12,11 @@ Add {% endif %}
    -
    NameemailNameemail
    +
    - - + + diff --git a/backend/templates/userwishlists.html b/backend/templates/userwishlists.html index be9e49a..b857ea7 100644 --- a/backend/templates/userwishlists.html +++ b/backend/templates/userwishlists.html @@ -2,11 +2,11 @@ {% block title %}Wish Lists{% endblock %} {% block center %}

    Wishlists

    -
    ItemStateItemState Action
    +
    - - + +
    NameemailNameemail