Refactor database error handling across repositories to use IntoDbResult for improved error management
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m30s
test / unit (pull_request) Successful in 16m10s
test / integration (pull_request) Failing after 16m44s
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m30s
test / unit (pull_request) Successful in 16m10s
test / integration (pull_request) Failing after 16m44s
- Updated PgNotificationRepository to utilize IntoDbResult for error handling in various methods. - Refactored PgRemoteActorRepository to replace manual error mapping with IntoDbResult. - Modified PgRemoteActorConnectionRepository to implement IntoDbResult for error handling. - Adjusted PgTagRepository to use IntoDbResult for consistent error management. - Introduced test_helpers module for seeding users and thoughts in tests. - Enhanced PgThoughtRepository to leverage IntoDbResult for error handling. - Updated PgTopFriendRepository to utilize IntoDbResult for error management. - Refactored PgUserRepository to implement IntoDbResult for error handling. - Added constants for pagination defaults in requests. - Introduced MAX_TOP_FRIENDS constant for top friends validation. - Refactored JWT expiration time to use a constant. - Improved rate limiter configuration with constants for better readability. - Added utility methods for FollowState and Visibility enums for string conversions. - Introduced maximum length constants for Username, Email, and Content value objects. - Cleaned up test modules by removing redundant code and utilizing a shared testing state.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::db_error::IntoDbResult;
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use domain::{
|
||||
@@ -18,7 +19,7 @@ impl PgUserRepository {
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
pub(crate) struct UserRow {
|
||||
pub struct UserRow {
|
||||
pub id: uuid::Uuid,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
@@ -56,7 +57,7 @@ impl From<UserRow> for User {
|
||||
}
|
||||
}
|
||||
|
||||
const USER_SELECT: &str = "SELECT id,username,email,password_hash,display_name,bio,avatar_url,header_url,custom_css,local,ap_id,inbox_url,created_at,updated_at FROM users";
|
||||
pub const USER_SELECT: &str = "SELECT id,username,email,password_hash,display_name,bio,avatar_url,header_url,custom_css,local,ap_id,inbox_url,created_at,updated_at FROM users";
|
||||
|
||||
#[async_trait]
|
||||
impl UserRepository for PgUserRepository {
|
||||
@@ -65,7 +66,7 @@ impl UserRepository for PgUserRepository {
|
||||
.bind(id.as_uuid())
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.map_err(|e| DomainError::Internal(e.to_string()))
|
||||
.into_domain()
|
||||
.map(|o| o.map(User::from))
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ impl UserRepository for PgUserRepository {
|
||||
.bind(username.as_str())
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.map_err(|e| DomainError::Internal(e.to_string()))
|
||||
.into_domain()
|
||||
.map(|o| o.map(User::from))
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ impl UserRepository for PgUserRepository {
|
||||
.bind(email.as_str())
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.map_err(|e| DomainError::Internal(e.to_string()))
|
||||
.into_domain()
|
||||
.map(|o| o.map(User::from))
|
||||
}
|
||||
|
||||
@@ -115,7 +116,7 @@ impl UserRepository for PgUserRepository {
|
||||
.bind(user.updated_at)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_err(|e| DomainError::Internal(e.to_string()))
|
||||
.into_domain()
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ impl UserRepository for PgUserRepository {
|
||||
.bind(custom_css)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_err(|e| DomainError::Internal(e.to_string()))
|
||||
.into_domain()
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
@@ -170,7 +171,7 @@ impl UserRepository for PgUserRepository {
|
||||
)
|
||||
.fetch_all(&self.pool)
|
||||
.await
|
||||
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
||||
.into_domain()?;
|
||||
|
||||
Ok(rows
|
||||
.into_iter()
|
||||
@@ -191,7 +192,7 @@ impl UserRepository for PgUserRepository {
|
||||
sqlx::query_scalar::<_, i64>("SELECT COUNT(*) FROM users WHERE local = true")
|
||||
.fetch_one(&self.pool)
|
||||
.await
|
||||
.map_err(|e| DomainError::Internal(e.to_string()))
|
||||
.into_domain()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user