-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/s3integration #4
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
gurkvatten
wants to merge
12
commits into
main
Choose a base branch
from
feature/s3integration
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
41cfdc5
added s3config
gurkvatten 5a93214
added createbucket bean
gurkvatten 09b2030
s3 integration for report
gurkvatten 79b2c68
added pdf and file upload to s3
gurkvatten ebd8ed6
added so user can download reports
gurkvatten 1a52a25
renamed the bucket
gurkvatten 342d703
Merge branch 'main' into feature/s3integration
gurkvatten ca46689
update s3 syntax to aws v2
gurkvatten 92dc9aa
fixes after coderabbit comments
gurkvatten 388b85f
fixed HomeController after coderabbit comments
gurkvatten d1f5229
fixed ReportService after coderabbit comments
gurkvatten 65e45ce
added functionality so that when user uploads picture,pdf or word doc…
gurkvatten 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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/example/crimearchive/DTO/ReportResponse.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,9 @@ | ||
| package org.example.crimearchive.DTO; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record ReportResponse( | ||
| UUID uuid, | ||
| String name, | ||
| String event | ||
| ) {} |
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
64 changes: 64 additions & 0 deletions
64
src/main/java/org/example/crimearchive/config/S3Config.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,64 @@ | ||
| package org.example.crimearchive.config; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.ApplicationRunner; | ||
| 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.model.CreateBucketRequest; | ||
| import software.amazon.awssdk.services.s3.model.HeadBucketRequest; | ||
| import software.amazon.awssdk.services.s3.model.S3Exception; | ||
|
|
||
| import java.net.URI; | ||
|
|
||
| @Configuration | ||
| public class S3Config { | ||
|
|
||
| @Value("${minio.endpoint}") | ||
| private String endpoint; | ||
|
|
||
| @Value("${minio.access-key}") | ||
| private String accessKey; | ||
|
|
||
| @Value("${minio.secret-key}") | ||
| private String secretKey; | ||
|
|
||
| @Value("${minio.bucket}") | ||
| private String bucket; | ||
|
|
||
| @Bean | ||
| public S3Client s3Client() { | ||
| return S3Client.builder() | ||
| .endpointOverride(URI.create(endpoint)) | ||
| .credentialsProvider(StaticCredentialsProvider.create( | ||
| AwsBasicCredentials.create(accessKey, secretKey) | ||
| )) | ||
| .region(Region.US_EAST_1) | ||
| .forcePathStyle(true) | ||
| .build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public ApplicationRunner createBucket(S3Client s3Client) { | ||
| return args -> { | ||
| try { | ||
| s3Client.headBucket(HeadBucketRequest.builder() | ||
| .bucket(bucket) | ||
| .build()); | ||
| System.out.println("Bucket finns redan: " + bucket); | ||
| } catch (S3Exception e) { | ||
| if (e.statusCode() == 404) { | ||
| s3Client.createBucket(CreateBucketRequest.builder() | ||
| .bucket(bucket) | ||
| .build()); | ||
| System.out.println("Bucket skapad: " + bucket); | ||
| } else { | ||
| throw new RuntimeException("Fel vid kontroll av bucket: " + e.getMessage(), e); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.