Skip to content

Commit d365c2a

Browse files
Merge pull request #97 from wafflestudio/feat/profile-image-oci
Feat/profile image oci
2 parents bcc5c93 + 0b73030 commit d365c2a

8 files changed

Lines changed: 25 additions & 108 deletions

File tree

hangsha/src/main/kotlin/com/team1/hangsha/common/upload/LocalUploadService.kt

Lines changed: 0 additions & 72 deletions
This file was deleted.

hangsha/src/main/kotlin/com/team1/hangsha/common/upload/UploadProperties.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties
44

55
@ConfigurationProperties(prefix = "upload")
66
data class UploadProperties(
7-
val dir: String,
8-
val publicBaseUrl: String,
97
val maxSizeBytes: Long = 10 * 1024 * 1024,
10-
)
8+
)

hangsha/src/main/kotlin/com/team1/hangsha/common/upload/UploadWebConfig.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.team1.hangsha.config
22

33
import com.team1.hangsha.user.UserArgumentResolver
4-
import org.springframework.beans.factory.annotation.Value
54
import org.springframework.context.annotation.Configuration
65
import org.springframework.web.method.support.HandlerMethodArgumentResolver
76
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
@@ -10,7 +9,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
109
@Configuration
1110
class WebConfig(
1211
private val userArgumentResolver: UserArgumentResolver,
13-
@Value("\${upload.dir}") private val uploadDir: String
1412
) : WebMvcConfigurer {
1513

1614
override fun addArgumentResolvers(resolvers: MutableList<HandlerMethodArgumentResolver>) {
@@ -19,6 +17,6 @@ class WebConfig(
1917

2018
override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
2119
registry.addResourceHandler("/static/**")
22-
.addResourceLocations("file:$uploadDir/", "classpath:/static/")
20+
.addResourceLocations("classpath:/static/")
2321
}
24-
}
22+
}

hangsha/src/main/kotlin/com/team1/hangsha/user/controller/UserController.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.team1.hangsha.user.controller
22

33
import com.fasterxml.jackson.databind.JsonNode
4-
import com.team1.hangsha.common.upload.LocalUploadService
54
import com.team1.hangsha.common.upload.dto.UploadResponse
65
import com.team1.hangsha.user.LoggedInUser
76
import com.team1.hangsha.user.model.User
@@ -21,7 +20,6 @@ import io.swagger.v3.oas.annotations.media.Schema
2120
@RequestMapping("/api/v1/users/me")
2221
class UserController(
2322
private val userService: UserService,
24-
private val localUploadService: LocalUploadService,
2523
) {
2624
@GetMapping
2725
fun getMe(
@@ -115,8 +113,8 @@ class UserController(
115113
@Parameter(hidden = true) @LoggedInUser user: User,
116114
@RequestPart("file") file: MultipartFile,
117115
): ResponseEntity<UploadResponse> {
118-
val url = localUploadService.uploadProfileImage(user.id!!, file)
116+
val url = userService.uploadProfile(user.id!!, file)
119117
userService.updateProfileImageUrl(user.id!!, url)
120118
return ResponseEntity.ok(UploadResponse(url = url))
121119
}
122-
}
120+
}

hangsha/src/main/kotlin/com/team1/hangsha/user/dto/core/UserDto.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ data class UserDto(
1717
id = user.id!!,
1818
username = user.username,
1919
email = user.email,
20-
profileImageUrl = user.profileImageUrl ?: "https://hangsha.site/static/default-profile.png",
20+
profileImageUrl = user.profileImageUrl ?: "https://objectstorage.ap-chuncheon-1.oraclecloud.com/n/ax1dvc8vmenm/b/hangsha-asset/o/default/43513b43-2f84-4f0f-8de8-7d61120fe3aa.png",
21+
// default-profile.png는 oci에 업로드 해 두었음.
22+
2123
interestCategories = interestCategories
2224
)
23-
}
25+
}

hangsha/src/main/kotlin/com/team1/hangsha/user/service/UserService.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.team1.hangsha.user.repository.UserIdentityRepository
1111
import com.team1.hangsha.user.model.AuthProvider
1212
import com.team1.hangsha.user.dto.IssuedTokens
1313
import com.team1.hangsha.user.repository.RefreshTokenRepository
14+
import com.team1.hangsha.common.upload.OciUploadService
1415
import org.springframework.beans.factory.annotation.Value
1516
import com.team1.hangsha.user.AuthCookieSupport
1617
import com.team1.hangsha.user.model.RefreshToken
@@ -23,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional
2324
import org.slf4j.LoggerFactory
2425
import java.net.URI
2526
import java.time.Instant
27+
import org.springframework.web.multipart.MultipartFile
2628

2729
@Service
2830
class UserService(
@@ -33,6 +35,7 @@ class UserService(
3335
private val tokenHasher: TokenHasher,
3436
private val cookieSupport: AuthCookieSupport,
3537
private val userPreferenceService: UserPreferenceService,
38+
private val ociUploadService: OciUploadService,
3639
@Value("\${jwt.refresh-expiration-ms}") private val refreshExpirationMs: Long,
3740
) {
3841

@@ -276,4 +279,16 @@ class UserService(
276279
user.profileImageUrl = profileImageUrl
277280
userRepository.save(user)
278281
}
279-
}
282+
283+
fun uploadProfile(userId: Long, file: MultipartFile): String {
284+
val contentType = file.contentType ?: ""
285+
if (!contentType.startsWith("image/")) {
286+
throw DomainException(ErrorCode.UPLOAD_UNSUPPORTED_MEDIA_TYPE, "이미지 파일만 업로드할 수 있습니다")
287+
}
288+
289+
return ociUploadService.uploadFile(
290+
prefix = "uploads/users/$userId",
291+
file = file,
292+
)
293+
}
294+
}

hangsha/src/main/resources/application.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ springdoc:
8585
path: /api-docs
8686

8787

88-
# TODO : 삭제 예정. 이미지 업로드는 외부 스토리지로 모두 마이그레이션 할 것.
8988
upload:
90-
dir: /data/uploads
91-
public-base-url: "https://hangsha.site/static"
9289
max-size-bytes: 10485760
9390

9491
# TODO: 프로퍼티 정상 주입 확인 목적. 배포 완료 시 내리기.

0 commit comments

Comments
 (0)