Skip to content

Commit

Permalink
Respond with filename, instead of key
Browse files Browse the repository at this point in the history
  • Loading branch information
evanjt committed Oct 29, 2024
1 parent 630eafe commit 663a238
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
20 changes: 20 additions & 0 deletions src/external/s3/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,23 @@ impl From<aws_sdk_s3::types::Object> for OutputObject {
}
}
}

#[derive(ToSchema, Serialize, FromQueryResult, Debug)]
pub struct OutputObjectResponse {
// Let's not show the full key path through the API
filename: String,
last_modified: DateTime<Utc>,
size_bytes: i64,
}

impl From<OutputObject> for OutputObjectResponse {
fn from(model: OutputObject) -> Self {
// Filename is the split of the key by the last '/'
let filename = model.key.split('/').last().unwrap().to_string();
Self {
last_modified: model.last_modified,
filename: filename,
size_bytes: model.size_bytes,
}
}
}
22 changes: 2 additions & 20 deletions src/submissions/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Submission {
created_on: NaiveDateTime,
last_updated: NaiveDateTime,
pub(super) associations: Option<Vec<crate::uploads::models::UploadRead>>,
outputs: Option<Vec<crate::external::s3::models::OutputObject>>,
outputs: Option<Vec<crate::external::s3::models::OutputObjectResponse>>,
}

impl From<super::db::Model> for Submission {
Expand Down Expand Up @@ -66,29 +66,11 @@ impl
.map(|association| association.into())
.collect(),
),
outputs: Some(outputs),
outputs: Some(outputs.into_iter().map(|output| output.into()).collect()),
}
}
}

// impl From<(super::db::Model, crate::uploads::associations::db::Model)> for Submission {
// fn from(model_tuple: (super::db::Model, crate::uploads::associations::db::Model)) -> Self {
// let submission = model_tuple.0;
// let upload_association = model_tuple.1;

// Self {
// id: submission.id,
// name: submission.name,
// processing_has_started: submission.processing_has_started,
// processing_success: submission.processing_success,
// comment: submission.comment,
// created_on: submission.created_on,
// last_updated: submission.last_updated,
// associations:
// }
// }
// }

#[derive(ToSchema, Deserialize, Serialize, DeriveIntoActiveModel)]
pub struct SubmissionCreate {
pub name: String,
Expand Down

0 comments on commit 663a238

Please sign in to comment.