Move DatabaseError to database module

This commit is contained in:
silverpill 2022-12-03 22:09:42 +00:00
parent 4185cbefb0
commit d1939b10d5
61 changed files with 157 additions and 126 deletions

View file

@ -3,7 +3,7 @@ use serde_json::Value;
use tokio_postgres::GenericClient;
use crate::config::Config;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::http_signatures::verify::{
parse_http_signature,
verify_http_signature,

View file

@ -10,7 +10,7 @@ use crate::activitypub::{
vocabulary::ANNOUNCE,
};
use crate::config::Instance;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::types::Post;
use crate::models::relationships::queries::get_followers;
use crate::models::users::types::User;

View file

@ -16,7 +16,7 @@ use crate::activitypub::{
vocabulary::{CREATE, DOCUMENT, HASHTAG, LINK, MENTION, NOTE},
};
use crate::config::Instance;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::frontend::get_tag_page_url;
use crate::models::posts::queries::get_post_author;
use crate::models::posts::types::{Post, Visibility};

View file

@ -6,7 +6,7 @@ use crate::activitypub::constants::AP_CONTEXT;
use crate::activitypub::deliverer::OutgoingActivity;
use crate::activitypub::vocabulary::{DELETE, NOTE, TOMBSTONE};
use crate::config::Instance;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::helpers::add_related_posts;
use crate::models::posts::types::Post;
use crate::models::users::types::User;

View file

@ -9,7 +9,7 @@ use crate::activitypub::{
vocabulary::DELETE,
};
use crate::config::Instance;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::relationships::queries::{get_followers, get_following};
use crate::models::users::types::User;

View file

@ -10,7 +10,7 @@ use crate::activitypub::{
vocabulary::LIKE,
};
use crate::config::Instance;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::types::{Post, Visibility};
use crate::models::profiles::types::DbActorProfile;
use crate::models::users::types::User;

View file

@ -9,7 +9,7 @@ use crate::activitypub::{
vocabulary::UNDO,
};
use crate::config::Instance;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::types::Post;
use crate::models::profiles::types::DbActorProfile;
use crate::models::users::types::User;

View file

@ -8,7 +8,7 @@ use crate::activitypub::{
vocabulary::UNDO,
};
use crate::config::Instance;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::types::{Post, Visibility};
use crate::models::profiles::types::DbActorProfile;
use crate::models::users::types::User;

View file

@ -11,7 +11,7 @@ use crate::activitypub::{
vocabulary::UPDATE,
};
use crate::config::Instance;
use crate::errors::{ConversionError, DatabaseError};
use crate::database::{DatabaseError, DatabaseTypeError};
use crate::models::relationships::queries::get_followers;
use crate::models::users::types::User;
use crate::utils::id::new_uuid;
@ -75,7 +75,7 @@ pub async fn prepare_update_person(
user: &User,
) -> Result<OutgoingActivity<UpdatePerson>, DatabaseError> {
let activity = build_update_person(&instance.url(), user, None)
.map_err(|_| ConversionError)?;
.map_err(|_| DatabaseTypeError)?;
let recipients = get_update_person_recipients(db_client, &user.id).await?;
Ok(OutgoingActivity {
instance: instance.clone(),
@ -95,9 +95,9 @@ pub async fn prepare_signed_update_person(
&instance.url(),
user,
Some(internal_activity_id),
).map_err(|_| ConversionError)?;
).map_err(|_| DatabaseTypeError)?;
let activity_value = serde_json::to_value(activity)
.map_err(|_| ConversionError)?;
.map_err(|_| DatabaseTypeError)?;
let recipients = get_update_person_recipients(db_client, &user.id).await?;
Ok(OutgoingActivity {
instance: instance.clone(),

View file

@ -14,7 +14,8 @@ use crate::activitypub::{
receiver::HandlerError,
};
use crate::config::{Config, Instance};
use crate::errors::{DatabaseError, ValidationError};
use crate::database::DatabaseError;
use crate::errors::ValidationError;
use crate::models::posts::helpers::get_local_post_by_id;
use crate::models::posts::queries::get_post_by_remote_object_id;
use crate::models::posts::types::Post;

View file

@ -8,7 +8,7 @@ use crate::activitypub::{
vocabulary::{CREATE, LIKE, NOTE, UNDO, UPDATE},
};
use crate::config::Config;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::queries::{
create_post,
get_post_by_remote_object_id,

View file

@ -19,7 +19,8 @@ use crate::activitypub::{
vocabulary::*,
};
use crate::config::Instance;
use crate::errors::{ConversionError, DatabaseError, ValidationError};
use crate::database::DatabaseError;
use crate::errors::{ConversionError, ValidationError};
use crate::models::attachments::queries::create_attachment;
use crate::models::posts::{
hashtags::normalize_hashtag,

View file

@ -6,7 +6,8 @@ use crate::activitypub::{
vocabulary::{NOTE, PERSON},
};
use crate::config::Config;
use crate::errors::{DatabaseError, ValidationError};
use crate::database::DatabaseError;
use crate::errors::ValidationError;
use crate::models::posts::queries::{
delete_post,
get_post_by_remote_object_id,

View file

@ -9,7 +9,7 @@ use crate::activitypub::{
vocabulary::PERSON,
};
use crate::config::Config;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::relationships::queries::follow;
use crate::models::users::queries::get_user_by_name;
use super::{HandlerError, HandlerResult};

View file

@ -8,7 +8,7 @@ use crate::activitypub::{
vocabulary::NOTE,
};
use crate::config::Config;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::reactions::queries::create_reaction;
use crate::models::posts::queries::get_post_by_remote_object_id;
use super::HandlerResult;

View file

@ -12,7 +12,8 @@ use crate::activitypub::{
vocabulary::PERSON,
};
use crate::config::Config;
use crate::errors::{DatabaseError, ValidationError};
use crate::database::DatabaseError;
use crate::errors::ValidationError;
use crate::models::{
notifications::queries::create_move_notification,
profiles::queries::search_profiles_by_did_only,

View file

@ -7,7 +7,8 @@ use crate::activitypub::{
vocabulary::PERSON,
};
use crate::config::Config;
use crate::errors::{DatabaseError, ValidationError};
use crate::database::DatabaseError;
use crate::errors::ValidationError;
use crate::models::notifications::queries::{
create_subscription_expiration_notification,
};

View file

@ -5,7 +5,8 @@ use crate::activitypub::{
receiver::find_object_id,
vocabulary::{ANNOUNCE, LIKE},
};
use crate::errors::{DatabaseError, ValidationError};
use crate::database::DatabaseError;
use crate::errors::ValidationError;
use crate::models::posts::queries::{
delete_post,
get_post_by_remote_object_id,

View file

@ -6,7 +6,8 @@ use crate::activitypub::{
vocabulary::FOLLOW,
};
use crate::config::Config;
use crate::errors::{DatabaseError, ValidationError};
use crate::database::DatabaseError;
use crate::errors::ValidationError;
use crate::models::profiles::queries::{
get_profile_by_acct,
get_profile_by_remote_actor_id,

View file

@ -3,7 +3,7 @@ use tokio_postgres::GenericClient;
use crate::activitypub::activity::Object;
use crate::activitypub::vocabulary::NOTE;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::queries::{
get_post_by_remote_object_id,
update_post,

View file

@ -4,9 +4,9 @@ use serde_json::Value;
use tokio_postgres::GenericClient;
use crate::config::Config;
use crate::database::DatabaseError;
use crate::errors::{
ConversionError,
DatabaseError,
HttpError,
ValidationError,
};

View file

@ -1,6 +1,5 @@
use tokio_postgres::config::{Config as DbConfig};
use tokio_postgres::error::{Error as PgError, SqlState};
use crate::errors::DatabaseError;
pub mod int_enum;
pub mod json_macro;
@ -12,6 +11,31 @@ pub mod test_utils;
pub type DbPool = deadpool_postgres::Pool;
#[derive(thiserror::Error, Debug)]
#[error("database type error")]
pub struct DatabaseTypeError;
#[derive(thiserror::Error, Debug)]
pub enum DatabaseError {
#[error("database pool error")]
DatabasePoolError(#[from] deadpool_postgres::PoolError),
#[error("database query error")]
DatabaseQueryError(#[from] postgres_query::Error),
#[error("database client error")]
DatabaseClientError(#[from] tokio_postgres::Error),
#[error(transparent)]
DatabaseTypeError(#[from] DatabaseTypeError),
#[error("{0} not found")]
NotFound(&'static str), // object type
#[error("{0} already exists")]
AlreadyExists(&'static str), // object type
}
pub async fn create_database_client(db_config: &DbConfig) -> tokio_postgres::Client {
let (client, connection) = db_config.connect(tokio_postgres::NoTls)
.await.unwrap();

View file

@ -5,6 +5,8 @@ use actix_web::{
};
use serde::Serialize;
use crate::database::DatabaseError;
#[derive(thiserror::Error, Debug)]
#[error("conversion error")]
pub struct ConversionError;
@ -13,27 +15,6 @@ pub struct ConversionError;
#[error("{0}")]
pub struct ValidationError(pub &'static str);
#[derive(thiserror::Error, Debug)]
pub enum DatabaseError {
#[error("database pool error")]
DatabasePoolError(#[from] deadpool_postgres::PoolError),
#[error("database query error")]
DatabaseQueryError(#[from] postgres_query::Error),
#[error("database client error")]
DatabaseClientError(#[from] tokio_postgres::Error),
#[error("database type error")]
DatabaseTypeError(#[from] ConversionError),
#[error("{0} not found")]
NotFound(&'static str), // object type
#[error("{0} already exists")]
AlreadyExists(&'static str), // object type
}
#[derive(thiserror::Error, Debug)]
pub enum HttpError {
#[error(transparent)]

View file

@ -1,4 +1,4 @@
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use super::contracts::ArtifactError;
use super::signatures::SignatureError;
use super::utils::AddressError;

View file

@ -12,8 +12,7 @@ use web3::{
};
use crate::config::EthereumConfig;
use crate::database::{get_database_client, DbPool};
use crate::errors::DatabaseError;
use crate::database::{get_database_client, DatabaseError, DbPool};
use crate::ipfs::utils::parse_ipfs_url;
use crate::models::posts::queries::{
get_post_by_ipfs_cid,

View file

@ -17,8 +17,8 @@ use crate::activitypub::builders::{
};
use crate::activitypub::identifiers::LocalActorCollection;
use crate::config::{EthereumConfig, Instance};
use crate::database::{get_database_client, DbPool};
use crate::errors::{ConversionError, DatabaseError};
use crate::database::{get_database_client, DatabaseError, DbPool};
use crate::errors::ConversionError;
use crate::models::notifications::queries::{
create_subscription_notification,
create_subscription_expiration_notification,

View file

@ -1,7 +1,7 @@
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::relationships::queries::get_relationships;
use crate::models::relationships::types::RelationshipType;
use super::types::RelationshipMap;

View file

@ -22,8 +22,8 @@ use crate::activitypub::builders::{
},
};
use crate::config::Config;
use crate::database::{get_database_client, DbPool};
use crate::errors::{DatabaseError, HttpError, ValidationError};
use crate::database::{get_database_client, DatabaseError, DbPool};
use crate::errors::{HttpError, ValidationError};
use crate::ethereum::contracts::ContractSet;
use crate::ethereum::eip4361::verify_eip4361_signature;
use crate::ethereum::gate::is_allowed_user;

View file

@ -7,7 +7,8 @@ use actix_web::{
use serde_json::json;
use tokio_postgres::GenericClient;
use crate::errors::{DatabaseError, HttpError};
use crate::database::DatabaseError;
use crate::errors::HttpError;
use crate::models::oauth::queries::get_user_by_oauth_token;
use crate::models::users::types::User;

View file

@ -3,8 +3,8 @@ use actix_web_httpauth::extractors::bearer::BearerAuth;
use chrono::{Duration, Utc};
use crate::config::Config;
use crate::database::{get_database_client, DbPool};
use crate::errors::{DatabaseError, HttpError, ValidationError};
use crate::database::{get_database_client, DatabaseError, DbPool};
use crate::errors::{HttpError, ValidationError};
use crate::ethereum::eip4361::verify_eip4361_signature;
use crate::models::oauth::queries::{
delete_oauth_token,

View file

@ -14,7 +14,8 @@ use crate::activitypub::{
identifiers::{parse_local_actor_id, parse_local_object_id},
};
use crate::config::Config;
use crate::errors::{DatabaseError, HttpError, ValidationError};
use crate::database::DatabaseError;
use crate::errors::{HttpError, ValidationError};
use crate::identity::did::Did;
use crate::mastodon_api::accounts::types::Account;
use crate::mastodon_api::statuses::helpers::build_status_list;

View file

@ -1,7 +1,7 @@
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::profiles::types::DbActorProfile;
use crate::models::relationships::queries::{get_followers, get_following};

View file

@ -1,6 +1,6 @@
use tokio_postgres::GenericClient;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::helpers::{
add_user_actions,
add_related_posts,

View file

@ -14,8 +14,8 @@ use crate::activitypub::builders::{
undo_like_note::prepare_undo_like_note,
};
use crate::config::Config;
use crate::database::{get_database_client, DbPool};
use crate::errors::{DatabaseError, HttpError, ValidationError};
use crate::database::{get_database_client, DatabaseError, DbPool};
use crate::errors::{HttpError, ValidationError};
use crate::ethereum::nft::create_mint_signature;
use crate::ipfs::store as ipfs_store;
use crate::ipfs::posts::PostMetadata;

View file

@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::cleanup::{
find_orphaned_files,
find_orphaned_ipfs_objects,

View file

@ -1,7 +1,7 @@
use tokio_postgres::GenericClient;
use crate::config::Config;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::ipfs::store as ipfs_store;
use crate::utils::files::remove_files;

View file

@ -1,6 +1,6 @@
use tokio_postgres::GenericClient;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
pub async fn create_instance(
db_client: &impl GenericClient,

View file

@ -1,8 +1,7 @@
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::database::catch_unique_violation;
use crate::errors::DatabaseError;
use crate::database::{catch_unique_violation, DatabaseError};
use crate::utils::caip2::ChainId;
use crate::utils::id::new_uuid;
use super::types::{DbInvoice, InvoiceStatus};

View file

@ -4,8 +4,10 @@ use chrono::{DateTime, Utc};
use postgres_types::FromSql;
use uuid::Uuid;
use crate::database::int_enum::{int_enum_from_sql, int_enum_to_sql};
use crate::errors::ConversionError;
use crate::database::{
int_enum::{int_enum_from_sql, int_enum_to_sql},
DatabaseTypeError,
};
use crate::utils::caip2::ChainId;
#[derive(Debug, PartialEq)]
@ -28,7 +30,7 @@ impl From<&InvoiceStatus> for i16 {
}
impl TryFrom<i16> for InvoiceStatus {
type Error = ConversionError;
type Error = DatabaseTypeError;
fn try_from(value: i16) -> Result<Self, Self::Error> {
let invoice_status = match value {
@ -36,7 +38,7 @@ impl TryFrom<i16> for InvoiceStatus {
2 => Self::Paid,
3 => Self::Forwarded,
4 => Self::Timeout,
_ => return Err(ConversionError),
_ => return Err(DatabaseTypeError),
};
Ok(invoice_status)
}

View file

@ -1,7 +1,7 @@
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use super::types::{DbTimelineMarker, Timeline};
pub async fn create_or_update_marker(

View file

@ -4,8 +4,10 @@ use chrono::{DateTime, Utc};
use postgres_types::FromSql;
use uuid::Uuid;
use crate::database::int_enum::{int_enum_from_sql, int_enum_to_sql};
use crate::errors::ConversionError;
use crate::database::{
int_enum::{int_enum_from_sql, int_enum_to_sql},
DatabaseTypeError,
};
#[derive(Debug)]
pub enum Timeline {
@ -23,13 +25,13 @@ impl From<&Timeline> for i16 {
}
impl TryFrom<i16> for Timeline {
type Error = ConversionError;
type Error = DatabaseTypeError;
fn try_from(value: i16) -> Result<Self, Self::Error> {
let timeline = match value {
1 => Self::Home,
2 => Self::Notifications,
_ => return Err(ConversionError),
_ => return Err(DatabaseTypeError),
};
Ok(timeline)
}

View file

@ -3,7 +3,7 @@ use std::convert::TryFrom;
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::helpers::{add_related_posts, add_user_actions};
use crate::models::posts::queries::{
RELATED_ATTACHMENTS,

View file

@ -5,8 +5,11 @@ use postgres_types::FromSql;
use tokio_postgres::Row;
use uuid::Uuid;
use crate::database::int_enum::{int_enum_from_sql, int_enum_to_sql};
use crate::errors::{ConversionError, DatabaseError};
use crate::database::{
int_enum::{int_enum_from_sql, int_enum_to_sql},
DatabaseError,
DatabaseTypeError,
};
use crate::models::attachments::types::DbMediaAttachment;
use crate::models::posts::types::{DbPost, Post};
use crate::models::profiles::types::DbActorProfile;
@ -43,7 +46,7 @@ impl From<&EventType> for i16 {
}
impl TryFrom<i16> for EventType {
type Error = ConversionError;
type Error = DatabaseTypeError;
fn try_from(value: i16) -> Result<Self, Self::Error> {
let event_type = match value {
@ -57,7 +60,7 @@ impl TryFrom<i16> for EventType {
8 => Self::SubscriptionStart,
9 => Self::SubscriptionExpiration,
10 => Self::Move,
_ => return Err(ConversionError),
_ => return Err(DatabaseTypeError),
};
Ok(event_type)
}

View file

@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::profiles::types::DbActorProfile;
use crate::models::users::types::{DbUser, User};

View file

@ -2,7 +2,7 @@ use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::activitypub::identifiers::parse_local_object_id;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::reactions::queries::find_favourited_by_user;
use crate::models::relationships::queries::has_relationship;
use crate::models::relationships::types::RelationshipType;

View file

@ -3,7 +3,7 @@ use std::collections::HashMap;
use regex::{Captures, Regex};
use tokio_postgres::GenericClient;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use super::helpers::get_post_by_object_id;
use super::types::Post;

View file

@ -4,7 +4,8 @@ use regex::{Captures, Regex};
use tokio_postgres::GenericClient;
use crate::activitypub::actors::types::ActorAddress;
use crate::errors::{DatabaseError, ValidationError};
use crate::database::DatabaseError;
use crate::errors::ValidationError;
use crate::models::profiles::queries::get_profiles_by_accts;
use crate::models::profiles::types::DbActorProfile;

View file

@ -4,9 +4,11 @@ use chrono::{DateTime, Utc};
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::database::catch_unique_violation;
use crate::database::query_macro::query;
use crate::errors::DatabaseError;
use crate::database::{
catch_unique_violation,
query_macro::query,
DatabaseError,
};
use crate::models::attachments::queries::set_attachment_ipfs_cid;
use crate::models::attachments::types::DbMediaAttachment;
use crate::models::cleanup::{

View file

@ -6,8 +6,12 @@ use tokio_postgres::Row;
use uuid::Uuid;
use crate::activitypub::identifiers::local_object_id;
use crate::database::int_enum::{int_enum_from_sql, int_enum_to_sql};
use crate::errors::{ConversionError, DatabaseError, ValidationError};
use crate::database::{
int_enum::{int_enum_from_sql, int_enum_to_sql},
DatabaseError,
DatabaseTypeError,
};
use crate::errors::ValidationError;
use crate::models::attachments::types::DbMediaAttachment;
use crate::models::profiles::types::DbActorProfile;
use super::validators::clean_content;
@ -36,7 +40,7 @@ impl From<&Visibility> for i16 {
}
impl TryFrom<i16> for Visibility {
type Error = ConversionError;
type Error = DatabaseTypeError;
fn try_from(value: i16) -> Result<Self, Self::Error> {
let visibility = match value {
@ -44,7 +48,7 @@ impl TryFrom<i16> for Visibility {
2 => Self::Direct,
3 => Self::Followers,
4 => Self::Subscribers,
_ => return Err(ConversionError),
_ => return Err(DatabaseTypeError),
};
Ok(visibility)
}
@ -118,13 +122,13 @@ impl Post {
db_mentions: Vec<DbActorProfile>,
db_tags: Vec<String>,
db_links: Vec<Uuid>,
) -> Result<Self, ConversionError> {
) -> Result<Self, DatabaseTypeError> {
// Consistency checks
if db_post.author_id != db_author.id {
return Err(ConversionError);
return Err(DatabaseTypeError);
};
if db_author.is_local() != db_post.object_id.is_none() {
return Err(ConversionError);
return Err(DatabaseTypeError);
};
if db_post.repost_of_id.is_some() && (
db_post.content.len() != 0 ||
@ -137,7 +141,7 @@ impl Post {
!db_tags.is_empty() ||
!db_links.is_empty()
) {
return Err(ConversionError);
return Err(DatabaseTypeError);
};
let post = Self {
id: db_post.id,

View file

@ -2,9 +2,11 @@ use chrono::{DateTime, Utc};
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::database::catch_unique_violation;
use crate::database::query_macro::query;
use crate::errors::DatabaseError;
use crate::database::{
catch_unique_violation,
query_macro::query,
DatabaseError,
};
use crate::identity::{did::Did, did_pkh::DidPkh};
use crate::models::cleanup::{
find_orphaned_files,

View file

@ -14,7 +14,10 @@ use uuid::Uuid;
use crate::activitypub::actors::types::{Actor, ActorAddress};
use crate::activitypub::identifiers::local_actor_id;
use crate::database::json_macro::{json_from_sql, json_to_sql};
use crate::database::{
json_macro::{json_from_sql, json_to_sql},
DatabaseTypeError,
};
use crate::errors::{ConversionError, ValidationError};
use crate::identity::{
did::Did,
@ -124,14 +127,14 @@ impl From<&PaymentType> for i16 {
}
impl TryFrom<i16> for PaymentType {
type Error = ConversionError;
type Error = DatabaseTypeError;
fn try_from(value: i16) -> Result<Self, Self::Error> {
let payment_type = match value {
1 => Self::Link,
2 => Self::EthereumSubscription,
3 => Self::MoneroSubscription,
_ => return Err(ConversionError),
_ => return Err(DatabaseTypeError),
};
Ok(payment_type)
}

View file

@ -1,8 +1,7 @@
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::database::catch_unique_violation;
use crate::errors::DatabaseError;
use crate::database::{catch_unique_violation, DatabaseError};
use crate::models::notifications::queries::create_reaction_notification;
use crate::models::posts::queries::{
update_reaction_count,

View file

@ -3,8 +3,7 @@ use std::convert::TryFrom;
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::database::catch_unique_violation;
use crate::errors::DatabaseError;
use crate::database::{catch_unique_violation, DatabaseError};
use crate::models::notifications::queries::create_follow_notification;
use crate::models::profiles::queries::{
update_follower_count,
@ -506,8 +505,10 @@ pub async fn show_replies(
mod tests {
use serial_test::serial;
use crate::activitypub::actors::types::Actor;
use crate::database::test_utils::create_test_database;
use crate::errors::DatabaseError;
use crate::database::{
test_utils::create_test_database,
DatabaseError,
};
use crate::models::profiles::queries::create_profile;
use crate::models::profiles::types::ProfileCreateData;
use crate::models::users::queries::create_user;

View file

@ -4,8 +4,11 @@ use postgres_types::FromSql;
use tokio_postgres::Row;
use uuid::Uuid;
use crate::database::int_enum::{int_enum_from_sql, int_enum_to_sql};
use crate::errors::{ConversionError, DatabaseError};
use crate::database::{
int_enum::{int_enum_from_sql, int_enum_to_sql},
DatabaseError,
DatabaseTypeError,
};
use crate::models::profiles::types::DbActorProfile;
#[derive(Debug)]
@ -30,7 +33,7 @@ impl From<&RelationshipType> for i16 {
}
impl TryFrom<i16> for RelationshipType {
type Error = ConversionError;
type Error = DatabaseTypeError;
fn try_from(value: i16) -> Result<Self, Self::Error> {
let relationship_type = match value {
@ -39,7 +42,7 @@ impl TryFrom<i16> for RelationshipType {
3 => Self::Subscription,
4 => Self::HideReposts,
5 => Self::HideReplies,
_ => return Err(ConversionError),
_ => return Err(DatabaseTypeError),
};
Ok(relationship_type)
}
@ -59,13 +62,13 @@ impl DbRelationship {
&self,
source_id: &Uuid,
target_id: &Uuid,
) -> Result<bool, ConversionError> {
) -> Result<bool, DatabaseTypeError> {
if &self.source_id == source_id && &self.target_id == target_id {
Ok(true)
} else if &self.source_id == target_id && &self.target_id == source_id {
Ok(false)
} else {
Err(ConversionError)
Err(DatabaseTypeError)
}
}
}
@ -102,14 +105,14 @@ impl From<&FollowRequestStatus> for i16 {
}
impl TryFrom<i16> for FollowRequestStatus {
type Error = ConversionError;
type Error = DatabaseTypeError;
fn try_from(value: i16) -> Result<Self, Self::Error> {
let status = match value {
1 => Self::Pending,
2 => Self::Accepted,
3 => Self::Rejected,
_ => return Err(ConversionError),
_ => return Err(DatabaseTypeError),
};
Ok(status)
}

View file

@ -4,8 +4,7 @@ use chrono::{DateTime, Utc};
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::database::catch_unique_violation;
use crate::errors::DatabaseError;
use crate::database::{catch_unique_violation, DatabaseError};
use crate::models::profiles::types::PaymentType;
use crate::models::relationships::queries::{subscribe, subscribe_opt};
use crate::models::relationships::types::RelationshipType;

View file

@ -5,7 +5,7 @@ use postgres_types::FromSql;
use tokio_postgres::Row;
use uuid::Uuid;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::profiles::types::DbActorProfile;
use crate::utils::caip2::ChainId;

View file

@ -1,6 +1,6 @@
use tokio_postgres::GenericClient;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
pub async fn search_tags(
db_client: &impl GenericClient,

View file

@ -1,8 +1,7 @@
use tokio_postgres::GenericClient;
use uuid::Uuid;
use crate::database::catch_unique_violation;
use crate::errors::DatabaseError;
use crate::database::{catch_unique_violation, DatabaseError};
use crate::identity::{did::Did, did_pkh::DidPkh};
use crate::models::profiles::queries::create_profile;
use crate::models::profiles::types::{DbActorProfile, ProfileCreateData};

View file

@ -6,8 +6,7 @@ use monero_rpc::TransferType;
use monero_rpc::monero::{Address, Amount};
use crate::config::{Instance, MoneroConfig};
use crate::database::{get_database_client, DbPool};
use crate::errors::DatabaseError;
use crate::database::{get_database_client, DatabaseError, DbPool};
use crate::ethereum::subscriptions::send_subscription_notifications;
use crate::models::{
invoices::queries::{

View file

@ -14,7 +14,7 @@ use monero_rpc::monero::{
};
use crate::config::MoneroConfig;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
pub const DEFAULT_ACCOUNT: u32 = 0;

View file

@ -1,6 +1,6 @@
use tokio_postgres::GenericClient;
use crate::errors::DatabaseError;
use crate::database::DatabaseError;
use crate::models::posts::queries::get_local_post_count;
use crate::models::users::queries::get_user_count;
use super::types::{Usage, Users};