Add frontend tests and other stuff
This commit is contained in:
parent
d28e765e39
commit
642dd8a80c
26 changed files with 730 additions and 85 deletions
|
|
@ -14,6 +14,8 @@ use crate::user::User;
|
|||
use crate::model;
|
||||
use crate::data::{db, asynchronous};
|
||||
|
||||
mod api;
|
||||
|
||||
///// UTILS /////
|
||||
|
||||
fn get_ip_and_user_agent(req: &HttpRequest) -> (String, String) {
|
||||
|
|
@ -119,8 +121,8 @@ impl actix_web::error::ResponseError for ServiceError {
|
|||
#[template(path = "home.html")]
|
||||
struct HomeTemplate {
|
||||
user: Option<User>,
|
||||
recipes: Vec<(i32, String)>,
|
||||
current_recipe_id: Option<i32>,
|
||||
recipes: Vec<(i64, String)>,
|
||||
current_recipe_id: Option<i64>,
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
|
|
@ -137,13 +139,13 @@ pub async fn home_page(req: HttpRequest, connection: web::Data<db::Connection>)
|
|||
#[template(path = "view_recipe.html")]
|
||||
struct ViewRecipeTemplate {
|
||||
user: Option<User>,
|
||||
recipes: Vec<(i32, String)>,
|
||||
current_recipe_id: Option<i32>,
|
||||
recipes: Vec<(i64, String)>,
|
||||
current_recipe_id: Option<i64>,
|
||||
current_recipe: model::Recipe,
|
||||
}
|
||||
|
||||
#[get("/recipe/view/{id}")]
|
||||
pub async fn view_recipe(req: HttpRequest, path: web::Path<(i32,)>, connection: web::Data<db::Connection>) -> Result<HttpResponse> {
|
||||
pub async fn view_recipe(req: HttpRequest, path: web::Path<(i64,)>, connection: web::Data<db::Connection>) -> Result<HttpResponse> {
|
||||
let (id,)= path.into_inner();
|
||||
let user = get_current_user(&req, connection.clone()).await;
|
||||
let recipes = connection.get_all_recipe_titles_async().await?;
|
||||
|
|
@ -255,10 +257,10 @@ pub async fn sign_up_post(req: HttpRequest, form: web::Form<SignUpFormData>, con
|
|||
Ok(db::SignUpResult::UserCreatedWaitingForValidation(token)) => {
|
||||
let url = {
|
||||
let host = req.headers().get(header::HOST).map(|v| v.to_str().unwrap_or_default()).unwrap_or_default();
|
||||
let port: Option<i32> = 'p: {
|
||||
let port: Option<u16> = 'p: {
|
||||
let split_port: Vec<&str> = host.split(':').collect();
|
||||
if split_port.len() == 2 {
|
||||
if let Ok(p) = split_port[1].parse::<i32>() {
|
||||
if let Ok(p) = split_port[1].parse::<u16>() {
|
||||
break 'p Some(p)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue