Skip to content

Commit

Permalink
chore: merge from main (resolve conflict)
Browse files Browse the repository at this point in the history
  • Loading branch information
hun-ca committed Jun 23, 2024
2 parents 72795d8 + be09bd6 commit 20141ce
Show file tree
Hide file tree
Showing 45 changed files with 1,091 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.few.api.repo.dao.article

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.record.SelectArticleRecord
import com.few.api.repo.dao.article.record.SelectWorkBookArticleRecord
import jooq.jooq_dsl.tables.ArticleIfo
import jooq.jooq_dsl.tables.ArticleMst
import jooq.jooq_dsl.tables.MappingWorkbookArticle
import org.jooq.DSLContext
import org.springframework.stereotype.Repository

@Repository
class ArticleDao(
private val dslContext: DSLContext
) {
fun selectArticleRecord(query: SelectArticleRecordQuery): SelectArticleRecord {
val articleId = query.articleId

return dslContext.select(
ArticleMst.ARTICLE_MST.ID.`as`(SelectArticleRecord::articleId.name),
ArticleMst.ARTICLE_MST.MEMBER_ID.`as`(SelectArticleRecord::writerId.name),
ArticleMst.ARTICLE_MST.MAIN_IMAGE_URL.`as`(SelectArticleRecord::mainImageURL.name),
ArticleMst.ARTICLE_MST.TITLE.`as`(SelectArticleRecord::title.name),
ArticleMst.ARTICLE_MST.CATEGORY_CD.`as`(SelectArticleRecord::category.name),
ArticleIfo.ARTICLE_IFO.CONTENT.`as`(SelectArticleRecord::content.name),
ArticleMst.ARTICLE_MST.CREATED_AT.`as`(SelectArticleRecord::createdAt.name)
).from(ArticleMst.ARTICLE_MST)
.join(ArticleIfo.ARTICLE_IFO)
.on(ArticleMst.ARTICLE_MST.ID.eq(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID))
.where(ArticleMst.ARTICLE_MST.ID.eq(articleId))
.fetchOneInto(SelectArticleRecord::class.java)
?: throw IllegalArgumentException("cannot find article record by articleId: $articleId")
}

fun selectWorkBookArticleRecord(query: SelectWorkBookArticleRecordQuery): SelectWorkBookArticleRecord {
val articleMst = ArticleMst.ARTICLE_MST
val articleIfo = ArticleIfo.ARTICLE_IFO
val mappingWorkbookArticle = MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE

val articleId = query.articleId
val workbookId = query.workbookId

return dslContext.select(
articleMst.ID.`as`(SelectWorkBookArticleRecord::articleId.name),
articleMst.MEMBER_ID.`as`(SelectWorkBookArticleRecord::writerId.name),
articleMst.MAIN_IMAGE_URL.`as`(SelectWorkBookArticleRecord::mainImageURL.name),
articleMst.TITLE.`as`(SelectWorkBookArticleRecord::title.name),
articleMst.CATEGORY_CD.`as`(SelectWorkBookArticleRecord::category.name),
articleIfo.CONTENT.`as`(SelectWorkBookArticleRecord::content.name),
articleMst.CREATED_AT.`as`(SelectWorkBookArticleRecord::createdAt.name),
mappingWorkbookArticle.DAY_COL.`as`(SelectWorkBookArticleRecord::day.name)
).from(articleMst)
.join(articleIfo)
.on(articleMst.ID.eq(articleIfo.ARTICLE_MST_ID))
.join(mappingWorkbookArticle)
.on(mappingWorkbookArticle.WORKBOOK_ID.eq(workbookId))
.and(mappingWorkbookArticle.ARTICLE_ID.eq(articleMst.ID))
.where(articleMst.ID.eq(articleId))
.fetchOneInto(SelectWorkBookArticleRecord::class.java)
?: throw IllegalArgumentException("cannot find $workbookId article record by articleId: $articleId")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.article.query

data class SelectArticleRecordQuery(
val articleId: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.few.api.repo.dao.article.query

data class SelectWorkBookArticleRecordQuery(
val workbookId: Long,
val articleId: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.few.api.repo.dao.article.record

import java.time.LocalDateTime

data class SelectArticleRecord(
val articleId: Long,
val writerId: Long,
val mainImageURL: String,
val title: String,
val category: Byte,
val content: String,
val createdAt: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.few.api.repo.dao.article.record

import java.time.LocalDateTime

data class SelectWorkBookArticleRecord(
val articleId: Long,
val writerId: Long,
val mainImageURL: String,
val title: String,
val category: Byte,
val content: String,
val createdAt: LocalDateTime,
val day: Long
)
29 changes: 29 additions & 0 deletions api-repo/src/main/kotlin/com/few/api/repo/dao/member/MemberDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.few.api.repo.dao.member

import com.few.api.repo.dao.member.query.SelectWriterQuery
import com.few.api.repo.dao.member.record.WriterRecord
import jooq.jooq_dsl.tables.Member
import org.jooq.DSLContext
import org.jooq.impl.DSL
import org.springframework.stereotype.Repository

@Repository
class MemberDao(
private val dslContext: DSLContext
) {

fun selectWriter(query: SelectWriterQuery): WriterRecord {
val writerId = query.writerId

return dslContext.select(
Member.MEMBER.ID.`as`(WriterRecord::writerId.name),
DSL.jsonGetAttributeAsText(Member.MEMBER.DESCRIPTION, "name").`as`(WriterRecord::name.name),
DSL.jsonGetAttribute(Member.MEMBER.DESCRIPTION, "url").`as`(WriterRecord::url.name)
)
.from(Member.MEMBER)
.where(Member.MEMBER.ID.eq(writerId))
.and(Member.MEMBER.TYPE_CD.eq(1)) // todo fix after considering the type_cd
.fetchOneInto(WriterRecord::class.java)
?: throw IllegalArgumentException("cannot find writer record by writerId: $writerId")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.member.query

data class SelectWriterQuery(
val writerId: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.few.api.repo.dao.member.record

import java.net.URL

data class WriterRecord(
val writerId: Long,
val name: String,
val url: URL
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.few.api.repo.dao.member.support

import java.net.URL

data class WriterDescription(
val name: String,
val url: URL
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.few.api.repo.dao.member.support

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import org.springframework.stereotype.Component

@Component
class WriterDescriptionJsonMapper(
private val objectMapper: ObjectMapper
) {
init {
objectMapper.registerKotlinModule()
}

fun toJson(writerDescription: WriterDescription): String {
return objectMapper.writeValueAsString(writerDescription)
}

fun toObject(value: String): WriterDescription {
return objectMapper.readValue(value, WriterDescription::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.few.api.repo.dao.member.support

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import org.springframework.stereotype.Component

@Component
class WriterDescriptionMapper(
private val objectMapper: ObjectMapper
) {
init {
objectMapper.registerKotlinModule()
}

fun toJson(writerDescription: WriterDescription): String {
return objectMapper.writeValueAsString(writerDescription)
}

fun toObject(value: String): WriterDescription {
return objectMapper.readValue(value, WriterDescription::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.few.api.repo.dao.problem

import com.few.api.repo.dao.problem.query.SelectProblemAnswerQuery
import com.few.api.repo.dao.problem.query.SelectProblemQuery
import com.few.api.repo.dao.problem.query.SelectProblemsByArticleIdQuery
import com.few.api.repo.dao.problem.record.ProblemIdsRecord
import com.few.api.repo.dao.problem.record.SelectProblemAnswerRecord
import com.few.api.repo.dao.problem.record.SelectProblemRecord
import jooq.jooq_dsl.tables.Problem
Expand Down Expand Up @@ -39,4 +41,15 @@ class ProblemDao(
.fetchOneInto(SelectProblemAnswerRecord::class.java)
?: throw RuntimeException("Problem Answer with ID ${query.problemId} not found") // TODO: 에러 표준화
}

fun selectProblemsByArticleId(query: SelectProblemsByArticleIdQuery): ProblemIdsRecord {
val articleId = query.articleId

return dslContext.select()
.from(Problem.PROBLEM)
.where(Problem.PROBLEM.ARTICLE_ID.eq(articleId))
.fetch()
.map { it[Problem.PROBLEM.ID] }
.let { ProblemIdsRecord(it) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.problem.query

data class SelectProblemsByArticleIdQuery(
val articleId: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.problem.record

data class ProblemIdsRecord(
val problemIds: List<Long>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.few.api.repo.dao.problem.support

data class Contents(
val contents: List<Content>
)

data class Content(
val number: Long,
val content: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.few.api.repo.dao.problem.support

import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.stereotype.Component

@Component
class ContentsJsonMapper(
private val objectMapper: ObjectMapper
) {

fun toJson(contents: Contents): String {
return objectMapper.writeValueAsString(contents)
}

fun toObject(value: String): Contents {
val contents = objectMapper.readTree(value).get("contents")
val contentList = mutableListOf<Content>()
contents.forEach {
contentList.add(Content(it.get("id").asLong(), it.get("content").asText()))
}
return Contents(contentList)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.few.api.repo.dao.problem.support

import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.stereotype.Component

@Component
class ContentsMapper(
private val objectMapper: ObjectMapper
) {

fun toJson(contents: Contents): String {
return objectMapper.writeValueAsString(contents)
}

fun toObject(value: String): Contents {
val contents = objectMapper.readTree(value).get("contents")
val contentList = mutableListOf<Content>()
contents.forEach {
contentList.add(Content(it.get("id").asLong(), it.get("content").asText()))
}
return Contents(contentList)
}
}
Loading

0 comments on commit 20141ce

Please sign in to comment.