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

[Fix] Local Image Store (#63) #64

Merged
merged 2 commits into from
Feb 6, 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
@@ -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
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
Loading