forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #111 from kookmin-sw/backend/develop/v3
Backend/develop/v3
- Loading branch information
Showing
23 changed files
with
1,365 additions
and
119 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
34 changes: 34 additions & 0 deletions
34
backend/moment/moment-server/core/src/main/java/com/moment/core/config/S3Config.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,34 @@ | ||
package com.moment.core.config; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
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 S3Config { | ||
|
||
@Value("${cloud.aws.s3.credentials.access-key}") | ||
private String accessKey; | ||
|
||
@Value("${cloud.aws.s3.credentials.secret-key}") | ||
private String secretKey; | ||
|
||
@Value("${cloud.aws.s3.region.static}") | ||
private String region; | ||
|
||
@Bean | ||
public AmazonS3Client amazonS3Client() { | ||
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); | ||
|
||
return (AmazonS3Client) AmazonS3ClientBuilder | ||
.standard() | ||
.withRegion(region) | ||
.withCredentials(new AWSStaticCredentialsProvider(credentials)) | ||
.build(); | ||
} | ||
} |
42 changes: 39 additions & 3 deletions
42
...nd/moment/moment-server/core/src/main/java/com/moment/core/controller/RootController.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 |
---|---|---|
@@ -1,24 +1,60 @@ | ||
package com.moment.core.controller; | ||
|
||
import com.moment.core.service.S3Service; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
|
||
@RestController | ||
@AllArgsConstructor | ||
@Slf4j | ||
public class RootController { | ||
|
||
private final Environment env; | ||
private final S3Service s3Service; | ||
|
||
@GetMapping("/health-check") | ||
public ResponseEntity<String> healthCheck() { | ||
// 서버 아이디와 포트 출력 | ||
log.info("health-check called" ); | ||
return ResponseEntity.ok("I'm alive : " + env.getProperty("server.port")); | ||
} | ||
|
||
@PostMapping("/test/s3") | ||
public ResponseEntity<String> testS3( | ||
@RequestHeader Long userId, | ||
@RequestPart MultipartFile recordFile | ||
) { | ||
try { | ||
return ResponseEntity.ok(s3Service.uploadFile(recordFile, userId, LocalDateTime.now().toString(), true)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@PostMapping("/test/s3/folder") | ||
public ResponseEntity<String> testS3Folder( | ||
@RequestHeader Long userId, | ||
@RequestParam String folderName | ||
) { | ||
s3Service.createFolder(userId.toString()); | ||
return ResponseEntity.ok("test-s3-folder called"); | ||
} | ||
|
||
@DeleteMapping("/test/s3") | ||
public ResponseEntity<String> deleteS3( | ||
@RequestHeader Long userId, | ||
@RequestParam String fileName | ||
) { | ||
// fileName = "users/" + userId.toString() + "/" + fileName; | ||
fileName = "users/" + userId.toString(); | ||
s3Service.deleteFile(fileName); | ||
return ResponseEntity.ok("delete-s3 called"); | ||
} | ||
} |
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.