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

[Fix] Photo url #36 #37

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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