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,10 +1,31 @@
use async_trait::async_trait;
use chrono::{DateTime, Utc};
fn visibility_from_str(s: &str) -> domain::models::thought::Visibility {
use domain::models::thought::Visibility;
match s {
"followers" => Visibility::Followers,
"unlisted" => Visibility::Unlisted,
"direct" => Visibility::Direct,
_ => Visibility::Public,
}
}
fn visibility_as_str(v: &domain::models::thought::Visibility) -> &'static str {
use domain::models::thought::Visibility;
match v {
Visibility::Public => "public",
Visibility::Followers => "followers",
Visibility::Unlisted => "unlisted",
Visibility::Direct => "direct",
}
}
use domain::{
errors::DomainError,
models::{
feed::{PageParams, Paginated},
thought::{Thought, Visibility},
thought::Thought,
},
ports::ThoughtRepository,
value_objects::{Content, ThoughtId, UserId},
@@ -45,7 +66,7 @@ impl From<ThoughtRow> for Thought {
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
in_reply_to_url: r.in_reply_to_url,
ap_id: r.ap_id,
visibility: Visibility::from_db_str(&r.visibility),
visibility: visibility_from_str(&r.visibility),
content_warning: r.content_warning,
sensitive: r.sensitive,
local: r.local,
@@ -72,7 +93,7 @@ impl ThoughtRepository for PgThoughtRepository {
.bind(t.in_reply_to_id.as_ref().map(|x| x.as_uuid()))
.bind(&t.in_reply_to_url)
.bind(&t.ap_id)
.bind(t.visibility.as_str())
.bind(visibility_as_str(&t.visibility))
.bind(&t.content_warning)
.bind(t.sensitive)
.bind(t.local)