Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/#293] 멤버 이미지 컬럼 추가 반영 #297

Closed
wants to merge 8 commits into from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ api-repo/**/*.sql
batch/**/*.sql
email/**/*.sql
storage/**/*.sql

# DB explain result files
**/resources/explain/
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ class ArticleMainCardDao(
ARTICLE_MAIN_CARD.CREATED_AT.`as`(ArticleMainCardRecord::createdAt.name),
ARTICLE_MAIN_CARD.WRITER_ID.`as`(ArticleMainCardRecord::writerId.name),
ARTICLE_MAIN_CARD.WRITER_EMAIL.`as`(ArticleMainCardRecord::writerEmail.name),
ARTICLE_MAIN_CARD.WRITER_IMG_URL.`as`(ArticleMainCardRecord::writerImgUrl.name),
jsonGetAttributeAsText(
ARTICLE_MAIN_CARD.WRITER_DESCRIPTION,
"name"
).`as`(ArticleMainCardRecord::writerName.name),
jsonGetAttribute(ARTICLE_MAIN_CARD.WRITER_DESCRIPTION, "url").`as`(ArticleMainCardRecord::writerImgUrl.name),
jsonGetAttribute(ARTICLE_MAIN_CARD.WRITER_DESCRIPTION, "url").`as`(ArticleMainCardRecord::writerUrl.name),
ARTICLE_MAIN_CARD.WORKBOOKS.`as`(ArticleMainCardRecord::workbooks.name)
).from(ARTICLE_MAIN_CARD)
.where(ARTICLE_MAIN_CARD.ID.`in`(articleIds))
Expand All @@ -48,29 +49,22 @@ class ArticleMainCardDao(
insertArticleMainCardQuery(command).execute()

fun insertArticleMainCardQuery(command: ArticleMainCardExcludeWorkbookCommand) = dslContext
.insertInto(
ARTICLE_MAIN_CARD,
ARTICLE_MAIN_CARD.ID,
ARTICLE_MAIN_CARD.TITLE,
ARTICLE_MAIN_CARD.MAIN_IMAGE_URL,
ARTICLE_MAIN_CARD.CATEGORY_CD,
ARTICLE_MAIN_CARD.CREATED_AT,
ARTICLE_MAIN_CARD.WRITER_ID,
ARTICLE_MAIN_CARD.WRITER_EMAIL,
ARTICLE_MAIN_CARD.WRITER_DESCRIPTION
).values(
command.articleId,
command.articleTitle,
command.mainImageUrl.toString(),
command.categoryCd,
command.createdAt,
command.writerId,
command.writerEmail,
.insertInto(ARTICLE_MAIN_CARD)
.set(ARTICLE_MAIN_CARD.ID, command.articleId)
.set(ARTICLE_MAIN_CARD.TITLE, command.articleTitle)
.set(ARTICLE_MAIN_CARD.MAIN_IMAGE_URL, command.mainImageUrl.toString())
.set(ARTICLE_MAIN_CARD.CATEGORY_CD, command.categoryCd)
.set(ARTICLE_MAIN_CARD.CREATED_AT, command.createdAt)
.set(ARTICLE_MAIN_CARD.WRITER_ID, command.writerId)
.set(ARTICLE_MAIN_CARD.WRITER_EMAIL, command.writerEmail)
.set(ARTICLE_MAIN_CARD.WRITER_IMG_URL, command.writerImgUrl.toString())
.set(
ARTICLE_MAIN_CARD.WRITER_DESCRIPTION,
JSON.valueOf(
commonJsonMapper.toJsonStr(
mapOf(
"name" to command.writerName,
"url" to command.writerImgUrl
"url" to command.writerUrl
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ data class ArticleMainCardExcludeWorkbookCommand(
val writerEmail: String,
val writerName: String,
val writerImgUrl: URL,
val writerUrl: URL,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class ArticleMainCardRecord(
val writerId: Long,
val writerEmail: String,
val writerName: String,
val writerUrl: URL,
val writerImgUrl: URL,
val workbooks: List<WorkbookRecord> = emptyList(),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ArticleMainCardMapper(
writerId = record.get(ArticleMainCardRecord::writerId.name, Long::class.java),
writerEmail = record.get(ArticleMainCardRecord::writerEmail.name, String::class.java),
writerName = record.get(ArticleMainCardRecord::writerName.name, String::class.java),
writerUrl = record.get(ArticleMainCardRecord::writerUrl.name, URL::class.java),
writerImgUrl = record.get(ArticleMainCardRecord::writerImgUrl.name, URL::class.java),
workbooks = record.get(ArticleMainCardRecord::workbooks.name, JSON::class.java)?.data()?.let {
if ("{}".equals(it)) {
Expand Down
22 changes: 15 additions & 7 deletions api-repo/src/main/kotlin/com/few/api/repo/dao/member/MemberDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.few.api.repo.dao.member.query.SelectMemberByEmailQuery
import com.few.api.repo.dao.member.query.SelectWriterQuery
import com.few.api.repo.dao.member.query.SelectWritersQuery
import com.few.api.repo.dao.member.record.MemberIdAndIsDeletedRecord
import com.few.api.repo.dao.member.record.MemberIdAndNameRecord
import com.few.api.repo.dao.member.record.MemberRecord
import com.few.api.repo.dao.member.record.MemberEmailAndTypeRecord
import com.few.api.repo.dao.member.record.WriterRecord
import com.few.api.repo.dao.member.record.WriterRecordMappedWorkbook
Expand All @@ -22,6 +22,7 @@ import jooq.jooq_dsl.tables.MappingWorkbookArticle
import jooq.jooq_dsl.tables.Member
import org.jooq.DSLContext
import org.jooq.impl.DSL
import org.jooq.impl.DSL.jsonGetAttribute
import org.jooq.impl.DSL.jsonGetAttributeAsText
import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Repository
Expand All @@ -42,7 +43,8 @@ class MemberDao(
fun selectWriterQuery(query: SelectWriterQuery) = 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)
DSL.jsonGetAttribute(Member.MEMBER.DESCRIPTION, "url").`as`(WriterRecord::url.name),
Member.MEMBER.IMG_URL.`as`(WriterRecord::imgUrl.name)
)
.from(Member.MEMBER)
.where(Member.MEMBER.ID.eq(query.writerId))
Expand Down Expand Up @@ -73,7 +75,8 @@ class MemberDao(
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)
DSL.jsonGetAttribute(Member.MEMBER.DESCRIPTION, "url").`as`(WriterRecord::url.name),
Member.MEMBER.IMG_URL.`as`(WriterRecord::imgUrl.name)
)
.from(Member.MEMBER)
.where(Member.MEMBER.ID.`in`(notCachedIds))
Expand Down Expand Up @@ -125,14 +128,18 @@ class MemberDao(
.where(Member.MEMBER.TYPE_CD.eq(MemberType.WRITER.code))
.and(Member.MEMBER.DELETED_AT.isNull)

fun selectMemberByEmail(query: SelectMemberByEmailQuery): MemberIdAndNameRecord? {
fun selectMemberByEmail(query: SelectMemberByEmailQuery): MemberRecord? {
return selectMemberByEmailQuery(query)
.fetchOneInto(MemberIdAndNameRecord::class.java)
.fetchOneInto(MemberRecord::class.java)
}

fun selectMemberByEmailQuery(query: SelectMemberByEmailQuery) = dslContext.select(
Member.MEMBER.ID.`as`(MemberIdAndNameRecord::memberId.name),
jsonGetAttributeAsText(Member.MEMBER.DESCRIPTION, "name").`as`(MemberIdAndNameRecord::writerName.name) // writer only(nullable)
Member.MEMBER.ID.`as`(MemberRecord::memberId.name),
Member.MEMBER.IMG_URL.`as`(MemberRecord::imageUrl.name),
// writer only(nullable)
jsonGetAttributeAsText(Member.MEMBER.DESCRIPTION, "name").`as`(MemberRecord::writerName.name),
// writer only(nullable)
jsonGetAttribute(Member.MEMBER.DESCRIPTION, "url").`as`(MemberRecord::writerUrl.name)
)
.from(Member.MEMBER)
.where(Member.MEMBER.EMAIL.eq(query.email))
Expand Down Expand Up @@ -162,6 +169,7 @@ class MemberDao(
dslContext.insertInto(Member.MEMBER)
.set(Member.MEMBER.EMAIL, command.email)
.set(Member.MEMBER.TYPE_CD, command.memberType.code)
.set(Member.MEMBER.IMG_URL, command.imageUrl)

fun selectMemberEmailAndType(memberId: Long): MemberEmailAndTypeRecord? {
return selectMemberIdAndTypeQuery(memberId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import com.few.data.common.code.MemberType
data class InsertMemberCommand(
val email: String,
val memberType: MemberType,
val imageUrl: String,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.few.api.repo.dao.member.record

data class MemberIdAndNameRecord(
import java.net.URL

data class MemberRecord(
val memberId: Long,
val imageUrl: URL,
val writerUrl: URL,
val writerName: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ data class WriterRecord(
val writerId: Long,
val name: String,
val url: URL,
val imgUrl: URL,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.few.api.repo.dao.member.query.SelectWritersQuery
import com.few.api.repo.dao.member.support.WriterDescription
import com.few.api.repo.dao.member.support.WriterDescriptionJsonMapper
import com.few.api.repo.jooq.JooqTestSpec
import com.few.data.common.code.MEMBER_DEFAULT_IMG_URL
import com.few.data.common.code.MemberType
import io.github.oshai.kotlinlogging.KotlinLogging
import jooq.jooq_dsl.tables.Member
Expand Down Expand Up @@ -40,6 +41,7 @@ class MemberDaoTest : JooqTestSpec() {
.set(Member.MEMBER.ID, 1)
.set(Member.MEMBER.EMAIL, "[email protected]")
.set(Member.MEMBER.TYPE_CD, MemberType.NORMAL.code)
.set(Member.MEMBER.IMG_URL, MEMBER_DEFAULT_IMG_URL)
.execute()

val writerDescription = writerDescriptionJsonMapper.toJson(
Expand All @@ -51,6 +53,7 @@ class MemberDaoTest : JooqTestSpec() {
.set(Member.MEMBER.EMAIL, "[email protected]")
.set(Member.MEMBER.TYPE_CD, MemberType.WRITER.code)
.set(Member.MEMBER.DESCRIPTION, JSON.valueOf(writerDescription))
.set(Member.MEMBER.IMG_URL, MEMBER_DEFAULT_IMG_URL)
.execute()
log.debug { "===== finish setUp =====" }
}
Expand Down Expand Up @@ -107,6 +110,7 @@ class MemberDaoTest : JooqTestSpec() {
.set(Member.MEMBER.EMAIL, "[email protected]")
.set(Member.MEMBER.TYPE_CD, MemberType.WRITER.code)
.set(Member.MEMBER.DESCRIPTION, JSON.valueOf(writerDescription))
.set(Member.MEMBER.IMG_URL, MEMBER_DEFAULT_IMG_URL)
.execute()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.few.api.repo.dao.member.support.WriterDescriptionJsonMapper
import com.few.api.repo.explain.InsertUpdateExplainGenerator
import com.few.api.repo.explain.ResultGenerator
import com.few.api.repo.jooq.JooqTestSpec
import com.few.data.common.code.MEMBER_DEFAULT_IMG_URL
import com.few.data.common.code.MemberType
import io.github.oshai.kotlinlogging.KotlinLogging
import jooq.jooq_dsl.tables.Member
Expand Down Expand Up @@ -114,7 +115,8 @@ class MemberDaoExplainGenerateTest : JooqTestSpec() {
fun insertMemberCommandExplain() {
val command = InsertMemberCommand(
email = "[email protected]",
memberType = MemberType.NORMAL
memberType = MemberType.NORMAL,
imageUrl = MEMBER_DEFAULT_IMG_URL
).let {
memberDao.insertMemberCommand(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class ArticleMainCardService(
writerId = inDto.writerId,
writerEmail = inDto.writerEmail,
writerName = inDto.writerName,
writerImgUrl = inDto.writerImgUrl
writerImgUrl = inDto.writerImgUrl,
writerUrl = inDto.writerUrl
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ data class InitializeArticleMainCardInDto(
val writerEmail: String,
val writerName: String,
val writerImgUrl: URL,
val writerUrl: URL,
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.few.storage.document.service.PutDocumentService
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import java.io.File
import java.net.URL
import java.time.LocalDateTime
import java.util.*

Expand All @@ -46,7 +45,7 @@ class AddArticleUseCase(
@Transactional
fun execute(useCaseIn: AddArticleUseCaseIn): AddArticleUseCaseOut {
/** select writerId */
val writerIdRecord = SelectMemberByEmailQuery(useCaseIn.writerEmail).let {
val writerRecord = SelectMemberByEmailQuery(useCaseIn.writerEmail).let {
memberDao.selectMemberByEmail(it)
} ?: throw NotFoundException("member.notfound.id")

Expand Down Expand Up @@ -101,7 +100,7 @@ class AddArticleUseCase(

/** insert article */
val articleMstId = InsertFullArticleRecordCommand(
writerId = writerIdRecord.memberId,
writerId = writerRecord.memberId,
mainImageURL = useCaseIn.articleImageUrl,
title = useCaseIn.title,
category = category.code,
Expand Down Expand Up @@ -141,10 +140,11 @@ class AddArticleUseCase(
mainImageUrl = useCaseIn.articleImageUrl,
categoryCd = category.code,
createdAt = LocalDateTime.now(), // TODO: DB insert 시점으로 변경
writerId = writerIdRecord.memberId,
writerId = writerRecord.memberId,
writerEmail = useCaseIn.writerEmail,
writerName = writerIdRecord.writerName ?: throw NotFoundException("article.writer.name"),
writerImgUrl = URL("https://github.com/user-attachments/assets/528a6531-2cba-4efc-b8df-64a083d38be8") //TODO: 작가 이미지로 변환
writerName = writerRecord.writerName ?: throw NotFoundException("article.writer.name"),
writerImgUrl = writerRecord.imageUrl,
writerUrl = writerRecord.writerUrl
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class ReadArticleWriterRecordService(
ReadWriterOutDto(
writerId = it.writerId,
name = it.name,
url = it.url
url = it.url,
imgUrl = it.imgUrl
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ data class ReadWriterOutDto(
val writerId: Long,
val name: String,
val url: URL,
val imgUrl: URL,
)
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class ReadArticleUseCase(
writer = WriterDetail(
id = writerRecord.writerId,
name = writerRecord.name,
url = writerRecord.url
url = writerRecord.url,
imgUrl = writerRecord.imgUrl
),
mainImageUrl = articleRecord.mainImageURL,
title = articleRecord.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class ReadArticlesUseCase(
writer = WriterDetail(
id = a.writerId,
name = a.writerName,
url = a.writerImgUrl
url = a.writerUrl,
imgUrl = a.writerImgUrl
),
mainImageUrl = a.mainImageUrl,
title = a.articleTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data class WriterDetail(
val id: Long,
val name: String,
val url: URL,
val imgUrl: URL,
)

data class WorkbookDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.few.api.repo.dao.member.MemberDao
import com.few.api.repo.dao.member.command.InsertMemberCommand
import com.few.api.repo.dao.member.command.UpdateDeletedMemberTypeCommand
import com.few.api.repo.dao.member.query.SelectMemberByEmailNotConsiderDeletedAtQuery
import com.few.data.common.code.MEMBER_DEFAULT_IMG_URL
import com.few.data.common.code.MemberType
import com.few.email.service.member.SendAuthEmailService
import com.few.email.service.member.dto.Content
Expand Down Expand Up @@ -36,7 +37,8 @@ class SaveMemberUseCase(
val token = if (Objects.isNull(isSignUpBeforeMember)) {
InsertMemberCommand(
email = useCaseIn.email,
memberType = MemberType.PREAUTH
memberType = MemberType.PREAUTH,
MEMBER_DEFAULT_IMG_URL
).let {
memberDao.insertMember(it) ?: throw InsertException("member.insertfail.record")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.few.api.exception.common.InsertException
import com.few.api.repo.dao.member.MemberDao
import com.few.api.repo.dao.member.command.InsertMemberCommand
import com.few.api.repo.dao.member.query.SelectMemberByEmailQuery
import com.few.data.common.code.MEMBER_DEFAULT_IMG_URL
import org.springframework.stereotype.Service

@Service
Expand All @@ -19,7 +20,8 @@ class MemberService(
}

fun insertMember(dto: InsertMemberInDto): MemberIdOutDto {
return memberDao.insertMember(InsertMemberCommand(dto.email, dto.memberType))?.let { MemberIdOutDto(it) }
return memberDao.insertMember(InsertMemberCommand(dto.email, dto.memberType, MEMBER_DEFAULT_IMG_URL))
?.let { MemberIdOutDto(it) }
?: throw InsertException("member.insertfail.record")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class ArticleController(
writer = WriterInfo(
useCaseOut.writer.id,
useCaseOut.writer.name,
useCaseOut.writer.url
useCaseOut.writer.url,
useCaseOut.writer.imgUrl
),
mainImageUrl = useCaseOut.mainImageUrl,
content = useCaseOut.content,
Expand Down Expand Up @@ -74,7 +75,8 @@ class ArticleController(
writer = WriterInfo(
a.writer.id,
a.writer.name,
a.writer.url
a.writer.url,
a.writer.imgUrl
),
mainImageUrl = a.mainImageUrl,
content = a.content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data class WriterInfo(
val id: Long,
val name: String,
val url: URL,
val imgUrl: URL,
)

data class WorkbookInfo(
Expand Down
Loading
Loading