Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/image service #3

Merged
merged 39 commits into from
Jan 4, 2024
Merged

Feature/image service #3

merged 39 commits into from
Jan 4, 2024

Conversation

bookpanda
Copy link
Contributor

@bookpanda bookpanda commented Jan 1, 2024

  • Add build package workflow
  • imageService: FindByPetId, Upload, AssignPet, Delete

Business Logic

image.FindByPetId(): finds images of that pet

image.Upload(): uploads to S3 and create a row with url of that S3 (empty foreign key)
If upload has field petId, then it create the row with petId (have foreign key)

image.AssignPet(): assigns row with specified url with that pet id (add foreign key)

image.Delete(): deletes row and object in S3

When creating pet

For image upload, keep the url from response, imageService.Upload(file) returns Image

For pet create, attach images’ urls into the POST request, petService.Create(pet + urls) ==calls==> imageService.AssignPet(urls, petId)

If delete image, imageService.Delete(id)

When updating pet

If delete image -> imageService.Delete(id) (image id got from petService.FindOne() fetched by client)

If upload image -> imageSrv.Upload(petId)

How to connect S3 bucket

make an AWS account, make an S3 bucket in ap-southeast-1 region, name it anything and paste the name in config.yaml, make sure S3 bucket has public policy

Tests

(FindPetById, AssignPet needs to wait for johnjud-backend)

Upload

Screenshot 2567-01-02 at 01 56 21
Screenshot 2567-01-02 at 01 56 41

Delete

Screenshot 2567-01-02 at 01 58 12

Screenshot 2567-01-02 at 01 58 01 Screenshot 2567-01-02 at 01 58 37

file's URL works

@bookpanda bookpanda requested a review from Nitiwat-owen January 1, 2024 18:59
Copy link
Member

@Nitiwat-owen Nitiwat-owen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, sorry for late notice. One question, don't we need any access key or secret key in order to manage our S3 bucket?

client/bucket/bucket.client.go Outdated Show resolved Hide resolved
internal/service/image/image.service.go Outdated Show resolved Hide resolved
internal/service/image/image.service.go Outdated Show resolved Hide resolved
internal/service/image/image.service.go Outdated Show resolved Hide resolved
@bookpanda
Copy link
Contributor Author

Hello, sorry for late notice. One question, don't we need any access key or secret key in order to manage our S3 bucket?

it's in ~/. aws/credentials of the local machine. The AWS SDK uses the key from that directory, no need to specify.
We will only use AWS as test, The prod bucket will not be AWS from what I've heard

@Nitiwat-owen
Copy link
Member

If the prod bucket is not AWS, so we need to change our codes in the future right?

@bookpanda
Copy link
Contributor Author

yes, but Tar said it is AWS-compatible, so I hope the code would stay the same.

@bookpanda bookpanda requested a review from Nitiwat-owen January 3, 2024 17:05
@bookpanda bookpanda merged commit 56600e8 into dev Jan 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants