-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f8011d
commit 5a59dcd
Showing
17 changed files
with
191 additions
and
23 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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/ohayo/moyamoya/api/upload/UploadApi.kt
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,16 @@ | ||
package com.ohayo.moyamoya.api.upload | ||
|
||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
import org.springframework.web.multipart.MultipartFile | ||
|
||
@RestController | ||
@RequestMapping("upload") | ||
class UploadApi( | ||
private val uploadService: UploadService | ||
) { | ||
@PostMapping | ||
fun uploadFile(@RequestParam("file") file: MultipartFile) = uploadService.uploadFile(file) | ||
} |
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,5 @@ | ||
package com.ohayo.moyamoya.api.upload | ||
|
||
data class UploadRes( | ||
val url: String | ||
) |
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/com/ohayo/moyamoya/api/upload/UploadService.kt
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.ohayo.moyamoya.api.upload | ||
|
||
import com.amazonaws.services.s3.AmazonS3 | ||
import com.amazonaws.services.s3.model.ObjectMetadata | ||
import com.amazonaws.services.s3.model.PutObjectRequest | ||
import com.ohayo.moyamoya.global.CustomException | ||
import com.ohayo.moyamoya.infra.s3.S3Properties | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.stereotype.Service | ||
import org.springframework.web.multipart.MultipartFile | ||
import java.util.UUID | ||
|
||
@Service | ||
class UploadService( | ||
private val amazonS3: AmazonS3, | ||
private val s3Properties: S3Properties | ||
) { | ||
fun uploadFile(file: MultipartFile): UploadRes { | ||
if (file.isEmpty || file.equals("") || file.originalFilename == null) { | ||
throw CustomException(HttpStatus.BAD_REQUEST, "올바르지 않은 파일") | ||
} | ||
|
||
val fileName = "uploads/" + UUID.randomUUID().toString().substring(0, 10) + file.originalFilename!! | ||
|
||
try { | ||
amazonS3.putObject( | ||
PutObjectRequest(s3Properties.s3bucket, fileName, file.inputStream, ObjectMetadata().apply { | ||
contentType = file.contentType | ||
contentLength = file.size | ||
}) | ||
) | ||
|
||
return UploadRes( | ||
url = amazonS3.getUrl(s3Properties.s3bucket, fileName).toString() | ||
) | ||
} catch (e: Exception) { | ||
throw CustomException(HttpStatus.INTERNAL_SERVER_ERROR, "s3 업로드 실패") | ||
} | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/ohayo/moyamoya/api/user/value/SendCodeReq.kt
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,8 @@ | ||
package com.ohayo.moyamoya.api.user.value | ||
|
||
import jakarta.validation.constraints.NotNull | ||
|
||
data class SendCodeReq( | ||
@field:NotNull | ||
val phone: String, | ||
) |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/ohayo/moyamoya/api/user/value/VerifyCodeReq.kt
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,11 @@ | ||
package com.ohayo.moyamoya.api.user.value | ||
|
||
import jakarta.validation.constraints.NotNull | ||
|
||
data class VerifyCodeReq( | ||
@field:NotNull | ||
val phone: String, | ||
|
||
@field:NotNull | ||
val code: String | ||
) |
2 changes: 1 addition & 1 deletion
2
...m/ohayo/moyamoya/global/FirebaseConfig.kt → .../moyamoya/global/config/FirebaseConfig.kt
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
2 changes: 1 addition & 1 deletion
2
...com/ohayo/moyamoya/global/GlobalConfig.kt → ...yo/moyamoya/global/config/GlobalConfig.kt
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
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/ohayo/moyamoya/global/config/S3Config.kt
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,27 @@ | ||
package com.ohayo.moyamoya.global.config | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider | ||
import com.amazonaws.auth.BasicAWSCredentials | ||
import com.amazonaws.services.s3.AmazonS3Client | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder | ||
import com.ohayo.moyamoya.infra.s3.S3Properties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class S3Config( | ||
private val s3Properties: S3Properties | ||
) { | ||
@Bean | ||
fun AmazonS3Client(): AmazonS3Client = AmazonS3ClientBuilder.standard() | ||
.withRegion(s3Properties.region.static) | ||
.withCredentials( | ||
AWSStaticCredentialsProvider( | ||
BasicAWSCredentials( | ||
s3Properties.credentials.accessKey, | ||
s3Properties.credentials.secretKey | ||
) | ||
) | ||
) | ||
.build() as AmazonS3Client | ||
} |
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
3 changes: 1 addition & 2 deletions
3
...om/ohayo/moyamoya/global/SwaggerConfig.kt → ...o/moyamoya/global/config/SwaggerConfig.kt
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
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/ohayo/moyamoya/infra/s3/S3Properties.kt
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,19 @@ | ||
package com.ohayo.moyamoya.infra.s3 | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding | ||
|
||
@ConfigurationProperties("cloud.aws") | ||
class S3Properties @ConstructorBinding constructor( | ||
val credentials: Credentials, | ||
val s3bucket: String, | ||
val region: Region, | ||
) { | ||
class Credentials( | ||
val accessKey: String, | ||
val secretKey: String | ||
) | ||
class Region( | ||
val static: String | ||
) | ||
} |
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