Skip to content

Commit aadf7d5

Browse files
authored
MARA-87 : 최종 배포 전 코드 리팩토링 (#48)
* Optional<> 제거 * dev 환경 log level info -> warn 변경 * S3 Service 적재 예외 경우 추가
1 parent abe0ebb commit aadf7d5

File tree

8 files changed

+11
-38
lines changed

8 files changed

+11
-38
lines changed

src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorService.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class FriendRefrigeratorService(
1515

1616
fun getRecentFriendRefrigeratorList(): List<FriendRefrigeratorResponse> {
1717
val currentLoginUser = userService.getCurrentLoginUser()
18-
val friendshipList = friendshipRepository.findByFromUser(currentLoginUser)
19-
.orElseThrow { NoSuchElementException("친구 관계가 존재하지 않습니다.") }
18+
val friendshipList = friendshipRepository.findByFromUser(currentLoginUser) ?: throw NoSuchElementException("친구 관계가 존재하지 않습니다.")
2019

2120
val userList = friendshipList.map { it.toUser }
2221
val refrigeratorList = refrigeratorRepository.findByUserList(userList, 5)

src/main/kotlin/mara/server/domain/friend/FriendshipController.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ class FriendshipController(
3939
return success(friendshipService.getFriendshipList(pageable))
4040
}
4141

42-
@GetMapping("/count")
43-
@Operation(summary = "친구 수 조회 API")
44-
fun getFriendshipCount(): CommonResponse<Long> {
45-
return success(friendshipService.getFriendshipCount())
46-
}
47-
4842
@PostMapping("/delete")
4943
@Operation(summary = "친구 삭제 API")
5044
fun deleteFriendship(@RequestBody friendshipDeleteRequestList: List<FriendshipDeleteRequest>): CommonResponse<String> {

src/main/kotlin/mara/server/domain/friend/FriendshipDto.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,3 @@ data class FriendshipRequest(
77
data class FriendshipDeleteRequest(
88
val friendId: Long
99
)
10-
11-
data class FriendshipResponse(
12-
val friendshipId: Long,
13-
val fromFriend: Long,
14-
val toFriend: Long
15-
) {
16-
constructor(friendship: Friendship) : this(
17-
friendshipId = friendship.friendshipId,
18-
fromFriend = friendship.fromUser.userId,
19-
toFriend = friendship.toUser.userId
20-
)
21-
}
22-
23-
fun List<Friendship>.toFriendshipResponseList(): List<FriendshipResponse> {
24-
return this.map { FriendshipResponse(it) }
25-
}

src/main/kotlin/mara/server/domain/friend/FriendshipRepository.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import org.springframework.data.domain.Page
88
import org.springframework.data.domain.Pageable
99
import org.springframework.data.jpa.repository.JpaRepository
1010
import org.springframework.data.support.PageableExecutionUtils
11-
import java.util.Optional
1211

1312
interface FriendshipRepository : JpaRepository<Friendship, Long>, CustomFriendshipRepository {
1413
fun findByFromUser(
1514
user: User,
16-
): Optional<List<Friendship>>
15+
): List<Friendship>?
1716

1817
fun countByFromUser(
1918
user: User

src/main/kotlin/mara/server/domain/friend/FriendshipService.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FriendshipService(
2929
val fromUser = userRepository.findById(currentUserId)
3030
.orElseThrow { NoSuchElementException("해당 유저가 존재하지 않습니다. ID: $currentUserId") }
3131
val toUser = userRepository.findByInviteCode(friendshipRequest.inviteCode)
32-
.orElseThrow { NoSuchElementException("해당 초대코드를 가진 사용자가 존재하지 않습니다.") }
32+
?: throw NoSuchElementException("해당 초대코드를 가진 사용자가 존재하지 않습니다. 초대코드: ${friendshipRequest.inviteCode}")
3333

3434
addFriendship(fromUser, toUser)
3535
addFriendship(toUser, fromUser)
@@ -50,11 +50,6 @@ class FriendshipService(
5050
return userFriendResponseList
5151
}
5252

53-
fun getFriendshipCount(): Long {
54-
val currentLoginUser = userService.getCurrentLoginUser()
55-
return friendshipRepository.countByFromUser(currentLoginUser)
56-
}
57-
5853
@Transactional
5954
fun deleteFriendship(friendshipDeleteRequestList: List<FriendshipDeleteRequest>): String {
6055
val currentLoginUser = userService.getCurrentLoginUser()

src/main/kotlin/mara/server/domain/s3/S3Service.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ class S3Service(
2121
private val dir: String
2222
) {
2323
@Transactional
24-
fun upload(file: MultipartFile, customDir: String? = dir): String {
24+
fun upload(file: MultipartFile, customDir: String?): String {
25+
val resultDir = customDir ?: dir
26+
if (resultDir.startsWith("/")) throw IllegalArgumentException("올바르지 않은 경로입니다. $resultDir")
27+
2528
val fileName = UUID.randomUUID().toString() + "-" + file.originalFilename
2629
val objMeta = ObjectMetadata()
2730

@@ -31,10 +34,10 @@ class S3Service(
3134
val byteArrayIs = ByteArrayInputStream(bytes)
3235

3336
s3Client.putObject(
34-
PutObjectRequest(bucket, dir + fileName, byteArrayIs, objMeta)
37+
PutObjectRequest(bucket, resultDir + fileName, byteArrayIs, objMeta)
3538
.withCannedAcl(CannedAccessControlList.PublicRead)
3639
)
3740

38-
return s3Client.getUrl(bucket, dir + fileName).toString()
41+
return s3Client.getUrl(bucket, resultDir + fileName).toString()
3942
}
4043
}

src/main/kotlin/mara/server/domain/user/UserRepository.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package mara.server.domain.user
33
import com.querydsl.jpa.impl.JPAQueryFactory
44
import mara.server.domain.user.QUser.user
55
import org.springframework.data.jpa.repository.JpaRepository
6-
import java.util.Optional
76

87
interface UserRepository : JpaRepository<User, Long>, CustomUserRepository {
98

109
fun findByKakaoId(id: Long): User?
1110
fun findByGoogleEmail(email: String): User?
12-
fun findByInviteCode(inviteCode: String): Optional<User>
11+
fun findByInviteCode(inviteCode: String): User?
1312
fun existsByNickname(nickname: String): Boolean
1413
}
1514

src/main/resources/application-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ jwt:
4040

4141
logging:
4242
level:
43-
root: info
43+
root: warn
4444
mara.server: TRACE

0 commit comments

Comments
 (0)