minor re-org and rename of main page template struct.

This commit is contained in:
Joe Ardent 2023-06-08 09:16:38 -07:00
parent 898e8d381e
commit 9505266ef9
7 changed files with 12 additions and 15 deletions

View File

@ -1,6 +1,6 @@
use axum::response::{IntoResponse, Redirect}; use axum::response::{IntoResponse, Redirect};
use crate::{templates::Index, AuthContext}; use crate::{AuthContext, MainPage};
pub async fn handle_slash_redir() -> impl IntoResponse { pub async fn handle_slash_redir() -> impl IntoResponse {
Redirect::to("/") Redirect::to("/")
@ -13,7 +13,7 @@ pub async fn handle_slash(auth: AuthContext) -> impl IntoResponse {
} else { } else {
tracing::debug!("Not logged in."); tracing::debug!("Not logged in.");
} }
Index { MainPage {
user: auth.current_user, user: auth.current_user,
} }
} }

View File

@ -18,6 +18,9 @@ pub(crate) mod templates;
pub mod users; pub mod users;
pub(crate) mod util; pub(crate) mod util;
pub mod watches; pub mod watches;
pub use templates::*;
pub use watches::templates::*;
use watches::{ShowKind, Watch};
#[cfg(test)] #[cfg(test)]
pub mod test_utils; pub mod test_utils;

View File

@ -10,11 +10,7 @@ use axum::{
}; };
use sqlx::SqlitePool; use sqlx::SqlitePool;
use crate::{ use crate::{util::form_decode, AuthContext, LoginGet, LoginPost, LogoutGet, LogoutPost, User};
templates::{LoginGet, LoginPost, LogoutGet, LogoutPost},
util::form_decode,
AuthContext, User,
};
//-************************************************************************ //-************************************************************************
// Constants // Constants
@ -104,7 +100,7 @@ pub async fn post_logout(mut auth: AuthContext) -> impl IntoResponse {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{ use crate::{
templates::{Index, LoginGet, LogoutGet, LogoutPost}, templates::{LoginGet, LogoutGet, LogoutPost, MainPage},
test_utils::{get_test_user, massage, server, FORM_CONTENT_TYPE}, test_utils::{get_test_user, massage, server, FORM_CONTENT_TYPE},
}; };
@ -198,7 +194,7 @@ mod test {
.await; .await;
assert_eq!(resp.status_code(), 303); assert_eq!(resp.status_code(), 303);
let logged_in = Index { let logged_in = MainPage {
user: Some(get_test_user()), user: Some(get_test_user()),
} }
.to_string(); .to_string();

View File

@ -11,10 +11,7 @@ use sqlx::{query_as, SqlitePool};
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use uuid::Uuid; use uuid::Uuid;
use crate::{ use crate::{CreateUser, CreateUserSuccess, User};
templates::{CreateUser, CreateUserSuccess},
User,
};
pub(crate) const CREATE_QUERY: &str = pub(crate) const CREATE_QUERY: &str =
"insert into witches (id, username, displayname, email, pwhash) values ($1, $2, $3, $4, $5)"; "insert into witches (id, username, displayname, email, pwhash) values ($1, $2, $3, $4, $5)";
@ -29,7 +26,7 @@ const ID_QUERY: &str = "select * from witches where id = $1";
pub struct CreateUserError(#[from] CreateUserErrorKind); pub struct CreateUserError(#[from] CreateUserErrorKind);
impl IntoResponse for CreateUserError { impl IntoResponse for CreateUserError {
fn into_response(self) -> askama_axum::Response { fn into_response(self) -> Response {
match self.0 { match self.0 {
CreateUserErrorKind::UnknownDBError => { CreateUserErrorKind::UnknownDBError => {
(StatusCode::INTERNAL_SERVER_ERROR, format!("{self}")).into_response() (StatusCode::INTERNAL_SERVER_ERROR, format!("{self}")).into_response()

View File

@ -41,6 +41,6 @@ pub struct LogoutPost;
#[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq)] #[derive(Debug, Default, Template, Deserialize, Serialize, PartialEq, Eq)]
#[template(path = "index.html")] #[template(path = "index.html")]
pub struct Index { pub struct MainPage {
pub user: Option<User>, pub user: Option<User>,
} }

1
src/watches/templates.rs Normal file
View File

@ -0,0 +1 @@

0
templates/get_watches.rs Normal file
View File