Compare commits
No commits in common. "f47543efd9e44d92b3f1c3f363e3b77e2fb67a74" and "f3bc62e4c02e89a86d18d1809d43716bc55dd22b" have entirely different histories.
f47543efd9
...
f3bc62e4c0
|
|
@ -1,2 +0,0 @@
|
||||||
-- Add down migration script here
|
|
||||||
alter table wishlist_items drop column received_at;
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
-- Add up migration script here
|
|
||||||
alter table wishlist_items add column received_at integer null;
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
cargo build --release
|
cargo build --release
|
||||||
ssh chris@192.168.59.31 'pkill jean-marie'
|
ssh chris@192.168.59.31 'pkill jean-marie'
|
||||||
scp target/release/jean-marie chris@192.168.59.31:/opt/jean-marie
|
scp target/release/jean-marie chris@192.168.59.31:/opt/jean-marie
|
||||||
scp .env chris@192.168.59.31:/opt/jean-marie
|
scp .env www@192.168.59.31:/opt/jean-marie
|
||||||
scp -r templates chris@192.168.59.31:/opt/jean-marie
|
scp -r templates chris@192.168.59.31:/opt/jean-marie
|
||||||
ssh chris@192.168.59.31 'cd /opt/jean-marie && ./jean-marie&'
|
ssh chris@192.168.59.31 'cd /opt/jean-marie && ./jean-marie&'
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,12 @@ mod google_oauth;
|
||||||
mod middlewares;
|
mod middlewares;
|
||||||
mod routes;
|
mod routes;
|
||||||
mod user;
|
mod user;
|
||||||
mod wishlist;
|
|
||||||
|
|
||||||
use error_handling::AppError;
|
use error_handling::AppError;
|
||||||
use middlewares::inject_user_data;
|
use middlewares::inject_user_data;
|
||||||
use google_oauth::{login, logout, google_auth_return};
|
use google_oauth::{login, logout, google_auth_return};
|
||||||
use routes::{about, contact, cottagecalendar, dashboard, index, profile, user_profile, useradmin};
|
use routes::{about, contact, cottagecalendar, dashboard, index, profile, user_profile, user_wishlist, user_wishlist_add, user_wishlist_add_item, useradmin, wishlists};
|
||||||
use user::{add_user_role, delete_user_role, UserData};
|
use user::{add_user_role, delete_user_role, UserData};
|
||||||
use wishlist::{user_wishlist, user_wishlist_add, user_wishlist_add_item, user_wishlist_bought_item, user_wishlist_received_item, wishlists};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
|
|
@ -58,8 +56,6 @@ async fn main() {
|
||||||
.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))
|
||||||
.route("/userwishlist/bought/:user_id", get(user_wishlist_bought_item))
|
|
||||||
.route("/userwishlist/received/:user_id", get(user_wishlist_received_item))
|
|
||||||
.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))
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,16 @@ use askama_axum::{Response, Template};
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
response::{Html, IntoResponse, Redirect},
|
response::{Html, IntoResponse, Redirect},
|
||||||
Extension,
|
Extension, Form,
|
||||||
};
|
};
|
||||||
|
use chrono::Utc;
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
|
use serde::Deserialize;
|
||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
middlewares::is_authorized,
|
middlewares::is_authorized,
|
||||||
user::{get_other_roles_display, get_user_roles_display},
|
user::{get_other_roles_display, get_user_roles_display, get_user_wishlist_items},
|
||||||
UserData,
|
UserData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -249,3 +251,155 @@ pub async fn cottagecalendar(
|
||||||
Redirect::to("/").into_response()
|
Redirect::to("/").into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "userwishlists.html")]
|
||||||
|
struct WishListsTemplate {
|
||||||
|
logged_in: bool,
|
||||||
|
name: String,
|
||||||
|
users: Vec<UserData>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn wishlists(
|
||||||
|
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();
|
||||||
|
|
||||||
|
let users = sqlx::query_as::<_, UserData>("SELECT * FROM users")
|
||||||
|
.fetch_all(&db_pool)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if is_authorized("/userwishlists", user_data, db_pool).await {
|
||||||
|
let template = WishListsTemplate {
|
||||||
|
logged_in,
|
||||||
|
name,
|
||||||
|
users,
|
||||||
|
};
|
||||||
|
HtmlTemplate(template).into_response()
|
||||||
|
} else {
|
||||||
|
Redirect::to("/").into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "userwishlist.html")]
|
||||||
|
struct UserWishListTemplate {
|
||||||
|
logged_in: bool,
|
||||||
|
name: String,
|
||||||
|
user: UserData,
|
||||||
|
user_wishlist_items: Vec<crate::user::UserWishlistItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn user_wishlist(
|
||||||
|
Path(user_id): Path<i64>,
|
||||||
|
State(db_pool): State<SqlitePool>,
|
||||||
|
Extension(user_data): Extension<Option<UserData>>,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
// Extract the user's name from the user data.
|
||||||
|
let user_name = user_data.as_ref().map(|s| s.name.clone());
|
||||||
|
let logged_in = user_data.is_some();
|
||||||
|
let name = user_name.unwrap_or_default();
|
||||||
|
|
||||||
|
// Extract the user data.
|
||||||
|
let user = sqlx::query_as!(UserData, "SELECT * FROM users WHERE id = ?", user_id)
|
||||||
|
.fetch_one(&db_pool)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if is_authorized("/wishlist", user_data, db_pool.clone()).await {
|
||||||
|
// Get user roles
|
||||||
|
let user_wishlist_items = get_user_wishlist_items(user_id, &db_pool.clone()).await;
|
||||||
|
|
||||||
|
// Create the wishlist template.
|
||||||
|
let template = UserWishListTemplate {
|
||||||
|
logged_in,
|
||||||
|
name,
|
||||||
|
user: user,
|
||||||
|
user_wishlist_items,
|
||||||
|
};
|
||||||
|
return HtmlTemplate(template).into_response();
|
||||||
|
} else {
|
||||||
|
Redirect::to("/").into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "userwishlistadd.html")]
|
||||||
|
struct UserWishListAddTemplate {
|
||||||
|
logged_in: bool,
|
||||||
|
name: String,
|
||||||
|
user: UserData,
|
||||||
|
user_wishlist_items: Vec<crate::user::UserWishlistItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn user_wishlist_add(
|
||||||
|
Path(user_id): Path<i64>,
|
||||||
|
State(db_pool): State<SqlitePool>,
|
||||||
|
Extension(user_data): Extension<Option<UserData>>,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
// Extract the user's name from the user data.
|
||||||
|
let user_name = user_data.as_ref().map(|s| s.name.clone());
|
||||||
|
let logged_in = user_data.is_some();
|
||||||
|
let name = user_name.unwrap_or_default();
|
||||||
|
|
||||||
|
// Extract the user data.
|
||||||
|
let user = sqlx::query_as!(UserData, "SELECT * FROM users WHERE id = ?", user_id)
|
||||||
|
.fetch_one(&db_pool)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if is_authorized("/wishlist", user_data, db_pool.clone()).await {
|
||||||
|
// Get user roles
|
||||||
|
let user_wishlist_items = get_user_wishlist_items(user_id, &db_pool.clone()).await;
|
||||||
|
|
||||||
|
// Create the wishlist template.
|
||||||
|
let template = UserWishListAddTemplate {
|
||||||
|
logged_in,
|
||||||
|
name,
|
||||||
|
user: user,
|
||||||
|
user_wishlist_items,
|
||||||
|
};
|
||||||
|
return HtmlTemplate(template).into_response();
|
||||||
|
} else {
|
||||||
|
Redirect::to("/").into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct ItemForm {
|
||||||
|
item: String,
|
||||||
|
item_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn user_wishlist_add_item(
|
||||||
|
Path(user_id): Path<i64>,
|
||||||
|
State(db_pool): State<SqlitePool>,
|
||||||
|
Extension(user_data): Extension<Option<UserData>>,
|
||||||
|
Form(item_form): Form<ItemForm>
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await {
|
||||||
|
// Insert new item to database
|
||||||
|
let now = Utc::now().timestamp();
|
||||||
|
|
||||||
|
sqlx::query("insert into wishlist_items (created_at, created_by, updated_at, updated_by, user_id, item, item_url) values (?, ?, ?, ?, ?, ?, ?)")
|
||||||
|
.bind(now)// Created now
|
||||||
|
.bind(user_data.as_ref().unwrap().id)// Created by current user
|
||||||
|
.bind(now) // Updated now
|
||||||
|
.bind(user_data.as_ref().unwrap().id) // Updated by current user
|
||||||
|
.bind(user_id)
|
||||||
|
.bind(item_form.item)
|
||||||
|
.bind(item_form.item_url)
|
||||||
|
.execute(&db_pool)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let redirect_string = format!("/userwishlist/{user_id}");
|
||||||
|
Redirect::to(&redirect_string).into_response()
|
||||||
|
} else {
|
||||||
|
Redirect::to("/").into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use axum::{
|
||||||
Extension,
|
Extension,
|
||||||
};
|
};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
use reqwest::redirect;
|
||||||
///User related structs and functions
|
///User related structs and functions
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{prelude::FromRow, SqlitePool};
|
use sqlx::{prelude::FromRow, SqlitePool};
|
||||||
|
|
@ -71,7 +71,6 @@ pub struct UserWishlistItem {
|
||||||
pub item: String,
|
pub item: String,
|
||||||
pub item_url: String,
|
pub item_url: String,
|
||||||
pub purchased_by: i64,
|
pub purchased_by: i64,
|
||||||
pub received_at: i64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -159,7 +158,7 @@ pub async fn delete_user_role(
|
||||||
pub async fn get_user_wishlist_items(user_id: i64, db_pool: &SqlitePool) -> Vec<UserWishlistItem> {
|
pub async fn get_user_wishlist_items(user_id: i64, db_pool: &SqlitePool) -> Vec<UserWishlistItem> {
|
||||||
// Get wish list items for the user
|
// Get wish list items for the user
|
||||||
let user_wishlist_items = sqlx::query_as(
|
let user_wishlist_items = sqlx::query_as(
|
||||||
r#"select id, created_at, created_by, updated_at, updated_by, user_id, item, item_url, purchased_by, received_at from wishlist_items where user_id = ?"#
|
r#"select id, created_at, created_by, updated_at, updated_by, user_id, item, item_url, purchased_by from wishlist_items where user_id = ?"#
|
||||||
)
|
)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.fetch_all(db_pool)
|
.fetch_all(db_pool)
|
||||||
|
|
|
||||||
|
|
@ -1,243 +0,0 @@
|
||||||
use askama_axum::{IntoResponse, Response, Template};
|
|
||||||
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 crate::{middlewares::is_authorized, user::{get_user_wishlist_items, UserData, UserWishlistItem}};
|
|
||||||
|
|
||||||
struct HtmlTemplate<T>(T);
|
|
||||||
|
|
||||||
impl<T> IntoResponse for HtmlTemplate<T>
|
|
||||||
where
|
|
||||||
T: Template,
|
|
||||||
{
|
|
||||||
fn into_response(self) -> Response {
|
|
||||||
match self.0.render() {
|
|
||||||
Ok(html) => Html(html).into_response(),
|
|
||||||
Err(err) => (
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
format!("Failed to render template. Error: {}", err),
|
|
||||||
)
|
|
||||||
.into_response(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Template)]
|
|
||||||
#[template(path = "userwishlists.html")]
|
|
||||||
struct WishListsTemplate {
|
|
||||||
logged_in: bool,
|
|
||||||
name: String,
|
|
||||||
users: Vec<UserData>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn wishlists(
|
|
||||||
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();
|
|
||||||
|
|
||||||
let users = sqlx::query_as::<_, UserData>("SELECT * FROM users")
|
|
||||||
.fetch_all(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if is_authorized("/userwishlists", user_data, db_pool).await {
|
|
||||||
let template = WishListsTemplate {
|
|
||||||
logged_in,
|
|
||||||
name,
|
|
||||||
users,
|
|
||||||
};
|
|
||||||
HtmlTemplate(template).into_response()
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Template)]
|
|
||||||
#[template(path = "userwishlist.html")]
|
|
||||||
struct UserWishListTemplate {
|
|
||||||
logged_in: bool,
|
|
||||||
name: String,
|
|
||||||
my_wishlist: bool,
|
|
||||||
user: UserData,
|
|
||||||
user_wishlist_items: Vec<crate::user::UserWishlistItem>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn user_wishlist(
|
|
||||||
Path(user_id): Path<i64>,
|
|
||||||
State(db_pool): State<SqlitePool>,
|
|
||||||
Extension(user_data): Extension<Option<UserData>>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
// Extract the user's name from the user data.
|
|
||||||
let user_name = user_data.as_ref().map(|s| s.name.clone());
|
|
||||||
let logged_in = user_data.is_some();
|
|
||||||
let name = user_name.unwrap_or_default();
|
|
||||||
|
|
||||||
// Extract the user's id from the user data
|
|
||||||
let user_userid = user_data.as_ref().map(|s| s.id.clone());
|
|
||||||
let userid = user_userid.unwrap_or_default();
|
|
||||||
|
|
||||||
// Extract the user data.
|
|
||||||
let user = sqlx::query_as!(UserData, "SELECT * FROM users WHERE id = ?", user_id)
|
|
||||||
.fetch_one(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if is_authorized("/wishlist", user_data, db_pool.clone()).await {
|
|
||||||
// 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)?
|
|
||||||
let my_wishlist = user_id == userid;
|
|
||||||
|
|
||||||
// Create the wishlist template.
|
|
||||||
let template = UserWishListTemplate {
|
|
||||||
logged_in,
|
|
||||||
name,
|
|
||||||
my_wishlist,
|
|
||||||
user: user,
|
|
||||||
user_wishlist_items,
|
|
||||||
};
|
|
||||||
return HtmlTemplate(template).into_response();
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Template)]
|
|
||||||
#[template(path = "userwishlistadd.html")]
|
|
||||||
struct UserWishListAddTemplate {
|
|
||||||
logged_in: bool,
|
|
||||||
name: String,
|
|
||||||
user: UserData,
|
|
||||||
user_wishlist_items: Vec<crate::user::UserWishlistItem>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn user_wishlist_add(
|
|
||||||
Path(user_id): Path<i64>,
|
|
||||||
State(db_pool): State<SqlitePool>,
|
|
||||||
Extension(user_data): Extension<Option<UserData>>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
// Extract the user's name from the user data.
|
|
||||||
let user_name = user_data.as_ref().map(|s| s.name.clone());
|
|
||||||
let logged_in = user_data.is_some();
|
|
||||||
let name = user_name.unwrap_or_default();
|
|
||||||
|
|
||||||
// Extract the user data.
|
|
||||||
let user = sqlx::query_as!(UserData, "SELECT * FROM users WHERE id = ?", user_id)
|
|
||||||
.fetch_one(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if is_authorized("/wishlist", user_data, db_pool.clone()).await {
|
|
||||||
// Get user roles
|
|
||||||
let user_wishlist_items = get_user_wishlist_items(user_id, &db_pool.clone()).await;
|
|
||||||
|
|
||||||
// Create the wishlist template.
|
|
||||||
let template = UserWishListAddTemplate {
|
|
||||||
logged_in,
|
|
||||||
name,
|
|
||||||
user: user,
|
|
||||||
user_wishlist_items,
|
|
||||||
};
|
|
||||||
return HtmlTemplate(template).into_response();
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct ItemForm {
|
|
||||||
item: String,
|
|
||||||
item_url: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn user_wishlist_add_item(
|
|
||||||
Path(user_id): Path<i64>,
|
|
||||||
State(db_pool): State<SqlitePool>,
|
|
||||||
Extension(user_data): Extension<Option<UserData>>,
|
|
||||||
Form(item_form): Form<ItemForm>
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
if is_authorized("/wishlist", user_data.clone(), db_pool.clone()).await {
|
|
||||||
// Insert new item to database
|
|
||||||
let now = Utc::now().timestamp();
|
|
||||||
|
|
||||||
sqlx::query("insert into wishlist_items (created_at, created_by, updated_at, updated_by, user_id, item, item_url) values (?, ?, ?, ?, ?, ?, ?)")
|
|
||||||
.bind(now)// Created now
|
|
||||||
.bind(user_data.as_ref().unwrap().id)// Created by current user
|
|
||||||
.bind(now) // Updated now
|
|
||||||
.bind(user_data.as_ref().unwrap().id) // Updated by current user
|
|
||||||
.bind(user_id)
|
|
||||||
.bind(item_form.item)
|
|
||||||
.bind(item_form.item_url)
|
|
||||||
.execute(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let redirect_string = format!("/userwishlist/{user_id}");
|
|
||||||
Redirect::to(&redirect_string).into_response()
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn user_wishlist_bought_item(
|
|
||||||
Path(user_id): Path<i64>,
|
|
||||||
State(db_pool): State<SqlitePool>,
|
|
||||||
Extension(user_data): Extension<Option<UserData>>
|
|
||||||
) -> 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_id)
|
|
||||||
.execute(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Redirect to user wishlist
|
|
||||||
// Extract the user data.
|
|
||||||
let row = sqlx::query( "SELECT user_id FROM wishlist_items WHERE id = ?")
|
|
||||||
.bind(user_id)
|
|
||||||
.fetch_one(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let userid = row.get::<i64, _>("user_id");
|
|
||||||
let redirect_string = format!("/userwishlist/{userid}");
|
|
||||||
Redirect::to(&redirect_string).into_response()
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn user_wishlist_received_item(
|
|
||||||
Path(user_id): Path<i64>,
|
|
||||||
State(db_pool): State<SqlitePool>,
|
|
||||||
Extension(user_data): Extension<Option<UserData>>
|
|
||||||
) -> 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(user_id)
|
|
||||||
.execute(&db_pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Redirect to user wishlist
|
|
||||||
let userid = user_data.as_ref().unwrap().id;
|
|
||||||
let redirect_string = format!("/userwishlist/{userid}");
|
|
||||||
Redirect::to(&redirect_string).into_response()
|
|
||||||
} else {
|
|
||||||
Redirect::to("/").into_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +1,20 @@
|
||||||
{% extends "authorized.html" %}
|
{% extends "authorized.html" %}
|
||||||
{% block title %}User Profile{% endblock %}
|
{% block title %}User Profile{% endblock %}
|
||||||
{% block center %}
|
{% block center %}
|
||||||
{% if my_wishlist %}
|
|
||||||
<h1>My Wishlist</h1>
|
|
||||||
{% else %}
|
|
||||||
<h1>{{ user.given_name }} Wishlist</h1>
|
<h1>{{ user.given_name }} Wishlist</h1>
|
||||||
{% endif %}
|
|
||||||
<br/>
|
<br/>
|
||||||
<h2>List</h2>
|
<h2>List</h2>
|
||||||
{% if my_wishlist %}
|
|
||||||
<a href="/userwishlist/add/{{ user.id }}">Add</a>
|
<a href="/userwishlist/add/{{ user.id }}">Add</a>
|
||||||
{% endif %}
|
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Item</th>
|
<th scope="col">Item</th>
|
||||||
<th scope="col">Action</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for user_wishlist_item in user_wishlist_items %}
|
{% for user_wishlist_item in user_wishlist_items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ user_wishlist_item.item_url }}">{{ user_wishlist_item.item }}</a></td>
|
<td><a href="{{ user_wishlist_item.item_url }}">{{ user_wishlist_item.item }}</a></td>
|
||||||
{% if my_wishlist %}
|
|
||||||
{% if user_wishlist_item.received_at > 0 %}
|
|
||||||
<td>Got it!</td>
|
|
||||||
{% else %}
|
|
||||||
<td><a href="/userwishlist/received/{{ user_wishlist_item.id }}">Received</a></td>
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
|
||||||
{% if user_wishlist_item.purchased_by > 0 %}
|
|
||||||
<td>Purchased</td>
|
|
||||||
{% else %}
|
|
||||||
<td><a href="/userwishlist/bought/{{ user_wishlist_item.id }}">Bought</a></td>
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue