Skip to content

Commit cb33735

Browse files
authored
Merge pull request #109 from wafflestudio/107-프로필-이미지-응답-형식-수정
🐛 프로필 이미지 response를 key가 아닌 url로 변경
2 parents 3dcae51 + c26cabf commit cb33735

File tree

6 files changed

+20
-30
lines changed

6 files changed

+20
-30
lines changed

src/main/kotlin/com/wafflestudio/spring2025/common/image/service/ImageService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ImageService(
9696
)
9797
}
9898

99-
private fun presignedGetUrl(key: String): String {
99+
fun presignedGetUrl(key: String): String {
100100
val getRequest =
101101
GetObjectRequest
102102
.builder()

src/main/kotlin/com/wafflestudio/spring2025/config/AwsS3Properties.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties
66
data class AwsS3Properties(
77
val bucket: String,
88
val region: String,
9-
val presignExpireSeconds: Long = 300,
9+
val presignExpireSeconds: Long = 1800,
1010
)

src/main/kotlin/com/wafflestudio/spring2025/domain/auth/service/AuthService.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.wafflestudio.spring2025.domain.auth.service
22

3+
import com.wafflestudio.spring2025.common.image.service.ImageService
34
import com.wafflestudio.spring2025.domain.auth.JwtTokenProvider
45
import com.wafflestudio.spring2025.domain.auth.exception.AuthErrorCode
56
import com.wafflestudio.spring2025.domain.auth.exception.AuthValidationException
@@ -17,6 +18,7 @@ class AuthService(
1718
private val identityRepository: UserIdentityRepository,
1819
private val jwtTokenProvider: JwtTokenProvider,
1920
private val jwtBlacklistService: JwtBlacklistService,
21+
private val imageService: ImageService,
2022
) {
2123
fun login(
2224
email: String,
@@ -58,7 +60,12 @@ class AuthService(
5860
),
5961
)
6062

61-
return UserDto(user)
63+
return UserDto(
64+
id = user.id!!,
65+
email = user.email,
66+
name = user.name,
67+
profileImage = user.profileImage?.let { imageService.presignedGetUrl(it) },
68+
)
6269
}
6370

6471
private fun validateEmail(email: String) {

src/main/kotlin/com/wafflestudio/spring2025/domain/event/service/EventService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.wafflestudio.spring2025.domain.event.service
22

3+
import com.wafflestudio.spring2025.common.image.service.ImageService
34
import com.wafflestudio.spring2025.domain.event.dto.response.CapabilitiesInfo
45
import com.wafflestudio.spring2025.domain.event.dto.response.CreatorInfo
56
import com.wafflestudio.spring2025.domain.event.dto.response.EventDetailResponse
@@ -29,6 +30,7 @@ class EventService(
2930
private val eventRepository: EventRepository,
3031
private val registrationRepository: RegistrationRepository,
3132
private val userRepository: UserRepository,
33+
private val imageService: ImageService,
3234
) {
3335
/**
3436
* 일정 생성
@@ -189,7 +191,7 @@ class EventService(
189191
GuestPreview(
190192
id = it.id!!,
191193
name = it.name,
192-
profileImage = it.profileImage,
194+
profileImage = it.profileImage?.let { key -> imageService.presignedGetUrl(key) },
193195
)
194196
}
195197
}
@@ -212,7 +214,7 @@ class EventService(
212214
CreatorInfo(
213215
name = creatorUser.name,
214216
email = creatorUser.email,
215-
profileImage = creatorUser.profileImage,
217+
profileImage = creatorUser.profileImage?.let { imageService.presignedGetUrl(it) },
216218
),
217219
viewer = viewer,
218220
capabilities = capabilities,

src/main/kotlin/com/wafflestudio/spring2025/domain/registration/service/RegistrationService.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.wafflestudio.spring2025.domain.registration.service
22

33
import com.wafflestudio.spring2025.common.email.service.EmailService
4+
import com.wafflestudio.spring2025.common.image.service.ImageService
45
import com.wafflestudio.spring2025.domain.event.exception.EventFullException
56
import com.wafflestudio.spring2025.domain.event.exception.EventNotFoundException
67
import com.wafflestudio.spring2025.domain.event.model.Event
@@ -44,6 +45,7 @@ class RegistrationService(
4445
private val eventLockRepository: EventLockRepository,
4546
private val userRepository: UserRepository,
4647
private val emailService: EmailService,
48+
private val imageService: ImageService,
4749
) {
4850
private val emailRegex = Regex("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$")
4951
private val tokenValidity = Duration.ofHours(24)
@@ -443,7 +445,7 @@ class RegistrationService(
443445
null
444446
}
445447

446-
val profileImage = user?.profileImage
448+
val profileImage = user?.profileImage?.let { imageService.presignedGetUrl(it) }
447449
val item =
448450
EventRegistrationItem(
449451
registration = registration,

src/main/kotlin/com/wafflestudio/spring2025/domain/user/service/UserService.kt

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.wafflestudio.spring2025.domain.user.service
22

3+
import com.wafflestudio.spring2025.common.image.service.ImageService
34
import com.wafflestudio.spring2025.config.AwsS3Properties
45
import com.wafflestudio.spring2025.domain.auth.exception.AuthErrorCode
56
import com.wafflestudio.spring2025.domain.auth.exception.AuthValidationException
@@ -13,24 +14,20 @@ import com.wafflestudio.spring2025.domain.user.repository.UserRepository
1314
import org.mindrot.jbcrypt.BCrypt
1415
import org.springframework.stereotype.Service
1516
import software.amazon.awssdk.services.s3.S3Client
16-
import software.amazon.awssdk.services.s3.model.GetObjectRequest
1717
import software.amazon.awssdk.services.s3.model.HeadObjectRequest
1818
import software.amazon.awssdk.services.s3.model.NoSuchKeyException
19-
import software.amazon.awssdk.services.s3.presigner.S3Presigner
20-
import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest
21-
import java.time.Duration
2219

2320
@Service
2421
class UserService(
2522
private val userRepository: UserRepository,
2623
private val s3Client: S3Client,
27-
private val presigner: S3Presigner,
2824
private val s3Props: AwsS3Properties,
25+
private val imageService: ImageService,
2926
) {
3027
fun me(user: User?): UserDto {
3128
if (user == null) throw AuthenticationRequiredException()
3229

33-
val presignedUrl = user.profileImage?.let { key -> presignedGetUrl(key) }
30+
val presignedUrl = user.profileImage?.let { imageService.presignedGetUrl(it) }
3431

3532
return UserDto(
3633
id = user.id!!,
@@ -40,24 +37,6 @@ class UserService(
4037
)
4138
}
4239

43-
private fun presignedGetUrl(key: String): String {
44-
val getReq =
45-
GetObjectRequest
46-
.builder()
47-
.bucket(s3Props.bucket)
48-
.key(key)
49-
.build()
50-
51-
val presignReq =
52-
GetObjectPresignRequest
53-
.builder()
54-
.signatureDuration(Duration.ofSeconds(s3Props.presignExpireSeconds))
55-
.getObjectRequest(getReq)
56-
.build()
57-
58-
return presigner.presignGetObject(presignReq).url().toString()
59-
}
60-
6140
fun patchMe(
6241
user: User,
6342
name: String?,

0 commit comments

Comments
 (0)