fix(domain): from_db_str returns Result — unknown DB values are errors not silent defaults
This commit is contained in:
@@ -67,13 +67,13 @@ const FEED_SELECT: &str = "
|
||||
(SELECT COUNT(*) FROM thoughts r WHERE r.in_reply_to_id=t.id) AS reply_count
|
||||
FROM thoughts t JOIN users u ON u.id=t.user_id";
|
||||
|
||||
fn row_to_entry(r: FeedRow) -> FeedEntry {
|
||||
fn row_to_entry(r: FeedRow) -> Result<FeedEntry, DomainError> {
|
||||
let thought = Thought {
|
||||
id: ThoughtId::from_uuid(r.thought_id),
|
||||
user_id: UserId::from_uuid(r.t_user_id),
|
||||
content: Content::new_remote(r.content),
|
||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||
visibility: Visibility::from_db_str(&r.visibility),
|
||||
visibility: Visibility::from_db_str(&r.visibility)?,
|
||||
content_warning: r.content_warning,
|
||||
sensitive: r.sensitive,
|
||||
local: r.t_local,
|
||||
@@ -94,7 +94,7 @@ fn row_to_entry(r: FeedRow) -> FeedEntry {
|
||||
created_at: r.author_created_at,
|
||||
updated_at: r.author_updated_at,
|
||||
};
|
||||
FeedEntry {
|
||||
Ok(FeedEntry {
|
||||
thought,
|
||||
author,
|
||||
like_count: r.like_count,
|
||||
@@ -102,7 +102,7 @@ fn row_to_entry(r: FeedRow) -> FeedEntry {
|
||||
reply_count: r.reply_count,
|
||||
liked_by_viewer: false,
|
||||
boosted_by_viewer: false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -137,7 +137,10 @@ impl SearchPort for PgSearchRepository {
|
||||
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
||||
|
||||
Ok(Paginated {
|
||||
items: rows.into_iter().map(row_to_entry).collect(),
|
||||
items: rows
|
||||
.into_iter()
|
||||
.map(row_to_entry)
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
total,
|
||||
page: page.page,
|
||||
per_page: page.per_page,
|
||||
|
||||
Reference in New Issue
Block a user