From 8536e41c64811630ce8c99eb49d81f89bfb69456 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Fri, 27 Jan 2023 16:04:04 -0500 Subject: rusty boio finished --- src/api/auth.rs | 2 +- src/api/pages.rs | 1 - src/api/posts.rs | 8 ++++++-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/api') diff --git a/src/api/auth.rs b/src/api/auth.rs index b469d4d..54c4e06 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -26,7 +26,7 @@ impl Check for RegistrationRequet { Self::assert_length(&self.gender, 1, 100, "Gender can only by 1-100 characters long")?; Self::assert_range(self.day as u64, 1, 255, "Birthday day can only be between 1-255")?; Self::assert_range(self.month as u64, 1, 255, "Birthday month can only be between 1-255")?; - Self::assert_range(self.year as u64, 1, 2147483647, "Birthday year can only be between 1-2147483647")?; + Self::assert_range(self.year as u64, 1, 4294967295, "Birthday year can only be between 1-4294967295")?; Ok(()) } } diff --git a/src/api/pages.rs b/src/api/pages.rs index 749a686..4701795 100644 --- a/src/api/pages.rs +++ b/src/api/pages.rs @@ -3,7 +3,6 @@ use axum::{Router, response::{Response, Redirect, IntoResponse}, routing::get}; use crate::types::{extract::AuthorizedUser, response::ResponseCode}; async fn root(user: Option) -> Response { - println!("{}", user.is_some()); if user.is_some() { return Redirect::to("/home").into_response() } else { diff --git a/src/api/posts.rs b/src/api/posts.rs index 85ff2b2..6830c1a 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -18,11 +18,15 @@ impl Check for PostCreateRequest { async fn create(AuthorizedUser(user): AuthorizedUser, Json(body): Json) -> Response { - let Ok(_post) = Post::new(user.user_id, body.content) else { + let Ok(post) = Post::new(user.user_id, body.content) else { return ResponseCode::InternalServerError.msg("Failed to create post") }; - ResponseCode::Created.msg("Successfully created new post") + let Ok(json) = serde_json::to_string(&post) else { + return ResponseCode::InternalServerError.msg("Failed to create post") + }; + + ResponseCode::Created.json(&json) } #[derive(Deserialize)] -- cgit v1.2.3-freya