Skip to content

Commit

Permalink
refactor: CategoryType 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jul 1, 2024
1 parent 1bb73a9 commit 11742b5
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.few.api.repo.dao.workbook.command.InsertWorkBookCommand
import com.few.api.repo.dao.workbook.command.MapWorkBookToArticleCommand
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import com.few.api.repo.dao.workbook.record.SelectWorkBookRecord
import com.few.data.common.code.CategoryType
import jooq.jooq_dsl.tables.MappingWorkbookArticle
import jooq.jooq_dsl.tables.Workbook
import org.jooq.DSLContext
Expand Down Expand Up @@ -32,7 +33,7 @@ class WorkbookDao(
return dslContext.insertInto(Workbook.WORKBOOK)
.set(Workbook.WORKBOOK.TITLE, command.title)
.set(Workbook.WORKBOOK.MAIN_IMAGE_URL, command.mainImageUrl.toString())
.set(Workbook.WORKBOOK.CATEGORY_CD, 0) // todo fix
.set(Workbook.WORKBOOK.CATEGORY_CD, CategoryType.convertToCode(command.category))
.set(Workbook.WORKBOOK.DESCRIPTION, command.description)
.returning(Workbook.WORKBOOK.ID)
.fetchOne()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class SelectWorkBookRecord(
val id: Long,
val title: String,
val mainImageUrl: URL,
val category: Long,
val category: Byte,
val description: String,
val createdAt: LocalDateTime
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.few.api.repo.dao.article.query.SelectArticleRecordQuery
import com.few.api.repo.dao.article.query.SelectWorkBookArticleRecordQuery
import com.few.api.repo.dao.article.query.SelectWorkbookMappedArticleRecordsQuery
import com.few.api.repo.jooq.JooqTestSpec
import com.few.data.common.code.CategoryType
import jooq.jooq_dsl.tables.ArticleIfo
import jooq.jooq_dsl.tables.ArticleMst
import jooq.jooq_dsl.tables.MappingWorkbookArticle
Expand Down Expand Up @@ -36,7 +37,7 @@ class ArticleDaoTest : JooqTestSpec() {
.set(ArticleMst.ARTICLE_MST.MEMBER_ID, 1L)
.set(ArticleMst.ARTICLE_MST.MAIN_IMAGE_URL, "http://localhost:8080/image1.jpg")
.set(ArticleMst.ARTICLE_MST.TITLE, "this is title1")
.set(ArticleMst.ARTICLE_MST.CATEGORY_CD, 0)
.set(ArticleMst.ARTICLE_MST.CATEGORY_CD, CategoryType.fromCode(0)!!.code)
.execute()
dslContext.insertInto(ArticleIfo.ARTICLE_IFO)
.set(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID, 1L)
Expand All @@ -63,7 +64,7 @@ class ArticleDaoTest : JooqTestSpec() {
assertEquals(URL("http://localhost:8080/image1.jpg"), result.mainImageURL)
assertEquals("this is title1", result.title)
assertEquals("this is content1", result.content)
assertEquals(0, result.category)
assertEquals(CategoryType.fromCode(0)!!.code, result.category)
}

@Test
Expand All @@ -85,7 +86,7 @@ class ArticleDaoTest : JooqTestSpec() {
assertEquals(URL("http://localhost:8080/image1.jpg"), result.mainImageURL)
assertEquals("this is title1", result.title)
assertEquals("this is content1", result.content)
assertEquals(0, result.category)
assertEquals(CategoryType.fromCode(0)!!.code, result.category)
assertEquals(1L, result.day)
}

Expand All @@ -111,7 +112,7 @@ class ArticleDaoTest : JooqTestSpec() {
assertEquals(URL("http://localhost:8080/image${i + 1}.jpg"), result[i].mainImageURL)
assertEquals("this is title${i + 1}", result[i].title)
assertEquals("this is content${i + 1}", result[i].content)
assertEquals(0, result[i].category) // todo fix
assertEquals(CategoryType.fromCode(0)!!.code, result[i].category)
}
}

Expand Down Expand Up @@ -142,7 +143,7 @@ class ArticleDaoTest : JooqTestSpec() {
.set(ArticleMst.ARTICLE_MST.MEMBER_ID, 1L)
.set(ArticleMst.ARTICLE_MST.MAIN_IMAGE_URL, "http://localhost:8080/image$id.jpg")
.set(ArticleMst.ARTICLE_MST.TITLE, "this is title$id")
.set(ArticleMst.ARTICLE_MST.CATEGORY_CD, 0)
.set(ArticleMst.ARTICLE_MST.CATEGORY_CD, CategoryType.fromCode(0)!!.code)
.execute()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.few.api.repo.dao.workbook

import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import com.few.api.repo.jooq.JooqTestSpec
import com.few.data.common.code.CategoryType
import jooq.jooq_dsl.tables.Workbook
import org.jooq.DSLContext
import org.junit.jupiter.api.Assertions.*
Expand All @@ -25,7 +26,7 @@ class WorkbookDaoTest : JooqTestSpec() {
.set(Workbook.WORKBOOK.ID, 1)
.set(Workbook.WORKBOOK.TITLE, "title1")
.set(Workbook.WORKBOOK.MAIN_IMAGE_URL, "http://localhost:8080/image1.jpg")
.set(Workbook.WORKBOOK.CATEGORY_CD, 0) // todo fix
.set(Workbook.WORKBOOK.CATEGORY_CD, CategoryType.fromCode(0)!!.code)
.set(Workbook.WORKBOOK.DESCRIPTION, "description1")
.execute()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.few.api.repo.dao.problem.ProblemDao
import com.few.api.repo.dao.problem.command.InsertProblemsCommand
import com.few.api.repo.dao.problem.support.Content
import com.few.api.repo.dao.problem.support.Contents
import com.few.data.common.code.CategoryType
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional

Expand All @@ -31,7 +32,7 @@ class AddArticleUseCase(
writerId = writerId.memberId,
mainImageURL = useCaseIn.articleImageUrl,
title = useCaseIn.title,
category = 0, // todo fix
category = CategoryType.convertToCode(useCaseIn.category),
content = useCaseIn.contentSource
).let { articleDao.insertFullArticleRecord(it) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.few.api.domain.article.service.dto.BrowseArticleProblemIdsQuery
import com.few.api.domain.article.service.dto.ReadWriterRecordQuery
import com.few.api.repo.dao.article.ArticleDao
import com.few.api.repo.dao.article.query.SelectArticleRecordQuery
import com.few.data.common.code.CategoryType
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional

Expand Down Expand Up @@ -43,7 +44,7 @@ class ReadArticleUseCase(
title = articleRecord.title,
content = articleRecord.content,
problemIds = problemIds.problemIds,
category = articleRecord.category.toString(), // todo fix to enum
category = CategoryType.convertToDisplayName(articleRecord.category),
createdAt = articleRecord.createdAt
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.few.api.domain.workbook.article.dto.ReadWorkBookArticleOut
import com.few.api.domain.workbook.article.dto.WriterDetail
import com.few.api.repo.dao.article.ArticleDao
import com.few.api.repo.dao.article.query.SelectWorkBookArticleRecordQuery
import com.few.data.common.code.CategoryType
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

Expand Down Expand Up @@ -47,7 +48,7 @@ class ReadWorkBookArticleUseCase(
title = articleRecord.title,
content = articleRecord.content,
problemIds = problemIds.problemIds,
category = articleRecord.category.toString(), // todo fix to enum
category = CategoryType.convertToDisplayName(articleRecord.category),
createdAt = articleRecord.createdAt,
day = articleRecord.day
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.few.api.domain.workbook.service.dto.BrowseWorkbookArticlesQuery
import com.few.api.domain.workbook.service.dto.BrowseWriterRecordsQuery
import com.few.api.repo.dao.workbook.WorkbookDao
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import com.few.data.common.code.CategoryType
import org.springframework.stereotype.Component

@Component
Expand Down Expand Up @@ -36,7 +37,7 @@ class ReadWorkbookUseCase(
mainImageUrl = workbookRecord.mainImageUrl,
title = workbookRecord.title,
description = workbookRecord.description,
category = workbookRecord.category.toString(), // todo fix enum to string
category = CategoryType.convertToDisplayName(workbookRecord.category),
createdAt = workbookRecord.createdAt,
writers = writerRecords.toWriterDetails(),
articles = workbookMappedArticles.toArticleDetails()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.few.api.web.controller.admin.request.*
import com.few.api.web.controller.admin.response.ImageSourceResponse
import com.few.api.web.controller.description.Description
import com.few.api.web.controller.helper.*
import com.few.data.common.code.CategoryType
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -88,7 +89,7 @@ class AdminControllerTest : ControllerTestSpec() {
val uri = UriComponentsBuilder.newInstance().path("$BASE_URL/workbooks").build().toUriString()
val title = "title"
val mainImageUrl = URL("http://localhost:8080")
val category = "category"
val category = CategoryType.fromCode(0)!!.name
val description = "description"
val request = AddWorkbookRequest(title, mainImageUrl, category, description)
val body = objectMapper.writeValueAsString(request)
Expand Down Expand Up @@ -135,7 +136,7 @@ class AdminControllerTest : ControllerTestSpec() {
"[email protected]",
URL("http://localhost:8080"),
"title",
"category",
CategoryType.fromCode(0)!!.name,
"contentSource",
ProblemDto(
"title",
Expand All @@ -157,7 +158,7 @@ class AdminControllerTest : ControllerTestSpec() {
"[email protected]",
URL("http://localhost:8080"),
"title",
"category",
CategoryType.fromCode(0)!!.name,
"contentSource",
ProblemDetail(
"title",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.few.api.domain.article.usecase.ReadArticleUseCase
import com.few.api.web.controller.ControllerTestSpec
import com.few.api.web.controller.description.Description
import com.few.api.web.controller.helper.*
import com.few.data.common.code.CategoryType
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -77,7 +78,7 @@ class ArticleControllerTest : ControllerTestSpec() {
url = URL("http://localhost:8080/api/v1/writers/1")
),
title = "ETF(상장 지수 펀드)란? 모르면 손해라고?",
content = "content",
content = CategoryType.fromCode(0)!!.name,
problemIds = listOf(1L, 2L, 3L),
category = "경제",
createdAt = LocalDateTime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.few.api.domain.workbook.usecase.ReadWorkbookUseCase
import com.few.api.web.controller.ControllerTestSpec
import com.few.api.web.controller.description.Description
import com.few.api.web.controller.helper.*
import com.few.data.common.code.CategoryType
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
Expand Down Expand Up @@ -79,7 +80,7 @@ class WorkBookControllerTest : ControllerTestSpec() {
mainImageUrl = URL("http://localhost:8080/api/v1/workbooks/1/image"),
title = "재태크, 투자 필수 용어 모음집",
description = "사회 초년생부터, 직장인, 은퇴자까지 모두가 알아야 할 기본적인 재태크, 투자 필수 용어 모음집 입니다.",
category = "경제",
category = CategoryType.fromCode(0)!!.name,
createdAt = LocalDateTime.now(),
writers = listOf(
WriterDetail(1L, "안나포", URL("http://localhost:8080/api/v1/users/1")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.few.api.domain.workbook.article.usecase.ReadWorkBookArticleUseCase
import com.few.api.web.controller.ControllerTestSpec
import com.few.api.web.controller.description.Description
import com.few.api.web.controller.helper.*
import com.few.data.common.code.CategoryType
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -83,7 +84,7 @@ class WorkBookArticleControllerTest : ControllerTestSpec() {
title = "ETF(상장 지수 펀드)란? 모르면 손해라고?",
content = "content",
problemIds = listOf(1L, 2L, 3L),
category = "경제",
category = CategoryType.fromCode(0)!!.name,
createdAt = LocalDateTime.now(),
day = 1L
)
Expand Down

0 comments on commit 11742b5

Please sign in to comment.