From 1cfe059b5c30fabf4d13bd904ec150c8f1262537 Mon Sep 17 00:00:00 2001 From: Franklin Date: Sun, 23 Apr 2023 09:12:11 -0400 Subject: [PATCH] Added image upload logic --- src/services/admin.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/services/admin.rs b/src/services/admin.rs index 1262fac..8279c16 100644 --- a/src/services/admin.rs +++ b/src/services/admin.rs @@ -1,4 +1,5 @@ use actix_web_utils::extensions::typed_response::TypedHttpResponse; +use err::MessageResource; use jl_types::{ domain::{ agent::Agent, contact::Contact, count::Count, location::Location, project::Project, @@ -15,7 +16,7 @@ use jl_types::{ use sqlx::PgPool; use uuid::Uuid; -use crate::{dao, handle_db_read_op, handle_db_write_op, handle_tx, success, unwrap_or_not_found, utils::s3::{Item}}; +use crate::{dao, handle_db_read_op, handle_db_write_op, handle_tx, success, unwrap_or_not_found, utils::s3::{Item, self}}; // // Insert Methods @@ -196,7 +197,9 @@ pub async fn get_contact_count(conn: &PgPool) -> TypedHttpResponse { success!(count) } -pub async fn upload_image(_client: &aws_sdk_s3::Client, _item: Item, _id: Uuid, _file_name: String) -> TypedHttpResponse { - - success!(String::new()) +pub async fn upload_image(client: &aws_sdk_s3::Client, item: Item, id: Uuid, file_name: String) -> TypedHttpResponse { + match s3::upload_image(client, id, item, file_name).await { + Ok(url) => success!(url), + Err(error) => return TypedHttpResponse::return_standard_error(400, MessageResource::new_from_string(error.to_string())), + }; } \ No newline at end of file