refactor(domain): move DB string conversions out of domain enums
This commit is contained in:
@@ -21,13 +21,23 @@ use axum::{
|
||||
use domain::models::feed::PageParams;
|
||||
use domain::value_objects::UserId;
|
||||
|
||||
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",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_thought_response(e: &domain::models::feed::FeedEntry) -> ThoughtResponse {
|
||||
ThoughtResponse {
|
||||
id: e.thought.id.as_uuid(),
|
||||
content: e.thought.content.as_str().to_string(),
|
||||
author: to_user_response(&e.author),
|
||||
in_reply_to_id: e.thought.in_reply_to_id.as_ref().map(|id| id.as_uuid()),
|
||||
visibility: e.thought.visibility.as_str().to_string(),
|
||||
visibility: visibility_as_str(&e.thought.visibility).to_string(),
|
||||
content_warning: e.thought.content_warning.clone(),
|
||||
sensitive: e.thought.sensitive,
|
||||
like_count: e.like_count,
|
||||
|
||||
@@ -20,6 +20,16 @@ use axum::{
|
||||
use domain::value_objects::ThoughtId;
|
||||
use uuid::Uuid;
|
||||
|
||||
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",
|
||||
}
|
||||
}
|
||||
|
||||
fn thought_to_json(
|
||||
t: &domain::models::thought::Thought,
|
||||
author: &domain::models::user::User,
|
||||
@@ -32,7 +42,7 @@ fn thought_to_json(
|
||||
"content": t.content.as_str(),
|
||||
"author": to_user_response(author),
|
||||
"replyToId": t.in_reply_to_id.as_ref().map(|x| x.as_uuid()),
|
||||
"visibility": t.visibility.as_str(),
|
||||
"visibility": visibility_as_str(&t.visibility),
|
||||
"contentWarning": t.content_warning,
|
||||
"sensitive": t.sensitive,
|
||||
"likeCount": like_count,
|
||||
|
||||
Reference in New Issue
Block a user