-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 공유 컨텐츠 미리보기 API * fix: 타이틀 max 1000으로 조정 * fix: 오탈자 수정 * fix: datetime 포맷 수정 * fix: 필요없는 반환 삭제
- Loading branch information
Showing
21 changed files
with
274 additions
and
23 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
adapters/in-web/src/main/kotlin/com/pokit/category/CategoryShareController.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,51 @@ | ||
package com.pokit.category | ||
|
||
import com.pokit.auth.model.PrincipalUser | ||
import com.pokit.category.dto.response.SharedContentsResponse | ||
import com.pokit.category.port.`in`.CategoryUseCase | ||
import com.pokit.common.wrapper.ResponseWrapper.wrapOk | ||
import com.pokit.content.port.`in`.ContentUseCase | ||
import io.swagger.v3.oas.annotations.Operation | ||
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.* | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/category/share") | ||
class CategoryShareController( | ||
private val categoryUseCase: CategoryUseCase, | ||
private val contentUseCase: ContentUseCase, | ||
) { | ||
@Operation(summary = "포킷 공유 후 callback API") | ||
@PostMapping("/callback") | ||
fun completeShare( | ||
@AuthenticationPrincipal user: PrincipalUser, | ||
@RequestParam("categoryId") categoryId: Long, | ||
): ResponseEntity<Unit> { | ||
return categoryUseCase.completeShare(categoryId, user.id) | ||
.wrapOk() | ||
} | ||
|
||
@Operation(summary = "포킷 공유 시 포킷 내 컨텐츠 미리보기 API") | ||
@GetMapping("/{categoryId}") | ||
fun getSharedContents( | ||
@AuthenticationPrincipal user: PrincipalUser, | ||
@PathVariable categoryId: Long, | ||
@PageableDefault( | ||
page = 0, | ||
size = 10, | ||
sort = ["createdAt"], | ||
direction = Sort.Direction.DESC | ||
) pageable: Pageable, | ||
): ResponseEntity<SharedContentsResponse> { | ||
val category = categoryUseCase.getSharedCategory(categoryId, user.id) | ||
val content = contentUseCase.getSharedContents(categoryId, pageable) | ||
return SharedContentsResponse | ||
.from(content, category) | ||
.wrapOk() | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
adapters/in-web/src/main/kotlin/com/pokit/category/dto/response/SharedContentsResponse.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,66 @@ | ||
package com.pokit.category.dto.response | ||
|
||
import com.pokit.category.model.Category | ||
import com.pokit.common.dto.DateFormatters | ||
import com.pokit.common.dto.SliceResponseDto | ||
import com.pokit.common.wrapper.ResponseWrapper.wrapSlice | ||
import com.pokit.content.dto.response.SharedContentResult | ||
import org.springframework.data.domain.Slice | ||
import org.springframework.data.domain.SliceImpl | ||
|
||
data class SharedContentsResponse( | ||
var category: SharedCategoryResponse, | ||
var contents: SliceResponseDto<SharedContentResponse> | ||
) { | ||
companion object { | ||
fun from(sharedContents: Slice<SharedContentResult>, category: Category): SharedContentsResponse { | ||
val sharedContentResponse = sharedContents.content.map { SharedContentResponse.of(it) } | ||
val contents = SliceImpl(sharedContentResponse, sharedContents.pageable, sharedContents.hasNext()) | ||
|
||
return SharedContentsResponse( | ||
category = SharedCategoryResponse.of(category), | ||
contents = contents.wrapSlice(), | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class SharedContentResponse( | ||
val contentId: Long, | ||
val data: String, | ||
val domain: String, | ||
val title: String, | ||
val memo: String, | ||
val createdAt: String, | ||
val thumbNail: String, | ||
) { | ||
companion object { | ||
fun of(content: SharedContentResult): SharedContentResponse { | ||
return SharedContentResponse( | ||
contentId = content.contentId, | ||
data = content.data, | ||
domain = content.domain, | ||
title = content.title, | ||
memo = content.memo, | ||
createdAt = content.createdAt.format(DateFormatters.DATE_FORMAT_YYYY_MM_DD), | ||
thumbNail = content.thumbNail, | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class SharedCategoryResponse( | ||
val categoryId: Long = 0L, | ||
var categoryName: String, | ||
var contentCount: Int = 0, | ||
) { | ||
companion object { | ||
fun of(category: Category): SharedCategoryResponse { | ||
return SharedCategoryResponse( | ||
categoryId = category.categoryId, | ||
categoryName = category.categoryName, | ||
contentCount = category.contentCount, | ||
) | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
adapters/in-web/src/main/kotlin/com/pokit/common/dto/DateFormatter.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,7 @@ | ||
package com.pokit.common.dto | ||
|
||
import java.time.format.DateTimeFormatter | ||
|
||
object DateFormatters { | ||
val DATE_FORMAT_YYYY_MM_DD: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy.MM.dd") | ||
} |
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
Empty file.
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
3 changes: 3 additions & 0 deletions
3
application/src/main/kotlin/com/pokit/category/port/out/CategoryPort.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,14 +1,17 @@ | ||
package com.pokit.category.port.out | ||
|
||
import com.pokit.category.model.Category | ||
import com.pokit.category.model.OpenType | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.domain.Slice | ||
|
||
interface CategoryPort { | ||
fun loadAllByUserId(userId: Long, pageable: Pageable): Slice<Category> | ||
fun loadByIdAndUserId(id: Long, userId: Long): Category? | ||
fun loadById(id: Long): Category? | ||
fun existsByNameAndUserId(name: String, userId: Long): Boolean | ||
fun persist(category: Category): Category | ||
fun delete(category: Category) | ||
fun countByUserId(userId: Long): Int | ||
fun loadByIdAndOpenType(id: Long, openType: OpenType): Category? | ||
} |
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.