Skip to content

Commit

Permalink
[feat #208] 포킷 목록 조회 api v2 (#209)
Browse files Browse the repository at this point in the history
* feat : 포킷 목록 조회 API Ver2

* feat : 포킷 목록 조회 비즈니스 로직 ver2

* feat : 공유 포킷 조회 쿼리 구현

* feat : 카테고리 Id 리스트로 조회 쿼리 구현
  • Loading branch information
dlswns2480 authored Dec 20, 2024
1 parent d7e5166 commit ec506e7
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ package com.pokit.category.v2

import com.pokit.auth.config.ErrorOperation
import com.pokit.auth.model.PrincipalUser
import com.pokit.category.dto.CategoriesResponse
import com.pokit.category.exception.CategoryErrorCode
import com.pokit.category.port.`in`.CategoryUseCase
import com.pokit.category.v1.dto.response.CategoryResponse
import com.pokit.category.v1.dto.response.toResponse
import com.pokit.category.v2.dto.request.CreateCategoryRequestV2
import com.pokit.category.v2.dto.request.toDto
import com.pokit.common.dto.SliceResponseDto
import com.pokit.common.wrapper.ResponseWrapper.wrapOk
import com.pokit.common.wrapper.ResponseWrapper.wrapSlice
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Sort
import org.springframework.data.web.PageableDefault
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.*
Expand All @@ -34,7 +40,7 @@ class CategoryControllerV2(
.wrapOk()
}

@Operation(summary = "포킷 추가 API Ver2")
@Operation(summary = "포킷 수정 API Ver2")
@ErrorOperation(CategoryErrorCode::class)
@PatchMapping("/{categoryId}")
fun updateCategory(
Expand All @@ -47,4 +53,21 @@ class CategoryControllerV2(
.wrapOk()
}

@Operation(summary = "포킷 목록 조회 API Ver2")
@GetMapping
fun getCategory(
@AuthenticationPrincipal user: PrincipalUser,
@PageableDefault(
page = 0,
size = 10,
sort = ["createdAt"],
direction = Sort.Direction.DESC
) pageable: Pageable,
@RequestParam(defaultValue = "true") filterUncategorized: Boolean
): ResponseEntity<SliceResponseDto<CategoriesResponse>> {
return categoryUseCase.getCategoriesV2(user.id, pageable, filterUncategorized)
.wrapSlice()
.wrapOk()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ class CategoryAdapter(
?.toDomain()
}

override fun loadAllInId(categoryIds: List<Long>, pageable: Pageable): Slice<Category> {
return categoryRepository.findAllByIdInAndDeleted(categoryIds, pageable, false)
.map { it.toDomain() }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ class SharedCategoryAdapter(
false
)?.toDomain()
}

override fun loadByUserId(userId: Long): List<SharedCategory> {
return sharedCategoryRepository.findByUserIdAndIsDeleted(userId, false)
.map { it.toDomain() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ interface CategoryRepository : JpaRepository<CategoryEntity, Long> {
fun countByUserIdAndDeleted(userId: Long, deleted: Boolean): Int
fun findByIdAndOpenTypeAndDeleted(id: Long, openType: OpenType, deleted: Boolean): CategoryEntity?
fun findByNameAndUserId(name: String, userId: Long): CategoryEntity?
fun findAllByIdInAndDeleted(
categoryIds: List<Long>,
pageable: Pageable,
isDeleted: Boolean
): Slice<CategoryEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ interface SharedCategoryRepository : JpaRepository<SharedCategoryEntity, Long> {
categoryId: Long,
deleted: Boolean
): SharedCategoryEntity?

fun findByUserIdAndIsDeleted(userId: Long, isDeleted: Boolean): List<SharedCategoryEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ interface CategoryUseCase {
fun acceptCategory(userId: Long, categoryId: Long)
fun resignUser(userId: Long, categoryId: Long, resignUserId: Long)
fun outCategory(userId: Long, categoryId: Long)
fun getCategoriesV2(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice<CategoriesResponse>

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ interface CategoryPort {
fun countByUserId(userId: Long): Int
fun loadByIdAndOpenType(id: Long, openType: OpenType): Category?
fun loadByNameAndUserId(categoryName: String, userId: Long): Category?
fun loadAllInId(categoryIds: List<Long>, pageable: Pageable): Slice<Category>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ interface SharedCategoryPort {
fun delete(sharedCategory: SharedCategory)

fun loadFirstByCategoryId(categoryId: Long): SharedCategory?

fun loadByUserId(userId: Long): List<SharedCategory>
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ class CategoryService(
categoryPort.persist(category)
}

override fun getCategoriesV2(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice<CategoriesResponse> {
val sharedCategories = sharedCategoryPort.loadByUserId(userId)
val categoryIds = sharedCategories.map { it.categoryId }
val categories = categoryPort.loadAllInId(categoryIds, pageable)
return categories.map { it.toCategoriesResponse() }
}

override fun getAllCategoryImages(): List<CategoryImage> =
categoryImagePort.loadAll()

Expand Down

0 comments on commit ec506e7

Please sign in to comment.