refactor: apply clippy rules

This commit is contained in:
Matthieu Bessat 2026-01-13 21:15:27 +01:00
parent d205d722aa
commit 8f7d11226f
9 changed files with 153 additions and 245 deletions

View file

@ -1,6 +1,5 @@
use anyhow::Context;
use anyhow::Result;
use std::path::PathBuf;
use std::str::FromStr;
use fully_pub::fully_pub;
@ -16,14 +15,6 @@ struct Database(Pool<Sqlite>);
/// Initialize database
pub async fn provide_database(sqlite_db_path: &str) -> Result<Database> {
let path = PathBuf::from(sqlite_db_path);
let is_db_initialization = !path.exists();
// // database does not exists, trying to create it
// if path
// .parent()
// .filter(|pp| pp.exists())
// Err(anyhow!("Could not find parent directory of the db location.")));
let conn_str = format!("sqlite://{sqlite_db_path}");
let pool = SqlitePoolOptions::new()
@ -31,9 +22,6 @@ pub async fn provide_database(sqlite_db_path: &str) -> Result<Database> {
.connect_with(SqliteConnectOptions::from_str(&conn_str)?.create_if_missing(true))
.await
.context("could not connect to database_url")?;
// if is_db_initialization {
// initialize_db(Database(pool.clone())).await?;
// }
Ok(Database(pool))
}

View file

@ -1,4 +1,4 @@
use anyhow::{Context, Result};
use anyhow::Result;
use chrono::Utc;
use sqlx::types::Json;
@ -18,7 +18,7 @@ pub mod repositories;
async fn main() -> Result<()> {
println!("Sandbox");
let users = vec![
let users = [
User {
id: "idu1".into(),
handle: "john.doe".into(),
@ -50,13 +50,13 @@ async fn main() -> Result<()> {
avatar_bytes: None,
},
];
let user_token = UserToken {
let _user_token = UserToken {
id: "idtoken1".into(),
secret: "4LP5A3F3XBV5NM8VXRGZG3QDXO9PNAC0".into(),
last_use_time: None,
creation_time: Utc::now(),
expiration_time: Utc::now(),
user_id: ForeignRef::new(&users.get(0).unwrap()),
user_id: ForeignRef::new(users.first().unwrap()),
};
let db = provide_database("tmp/db.db").await?;
@ -70,7 +70,7 @@ async fn main() -> Result<()> {
last_use_time: None,
creation_time: Utc::now(),
expiration_time: Utc::now(),
user_id: ForeignRef::new(&users.get(0).unwrap()),
user_id: ForeignRef::new(users.first().unwrap()),
},
UserToken {
id: "idtoken3".into(),
@ -78,7 +78,7 @@ async fn main() -> Result<()> {
last_use_time: None,
creation_time: Utc::now(),
expiration_time: Utc::now(),
user_id: ForeignRef::new(&users.get(1).unwrap()),
user_id: ForeignRef::new(users.get(1).unwrap()),
},
UserToken {
id: "idtoken4".into(),
@ -86,7 +86,7 @@ async fn main() -> Result<()> {
last_use_time: None,
creation_time: Utc::now(),
expiration_time: Utc::now(),
user_id: ForeignRef::new(&users.get(1).unwrap()),
user_id: ForeignRef::new(users.get(1).unwrap()),
},
])
.await?;

View file

@ -40,8 +40,8 @@ impl UserRepository {
.bind(&entity.id)
.bind(&entity.handle)
.bind(&entity.full_name)
.bind(&entity.prefered_color)
.bind(&entity.last_login_at)
.bind(entity.prefered_color)
.bind(entity.last_login_at)
.bind(&entity.status)
.bind(&entity.groups)
.bind(&entity.avatar_bytes)
@ -75,8 +75,8 @@ impl UserRepository {
.bind(&entity.id)
.bind(&entity.handle)
.bind(&entity.full_name)
.bind(&entity.prefered_color)
.bind(&entity.last_login_at)
.bind(entity.prefered_color)
.bind(entity.last_login_at)
.bind(&entity.status)
.bind(&entity.groups)
.bind(&entity.avatar_bytes);
@ -92,8 +92,8 @@ impl UserRepository {
.bind(&entity.id)
.bind(&entity.handle)
.bind(&entity.full_name)
.bind(&entity.prefered_color)
.bind(&entity.last_login_at)
.bind(entity.prefered_color)
.bind(entity.last_login_at)
.bind(&entity.status)
.bind(&entity.groups)
.bind(&entity.avatar_bytes)

View file

@ -42,9 +42,9 @@ impl UserTokenRepository {
)
.bind(&entity.id)
.bind(&entity.secret)
.bind(&entity.last_use_time)
.bind(&entity.creation_time)
.bind(&entity.expiration_time)
.bind(entity.last_use_time)
.bind(entity.creation_time)
.bind(entity.expiration_time)
.bind(&entity.user_id.target_id)
.execute(&self.db.0)
.await?;
@ -75,9 +75,9 @@ impl UserTokenRepository {
query = query
.bind(&entity.id)
.bind(&entity.secret)
.bind(&entity.last_use_time)
.bind(&entity.creation_time)
.bind(&entity.expiration_time)
.bind(entity.last_use_time)
.bind(entity.creation_time)
.bind(entity.expiration_time)
.bind(&entity.user_id.target_id);
}
query.execute(&self.db.0).await?;
@ -90,9 +90,9 @@ impl UserTokenRepository {
.bind(item_id)
.bind(&entity.id)
.bind(&entity.secret)
.bind(&entity.last_use_time)
.bind(&entity.creation_time)
.bind(&entity.expiration_time)
.bind(entity.last_use_time)
.bind(entity.creation_time)
.bind(entity.expiration_time)
.bind(&entity.user_id.target_id)
.execute(&self.db.0)
.await?;