-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MARA-55 : 화면설계서 기반 냉장고, 친구 추가 API 개발, 리팩토링 (#25)
* FriendshipService @transactional 적용 * UserNameResponse -> UserFriendResponse 이름 변경 * 친구 삭제 기능 FriendshipDeleteRequest -> List<FriendshipDeleteRequest> 변경 * 친구 수 조회 기능 구현 * FriendRefrigerator Controller 껍데기 구현 * 자신의 냉장고 리스트 조회 기능 구현 * 냉장고 생성 기능 리팩토링 (로그인 한 사용자의 냉장고만 생성 가능하도록 변경) * 친구 냉장고 최신 근황 조회 기능 단순 구현 * 친구 냉장고 최근 근황 조회 기능 개선 * 친구 냉장고 최근 근황 조회 기능 오류 해결 * Pageable 적용 * ktlintFormat 적용 * 리뷰 사항 반영 1. FriendRefrigeratorDto 삭제 2. userPageable, ingredientPageable 적용 동일 Pageable 객체 사용으로 인해 @qualifier 적용 3. for (friendship: Friendship in friendshipList) -> friendshipList.forEach { friendshipRepository.delete(it) } 변경 * ktlintFormat 적용 * @PageableDefault 제거
- Loading branch information
1 parent
6e26469
commit d6c0e81
Showing
16 changed files
with
181 additions
and
30 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/mara/server/config/pageable/PageableConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package mara.server.config.pageable | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.domain.PageRequest | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.domain.Sort | ||
|
||
@Configuration | ||
class PageableConfig { | ||
|
||
@Bean | ||
@Qualifier("userPageable") | ||
fun userPageable(): Pageable = PageRequest.of(0, 5, Sort.Direction.DESC, "ingredientAddDate") | ||
|
||
@Bean | ||
@Qualifier("ingredientPageable") | ||
fun ingredientPageable(): Pageable = PageRequest.of(0, 4, Sort.Direction.DESC, "addDate") | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package mara.server.domain.friend | ||
|
||
import mara.server.common.CommonResponse | ||
import mara.server.common.success | ||
import org.springframework.beans.factory.annotation.Qualifier | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/friend-refrigs") | ||
class FriendRefrigeratorController( | ||
private val friendRefrigeratorService: FriendRefrigeratorService | ||
) { | ||
|
||
@GetMapping("/recent") | ||
fun getRecentFriendRefrigeratorList( | ||
@Qualifier("userPageable") | ||
userPageable: Pageable, | ||
@Qualifier("ingredientPageable") | ||
ingredientPageable: Pageable, | ||
): CommonResponse<Page<FriendRefrigeratorResponse>> { | ||
return success(friendRefrigeratorService.getRecentFriendRefrigeratorList(userPageable, ingredientPageable)) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package mara.server.domain.friend | ||
|
||
import mara.server.domain.ingredient.Ingredient | ||
import mara.server.domain.refrigerator.Refrigerator | ||
import mara.server.domain.user.User | ||
import org.springframework.data.domain.Page | ||
|
||
data class FriendRefrigeratorResponse( | ||
val nickname: String, | ||
val refrigeratorId: Long, | ||
val friendRefrigeratorIngredientGroupList: Page<FriendRefrigeratorIngredient> | ||
) { | ||
constructor(user: User, refrigerator: Refrigerator, ingredientList: Page<Ingredient>) : this( | ||
nickname = user.nickName, | ||
refrigeratorId = refrigerator.refrigeratorId, | ||
friendRefrigeratorIngredientGroupList = ingredientList.map { FriendRefrigeratorIngredient(it) } | ||
) | ||
} | ||
|
||
data class FriendRefrigeratorIngredient( | ||
val name: String, | ||
val iconImage: String, | ||
) { | ||
constructor(ingredient: Ingredient) : this( | ||
name = ingredient.name, | ||
iconImage = ingredient.iconImage | ||
) | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package mara.server.domain.friend | ||
|
||
import mara.server.domain.ingredient.IngredientDetailRepository | ||
import mara.server.domain.refrigerator.RefrigeratorRepository | ||
import mara.server.domain.user.UserService | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class FriendRefrigeratorService( | ||
private val userService: UserService, | ||
private val friendshipRepository: FriendshipRepository, | ||
private val refrigeratorRepository: RefrigeratorRepository, | ||
private val ingredientDetailRepository: IngredientDetailRepository | ||
) { | ||
|
||
fun getRecentFriendRefrigeratorList(userPageable: Pageable, ingredientPageable: Pageable): Page<FriendRefrigeratorResponse> { | ||
val currentLoginUser = userService.getCurrentLoginUser() | ||
val friendshipList = friendshipRepository.findAllByFromUser(currentLoginUser) | ||
.orElseThrow { NoSuchElementException("친구 관계가 존재하지 않습니다.") } | ||
|
||
val userList = friendshipList.map { it.toUser } | ||
val refrigeratorList = refrigeratorRepository.findRefrigeratorByUserIn(userList, userPageable) | ||
|
||
val friendRefrigeratorResponseList = refrigeratorList.map { refrig -> | ||
val ingredientDetailList = ingredientDetailRepository | ||
.findByRefrigeratorAndIsDeletedIsFalse(refrig, ingredientPageable) | ||
val ingredientList = ingredientDetailList.map { it.ingredient } | ||
FriendRefrigeratorResponse(refrig.user, refrig, ingredientList) | ||
} | ||
|
||
return friendRefrigeratorResponseList | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/kotlin/mara/server/domain/refrigerator/RefrigeratorRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package mara.server.domain.refrigerator | ||
|
||
import mara.server.domain.user.User | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface RefrigeratorRepository : JpaRepository<Refrigerator, Long> { | ||
fun findRefrigeratorsByUser(user: User): List<Refrigerator> | ||
|
||
fun findRefrigeratorByUserIn(user: List<User>, pageable: Pageable): Page<Refrigerator> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters