From a2933dbebcb72d5739e27218b0727a65385fe9d0 Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 3 Sep 2023 17:11:34 -0500 Subject: [PATCH] Implement all the todos --- src/error.rs | 2 +- src/error_code.rs | 4 ++++ src/lib.rs | 18 +++++++++--------- src/repo.rs | 2 +- src/repo/postgres.rs | 10 +++++++++- src/repo/postgres/schema.rs | 1 + 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/error.rs b/src/error.rs index 38c481e..de2d9a3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -166,7 +166,7 @@ impl UploadError { Self::InvalidToken => ErrorCode::INVALID_DELETE_TOKEN, Self::UnsupportedProcessExtension => ErrorCode::INVALID_FILE_EXTENSION, Self::DuplicateAlias => ErrorCode::DUPLICATE_ALIAS, - Self::PushJob(_) => todo!(), + Self::PushJob(_) => ErrorCode::PUSH_JOB, Self::Range => ErrorCode::RANGE_NOT_SATISFIABLE, Self::Limit(_) => ErrorCode::VALIDATE_FILE_SIZE, Self::Timeout(_) => ErrorCode::STREAM_TOO_SLOW, diff --git a/src/error_code.rs b/src/error_code.rs index 365b261..0a940ad 100644 --- a/src/error_code.rs +++ b/src/error_code.rs @@ -56,12 +56,16 @@ impl ErrorCode { code: "already-claimed", }; pub(crate) const SLED_ERROR: ErrorCode = ErrorCode { code: "sled-error" }; + pub(crate) const POSTGRES_ERROR: ErrorCode = ErrorCode { + code: "postgres-error", + }; pub(crate) const EXTRACT_DETAILS: ErrorCode = ErrorCode { code: "extract-details", }; pub(crate) const EXTRACT_UPLOAD_RESULT: ErrorCode = ErrorCode { code: "extract-upload-result", }; + pub(crate) const PUSH_JOB: ErrorCode = ErrorCode { code: "push-job" }; pub(crate) const EXTRACT_JOB: ErrorCode = ErrorCode { code: "extract-job", }; diff --git a/src/lib.rs b/src/lib.rs index e6476c7..f55e7de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2038,16 +2038,14 @@ impl PictRsConfiguration { match repo { Repo::Sled(sled_repo) => { - launch_file_store( - Arc::new(sled_repo.clone()), - store, - client, - config, - move |sc| sled_extra_config(sc, sled_repo.clone()), - ) + launch_file_store(arc_repo, store, client, config, move |sc| { + sled_extra_config(sc, sled_repo.clone()) + }) .await?; } - Repo::Postgres(_) => todo!(), + Repo::Postgres(_) => { + launch_file_store(arc_repo, store, client, config, |_| {}).await?; + } } } config::Store::ObjectStorage(config::ObjectStorage { @@ -2101,7 +2099,9 @@ impl PictRsConfiguration { }) .await?; } - Repo::Postgres(_) => todo!(), + Repo::Postgres(_) => { + launch_object_store(arc_repo, store, client, config, |_| {}).await?; + } } } } diff --git a/src/repo.rs b/src/repo.rs index 6d3b2e3..a177745 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -877,7 +877,7 @@ impl Repo { pub(crate) fn to_arc(&self) -> ArcRepo { match self { Self::Sled(sled_repo) => Arc::new(sled_repo.clone()), - Self::Postgres(_) => todo!(), + Self::Postgres(postgres_repo) => Arc::new(postgres_repo.clone()), } } } diff --git a/src/repo/postgres.rs b/src/repo/postgres.rs index 61835d9..d03a7c5 100644 --- a/src/repo/postgres.rs +++ b/src/repo/postgres.rs @@ -120,7 +120,15 @@ pub(crate) enum PostgresError { impl PostgresError { pub(super) const fn error_code(&self) -> ErrorCode { - todo!() + match self { + Self::Pool(_) + | Self::Diesel(_) + | Self::SerializeDetails(_) + | Self::SerializeUploadResult(_) + | Self::Hex(_) => ErrorCode::POSTGRES_ERROR, + Self::DeserializeDetails(_) => ErrorCode::EXTRACT_DETAILS, + Self::DeserializeUploadResult(_) => ErrorCode::EXTRACT_UPLOAD_RESULT, + } } } diff --git a/src/repo/postgres/schema.rs b/src/repo/postgres/schema.rs index 80c5d4e..964937b 100644 --- a/src/repo/postgres/schema.rs +++ b/src/repo/postgres/schema.rs @@ -83,6 +83,7 @@ diesel::table! { uploads (id) { id -> Uuid, result -> Nullable, + created_at -> Timestamp, } }