diff --git a/backend/src/cookie/jwt.rs b/backend/src/cookie/jwt.rs index 8f37315..e0a861c 100644 --- a/backend/src/cookie/jwt.rs +++ b/backend/src/cookie/jwt.rs @@ -57,8 +57,8 @@ pub fn encode_token(header: &Header, id: String, key: &EncodingKey) -> String { /// - `key`: The `DecodingKey` used to verify the JWT's signature. /// /// # Returns -/// - `Ok(Claims)`: If the token is successfully decoded and verified, returns the extracted `Claims`. -/// - `Err((StatusCode, Json))`: If the token is invalid, expired, or cannot be decoded, +/// - `200 OK`: If the token is successfully decoded and verified, returns the extracted `Claims`. +/// - `401 UNAUTHORIZED`: If the token is invalid, expired, or cannot be decoded, /// returns an `UNAUTHORIZED` status code along with a JSON error message. pub fn decode_token(token: String, key: &DecodingKey) -> Result)> { let mut validation = jsonwebtoken::Validation::new(jsonwebtoken::Algorithm::HS256); diff --git a/backend/src/cookie/validation.rs b/backend/src/cookie/validation.rs index e1d238c..4d36f53 100644 --- a/backend/src/cookie/validation.rs +++ b/backend/src/cookie/validation.rs @@ -26,13 +26,13 @@ use crate::{AppState, cookie::jwt::decode_token, handlers::auth::filter_user, mo /// /// # Arguments /// - `cookies`: The `CookieJar` from the request, used to extract the `token` cookie. -/// - `State(data)`: Application state containing `AppState` for database access and `token_secret`. -/// - `mut request`: The incoming HTTP request, which will have user data injected into its extensions. +/// - `request`: The incoming HTTP request, which will have user data injected into its extensions. /// - `next`: The next middleware or handler in the chain. /// /// # Returns -/// - `Ok(impl IntoResponse)`: If validation succeeds, the request proceeds to the next handler. -/// - `Err((StatusCode, Json))`: An error response if validation fails. +/// - `200 OK`: If validation succeeds, the request proceeds to the next handler. +/// - `401 UNAUTHORIZED`: If validating the user fails. +/// - `500 INTERNAL SERVER ERROR`: If the database query fails pub async fn validate_token( cookies: CookieJar, State(data): State>, @@ -119,14 +119,13 @@ pub async fn validate_token( /// /// # Arguments /// - `cookies`: The `CookieJar` from the request. -/// - `State(data)`: Application state containing `AppState`. -/// - `mut request`: The incoming HTTP request, which will have admin user data injected. +/// - `request`: The incoming HTTP request, which will have admin user data injected. /// - `next`: The next middleware or handler in the chain. /// /// # Returns -/// - `Ok(impl IntoResponse)`: If validation and admin check succeed, the request proceeds. -/// - `Err((StatusCode, Json))`: An error response if validation fails -/// or the user is not an admin. +/// - `200 OK`: If validation and admin check succeed, the request proceeds. +/// - `401 UNAUTHORIZED`: An error response if validation fails or the user is not an admin. +/// - `500 INTERNAL SERVER ERROR`: If the databse query fails pub async fn validate_admin( cookies: CookieJar, State(data): State>, diff --git a/backend/src/handlers/auth.rs b/backend/src/handlers/auth.rs index 4d251cb..529d646 100644 --- a/backend/src/handlers/auth.rs +++ b/backend/src/handlers/auth.rs @@ -26,7 +26,7 @@ use crate::{ /// before being stored. Only administrators can create new users. /// /// # Arguments -/// - `request`: User creation details including first/last name, username, admin flag, and password +/// - `request`: Json with [UserCreateScheme] as it's format /// /// # Returns /// - `200 OK` on successful user creation @@ -110,10 +110,10 @@ pub async fn create_user( /// The token is valid for 1 hour. /// /// # Arguments -/// - `request`: Login credentials (username, password) +/// - `request`: Login credentials in Json format using the [LoginScheme] /// /// # Returns -/// - `200 OK` with JSON containing token and filtered user info +/// - `200 OK` with JSON containing token and [FilteredUser] info /// - `400 Bad Request` if username not found or password invalid /// - `500 Internal Server Error` if database query fails /// @@ -231,7 +231,7 @@ pub async fn logout() -> Result Json { let v = EASY_FIX_COUNT.load(Ordering::SeqCst); Json(CounterResp { value: v }) } +/// Incremets the [EASY_FIX_COUNT] value by one +/// +/// # Returns +/// - `200 OK` with the new value on success async fn increment() -> Result, StatusCode> { let new = EASY_FIX_COUNT.fetch_add(1, Ordering::SeqCst) + 1; Ok(Json(CounterResp { value: new })) diff --git a/frontend/src/lib.rs b/frontend/src/lib.rs index e8e8222..5d4488e 100644 --- a/frontend/src/lib.rs +++ b/frontend/src/lib.rs @@ -91,7 +91,7 @@ fn sidebar_shell(props: &SidebarShellProps) -> Html { } } -/// Props for the AdminCheckWrapper component. +/// Props for the [AdminCheckWrapper] component. #[derive(Properties, PartialEq)] pub struct AdminCheckWrapperProps { pub children: Children, @@ -166,7 +166,7 @@ fn admin_check_wrapper(props: &AdminCheckWrapperProps) -> Html { /// The main routing logic for the application. /// -/// This function takes a `Route` enum variant and returns the corresponding HTML +/// This function takes a [Route] enum variant and returns the corresponding HTML /// content to be rendered. It acts as a central dispatcher for the application's /// navigation. /// @@ -259,12 +259,12 @@ fn switch(route: Route) -> Html { /// The root component of the Yew application. /// /// This component sets up the application's routing using `yew-router`'s -/// [`BrowserRouter`] and [`Switch`] components. All other application content +/// `BrowserRouter` and `Switch` components. All other application content /// is rendered based on the current route. /// /// # Structure -/// - [`BrowserRouter`]: Enables client-side routing. -/// - [`Switch`]: Renders components based on the matched [`Route`]. +/// - `BrowserRouter`: Enables client-side routing. +/// - `Switch`: Renders components based on the matched [Route]. #[component(App)] pub fn app() -> Html { html! { diff --git a/frontend/src/pages/basic_pages.rs b/frontend/src/pages/basic_pages.rs index fe5850e..1c02cde 100644 --- a/frontend/src/pages/basic_pages.rs +++ b/frontend/src/pages/basic_pages.rs @@ -97,10 +97,6 @@ pub fn not_found_component() -> Html { /// A component displayed when a user attempts to access a page for which they do not have sufficient permissions. /// -/// It informs the user about the access restriction and provides instructions to contact -/// a specific person ("Herr Winter") if they believe this is an error. -/// It also includes a link to return to the home page. -/// /// # Example /// ```rust /// html! {