🚧 common-util 모듈 추가

This commit is contained in:
jini
2022-11-30 04:31:38 +09:00
parent 23cff9d75f
commit 31b6c85b77
13 changed files with 57 additions and 33 deletions

View File

@@ -2,4 +2,5 @@ dependencies {
implementation("org.springframework.data:spring-data-commons")
implementation("org.springframework:spring-tx")
implementation(project(":util:common-util"))
}

View File

@@ -1,8 +1,8 @@
package me.jiniworld.demohx.application.notice.domain
import me.jiniworld.demohx.DateTimeUtils
import me.jiniworld.demohx.application.notice.port.output.NoticeDetail
import me.jiniworld.demohx.application.notice.port.output.NoticeSimple
import me.jiniworld.demohx.application.util.DateTimeUtils
import java.time.LocalDateTime
data class Notice(

View File

@@ -1,16 +1,16 @@
package me.jiniworld.demohx.application.notice.service
import me.jiniworld.demohx.annotation.UseCase
import me.jiniworld.demohx.application.notice.port.input.GetNoticeQuery
import me.jiniworld.demohx.application.notice.port.input.GetNoticesCommand
import me.jiniworld.demohx.application.notice.port.output.LoadNoticePort
import me.jiniworld.demohx.application.notice.port.output.NoticeDetail
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
@Transactional(readOnly = true)
@Component
@UseCase
internal class GetNoticeService(
private val loadNoticePort: LoadNoticePort,
) : GetNoticeQuery {

View File

@@ -3,5 +3,7 @@ apply(plugin = "kotlin-jpa")
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
implementation(project(":util:common-util"))
implementation(project(":core:demo-core"))
}

View File

@@ -1,13 +1,13 @@
package me.jiniworld.demohx.persistence.notice
import me.jiniworld.demohx.application.notice.port.output.LoadNoticePort
import me.jiniworld.demohx.annotation.PersistenceAdapter
import me.jiniworld.demohx.application.notice.domain.Notice
import me.jiniworld.demohx.application.notice.port.output.LoadNoticePort
import me.jiniworld.demohx.persistence.notice.repository.NoticeRepository
import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Component
@Component
@PersistenceAdapter
internal class NoticePersistenceAdapter(
private val noticeRepository: NoticeRepository,
) : LoadNoticePort {

View File

@@ -4,6 +4,7 @@ dependencies {
compileOnly("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.springdoc:springdoc-openapi-ui:1.6.13")
implementation(project(":util:common-util"))
implementation(project(":core:demo-core"))
implementation(project(":infrastructure:datastore-mariadb"))
}

View File

@@ -2,13 +2,12 @@ package me.jiniworld.demohx.web.notice
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import me.jiniworld.demohx.annotation.WebAdapter
import me.jiniworld.demohx.application.notice.port.input.GetNoticeQuery
import me.jiniworld.demohx.application.notice.port.input.GetNoticesCommand
import org.springframework.stereotype.Component
import org.springframework.web.bind.annotation.*
@Component
//@WebAdapter
@WebAdapter
@Tag(name = "setting-system", description = "설정-시스템(공지사항, FAQ, 이용약관, 메타정보 등)")
@RestController
@RequestMapping("/v1/notices")

View File

@@ -7,3 +7,5 @@ findProject(":infrastructure:datastore-mariadb")?.name = "datastore-mariadb"
include("server")
include("server:demo-app")
findProject(":server:demo-app")?.name = "demo-app"
include("util:common-util")
findProject(":util:common-util")?.name = "common-util"

View File

@@ -0,0 +1,2 @@
dependencies {
}

View File

@@ -1,14 +1,12 @@
package me.jiniworld.demohx.application.util
package me.jiniworld.demohx
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoField
import java.time.temporal.TemporalAdjusters
object DateTimeUtils {
private const val SIMPLE_PATTERN_MONTH = "yyyyMM"
private const val SIMPLE_PATTERN_DATE = "yyyyMMdd"
private const val DEFAULT_PATTERN_DATE = "yyyy-MM-dd"
@@ -36,27 +34,9 @@ object DateTimeUtils {
fun getLastDateTime(date: LocalDate): LocalDateTime =
LocalDateTime.of(date.with(TemporalAdjusters.lastDayOfMonth()), LOCALTIME_END)
fun getFirstDateTime(date: LocalDate, type: AnalysisType): LocalDateTime =
when (type) {
AnalysisType.weekly -> LocalDateTime.of(date.minusDays((date[ChronoField.DAY_OF_WEEK] - 1).toLong()).minusWeeks(6), LOCALTIME_START)
AnalysisType.monthly -> date.minusDays((date[ChronoField.DAY_OF_MONTH] - 1).toLong()).minusMonths(6).atStartOfDay()
else -> LocalDateTime.of(date.minusDays((date[ChronoField.DAY_OF_WEEK] - 1).toLong()), LOCALTIME_START)
}
fun toString(date: LocalDate): String = date.format(FORMATTER_DATE)
fun getLastDateTime(date: LocalDate, type: AnalysisType): LocalDateTime =
when (type) {
AnalysisType.monthly -> LocalDateTime.of(date.minusDays(date[ChronoField.DAY_OF_MONTH].toLong()).plusMonths(1), LOCALTIME_END)
else -> LocalDateTime.of(date.plusDays((7 - date[ChronoField.DAY_OF_WEEK]).toLong()), LOCALTIME_END)
}
fun toString(dateTime: LocalDateTime): String = dateTime.format(FORMATTER_DATETIME)
fun toString(date: LocalDate) = date.format(FORMATTER_DATE)
fun toString(dateTime: LocalDateTime) = dateTime.format(FORMATTER_DATETIME)
fun toDateString(dateTime: LocalDateTime) = dateTime.format(FORMATTER_DATE)
}
enum class AnalysisType {
daily, weekly, monthly
fun toDateString(dateTime: LocalDateTime) : String = dateTime.format(FORMATTER_DATE)
}

View File

@@ -0,0 +1,12 @@
package me.jiniworld.demohx.annotation
import org.springframework.stereotype.Component
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
@Component
annotation class PersistenceAdapter(
val value: String = ""
)

View File

@@ -0,0 +1,13 @@
package me.jiniworld.demohx.annotation
import org.springframework.stereotype.Component
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
@Component
annotation class UseCase(
val value: String = ""
)

View File

@@ -0,0 +1,12 @@
package me.jiniworld.demohx.annotation
import org.springframework.stereotype.Component
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
@Component
annotation class WebAdapter(
val value: String = ""
)