-
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-67 : Figma 화면설계서 기반 기능 점검을 통한 리팩토링 작업 수행 (#28)
* 냉장고 도메인 관련 코드 리팩토링 * 식자재 API documentation 추가 * 식자재 상세 API document 적용 * refrigerator QueryDSL 적용 * QueryDSL IngredientDetail 적용 * S3 API Documentation 추가 * Friendship API Documentation 추가 * FriendRefrigerator API Documentation 추가 * 불필요한 Pageable 사용 API 정리 * 친구 목록 조회 Pageable 추가 * S3 upload @transactional 적용 * kilintFormat 적용 * queryDSL 설정 변경 * IngredientDetail QueryDSL 재적용 * Refrigerator QueryDSL 적용 * friendship QueryDSL 적용 * orderBy 컬럼 추가 * 친구조회 등록일 순 정렬 추가 * ktlint 재적용 * query -> queryFactory 변경 --------- Co-authored-by: JUNGHO KANG <[email protected]>
- Loading branch information
1 parent
53edd17
commit 1bcd93f
Showing
21 changed files
with
269 additions
and
122 deletions.
There are no files selected for viewing
20 changes: 0 additions & 20 deletions
20
src/main/kotlin/mara/server/config/pageable/PageableConfig.kt
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/mara/server/config/querydsl/QueryDslConfig.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,17 @@ | ||
package mara.server.config.querydsl | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import jakarta.persistence.EntityManager | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class QueryDslConfig( | ||
private val em: EntityManager | ||
) { | ||
|
||
@Bean | ||
fun jpaQueryFactory(): JPAQueryFactory { | ||
return JPAQueryFactory(em) | ||
} | ||
} |
17 changes: 6 additions & 11 deletions
17
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 |
---|---|---|
@@ -1,27 +1,22 @@ | ||
package mara.server.domain.friend | ||
|
||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
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") | ||
@Tag(name = "친구 냉장고", description = "친구 냉장고 API") | ||
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)) | ||
@Operation(summary = "친구 냉장고 최신 근황 조회 API") | ||
fun getRecentFriendRefrigeratorList(): CommonResponse<List<FriendRefrigeratorResponse>> { | ||
return success(friendRefrigeratorService.getRecentFriendRefrigeratorList()) | ||
} | ||
} |
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
50 changes: 37 additions & 13 deletions
50
src/main/kotlin/mara/server/domain/friend/FriendshipRepository.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,26 +1,50 @@ | ||
package mara.server.domain.friend | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import mara.server.domain.friend.QFriendship.friendship | ||
import mara.server.domain.user.User | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.PageImpl | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
import org.springframework.stereotype.Repository | ||
import java.util.Optional | ||
|
||
@Repository | ||
interface FriendshipRepository : JpaRepository<Friendship, Long> { | ||
|
||
@Query("select f from Friendship f where f.fromUser = ?1") | ||
fun findAllByFromUser( | ||
user: User | ||
interface FriendshipRepository : JpaRepository<Friendship, Long>, CustomFriendshipRepository { | ||
fun findByFromUser( | ||
user: User, | ||
): Optional<List<Friendship>> | ||
|
||
fun countByFromUser( | ||
user: User | ||
): Long | ||
} | ||
|
||
@Query("select f from Friendship f where (f.fromUser = ?1 and f.toUser = ?2) or (f.fromUser = ?2 and f.toUser = ?1)") | ||
fun findAllByFromUserAndToUser( | ||
fromUser: User, | ||
toUser: User | ||
): Optional<List<Friendship>> | ||
interface CustomFriendshipRepository { | ||
|
||
fun findByFromUserPage(user: User, pageable: Pageable): Page<Friendship> | ||
|
||
fun findByFromUserAndToUser(fromUser: User, toUser: User): List<Friendship> | ||
} | ||
|
||
class CustomFriendshipRepositoryImpl( | ||
private val queryFactory: JPAQueryFactory | ||
) : CustomFriendshipRepository { | ||
|
||
override fun findByFromUserPage(user: User, pageable: Pageable): Page<Friendship> { | ||
val results = queryFactory.select(friendship).from(friendship).where(friendship.fromUser.eq(user)) | ||
.offset(pageable.offset).limit(pageable.pageSize.toLong()).fetch() | ||
|
||
val count = queryFactory.select(friendship.count()).from(friendship) | ||
.where(friendship.fromUser.eq(user)) | ||
.offset(pageable.offset).limit(pageable.pageSize.toLong()).orderBy(friendship.createdAt.asc()).fetchOne() ?: 0 | ||
|
||
return PageImpl(results, pageable, count) | ||
} | ||
|
||
override fun findByFromUserAndToUser(fromUser: User, toUser: User): List<Friendship> { | ||
return queryFactory.selectFrom(friendship).where( | ||
friendship.fromUser.eq(fromUser).and(friendship.toUser.eq(toUser)) | ||
.or(friendship.fromUser.eq(toUser).and(friendship.toUser.eq(fromUser))) | ||
).fetch() | ||
} | ||
} |
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
Oops, something went wrong.