-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #508 from COS301-SE-2023/backend/improvements
Backend/improvements
- Loading branch information
Showing
117 changed files
with
1,433 additions
and
916 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
26 changes: 26 additions & 0 deletions
26
...end/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/StorageConfig.java
This file contains 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,26 @@ | ||
package com.fragile.infosafe.primary.config; | ||
|
||
import com.amazonaws.auth.AWSCredentials; | ||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class StorageConfig { | ||
|
||
@Value("${AWS_ACCESS_KEY_ID}") | ||
private String accessKey; | ||
|
||
@Value("${AWS_SECRET_ACCESS_KEY}") | ||
private String secretKey; | ||
|
||
@Bean | ||
public AmazonS3 generateS3Client(){ | ||
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); | ||
return AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion("us-east-1").build(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...safe_backend/src/main/java/com/fragile/infosafe/primary/controller/StorageController.java
This file contains 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,40 @@ | ||
package com.fragile.infosafe.primary.controller; | ||
|
||
import com.fragile.infosafe.primary.service.StorageService; | ||
import com.sun.mail.iap.ByteArray; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.io.ByteArrayResource; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
@Slf4j | ||
@RequestMapping("api/storage") | ||
public class StorageController { | ||
|
||
private StorageService service; | ||
|
||
@PostMapping("/upload") | ||
public ResponseEntity<String> uploadFile(@RequestParam(value = "file") MultipartFile file){ | ||
return new ResponseEntity<>(service.uploadFile(file), HttpStatus.OK); | ||
} | ||
|
||
@GetMapping("/download/{fileName}") | ||
public ResponseEntity<ByteArrayResource> downloadFile(@PathVariable String fileName){ | ||
byte[] data = service.dowloadFile(fileName); | ||
ByteArrayResource resource = new ByteArrayResource(data); | ||
return ResponseEntity | ||
.ok() | ||
.contentLength(data.length) | ||
.header("Content-type", "application/octet-stream") | ||
.header("Content-disposition", "attachment; filename=\"" + fileName + "\"") | ||
.body(resource); | ||
} | ||
|
||
@DeleteMapping("/delete/{fileName}") | ||
public ResponseEntity<String> deleteFile(@PathVariable String fileName){ | ||
return new ResponseEntity<>(service.deleteFile(fileName), HttpStatus.OK); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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.