-
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.
Browse files
Browse the repository at this point in the history
[Feat]: Article 조회(단건, 페이징) API 설계
- Loading branch information
Showing
52 changed files
with
828 additions
and
60 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ spring: | |
config: | ||
import: | ||
- application-persistence.yml | ||
- application-internal.yml |
5 changes: 0 additions & 5 deletions
5
community-application/src/main/kotlin/gloddy/article/dto/read/ArticleIdReadData.kt
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
community-application/src/main/kotlin/gloddy/article/port/in/ArticleCommandUseCase.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,10 @@ | ||
package gloddy.article.port.`in` | ||
|
||
import gloddy.article.dto.command.ArticleCreateCommand | ||
import gloddy.article.dto.read.ArticleIdReadData | ||
import gloddy.article.port.`in`.dto.command.ArticleCreateRequest | ||
import gloddy.article.port.`in`.dto.read.ArticleCreateResponse | ||
|
||
interface ArticleCommandUseCase { | ||
fun create(userId: Long, command: ArticleCreateCommand): ArticleIdReadData | ||
fun create(userId: Long, command: ArticleCreateRequest): ArticleCreateResponse | ||
fun delete(userId: Long, articleId: Long) | ||
fun like(userId: Long, articleId: Long) | ||
fun upsertLike(userId: Long, articleId: Long) | ||
} |
7 changes: 7 additions & 0 deletions
7
community-application/src/main/kotlin/gloddy/article/port/in/ArticleOrder.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 gloddy.article.port.`in` | ||
|
||
enum class ArticleOrder( | ||
val value: String | ||
) { | ||
LATEST("최신순") | ||
} |
11 changes: 11 additions & 0 deletions
11
community-application/src/main/kotlin/gloddy/article/port/in/ArticleQueryUseCase.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,11 @@ | ||
package gloddy.article.port.`in` | ||
|
||
import gloddy.article.port.`in`.dto.command.ArticleDetailGetRequest | ||
import gloddy.article.port.`in`.dto.command.ArticleDetailPageGetRequest | ||
import gloddy.article.port.`in`.dto.read.ArticleDetailResponse | ||
import gloddy.core.dto.PageResponse | ||
|
||
interface ArticleQueryUseCase { | ||
fun getArticleDetailPage(request: ArticleDetailPageGetRequest): PageResponse<ArticleDetailResponse> | ||
fun getArticleDetail(request: ArticleDetailGetRequest): ArticleDetailResponse | ||
} |
4 changes: 2 additions & 2 deletions
4
...ticle/dto/command/ArticleCreateCommand.kt → ...rt/in/dto/command/ArticleCreateRequest.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
6 changes: 6 additions & 0 deletions
6
...application/src/main/kotlin/gloddy/article/port/in/dto/command/ArticleDetailGetRequest.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,6 @@ | ||
package gloddy.article.port.`in`.dto.command | ||
|
||
data class ArticleDetailGetRequest( | ||
val id: Long, | ||
val userId: Long | ||
) |
11 changes: 11 additions & 0 deletions
11
...ication/src/main/kotlin/gloddy/article/port/in/dto/command/ArticleDetailPageGetRequest.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,11 @@ | ||
package gloddy.article.port.`in`.dto.command | ||
|
||
import gloddy.article.port.`in`.ArticleOrder | ||
|
||
data class ArticleDetailPageGetRequest( | ||
val categoryId: Long?, | ||
val userId: Long, | ||
val size: Int, | ||
val page: Int, | ||
val order: ArticleOrder | ||
) |
5 changes: 5 additions & 0 deletions
5
...nity-application/src/main/kotlin/gloddy/article/port/in/dto/read/ArticleCreateResponse.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,5 @@ | ||
package gloddy.article.port.`in`.dto.read | ||
|
||
data class ArticleCreateResponse( | ||
val articleId: Long | ||
) |
8 changes: 8 additions & 0 deletions
8
...nity-application/src/main/kotlin/gloddy/article/port/in/dto/read/ArticleDetailResponse.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,8 @@ | ||
package gloddy.article.port.`in`.dto.read | ||
|
||
import gloddy.user.port.`in`.dto.UserPreviewUnit | ||
|
||
data class ArticleDetailResponse( | ||
val article: ArticleDetailUnit, | ||
val writer: UserPreviewUnit | ||
) |
18 changes: 18 additions & 0 deletions
18
community-application/src/main/kotlin/gloddy/article/port/in/dto/read/ArticleDetailUnit.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,18 @@ | ||
package gloddy.article.port.`in`.dto.read | ||
|
||
import gloddy.category.port.`in`.dto.CategoryGetResponse | ||
|
||
data class ArticleDetailUnit( | ||
val id: Long, | ||
val userId: Long, | ||
val isWriter: Boolean, | ||
val isLiked: Boolean, | ||
val category: CategoryGetResponse, | ||
val title: String, | ||
val content: String, | ||
val thumbnail: String?, | ||
val images: List<String>?, | ||
val likeCount: Int, | ||
val commentCount: Int, | ||
val createdAt: String | ||
) |
2 changes: 2 additions & 0 deletions
2
...nity-application/src/main/kotlin/gloddy/article/port/out/ArticleCommandPersistencePort.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,8 +1,10 @@ | ||
package gloddy.article.port.out | ||
|
||
import gloddy.article.Article | ||
import gloddy.article.ArticleLike | ||
|
||
interface ArticleCommandPersistencePort { | ||
fun save(article: Article) : Article | ||
fun delete(id: Long) | ||
fun upsertLike(articleLike: ArticleLike, article: Article) | ||
} |
16 changes: 16 additions & 0 deletions
16
community-application/src/main/kotlin/gloddy/article/port/out/ArticleQueryPersistencePort.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,7 +1,23 @@ | ||
package gloddy.article.port.out | ||
|
||
import gloddy.article.Article | ||
import gloddy.article.port.`in`.dto.read.ArticleDetailUnit | ||
import gloddy.article.port.`in`.ArticleOrder | ||
import gloddy.core.dto.PageResponse | ||
|
||
interface ArticleQueryPersistencePort { | ||
fun findById(id: Long): Article | ||
|
||
fun findArticleDetailUnitPageByCategoryId( | ||
categoryId: Long? = null, | ||
userId: Long, | ||
size: Int, | ||
page: Int, | ||
order: ArticleOrder, | ||
): PageResponse<ArticleDetailUnit> | ||
|
||
fun findArticleDetailUnitById( | ||
id: Long, | ||
userId: Long | ||
): ArticleDetailUnit | ||
} |
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
57 changes: 57 additions & 0 deletions
57
community-application/src/main/kotlin/gloddy/article/service/ArticleQueryService.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,57 @@ | ||
package gloddy.article.service | ||
|
||
import gloddy.article.port.`in`.ArticleQueryUseCase | ||
import gloddy.article.port.`in`.dto.command.ArticleDetailGetRequest | ||
import gloddy.article.port.`in`.dto.command.ArticleDetailPageGetRequest | ||
import gloddy.article.port.`in`.dto.read.ArticleDetailResponse | ||
import gloddy.article.port.out.ArticleQueryPersistencePort | ||
import gloddy.core.dto.PageResponse | ||
import gloddy.user.port.out.UserQueryPort | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ArticleQueryService( | ||
private val userQueryPort: UserQueryPort, | ||
private val articleQueryPersistencePort: ArticleQueryPersistencePort, | ||
) : ArticleQueryUseCase { | ||
|
||
override fun getArticleDetailPage(request: ArticleDetailPageGetRequest): PageResponse<ArticleDetailResponse> { | ||
val articleDetailUnitPage = articleQueryPersistencePort.findArticleDetailUnitPageByCategoryId( | ||
categoryId = request.categoryId, | ||
userId = request.userId, | ||
size = request.size, | ||
page = request.page, | ||
order = request.order | ||
) | ||
|
||
val userPreviewUnits = userQueryPort.getUserPreviewUnits( | ||
userIds = articleDetailUnitPage.contents.map { it.userId }.toSet() | ||
) | ||
|
||
return PageResponse( | ||
totalCount = articleDetailUnitPage.totalCount, | ||
currentCount = articleDetailUnitPage.currentCount, | ||
totalPage = articleDetailUnitPage.totalPage, | ||
currentPage = articleDetailUnitPage.currentPage, | ||
contents = articleDetailUnitPage.contents | ||
.map { | ||
ArticleDetailResponse( | ||
article = it, | ||
writer = userPreviewUnits[it.userId]!! | ||
) | ||
} | ||
) | ||
} | ||
|
||
override fun getArticleDetail(request: ArticleDetailGetRequest): ArticleDetailResponse { | ||
val articleDetailUnit = articleQueryPersistencePort.findArticleDetailUnitById( | ||
id = request.id, | ||
userId = request.userId | ||
) | ||
val userPreviewUnit = userQueryPort.getUserPreviewUnit(request.userId) | ||
return ArticleDetailResponse( | ||
article = articleDetailUnit, | ||
writer = userPreviewUnit | ||
) | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
community-application/src/main/kotlin/gloddy/category/port/dto/CategoryReadData.kt
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
community-application/src/main/kotlin/gloddy/category/port/in/CategoryQueryUseCase.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,7 +1,7 @@ | ||
package gloddy.category.port.`in` | ||
|
||
import gloddy.category.port.dto.CategoryReadData | ||
import gloddy.category.port.`in`.dto.CategoryGetResponse | ||
|
||
interface CategoryQueryUseCase { | ||
fun getAll(): List<CategoryReadData> | ||
fun getAll(): List<CategoryGetResponse> | ||
} |
6 changes: 6 additions & 0 deletions
6
community-application/src/main/kotlin/gloddy/category/port/in/dto/CategoryGetResponse.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,6 @@ | ||
package gloddy.category.port.`in`.dto | ||
|
||
data class CategoryGetResponse( | ||
val id: Long, | ||
val name: String | ||
) |
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
9 changes: 9 additions & 0 deletions
9
community-application/src/main/kotlin/gloddy/core/dto/PageResponse.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,9 @@ | ||
package gloddy.core.dto | ||
|
||
data class PageResponse<T>( | ||
val totalCount: Long, | ||
val currentCount: Int, | ||
val totalPage: Int, | ||
val currentPage: Int, | ||
val contents: List<T> | ||
) |
8 changes: 8 additions & 0 deletions
8
community-application/src/main/kotlin/gloddy/core/util/DateTimeUtil.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,8 @@ | ||
package gloddy.core.util | ||
|
||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter.* | ||
|
||
fun LocalDateTime.toResponse(): String = | ||
this.format(ofPattern("yyyy-MM-dd hh:mm")) | ||
.replace(" ", "T") |
11 changes: 11 additions & 0 deletions
11
community-application/src/main/kotlin/gloddy/user/port/in/dto/UserPreviewUnit.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,11 @@ | ||
package gloddy.user.port.`in`.dto | ||
|
||
data class UserPreviewUnit( | ||
val id: Long, | ||
val isCertifiedStudent: Boolean, | ||
val profileImage: String, | ||
val nickName: String, | ||
val countryName: String?, | ||
val countryImage: String?, | ||
val reliabilityLevel: String | ||
) |
8 changes: 8 additions & 0 deletions
8
community-application/src/main/kotlin/gloddy/user/port/out/UserQueryPort.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,8 @@ | ||
package gloddy.user.port.out | ||
|
||
import gloddy.user.port.`in`.dto.UserPreviewUnit | ||
|
||
interface UserQueryPort { | ||
fun getUserPreviewUnit(userId: Long): UserPreviewUnit | ||
fun getUserPreviewUnits(userIds: Set<Long>): Map<Long, UserPreviewUnit> | ||
} |
Oops, something went wrong.