refactor(domain): move DB string conversions out of domain enums

This commit is contained in:
2026-05-15 01:54:32 +02:00
parent a123c0b8cc
commit 344bcf34af
11 changed files with 124 additions and 74 deletions

View File

@@ -1,5 +1,24 @@
use async_trait::async_trait;
use chrono::{DateTime, Utc};
fn follow_state_from_str(s: &str) -> domain::models::social::FollowState {
use domain::models::social::FollowState;
match s {
"pending" => FollowState::Pending,
"rejected" => FollowState::Rejected,
_ => FollowState::Accepted,
}
}
fn follow_state_as_str(state: &domain::models::social::FollowState) -> &'static str {
use domain::models::social::FollowState;
match state {
FollowState::Pending => "pending",
FollowState::Accepted => "accepted",
FollowState::Rejected => "rejected",
}
}
use domain::{
errors::DomainError,
models::{
@@ -31,7 +50,7 @@ impl FollowRepository for PgFollowRepository {
)
.bind(f.follower_id.as_uuid())
.bind(f.following_id.as_uuid())
.bind(f.state.as_str())
.bind(follow_state_as_str(&f.state))
.bind(&f.ap_id)
.bind(f.created_at)
.execute(&self.pool)
@@ -77,7 +96,7 @@ impl FollowRepository for PgFollowRepository {
.map(|o| o.map(|r| Follow {
follower_id: UserId::from_uuid(r.follower_id),
following_id: UserId::from_uuid(r.following_id),
state: FollowState::from_db_str(&r.state),
state: follow_state_from_str(&r.state),
ap_id: r.ap_id,
created_at: r.created_at,
}))
@@ -92,7 +111,7 @@ impl FollowRepository for PgFollowRepository {
sqlx::query("UPDATE follows SET state=$3 WHERE follower_id=$1 AND following_id=$2")
.bind(follower_id.as_uuid())
.bind(following_id.as_uuid())
.bind(state.as_str())
.bind(follow_state_as_str(state))
.execute(&self.pool)
.await
.map_err(|e| DomainError::Internal(e.to_string()))