-
Notifications
You must be signed in to change notification settings - Fork 6
Dagim H. #6
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
Open
Unlock7
wants to merge
5
commits into
HackYourAssignment:main
Choose a base branch
from
Unlock7:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dagim H. #6
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62045ea
feat: create new PostgreSQL database
Unlock7 0ea1bb3
feat: return details JSONB in GET /products
Unlock7 baa6faf
feat: implement findByColor with JSONB filter
Unlock7 2df3235
feat: add SQL update to set product size to “M”
Unlock7 c783f69
feat: implement Task 3 — Backblaze upload + image_url DB updates
Unlock7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,4 @@ build/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
| .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/net/hackyourfuture/hyfshop/product/B2Config.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package net.hackyourfuture.hyfshop.product; | ||
|
|
||
| import java.net.URI; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
| import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
| import software.amazon.awssdk.regions.Region; | ||
| import software.amazon.awssdk.services.s3.S3Client; | ||
| import software.amazon.awssdk.services.s3.presigner.S3Presigner; | ||
|
|
||
|
|
||
| @Configuration | ||
| public class B2Config { | ||
|
|
||
| @Value("${b2.endpoint}") private String endpoint; | ||
| @Value("${b2.region}") private String region; | ||
| @Value("${b2.access-key}") private String accessKey; | ||
| @Value("${b2.secret-key}") private String secretKey; | ||
|
|
||
| @Bean | ||
| public S3Client s3Client() { | ||
| return S3Client.builder() | ||
| .credentialsProvider(StaticCredentialsProvider.create( | ||
| AwsBasicCredentials.create(accessKey, secretKey))) | ||
| .endpointOverride(URI.create(endpoint)) | ||
| .region(Region.of(region)) | ||
| .build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public S3Presigner s3Presigner() { | ||
| return S3Presigner.builder() | ||
| .credentialsProvider(StaticCredentialsProvider.create( | ||
| AwsBasicCredentials.create(accessKey, secretKey))) | ||
| .endpointOverride(URI.create(endpoint)) | ||
| .region(Region.of(region)) | ||
| .build(); | ||
| } | ||
| } | ||
4 changes: 4 additions & 0 deletions
4
src/main/java/net/hackyourfuture/hyfshop/product/FileService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package net.hackyourfuture.hyfshop.product; | ||
|
|
||
| public class FileService { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,14 @@ | |
| import org.springframework.stereotype.Service; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import java.io.File; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class ProductService { | ||
| private final ProductRepository productRepository; | ||
| private final FileService fileService; | ||
|
|
||
| public List<ProductResponse> getAllProducts() { | ||
| return productRepository.getAllProducts().stream().map(ProductResponse::from).toList(); | ||
|
|
@@ -26,14 +28,22 @@ public ProductResponse setProductSize(int id, String size) { | |
| } | ||
|
|
||
| public ProductResponse setProductImage(int id, MultipartFile file) { | ||
| // TODO: Implement | ||
| // call ProductRepository.setImageUrl() afterwards with the new URL | ||
| throw new UnsupportedOperationException("Not implemented yet"); | ||
| try { | ||
| String key = fileService.upload(file); | ||
| productRepository.setImageUrl(id, key); | ||
| return ProductResponse.from(productRepository.findById(id)); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to upload product image", e); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice to log the exception. |
||
| } | ||
| } | ||
|
|
||
| public ProductResponse deleteProductImage(int id) { | ||
| // TODO: Implement | ||
| // call ProductRepository.setImageUrl() to set the image url to null | ||
| throw new UnsupportedOperationException("Not implemented yet"); | ||
| Product product = productRepository.findById(id); | ||
| String key = product.getImageUrl(); | ||
| if (key != null) { | ||
| fileService.delete(key); | ||
| } | ||
| productRepository.setImageUrl(id, null); | ||
| return ProductResponse.from(productRepository.findById(id)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,20 @@ | ||
| spring: | ||
| application: | ||
| name: hyf_shop | ||
|
|
||
| datasource: | ||
| url: '${DB_URL}' | ||
| username: '${DB_USERNAME}' | ||
| password: '${DB_PASSWORD}' | ||
| url: ${DB_URL} | ||
| username: ${DB_USERNAME} | ||
| password: ${DB_PASSWORD} | ||
| driver-class-name: org.postgresql.Driver | ||
|
|
||
| b2: | ||
| endpoint: ${B2_ENDPOINT} | ||
| region: ${B2_REGION} | ||
| bucket: ${B2_BUCKET_NAME} | ||
| access-key: ${B2_ACCESS_KEY} | ||
| secret-key: ${B2_SECRET_KEY} | ||
| public-url: https://f003.backblazeb2.com/file/${B2_BUCKET_NAME} | ||
|
|
||
| server: | ||
| port: '8080' | ||
| port: 8080 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice that you use these values as config.