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

Commit

Permalink
Merge pull request #64 from gdsc-konkuk/develop
Browse files Browse the repository at this point in the history
[Fix] Local Image Store (#63)
  • Loading branch information
goldentrash authored Feb 6, 2024
2 parents 5cd7f16 + f1516eb commit 1ebbf23
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/main/kotlin/gdsc/plantory/common/config/WebMvcConfiguration.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package gdsc.plantory.common.config

import gdsc.plantory.common.support.DeviceUserResolver
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.web.method.support.HandlerMethodArgumentResolver
import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
class WebMvcConfiguration(
@Value("\${local.image.root}")
val imageRoot: String,

val deviceUserResolver: DeviceUserResolver,
) : WebMvcConfigurer {

override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
registry.addResourceHandler("/**")
.addResourceLocations("file:${imageRoot}/")
}

override fun addArgumentResolvers(resolvers: MutableList<HandlerMethodArgumentResolver>) {
resolvers.add(deviceUserResolver)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ private const val SLASH = "/"

@Component
class PhotoLocalManager(
@Value("\${local.url}")
private val serverURL: String,
@Value("\${local.image.root}")
private val localPath: String,
@Value("\${companionPlant.image.directory}")
Expand All @@ -30,6 +32,7 @@ class PhotoLocalManager(
uploadFileInLocal(multipartFile, uploadPath)

StringBuilder()
.append(serverURL)
.append(SLASH)
.append(workingDirectory)
.append(SLASH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ data class CompanionPlantCreateRequest(
@DateTimeFormat(pattern = "yyyy-MM-dd") val lastWaterDate: LocalDate,
) {
fun toEntity(imagePath: String, memberId: Long, waterCycle: Int, plantInformationId: Long): CompanionPlant {
// TODO : Cloud 환경으로 이전 후 제거, 로컬 사진 저장 테스트 용도
val baseUrl = "https://nongsaro.go.kr/"
return CompanionPlant(
_imageUrl = baseUrl + imagePath,
_imageUrl = imagePath,
_shortDescription = this.shortDescription,
_nickname = this.nickname,
nextWaterDate = this.lastWaterDate.plusDays(waterCycle.toLong()),
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/gdsc/plantory/plant/service/PlantService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ class PlantService(
companionPlantRepository.findByIdAndMemberIdOrThrow(companionPlantId, findMember.getId)
val imagePath: String = saveImageAndGetPath(image, findCompanionPlant.getImageUrl)

// TODO : Cloud 환경으로 이전 후 제거, 로컬 사진 저장 테스트 용도
val baseUrl = "https://nongsaro.go.kr/"
findCompanionPlant.saveRecord(request.comment, baseUrl + imagePath)
findCompanionPlant.saveRecord(request.comment, imagePath)
}

@Transactional(readOnly = true)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spring:
max-request-size: 25MB

local:
url: ${SERVER_URL}
image:
root: resources

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spring:
max-request-size: 25MB

local:
url: http://127.0.0.1:8080
image:
root: src/test/resources

Expand Down

0 comments on commit 1ebbf23

Please sign in to comment.