Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
[Fix] Photo url #36 (#37)
Browse files Browse the repository at this point in the history
* fix(application.yml): prod 환경의 fcm path 경로 수정

* fix(PhotoLocalManager): 경로 메서드를 호출하도록 변경

* setting: 멀티파트 데이터 전송 사이즈 제한

* feat(CompanionPlantCreateRequest): 임시 사진 baseUrl 경로 지정
  • Loading branch information
zbqmgldjfh authored Jan 24, 2024
1 parent e34fc3f commit 191e6fa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.multipart.MaxUploadSizeExceededException

@RestControllerAdvice
class CommonExceptionHandler {
Expand All @@ -27,4 +28,9 @@ class CommonExceptionHandler {

return ResponseEntity.internalServerError().body(ErrorResponse("서버 에러가 발생했습니다. 관리자에게 문의해주세요."))
}

@ExceptionHandler
fun handleMaxSizeException(ex: MaxUploadSizeExceededException): ResponseEntity<ErrorResponse> {
return ResponseEntity.badRequest().body(ErrorResponse("파일의 최대 사이즈를 확인해주세요."))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PhotoLocalManager(

private fun uploadFileInLocal(multipartFile: MultipartFile, uploadPath: File) {
try {
multipartFile.transferTo(uploadPath)
multipartFile.transferTo(uploadPath.toPath())
} catch (e: IOException) {
throw IllegalStateException("파일 변환이 실패했습니다.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ data class CompanionPlantCreateRequest(
@DateTimeFormat(pattern = "yyyy-MM-dd") val lastWaterDate: LocalDate,
) {
fun toEntity(imagePath: String, memberId: Long, waterCycle: Int): CompanionPlant {
// TODO : Cloud 환경으로 이전 후 제거, 로컬 사진 저장 테스트 용도
val baseUrl: String = "https://nongsaro.go.kr/"
return CompanionPlant(
_imageUrl = imagePath,
_imageUrl = baseUrl + imagePath,
_shortDescription = this.shortDescription,
_nickname = this.nickname,
nextWaterDate = this.lastWaterDate.plusDays(waterCycle.toLong()),
Expand All @@ -29,4 +31,4 @@ data class CompanionPlantCreateRequest(
memberId = memberId,
)
}
}
}
6 changes: 5 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ spring:
username: ${DB_USER}
password: ${DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
servlet:
multipart:
max-file-size: 20MB
max-request-size: 25MB

local:
image:
Expand All @@ -26,5 +30,5 @@ companionPlant:

fcm:
key:
path: src/main/resources/config/google-services.json
path: config/google-services.json
scope: prod
4 changes: 4 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ spring:
username: plantory
password: plantory1234
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
servlet:
multipart:
max-file-size: 20MB
max-request-size: 25MB

local:
image:
Expand Down

0 comments on commit 191e6fa

Please sign in to comment.