Skip to content

Commit

Permalink
[Feat/#105] 각 레이어 별 DTO 클래스명 통일 (#183)
Browse files Browse the repository at this point in the history
* refactor: rename controller dto name (body -> request)

* refactor: usecase 패키지 위치 통일 (usercase 아래 )

* refactor: DAO DTO 이름 일치 (query, command ,record)

* refactor: Service DTO 네이밍 통일 (InDto)

* refacotr: 로컬 환경에서 디스코드 웹훅 URL 임시처리

* refactor: 줄바꿈

* refactor: GetUrlOutDto 추가 및 적용

* refactor: article 도메인 서비스 out dto 적용

* refactor: article service에서 transactional 삭제

* refactor: subscription 도메인 서비스 out dto 추가

* refactor: workbook 도메인 서비스 out dto 적용

* test: DTO 적용 관련 변경 사항
  • Loading branch information
hun-ca authored Jul 10, 2024
1 parent c4ad8ce commit 1660784
Show file tree
Hide file tree
Showing 78 changed files with 254 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.few.api.repo.dao.subscription
import com.few.api.repo.dao.subscription.command.InsertWorkbookSubscriptionCommand
import com.few.api.repo.dao.subscription.command.UpdateDeletedAtInAllSubscriptionCommand
import com.few.api.repo.dao.subscription.command.UpdateDeletedAtInWorkbookSubscriptionCommand
import com.few.api.repo.dao.subscription.query.SelectAllWorkbookSubscriptionStatusQueryNotConsiderDeletedAt
import com.few.api.repo.dao.subscription.query.SelectAllWorkbookSubscriptionStatusNotConsiderDeletedAtQuery
import com.few.api.repo.dao.subscription.record.WorkbookSubscriptionStatus
import com.few.api.repo.dao.subscription.query.CountWorkbookMappedArticlesQuery
import com.few.api.repo.dao.subscription.record.CountAllSubscriptionStatusRecord
Expand Down Expand Up @@ -44,7 +44,7 @@ class SubscriptionDao(
.execute()
}

fun selectTopWorkbookSubscriptionStatus(query: SelectAllWorkbookSubscriptionStatusQueryNotConsiderDeletedAt): WorkbookSubscriptionStatus? {
fun selectTopWorkbookSubscriptionStatus(query: SelectAllWorkbookSubscriptionStatusNotConsiderDeletedAtQuery): WorkbookSubscriptionStatus? {
return dslContext.select(
SUBSCRIPTION.TARGET_WORKBOOK_ID.`as`(WorkbookSubscriptionStatus::workbookId.name),
SUBSCRIPTION.DELETED_AT.isNull.`as`(WorkbookSubscriptionStatus::isActiveSub.name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.few.api.repo.dao.subscription.query
/**
* DeleteAt을 고려하지 않고 모든 워크북 구독 상태를 조회하는 쿼리
*/
data class SelectAllWorkbookSubscriptionStatusQueryNotConsiderDeletedAt(
data class SelectAllWorkbookSubscriptionStatusNotConsiderDeletedAtQuery(
val workbookId: Long,
val memberId: Long
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.few.api.domain.admin.document.service

import com.few.api.domain.admin.document.service.dto.GetUrlQuery
import com.few.api.domain.admin.document.service.dto.GetUrlInDto
import com.few.api.domain.admin.document.service.dto.GetUrlOutDto
import com.few.api.domain.admin.document.service.dto.getPreSignedUrlServiceKey
import com.few.api.exception.common.ExternalIntegrationException
import com.few.storage.GetPreSignedObjectUrlService
Expand All @@ -11,15 +12,15 @@ import java.net.URL
import java.util.*

interface GetUrlService {
fun execute(query: GetUrlQuery): URL
fun execute(query: GetUrlInDto): GetUrlOutDto
}

@Profile("local")
@Service
class GetLocalUrlService(
private val services: Map<String, GetPreSignedObjectUrlService>
) : GetUrlService {
override fun execute(query: GetUrlQuery): URL {
override fun execute(query: GetUrlInDto): GetUrlOutDto {
val service = services.keys.stream().filter { key ->
key.lowercase(Locale.getDefault())
.contains(query.getPreSignedUrlServiceKey())
Expand All @@ -29,7 +30,7 @@ class GetLocalUrlService(
}

return service.execute(query.`object`)?.let {
URL(it)
GetUrlOutDto(URL(it))
} ?: throw ExternalIntegrationException("external.presignedfail.url")
}
}
Expand All @@ -39,7 +40,7 @@ class GetLocalUrlService(
class GetCdnUrlService(
private val cdnProperty: CdnProperty
) : GetUrlService {
override fun execute(query: GetUrlQuery): URL {
return URL(cdnProperty.url + "/" + query.`object`)
override fun execute(query: GetUrlInDto): GetUrlOutDto {
return GetUrlOutDto(URL(cdnProperty.url + "/" + query.`object`))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.few.api.domain.admin.document.service.dto
import java.util.*

/** query.object example: images/2024-07-01/14789db.png */
fun GetUrlQuery.getPreSignedUrlServiceKey(): String {
fun GetUrlInDto.getPreSignedUrlServiceKey(): String {
return this.`object`.split("/")[0].lowercase(Locale.getDefault()).replace("s", "")
}
data class GetUrlQuery(
data class GetUrlInDto(
val `object`: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.few.api.domain.admin.document.service.dto

import java.net.URL

data class GetUrlOutDto(
val url: URL
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.few.api.domain.admin.document.usecase

import com.few.api.domain.admin.document.dto.AddArticleUseCaseIn
import com.few.api.domain.admin.document.dto.AddArticleUseCaseOut
import com.few.api.domain.admin.document.usecase.dto.AddArticleUseCaseIn
import com.few.api.domain.admin.document.usecase.dto.AddArticleUseCaseOut
import com.few.api.domain.admin.document.service.GetUrlService
import com.few.api.domain.admin.document.service.dto.GetUrlQuery
import com.few.api.domain.admin.document.service.dto.GetUrlInDto
import com.few.api.domain.admin.document.utils.ObjectPathGenerator
import com.few.api.exception.common.ExternalIntegrationException
import com.few.api.exception.common.NotFoundException
Expand Down Expand Up @@ -63,16 +63,16 @@ class AddArticleUseCase(

putDocumentService.execute(documentName, document)?.let { res ->
val source = res.`object`
GetUrlQuery(source).let { query ->
GetUrlInDto(source).let { query ->
getUrlService.execute(query)
}.let { url ->
}.let { dto ->
InsertDocumentIfoCommand(
path = documentName,
url = url
url = dto.url
).let { command ->
documentDao.insertDocumentIfo(command)
}
url
dto.url
}
} ?: throw ExternalIntegrationException("external.putfail.docummet")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.few.api.domain.admin.document.usecase

import com.few.api.domain.admin.document.dto.AddWorkbookUseCaseIn
import com.few.api.domain.admin.document.dto.AddWorkbookUseCaseOut
import com.few.api.domain.admin.document.usecase.dto.AddWorkbookUseCaseIn
import com.few.api.domain.admin.document.usecase.dto.AddWorkbookUseCaseOut
import com.few.api.exception.common.InsertException
import com.few.api.repo.dao.workbook.WorkbookDao
import com.few.api.repo.dao.workbook.command.InsertWorkBookCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.few.api.domain.admin.document.usecase

import com.few.api.domain.admin.document.dto.ConvertContentUseCaseIn
import com.few.api.domain.admin.document.dto.ConvertContentUseCaseOut
import com.few.api.domain.admin.document.usecase.dto.ConvertContentUseCaseIn
import com.few.api.domain.admin.document.usecase.dto.ConvertContentUseCaseOut
import com.few.api.domain.admin.document.service.GetUrlService
import com.few.api.domain.admin.document.service.dto.GetUrlQuery
import com.few.api.domain.admin.document.service.dto.GetUrlInDto
import com.few.api.domain.admin.document.utils.ObjectPathGenerator
import com.few.api.exception.common.ExternalIntegrationException
import com.few.api.exception.common.InsertException
Expand Down Expand Up @@ -37,16 +37,16 @@ class ConvertContentUseCase(

val originDownloadUrl = putDocumentService.execute(documentName, document)?.let { res ->
val source = res.`object`
GetUrlQuery(source).let { query ->
GetUrlInDto(source).let { query ->
getUrlService.execute(query)
}.let { url ->
}.let { dto ->
InsertDocumentIfoCommand(
path = documentName,
url = url
url = dto.url
).let { command ->
documentDao.insertDocumentIfo(command) ?: throw InsertException("document.insertfail.record")
}
url
dto.url
}
} ?: throw ExternalIntegrationException("external.document.presignedfail")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.few.api.domain.admin.document.usecase

import com.few.api.domain.admin.document.dto.MapArticleUseCaseIn
import com.few.api.domain.admin.document.usecase.dto.MapArticleUseCaseIn
import com.few.api.repo.dao.workbook.WorkbookDao
import com.few.api.repo.dao.workbook.command.MapWorkBookToArticleCommand
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.few.api.domain.admin.document.usecase

import com.few.api.domain.admin.document.dto.PutImageUseCaseIn
import com.few.api.domain.admin.document.dto.PutImageUseCaseOut
import com.few.api.domain.admin.document.usecase.dto.PutImageUseCaseIn
import com.few.api.domain.admin.document.usecase.dto.PutImageUseCaseOut
import com.few.api.domain.admin.document.service.GetUrlService
import com.few.api.domain.admin.document.service.dto.GetUrlQuery
import com.few.api.domain.admin.document.service.dto.GetUrlInDto
import com.few.api.domain.admin.document.utils.ObjectPathGenerator
import com.few.api.exception.common.ExternalIntegrationException
import com.few.api.exception.common.InsertException
Expand Down Expand Up @@ -35,13 +35,13 @@ class PutImageUseCase(

val url = putImageService.execute(imageName, image)?.let { res ->
val source = res.`object`
GetUrlQuery(source).let { query ->
GetUrlInDto(source).let { query ->
getUrlService.execute(query)
}.let { url ->
InsertImageIfoCommand(source, url).let { command ->
}.let { dto ->
InsertImageIfoCommand(source, dto.url).let { command ->
imageDao.insertImageIfo(command) ?: throw InsertException("image.insertfail.record")
}
return@let url
return@let dto.url
}
} ?: throw ExternalIntegrationException("external.presignedfail.image")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.admin.document.dto
package com.few.api.domain.admin.document.usecase.dto

import java.net.URL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.admin.document.dto
package com.few.api.domain.admin.document.usecase.dto

data class AddArticleUseCaseOut(
val articleId: Long
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.admin.document.dto
package com.few.api.domain.admin.document.usecase.dto

import java.net.URL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.admin.document.dto
package com.few.api.domain.admin.document.usecase.dto

data class AddWorkbookUseCaseOut(
val workbookId: Long
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.admin.document.dto
package com.few.api.domain.admin.document.usecase.dto

import org.springframework.web.multipart.MultipartFile

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.admin.document.dto
package com.few.api.domain.admin.document.usecase.dto

import java.net.URL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.admin.document.dto
package com.few.api.domain.admin.document.usecase.dto

data class MapArticleUseCaseIn(
val workbookId: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.admin.document.dto
package com.few.api.domain.admin.document.usecase.dto

import org.springframework.web.multipart.MultipartFile

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.few.api.domain.admin.document.dto
package com.few.api.domain.admin.document.usecase.dto

import java.net.URL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.few.api.domain.article.service

import com.few.api.domain.article.service.dto.BrowseArticleProblemIdsQuery
import com.few.api.domain.article.service.dto.BrowseArticleProblemIdsInDto
import com.few.api.domain.article.service.dto.BrowseArticleProblemsOutDto
import com.few.api.exception.common.NotFoundException
import com.few.api.repo.dao.problem.ProblemDao
import com.few.api.repo.dao.problem.query.SelectProblemsByArticleIdQuery
import com.few.api.repo.dao.problem.record.ProblemIdsRecord
import org.springframework.stereotype.Service

@Service
class BrowseArticleProblemsService(
private val problemDao: ProblemDao
) {

fun execute(query: BrowseArticleProblemIdsQuery): ProblemIdsRecord {
fun execute(query: BrowseArticleProblemIdsInDto): BrowseArticleProblemsOutDto {
SelectProblemsByArticleIdQuery(query.articleId).let { query: SelectProblemsByArticleIdQuery ->
return problemDao.selectProblemsByArticleId(query) ?: throw NotFoundException("problem.notfound.articleId")
return problemDao.selectProblemsByArticleId(query)?.let { BrowseArticleProblemsOutDto(it.problemIds) }
?: throw NotFoundException("problem.notfound.articleId")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package com.few.api.domain.article.service

import com.few.api.domain.article.service.dto.ReadWriterRecordQuery
import com.few.api.domain.article.service.dto.ReadWriterOutDto
import com.few.api.domain.article.service.dto.ReadWriterRecordInDto
import com.few.api.repo.dao.member.MemberDao
import com.few.api.repo.dao.member.query.SelectWriterQuery
import com.few.api.repo.dao.member.record.WriterRecord
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class ReadArticleWriterRecordService(
private val memberDao: MemberDao
) {

@Transactional(readOnly = true)
fun execute(query: ReadWriterRecordQuery): WriterRecord? {
fun execute(query: ReadWriterRecordInDto): ReadWriterOutDto? {
SelectWriterQuery(query.writerId).let { query: SelectWriterQuery ->
return memberDao.selectWriter(query)
val record = memberDao.selectWriter(query)
return record?.let {
ReadWriterOutDto(
writerId = it.writerId,
name = it.name,
url = it.url
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.few.api.domain.article.service.dto

data class BrowseArticleProblemIdsQuery(
data class BrowseArticleProblemIdsInDto(
val articleId: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.domain.article.service.dto

data class BrowseArticleProblemsOutDto(
val problemIds: List<Long>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.few.api.domain.article.service.dto

import java.net.URL

data class ReadWriterOutDto(
val writerId: Long,
val name: String,
val url: URL
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.few.api.domain.article.service.dto

data class ReadWriterRecordQuery(
data class ReadWriterRecordInDto(
val writerId: Long
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.few.api.domain.article.usecase

import com.few.api.domain.article.dto.ReadArticleUseCaseIn
import com.few.api.domain.article.dto.ReadArticleUseCaseOut
import com.few.api.domain.article.dto.WriterDetail
import com.few.api.domain.article.usecase.dto.ReadArticleUseCaseIn
import com.few.api.domain.article.usecase.dto.ReadArticleUseCaseOut
import com.few.api.domain.article.usecase.dto.WriterDetail
import com.few.api.domain.article.service.BrowseArticleProblemsService
import com.few.api.domain.article.service.ReadArticleWriterRecordService
import com.few.api.domain.article.service.dto.BrowseArticleProblemIdsQuery
import com.few.api.domain.article.service.dto.ReadWriterRecordQuery
import com.few.api.domain.article.service.dto.BrowseArticleProblemIdsInDto
import com.few.api.domain.article.service.dto.ReadWriterRecordInDto
import com.few.api.exception.common.NotFoundException
import com.few.api.repo.dao.article.ArticleDao
import com.few.api.repo.dao.article.query.SelectArticleRecordQuery
Expand All @@ -27,11 +27,11 @@ class ReadArticleUseCase(
articleDao.selectArticleRecord(query)
} ?: throw NotFoundException("article.notfound.id")

val writerRecord = ReadWriterRecordQuery(articleRecord.writerId).let { query: ReadWriterRecordQuery ->
val writerRecord = ReadWriterRecordInDto(articleRecord.writerId).let { query: ReadWriterRecordInDto ->
readArticleWriterRecordService.execute(query) ?: throw NotFoundException("writer.notfound.id")
}

val problemIds = BrowseArticleProblemIdsQuery(articleRecord.articleId).let { query: BrowseArticleProblemIdsQuery ->
val problemIds = BrowseArticleProblemIdsInDto(articleRecord.articleId).let { query: BrowseArticleProblemIdsInDto ->
browseArticleProblemsService.execute(query)
}

Expand Down
Loading

0 comments on commit 1660784

Please sign in to comment.