Skip to content

Instantly share code, notes, and snippets.

@MakotoE
Last active March 10, 2022 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MakotoE/139bc03e9efaa70ca2bf32f3d3eff302 to your computer and use it in GitHub Desktop.
Save MakotoE/139bc03e9efaa70ca2bf32f3d3eff302 to your computer and use it in GitHub Desktop.
Architectural design and photo gallery implementation notes

Architectural design (2 min)

  • Architecture diagram
  • All services are up and running
  • Google services were added: Google Maps Embed API and Google Identity Services
    • Embeded Google Map on vendor page
    • Sign-in with Google feature

Photo gallery implementation (4 min)

Creating a review and photo

  • Review-photo diagram
  1. The server creates temporary credentials for S3 with write permissions and forwards them to the client
// In the server
params := &sts.AssumeRoleInput{
  RoleArn:         aws.String("arn:aws:iam::00000000:role/SFLPhotoUpload"),
  RoleSessionName: aws.String("streetfoodlove"),
  DurationSeconds: aws.Int32(900),
}

response, err := a.client.AssumeRole(ctx, params)
  1. The client uses the temporary credentials to create a S3 object from the image file
const photoID = uuid(); // Generate a random ID
await uploadToS3(s3Credentials, photoID, file);
  1. Review is created
const review = {
  ID: uuid(),
  Text: text,
  DatePosted: DateTime.now(),
  VendorID: vendorID,
  UserID: userID,
  StarRating: starRating,
  ReplyTo: null,
  VendorFavorite: false,
};
await submitReview(review);
  1. Photo is created
const photo: Photo = {
  ID: photoID,                // Photo ID is the same as the S3 object name
  DatePosted: DateTime.now(),
  LinkID: review.ID,          // LinkID references the review
};
await createPhoto(photo);

Retrieving a review and its photo

  1. Get the Review
SELECT * FROM Review WHERE ID=?
  1. Get the Photos associated with the review. Review and photo is a one-to-many relationship
SELECT * FROM Photo WHERE ReviewID=?
  1. Get the image file associated with the photo, using the photo ID
<img src="https://bucket.s3.us-west-2.amazonaws.com/<Photo ID>" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment