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

[Refactor/#372] 범위지정 함수 구현 통일 #373

Merged
merged 3 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ class SubscriptionDao(
.orderBy(SUBSCRIPTION.CREATED_AT.desc())
.limit(1)

fun selectAllInActiveWorkbookSubscriptionStatus(query: SelectAllMemberWorkbookInActiveSubscription): List<MemberWorkbookSubscriptionStatusRecord> {
fun selectAllInActiveWorkbookSubscriptionStatus(query: SelectAllMemberWorkbookInActiveSubscriptionQuery): List<MemberWorkbookSubscriptionStatusRecord> {
return selectAllWorkbookInActiveSubscriptionStatusQuery(query)
.fetchInto(MemberWorkbookSubscriptionStatusRecord::class.java)
}

fun selectAllWorkbookInActiveSubscriptionStatusQuery(query: SelectAllMemberWorkbookInActiveSubscription) =
fun selectAllWorkbookInActiveSubscriptionStatusQuery(query: SelectAllMemberWorkbookInActiveSubscriptionQuery) =
dslContext.select(
SUBSCRIPTION.TARGET_WORKBOOK_ID.`as`(MemberWorkbookSubscriptionStatusRecord::workbookId.name),
SUBSCRIPTION.DELETED_AT.isNull.`as`(MemberWorkbookSubscriptionStatusRecord::isActiveSub.name),
Expand All @@ -91,12 +91,12 @@ class SubscriptionDao(
.groupBy(SUBSCRIPTION.TARGET_WORKBOOK_ID, SUBSCRIPTION.DELETED_AT)
.query

fun selectAllActiveWorkbookSubscriptionStatus(query: SelectAllMemberWorkbookActiveSubscription): List<MemberWorkbookSubscriptionStatusRecord> {
fun selectAllActiveWorkbookSubscriptionStatus(query: SelectAllMemberWorkbookActiveSubscriptionQuery): List<MemberWorkbookSubscriptionStatusRecord> {
return selectAllWorkbookActiveSubscriptionStatusQuery(query)
.fetchInto(MemberWorkbookSubscriptionStatusRecord::class.java)
}

fun selectAllWorkbookActiveSubscriptionStatusQuery(query: SelectAllMemberWorkbookActiveSubscription) =
fun selectAllWorkbookActiveSubscriptionStatusQuery(query: SelectAllMemberWorkbookActiveSubscriptionQuery) =
dslContext.select(
SUBSCRIPTION.TARGET_WORKBOOK_ID.`as`(MemberWorkbookSubscriptionStatusRecord::workbookId.name),
SUBSCRIPTION.DELETED_AT.isNull.`as`(MemberWorkbookSubscriptionStatusRecord::isActiveSub.name),
Expand Down Expand Up @@ -148,7 +148,7 @@ class SubscriptionDao(
* key: workbookId
* value: workbook 구독 전체 기록 수
*/
fun countAllWorkbookSubscription(query: CountAllWorkbooksSubscription): Map<Long, Int> {
fun countAllWorkbookSubscription(query: CountAllWorkbooksSubscriptionQuery): Map<Long, Int> {
return countAllWorkbookSubscriptionQuery()
.fetch()
.intoMap(SUBSCRIPTION.TARGET_WORKBOOK_ID, DSL.count(SUBSCRIPTION.TARGET_WORKBOOK_ID))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.few.api.repo.dao.subscription.query

data class CountAllWorkbooksSubscription(
data class CountAllWorkbooksSubscriptionQuery(
val workbookIds: List<Long>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.few.api.repo.dao.subscription.query
/**
* 멤버의 구독 중인 워크북 목록을 조회합니다.
*/
data class SelectAllMemberWorkbookActiveSubscription(
data class SelectAllMemberWorkbookActiveSubscriptionQuery(
val memberId: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.few.api.repo.dao.subscription.query
/**
* 멤버의 구독 완료 워크북 목록을 조회합니다.
*/
data class SelectAllMemberWorkbookInActiveSubscription(
data class SelectAllMemberWorkbookInActiveSubscriptionQuery(
val memberId: Long,
val unsubOpinion: String = "receive.all",
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.few.api.repo.config.LocalCacheConfig
import com.few.api.repo.config.LocalCacheConfig.Companion.LOCAL_CM
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.BrowseWorkBookQueryWithSubscriptionCount
import com.few.api.repo.dao.workbook.query.BrowseWorkBookQueryWithSubscriptionCountQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookLastArticleIdQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import com.few.api.repo.dao.workbook.record.SelectWorkBookRecord
Expand Down Expand Up @@ -71,12 +71,12 @@ class WorkbookDao(
* category에 따라서 조회된 구독자 수가 포함된 Workbook 목록을 반환한다.
* 정렬 순서는 구독자 수가 많은 순서로, 구독자 수가 같다면 생성일자가 최신인 순서로 반환한다.
*/
fun browseWorkBookWithSubscriptionCount(query: BrowseWorkBookQueryWithSubscriptionCount): List<SelectWorkBookRecordWithSubscriptionCount> {
fun browseWorkBookWithSubscriptionCount(query: BrowseWorkBookQueryWithSubscriptionCountQuery): List<SelectWorkBookRecordWithSubscriptionCount> {
return browseWorkBookQuery(query)
.fetchInto(SelectWorkBookRecordWithSubscriptionCount::class.java)
}

fun browseWorkBookQuery(query: BrowseWorkBookQueryWithSubscriptionCount) =
fun browseWorkBookQuery(query: BrowseWorkBookQueryWithSubscriptionCountQuery) =
dslContext.select(
Workbook.WORKBOOK.ID.`as`(SelectWorkBookRecordWithSubscriptionCount::id.name),
Workbook.WORKBOOK.TITLE.`as`(SelectWorkBookRecordWithSubscriptionCount::title.name),
Expand Down Expand Up @@ -124,7 +124,7 @@ class WorkbookDao(
/**
* category에 따라서 조건을 생성한다.
*/
private fun browseWorkBookCategoryCondition(query: BrowseWorkBookQueryWithSubscriptionCount): Condition {
private fun browseWorkBookCategoryCondition(query: BrowseWorkBookQueryWithSubscriptionCountQuery): Condition {
return when (query.category) {
(-1).toByte() -> DSL.noCondition()
else -> Workbook.WORKBOOK.CATEGORY_CD.eq(query.category)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.few.api.repo.dao.workbook.query

data class BrowseWorkBookQueryWithSubscriptionCount(
data class BrowseWorkBookQueryWithSubscriptionCountQuery(
/**
* @see com.few.api.web.support.WorkBookCategory
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.few.api.repo.explain.subscription
import com.few.api.repo.dao.subscription.SubscriptionDao
import com.few.api.repo.dao.subscription.command.*
import com.few.api.repo.dao.subscription.query.CountWorkbookMappedArticlesQuery
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookActiveSubscription
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookActiveSubscriptionQuery
import com.few.api.repo.dao.subscription.query.SelectAllWorkbookSubscriptionStatusNotConsiderDeletedAtQuery
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookInActiveSubscription
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookInActiveSubscriptionQuery
import com.few.api.repo.explain.ExplainGenerator
import com.few.api.repo.explain.InsertUpdateExplainGenerator
import com.few.api.repo.explain.ResultGenerator
Expand Down Expand Up @@ -63,7 +63,7 @@ class SubscriptionDaoExplainGenerateTest : JooqTestSpec() {

@Test
fun selectAllWorkbookInActiveSubscriptionStatusQueryExplain() {
val query = SelectAllMemberWorkbookInActiveSubscription(
val query = SelectAllMemberWorkbookInActiveSubscriptionQuery(
memberId = 1L,
unsubOpinion = "receive.all"
).let {
Expand All @@ -77,7 +77,7 @@ class SubscriptionDaoExplainGenerateTest : JooqTestSpec() {

@Test
fun selectAllWorkbookActiveSubscriptionStatusQueryExplain() {
val query = SelectAllMemberWorkbookActiveSubscription(
val query = SelectAllMemberWorkbookActiveSubscriptionQuery(
memberId = 1L
).let {
subscriptionDao.selectAllWorkbookActiveSubscriptionStatusQuery(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.few.api.repo.explain.workbook
import com.few.api.repo.dao.workbook.WorkbookDao
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.BrowseWorkBookQueryWithSubscriptionCount
import com.few.api.repo.dao.workbook.query.BrowseWorkBookQueryWithSubscriptionCountQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookLastArticleIdQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import com.few.api.repo.explain.ExplainGenerator
Expand Down Expand Up @@ -73,7 +73,7 @@ class WorkbookDaoExplainGenerateTest : JooqTestSpec() {

@Test
fun browseWorkBookQueryNoConditionQueryExplain() {
val query = BrowseWorkBookQueryWithSubscriptionCount(-1).let {
val query = BrowseWorkBookQueryWithSubscriptionCountQuery(-1).let {
workbookDao.browseWorkBookQuery(it)
}

Expand All @@ -84,7 +84,7 @@ class WorkbookDaoExplainGenerateTest : JooqTestSpec() {

@Test
fun browseWorkBookQueryCategoryConditionExplain() {
val query = BrowseWorkBookQueryWithSubscriptionCount(CategoryType.fromCode(0)!!.code).let {
val query = BrowseWorkBookQueryWithSubscriptionCountQuery(CategoryType.fromCode(0)!!.code).let {
workbookDao.browseWorkBookQuery(it)
}

Expand Down
46 changes: 23 additions & 23 deletions api/src/main/kotlin/com/few/api/client/repo/RepoClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ class RepoClient(
private val log = KotlinLogging.logger {}

fun announceRepoAlter(args: RepoAlterArgs) {
val embedsList = ArrayList<Embed>()
args.let {
embedsList.add(
Embed(
title = "Exception",
description = "Slow Query Detected"
)
val embedsList = mutableListOf(
Embed(
title = "Exception",
description = "Slow Query Detected"
)
it.requestURL.let { requestURL ->
)

args.let { arg ->
arg.requestURL.let { requestURL ->
embedsList.add(
Embed(
title = "Request URL",
description = requestURL
)
)
}
it.query?.let { query ->

arg.query?.let { query ->
embedsList.add(
Embed(
title = "Slow Query Detected",
Expand All @@ -43,20 +44,19 @@ class RepoClient(
)
}
}
args.let {
DiscordBodyProperty(
content = "😭 DB 이상 발생",
embeds = embedsList
)
}.let { body ->
restTemplate.exchange(
discordWebhook,
HttpMethod.POST,
HttpEntity(body),
String::class.java
).let { res ->
log.info { "Discord webhook response: ${res.statusCode}" }
}

restTemplate.exchange(
discordWebhook,
HttpMethod.POST,
HttpEntity(
DiscordBodyProperty(
content = "😭 DB 이상 발생",
embeds = embedsList
)
),
String::class.java
).let { res ->
log.info { "Discord webhook response: ${res.statusCode}" }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ class SlowQueryEventListener(
@Async(value = DISCORD_HOOK_EVENT_POOL)
@EventListener
fun handleSlowQueryEvent(event: SlowQueryEvent) {
RepoAlterArgs(
val args = RepoAlterArgs(
requestURL = MDC.get("Request-URL") ?: "",
query = event.slowQuery
).let {
repoClient.announceRepoAlter(it)
}
)
repoClient.announceRepoAlter(args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@ class SubscriptionClient(
private val log = KotlinLogging.logger {}

fun announceWorkbookSubscription(args: WorkbookSubscriptionArgs) {
args.let {
val body = args.let { arg ->
DiscordBodyProperty(
content = "🎉 신규 구독 알림 ",
embeds = listOf(
Embed(
title = "Total Subscriptions",
description = it.totalSubscriptions.toString()
description = arg.totalSubscriptions.toString()
),
Embed(
title = "Active Subscriptions",
description = it.activeSubscriptions.toString()
description = arg.activeSubscriptions.toString()
),
Embed(
title = "Workbook Title",
description = it.workbookTitle
description = arg.workbookTitle
)
)
)
}.let { body ->
restTemplate.exchange(
discordWebhook,
HttpMethod.POST,
HttpEntity(body),
String::class.java
).let { res ->
log.info { "Discord webhook response: ${res.statusCode}" }
}
}

restTemplate.exchange(
discordWebhook,
HttpMethod.POST,
HttpEntity(body),
String::class.java
).let { res ->
log.info { "Discord webhook response: ${res.statusCode}" }
}
}
}
23 changes: 10 additions & 13 deletions api/src/main/kotlin/com/few/api/config/crypto/IdEncryption.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ class IdEncryption(
@Value("\${security.encryption.iv}") private val iv: String,
) : Encryption<String, String> {

private lateinit var key: SecretKeySpec
private lateinit var encodeCipher: Cipher
private lateinit var decodeCipher: Cipher

init {
KeyGenerator.getInstance(algorithm).apply {
init(keySize)
key = SecretKeySpec(secretKey.toByteArray(), algorithm)
}
encodeCipher = Cipher.getInstance(transformation)
decodeCipher = Cipher.getInstance(transformation)
encodeCipher.init(Cipher.ENCRYPT_MODE, key, IvParameterSpec(iv.toByteArray()))
decodeCipher.init(Cipher.DECRYPT_MODE, key, IvParameterSpec(iv.toByteArray()))
private var key: SecretKeySpec = KeyGenerator.getInstance(algorithm).apply {
init(keySize)
}.run {
SecretKeySpec(secretKey.toByteArray(), [email protected])
}
private var encodeCipher: Cipher = Cipher.getInstance(transformation).apply {
init(Cipher.ENCRYPT_MODE, key, IvParameterSpec([email protected]()))
}
private var decodeCipher: Cipher = Cipher.getInstance(transformation).apply {
init(Cipher.DECRYPT_MODE, key, IvParameterSpec([email protected]()))
Comment on lines +19 to +28
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스크린샷 2024-08-29 오후 9 41 32

이전에 암화한것 파싱하였는데 문제없이 동작합니다.!

}

override fun encrypt(plainText: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class ArticleMainCardService(

val articleMainCardRecord: ArticleMainCardRecord =
articleMainCardDao.selectArticleMainCardsRecord(setOf(inDto.articleId))
.ifEmpty { throw NotFoundException("articlemaincard.notfound.id") }
.first()
.firstOrNull() ?: throw NotFoundException("article.notfound.id")

val workbookCommands =
articleMainCardRecord.workbooks.map { WorkbookCommand(it.id!!, it.title!!) }.toMutableList()
workbookCommands.add(toBeAddedWorkbook)
articleMainCardRecord.workbooks.map { WorkbookCommand(it.id!!, it.title!!) }
.toMutableList()
.apply { add(toBeAddedWorkbook) }

articleMainCardDao.updateArticleMainCardSetWorkbook(
UpdateArticleMainCardWorkbookCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ class GetLocalUrlService(
private val services: Map<String, GetPreSignedObjectUrlService>,
) : GetUrlService {
override fun execute(query: GetUrlInDto): GetUrlOutDto {
val service = services.keys.stream().filter { key ->
key.lowercase(Locale.getDefault())
.contains(query.getPreSignedUrlServiceKey())
}.findAny().let {
if (it.isEmpty) throw IllegalArgumentException("Cannot find service for ${query.getPreSignedUrlServiceKey()}")
services[it.get()]!!
}
val service = services.keys.firstOrNull { key ->
key.lowercase(Locale.getDefault()).contains(query.getPreSignedUrlServiceKey())
}?.let { services[it] } ?: throw IllegalArgumentException("Cannot find service for ${query.getPreSignedUrlServiceKey()}")

return service.execute(query.`object`)?.let {
GetUrlOutDto(URL(it))
Expand Down
Loading
Loading