cargo fmt

This commit is contained in:
Greg Shuflin 2025-02-02 21:01:54 -08:00
parent c33b54383d
commit 202a7e5224
3 changed files with 20 additions and 15 deletions

View File

@ -10,7 +10,7 @@ mod user;
use rocket::fs::FileServer; use rocket::fs::FileServer;
use rocket::response::Redirect; use rocket::response::Redirect;
use rocket_db_pools::{sqlx, Database, Connection}; use rocket_db_pools::{sqlx, Connection, Database};
use rocket_dyn_templates::{context, Template}; use rocket_dyn_templates::{context, Template};
use user::AuthenticatedUser; use user::AuthenticatedUser;

View File

@ -1,9 +1,9 @@
use crate::user::AuthenticatedUser;
use crate::{feed_utils::fetch_feed, Db}; use crate::{feed_utils::fetch_feed, Db};
use rocket::http::Status; use rocket::http::Status;
use rocket::serde::uuid::Uuid; use rocket::serde::uuid::Uuid;
use rocket::serde::{json::Json, Serialize}; use rocket::serde::{json::Json, Serialize};
use rocket_db_pools::Connection; use rocket_db_pools::Connection;
use crate::user::AuthenticatedUser;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(crate = "rocket::serde")] #[serde(crate = "rocket::serde")]
@ -15,7 +15,7 @@ pub struct FeedPollResponse {
pub async fn poll_feed( pub async fn poll_feed(
mut db: Connection<Db>, mut db: Connection<Db>,
feed_id: Uuid, feed_id: Uuid,
user: AuthenticatedUser user: AuthenticatedUser,
) -> Result<Json<FeedPollResponse>, Status> { ) -> Result<Json<FeedPollResponse>, Status> {
let feed_id = feed_id.to_string(); let feed_id = feed_id.to_string();
let user_id = user.user_id.to_string(); let user_id = user.user_id.to_string();
@ -32,8 +32,7 @@ pub async fn poll_feed(
.url; .url;
// Parse the URL // Parse the URL
let url = url::Url::parse(&feed_url) let url = url::Url::parse(&feed_url).map_err(|_| Status::InternalServerError)?;
.map_err(|_| Status::InternalServerError)?;
let feed_data = fetch_feed(&url).await.map_err(|_| Status::BadGateway)?; let feed_data = fetch_feed(&url).await.map_err(|_| Status::BadGateway)?;

View File

@ -279,7 +279,10 @@ pub async fn setup_page(mut db: Connection<Db>) -> Result<Template, Status> {
} }
#[post("/setup", data = "<new_user>")] #[post("/setup", data = "<new_user>")]
pub async fn setup(mut db: Connection<Db>, new_user: Json<NewUser>) -> Result<Status, Json<SetupError>> { pub async fn setup(
mut db: Connection<Db>,
new_user: Json<NewUser>,
) -> Result<Status, Json<SetupError>> {
// Check if any users exist // Check if any users exist
let count = sqlx::query!("SELECT COUNT(*) as count FROM users") let count = sqlx::query!("SELECT COUNT(*) as count FROM users")
.fetch_one(&mut **db) .fetch_one(&mut **db)
@ -299,7 +302,8 @@ pub async fn setup(mut db: Connection<Db>, new_user: Json<NewUser>) -> Result<St
} }
// Hash the password // Hash the password
let password_hash = bcrypt::hash(new_user.password.as_bytes(), bcrypt::DEFAULT_COST).map_err(|e| { let password_hash =
bcrypt::hash(new_user.password.as_bytes(), bcrypt::DEFAULT_COST).map_err(|e| {
eprintln!("Password hashing error: {}", e); eprintln!("Password hashing error: {}", e);
Json(SetupError { Json(SetupError {
error: "Failed to process password".to_string(), error: "Failed to process password".to_string(),
@ -329,9 +333,11 @@ pub async fn setup(mut db: Connection<Db>, new_user: Json<NewUser>) -> Result<St
Err(e) => { Err(e) => {
eprintln!("Database error: {}", e); eprintln!("Database error: {}", e);
match e { match e {
sqlx::Error::Database(db_err) if db_err.is_unique_violation() => Err(Json(SetupError { sqlx::Error::Database(db_err) if db_err.is_unique_violation() => {
Err(Json(SetupError {
error: "Username already exists".to_string(), error: "Username already exists".to_string(),
})), }))
}
_ => Err(Json(SetupError { _ => Err(Json(SetupError {
error: "Failed to create user".to_string(), error: "Failed to create user".to_string(),
})), })),