Skip to content

Commit

Permalink
feat: updated bl to follow ownership change
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbchron committed Feb 19, 2024
1 parent 9c43238 commit b3a4608
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions crates/bl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use core_types::{
PrivateArtifact, PublicArtifact,
};
use serde::{Deserialize, Serialize};
use surrealdb::opt::PatchOp;
use tracing::instrument;

#[derive(Clone, Debug, Deserialize, Serialize, thiserror::Error)]
Expand Down Expand Up @@ -79,10 +80,10 @@ pub async fn upload_single_photo(

// create a photo and upload it to surreal
let photo = Photo {
id: core_types::PhotoRecordId(ulid::Ulid::new()),
photographer: user_id,
owner: user_id,
artifacts: PhotoArtifacts {
id: core_types::PhotoRecordId(ulid::Ulid::new()),
// this is set to nil because we don't have a group yet
group: core_types::PhotoGroupRecordId(ulid::Ulid::nil()),
artifacts: PhotoArtifacts {
original: core_types::PrivateImageArtifact {
artifact_id: original_artifact.id,
size: (original_image.width(), original_image.height()),
Expand Down Expand Up @@ -119,10 +120,11 @@ pub async fn upload_single_photo(

// create a photo group and upload it to surreal
let group = PhotoGroup {
id: core_types::PhotoGroupRecordId(ulid::Ulid::new()),
owner: user_id,
photos: vec![photo.id],
public: group_meta.public,
id: core_types::PhotoGroupRecordId(ulid::Ulid::new()),
owner: user_id,
photographer: user_id,
photos: vec![photo.id],
public: group_meta.public,
};

let group: Vec<PhotoGroup> = client
Expand All @@ -141,6 +143,17 @@ pub async fn upload_single_photo(
)
})?;

// update the photo with the group id
let _photo: Option<Photo> = client
.update(photo.id)
.patch(PatchOp::replace("/group", group.id))
.await
.map_err(|e| {
PhotoUploadError::DBError(format!(
"Failed to update photo with group id in surreal: {e}"
))
})?;

Ok(group.clone())
}

Expand Down

0 comments on commit b3a4608

Please sign in to comment.