From aadf7d59a4d9d49cbef617edef6737eb5a39b9d2 Mon Sep 17 00:00:00 2001 From: blackswitch <50973746+jhkang1517@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:26:23 +0900 Subject: [PATCH] =?UTF-8?q?MARA-87=20:=20=EC=B5=9C=EC=A2=85=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=A0=84=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81=20=20(#48)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Optional<> 제거 * dev 환경 log level info -> warn 변경 * S3 Service 적재 예외 경우 추가 --- .../domain/friend/FriendRefrigeratorService.kt | 3 +-- .../server/domain/friend/FriendshipController.kt | 6 ------ .../mara/server/domain/friend/FriendshipDto.kt | 16 ---------------- .../server/domain/friend/FriendshipRepository.kt | 3 +-- .../server/domain/friend/FriendshipService.kt | 7 +------ .../kotlin/mara/server/domain/s3/S3Service.kt | 9 ++++++--- .../mara/server/domain/user/UserRepository.kt | 3 +-- src/main/resources/application-dev.yml | 2 +- 8 files changed, 11 insertions(+), 38 deletions(-) diff --git a/src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorService.kt b/src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorService.kt index 8736664..072161a 100644 --- a/src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorService.kt +++ b/src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorService.kt @@ -15,8 +15,7 @@ class FriendRefrigeratorService( fun getRecentFriendRefrigeratorList(): List { val currentLoginUser = userService.getCurrentLoginUser() - val friendshipList = friendshipRepository.findByFromUser(currentLoginUser) - .orElseThrow { NoSuchElementException("친구 관계가 존재하지 않습니다.") } + val friendshipList = friendshipRepository.findByFromUser(currentLoginUser) ?: throw NoSuchElementException("친구 관계가 존재하지 않습니다.") val userList = friendshipList.map { it.toUser } val refrigeratorList = refrigeratorRepository.findByUserList(userList, 5) diff --git a/src/main/kotlin/mara/server/domain/friend/FriendshipController.kt b/src/main/kotlin/mara/server/domain/friend/FriendshipController.kt index 28821af..9b43604 100644 --- a/src/main/kotlin/mara/server/domain/friend/FriendshipController.kt +++ b/src/main/kotlin/mara/server/domain/friend/FriendshipController.kt @@ -39,12 +39,6 @@ class FriendshipController( return success(friendshipService.getFriendshipList(pageable)) } - @GetMapping("/count") - @Operation(summary = "친구 수 조회 API") - fun getFriendshipCount(): CommonResponse { - return success(friendshipService.getFriendshipCount()) - } - @PostMapping("/delete") @Operation(summary = "친구 삭제 API") fun deleteFriendship(@RequestBody friendshipDeleteRequestList: List): CommonResponse { diff --git a/src/main/kotlin/mara/server/domain/friend/FriendshipDto.kt b/src/main/kotlin/mara/server/domain/friend/FriendshipDto.kt index 767bc83..77c2483 100644 --- a/src/main/kotlin/mara/server/domain/friend/FriendshipDto.kt +++ b/src/main/kotlin/mara/server/domain/friend/FriendshipDto.kt @@ -7,19 +7,3 @@ data class FriendshipRequest( data class FriendshipDeleteRequest( val friendId: Long ) - -data class FriendshipResponse( - val friendshipId: Long, - val fromFriend: Long, - val toFriend: Long -) { - constructor(friendship: Friendship) : this( - friendshipId = friendship.friendshipId, - fromFriend = friendship.fromUser.userId, - toFriend = friendship.toUser.userId - ) -} - -fun List.toFriendshipResponseList(): List { - return this.map { FriendshipResponse(it) } -} diff --git a/src/main/kotlin/mara/server/domain/friend/FriendshipRepository.kt b/src/main/kotlin/mara/server/domain/friend/FriendshipRepository.kt index c9f6b13..c9c8742 100644 --- a/src/main/kotlin/mara/server/domain/friend/FriendshipRepository.kt +++ b/src/main/kotlin/mara/server/domain/friend/FriendshipRepository.kt @@ -8,12 +8,11 @@ import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.support.PageableExecutionUtils -import java.util.Optional interface FriendshipRepository : JpaRepository, CustomFriendshipRepository { fun findByFromUser( user: User, - ): Optional> + ): List? fun countByFromUser( user: User diff --git a/src/main/kotlin/mara/server/domain/friend/FriendshipService.kt b/src/main/kotlin/mara/server/domain/friend/FriendshipService.kt index 2e68e12..9632e1c 100644 --- a/src/main/kotlin/mara/server/domain/friend/FriendshipService.kt +++ b/src/main/kotlin/mara/server/domain/friend/FriendshipService.kt @@ -29,7 +29,7 @@ class FriendshipService( val fromUser = userRepository.findById(currentUserId) .orElseThrow { NoSuchElementException("해당 유저가 존재하지 않습니다. ID: $currentUserId") } val toUser = userRepository.findByInviteCode(friendshipRequest.inviteCode) - .orElseThrow { NoSuchElementException("해당 초대코드를 가진 사용자가 존재하지 않습니다.") } + ?: throw NoSuchElementException("해당 초대코드를 가진 사용자가 존재하지 않습니다. 초대코드: ${friendshipRequest.inviteCode}") addFriendship(fromUser, toUser) addFriendship(toUser, fromUser) @@ -50,11 +50,6 @@ class FriendshipService( return userFriendResponseList } - fun getFriendshipCount(): Long { - val currentLoginUser = userService.getCurrentLoginUser() - return friendshipRepository.countByFromUser(currentLoginUser) - } - @Transactional fun deleteFriendship(friendshipDeleteRequestList: List): String { val currentLoginUser = userService.getCurrentLoginUser() diff --git a/src/main/kotlin/mara/server/domain/s3/S3Service.kt b/src/main/kotlin/mara/server/domain/s3/S3Service.kt index a660980..c936211 100644 --- a/src/main/kotlin/mara/server/domain/s3/S3Service.kt +++ b/src/main/kotlin/mara/server/domain/s3/S3Service.kt @@ -21,7 +21,10 @@ class S3Service( private val dir: String ) { @Transactional - fun upload(file: MultipartFile, customDir: String? = dir): String { + fun upload(file: MultipartFile, customDir: String?): String { + val resultDir = customDir ?: dir + if (resultDir.startsWith("/")) throw IllegalArgumentException("올바르지 않은 경로입니다. $resultDir") + val fileName = UUID.randomUUID().toString() + "-" + file.originalFilename val objMeta = ObjectMetadata() @@ -31,10 +34,10 @@ class S3Service( val byteArrayIs = ByteArrayInputStream(bytes) s3Client.putObject( - PutObjectRequest(bucket, dir + fileName, byteArrayIs, objMeta) + PutObjectRequest(bucket, resultDir + fileName, byteArrayIs, objMeta) .withCannedAcl(CannedAccessControlList.PublicRead) ) - return s3Client.getUrl(bucket, dir + fileName).toString() + return s3Client.getUrl(bucket, resultDir + fileName).toString() } } diff --git a/src/main/kotlin/mara/server/domain/user/UserRepository.kt b/src/main/kotlin/mara/server/domain/user/UserRepository.kt index 09a9d6b..9aa1873 100644 --- a/src/main/kotlin/mara/server/domain/user/UserRepository.kt +++ b/src/main/kotlin/mara/server/domain/user/UserRepository.kt @@ -3,13 +3,12 @@ package mara.server.domain.user import com.querydsl.jpa.impl.JPAQueryFactory import mara.server.domain.user.QUser.user import org.springframework.data.jpa.repository.JpaRepository -import java.util.Optional interface UserRepository : JpaRepository, CustomUserRepository { fun findByKakaoId(id: Long): User? fun findByGoogleEmail(email: String): User? - fun findByInviteCode(inviteCode: String): Optional + fun findByInviteCode(inviteCode: String): User? fun existsByNickname(nickname: String): Boolean } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index a8a9b62..ea0fb1f 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -40,5 +40,5 @@ jwt: logging: level: - root: info + root: warn mara.server: TRACE \ No newline at end of file