Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

83 aws sdk for java 2x #84

Merged
merged 14 commits into from
Mar 4, 2025
12 changes: 8 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ allOpen {
dependencyManagement {

imports {
mavenBom ("org.springframework.cloud:spring-cloud-dependencies:2022.0.3")
mavenBom("org.springframework.cloud:spring-cloud-dependencies:2022.0.3")
}
}

Expand All @@ -58,9 +58,14 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
implementation(platform("com.google.api-client:google-api-client-bom:2.6.0"))
implementation(platform("software.amazon.awssdk:bom:2.29.45"))

implementation("com.google.api-client:google-api-client-jackson2:2.2.0")
implementation("com.google.api-client:google-api-client:2.2.0")
implementation("software.amazon.awssdk:s3")


implementation("com.google.api-client:google-api-client-jackson2")
implementation("com.google.api-client:google-api-client")

implementation("ognl:ognl:3.3.4")

Expand All @@ -73,7 +78,6 @@ dependencies {
implementation("io.viascom.nanoid:nanoid:1.0.1")

// s3
implementation("com.amazonaws:aws-java-sdk-s3:1.12.261")

implementation("com.bucket4j:bucket4j-core:8.3.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/auth/valid")
@RequestMapping("/api/auth/valid")
class ValidController(
private val validService: ValidService
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class EmailDto(
regexp = "^[a-zA-Z0-9+-_.]+@[0-9a-zA-Z]+\\.[a-zA-Z]{2,3}\$",
message = "only email"
) val email: String, @field:NotBlank(message = "VerifyCode can't be blank.") @field:Pattern(
regexp = "^\\d{6}\$", message = "Verify Code can only be 6 characters long"
regexp = "^\\d{4}\$", message = "Verify Code can only be 4 characters long"
) val verifyCode: String
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import com.photo.server.starsnap.domain.auth.type.toOauth2
import com.photo.server.starsnap.domain.user.entity.Oauth2Entity
import com.photo.server.starsnap.domain.user.entity.UserEntity
import com.photo.server.starsnap.domain.user.repository.UserRepository
import com.photo.server.starsnap.domain.user.service.UserAwsS3Service
import com.photo.server.starsnap.global.security.jwt.JwtProvider
import com.photo.server.starsnap.global.service.AwsS3Service
import org.springframework.stereotype.Service

@Service
Expand All @@ -29,7 +29,7 @@ class Oauth2Service(
private val appleOauthHelper: AppleOauthHelper,
private val refreshTokenRepository: RefreshTokenRepository,
private val jwtProvider: JwtProvider,
private val userAwsS3Service: UserAwsS3Service
private val awsS3Service: AwsS3Service
) {
fun login(loginDto: Oauth2LoginDto): TokenDto {
val oidcDecodePayload = when (loginDto.type.toOauth2()) {
Expand Down Expand Up @@ -69,7 +69,7 @@ class Oauth2Service(
userId = user
)
oauth2Repository.save(oauth2)
userAwsS3Service.addOauthProfileImage(user.id, oidcDecodePayload.profileImageUrl)
awsS3Service.uploadUrlToS3(oidcDecodePayload.profileImageUrl, "profile/${user.id}", user.id)
}

fun unconnected(idToken: String, user: UserEntity, type: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class ValidService(
) {
fun validUsername(username: String): StatusDto {
val usernameExists = userRepository.existsByUsername(username)
if(!usernameExists) throw ExistUserNameException
if(usernameExists) throw ExistUserNameException
if (!Pattern.USERNAME.toPattern().matcher(username).matches()) throw InvalidUserNameFormatException

return StatusDto("사용가능한 닉네임입니다.", 200)
}

fun validEmail(email: String): StatusDto {
val emailExists = userRepository.existsByEmail(email)
if(!emailExists) throw ExistEmailException
if(emailExists) throw ExistEmailException
if(!Pattern.EMAIL.toPattern().matcher(email).matches()) throw InvalidEmailFormatException

return StatusDto("사용가능한 이메일입니다", 200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SnapController(
@ModelAttribute @Valid snapDto: UpdateSnapRequestDto,
@AuthenticationPrincipal user: CustomUserDetails
): SnapResponseDto {
val snapData = snapService.updateSnap(user.userId, snapDto)
val snapData = snapService.updateSnap(user.userId, snapDto, user.user)
return snapData
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ interface SnapRepository : JpaRepository<SnapEntity, String> {
AND (:blockUser IS NULL OR snap.user NOT IN :blockUser)
AND (:tags IS NULL OR snap.tags IN :tags)
AND (:title IS NULL OR snap.title LIKE %:title%)
AND (:user IS NULL OR snap.user IN :user)
AND (:user IS NULL OR snap.user.id IN :userId)
""")
fun findFilteredSnaps(
pageable: Pageable,
state: Boolean,
blockUser: List<UserEntity>?,
tags: List<String>?,
title: String?,
user: UserEntity?
): Slice<SnapEntity>
blockUser: List<UserEntity>? = null,
tags: List<String>? = null,
title: String? = null,
userId: String? = null
): Slice<SnapEntity>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import com.photo.server.starsnap.global.dto.SnapDto
import com.photo.server.starsnap.global.dto.toSnapDto
import com.photo.server.starsnap.global.error.exception.InvalidRoleException
import jakarta.transaction.Transactional
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Slice
import org.springframework.data.domain.Sort
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service

Expand All @@ -19,7 +21,13 @@ class DeleteSnapService(
) {
@Transactional
fun getDeleteSnap(page: Int, size: Int, userId: String): Slice<SnapDto> {
val snaps = snapRepository.findSliceByStateAndUserId(false, userId) ?: throw NotFoundSnapIdException
val pageRequest = PageRequest.of(
page, size, Sort.by(
Sort.Direction.DESC, "createdAt"
)
)
val snaps =
snapRepository.findFilteredSnaps(pageRequest, false, userId = userId) ?: throw NotFoundSnapIdException
return snaps.map {
it.toSnapDto()
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.photo.server.starsnap.domain.snap.entity.SnapEntity
import com.photo.server.starsnap.domain.snap.dto.SnapResponseDto
import com.photo.server.starsnap.domain.snap.dto.UpdateSnapRequestDto
import com.photo.server.starsnap.domain.snap.entity.TagEntity
import com.photo.server.starsnap.domain.snap.error.exception.NotFoundSnapException
import com.photo.server.starsnap.domain.snap.error.exception.NotFoundSnapIdException
import com.photo.server.starsnap.domain.snap.error.exception.NotFoundTagException
import com.photo.server.starsnap.domain.snap.error.exception.UnsupportedFileTypeException
Expand All @@ -18,6 +19,7 @@ import com.photo.server.starsnap.domain.user.repository.UserRepository
import com.photo.server.starsnap.global.dto.toSnapDto
import com.photo.server.starsnap.global.dto.toSnapUserDto
import com.photo.server.starsnap.global.error.exception.InvalidRoleException
import com.photo.server.starsnap.global.service.AwsS3Service
import com.photo.server.starsnap.global.utils.type.isValid
import io.viascom.nanoid.NanoId
import jakarta.transaction.Transactional
Expand All @@ -34,7 +36,7 @@ import javax.imageio.ImageIO
class SnapService(
private val snapRepository: SnapRepository,
private val tagRepository: TagRepository,
private val snapAwsS3Service: SnapAwsS3Service,
private val awsS3Service: AwsS3Service,
private val blackUserRepository: BlackUserRepository,
private val userRepository: UserRepository
) {
Expand All @@ -48,7 +50,7 @@ class SnapService(
val imageKey = NanoId.generate(16)
try {
val bufferedImage: BufferedImage = ImageIO.read(snapDto.image.inputStream)
snapAwsS3Service.uploadImage(snapDto.image, imageKey)
awsS3Service.uploadFileToS3(snapDto.image, imageKey, userData.id)
val snapData = SnapEntity(
title = snapDto.title,
imageSize = snapDto.image.size,
Expand Down Expand Up @@ -84,12 +86,13 @@ class SnapService(
@Transactional
fun updateSnap(
userId: String,
snapDto: UpdateSnapRequestDto
snapDto: UpdateSnapRequestDto,
userData: UserEntity
): SnapResponseDto {
val snapData = snapRepository.findByIdOrNull(snapDto.snapId) ?: throw NotFoundSnapIdException

if (snapData.user.id != userId) throw InvalidRoleException
if (snapDto.image != null) snapAwsS3Service.updateImage(snapDto.image, snapData.imageKey)
awsS3Service.uploadFileToS3(snapDto.image, snapData.imageKey, userData.id)

snapData.title = snapDto.title
snapData.source = snapDto.source
Expand Down Expand Up @@ -117,8 +120,8 @@ class SnapService(
blockUser = blockUser,
tags = getSnapResponseDto.tag,
title = getSnapResponseDto.title,
user = user
)
userId = user?.id
) ?: throw NotFoundSnapException

return snapData.map {
SnapResponseDto(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.photo.server.starsnap.domain.star.controller

import com.photo.server.starsnap.domain.star.dto.*
import com.photo.server.starsnap.domain.star.service.StarImageService
import com.photo.server.starsnap.domain.star.service.StarService
import com.photo.server.starsnap.global.dto.StatusDto
import com.photo.server.starsnap.global.security.principle.CustomUserDetails
import com.photo.server.starsnap.global.service.AwsS3Service
import jakarta.validation.Valid
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.*
Expand All @@ -14,7 +14,7 @@ import org.springframework.web.multipart.MultipartFile
@RequestMapping("api/star")
class StarController(
private val starService: StarService,
private val starImageService: StarImageService,
private val awsS3Service: AwsS3Service,
) {
@PostMapping("/create")
fun createStar(@Valid @RequestBody starDto: CreateStarRequestDto, @AuthenticationPrincipal user: CustomUserDetails) {
Expand Down Expand Up @@ -46,25 +46,28 @@ class StarController(
@PostMapping("image/upload")
fun uploadImage(
@RequestPart("image") image: MultipartFile, // 사진
@AuthenticationPrincipal user: CustomUserDetails
): StarImageResponseDto {
val imageKey = starImageService.uploadImage(image, "star")
val imageKey = awsS3Service.uploadFileToS3(image, "star", user.user.id)
return StarImageResponseDto(imageKey)
}

@PostMapping("image/update")
fun updateImage(
@RequestPart("image") image: MultipartFile, // 사진
@RequestPart("image-key") imageKey: String
@RequestPart("image-key") imageKey: String,
@AuthenticationPrincipal user: CustomUserDetails
): StatusDto {
starImageService.updateImage(image, imageKey)
awsS3Service.uploadFileToS3(image, imageKey, user.user.id)
return StatusDto("OK", 200)
}

@PatchMapping("image/delete")
fun deleteImage(
@RequestPart("image-key") imageKey: String
@RequestPart("image-key") imageKey: String,
@AuthenticationPrincipal user: CustomUserDetails
): StatusDto {
starImageService.deleteImage(imageKey)
awsS3Service.deleteFileTos3(imageKey)
return StatusDto("OK", 200)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.photo.server.starsnap.domain.star.controller

import com.photo.server.starsnap.domain.star.dto.*
import com.photo.server.starsnap.domain.star.service.StarGroupService
import com.photo.server.starsnap.domain.star.service.StarImageService
import com.photo.server.starsnap.global.dto.StatusDto
import com.photo.server.starsnap.global.security.principle.CustomUserDetails
import com.photo.server.starsnap.global.service.AwsS3Service
import jakarta.validation.Valid
import org.springframework.data.domain.Slice
import org.springframework.security.core.annotation.AuthenticationPrincipal
Expand All @@ -15,7 +15,7 @@ import org.springframework.web.multipart.MultipartFile
@RequestMapping("/api/star-group")
class StarGroupController(
private val starGroupService: StarGroupService,
private val starImageService: StarImageService
private val awsS3Service: AwsS3Service
) {
@GetMapping("/get")
fun getStarGroups(
Expand Down Expand Up @@ -53,25 +53,27 @@ class StarGroupController(
@PostMapping("image/upload")
fun uploadImage(
@RequestPart("image") image: MultipartFile, // 사진
@AuthenticationPrincipal user: CustomUserDetails
): StarGroupImageResponseDto {
val imageKey = starImageService.uploadImage(image, "star-group")
val imageKey = awsS3Service.uploadFileToS3(image, "star-group", user.user.id)
return StarGroupImageResponseDto(imageKey)
}

@PostMapping("image/update")
fun updateImage(
@RequestPart("image") image: MultipartFile, // 사진
@RequestPart("image-key") imageKey: String
@RequestPart("image-key") imageKey: String,
@AuthenticationPrincipal user: CustomUserDetails
): StatusDto {
starImageService.updateImage(image, imageKey)
awsS3Service.uploadFileToS3(image, imageKey, user.user.id)
return StatusDto("OK", 200)
}

@PatchMapping("image/delete")
fun deleteImage(
@RequestPart("image-key") imageKey: String
): StatusDto {
starImageService.deleteImage(imageKey)
awsS3Service.deleteFileTos3(imageKey)
return StatusDto("OK", 200)
}
}
Loading