diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 51ae777..0fe2e55 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,8 @@ env: VERSION: "0.0.1-SNAPSHOT" USERNAME: ${{ secrets.OSSRH_USERNAME }} TOKEN: ${{ secrets.OSSRH_TOKEN }} + ORDER_URL: http://localhost:8085 + KAFKA_SERVER: localhost:9092 jobs: build: name: Build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 13afd73..c957bae 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,6 +15,8 @@ on: env: USERNAME: ${{ secrets.OSSRH_USERNAME }} TOKEN: ${{ secrets.OSSRH_TOKEN }} + ORDER_URL: http://localhost:8085 + KAFKA_SERVER: localhost:9092 jobs: build: name: Build diff --git a/build.gradle.kts b/build.gradle.kts index e323a57..47effc0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -55,6 +55,10 @@ dependencies { implementation("io.projectreactor.kafka:reactor-kafka") implementation("org.springframework.kafka:spring-kafka") testImplementation("org.springframework.kafka:spring-kafka-test") + // API-Call + implementation("com.hrv.mart:api-call:0.0.3") + // Custom-Pageable + implementation("com.hrv.mart:custom-pageable:0.0.2") } tasks.withType { diff --git a/src/main/kotlin/com/hrv/mart/orderlibrary/config/APICallerConfig.kt b/src/main/kotlin/com/hrv/mart/orderlibrary/config/APICallerConfig.kt new file mode 100644 index 0000000..48d2488 --- /dev/null +++ b/src/main/kotlin/com/hrv/mart/orderlibrary/config/APICallerConfig.kt @@ -0,0 +1,16 @@ +package com.hrv.mart.orderlibrary.config + +import com.hrv.mart.apicall.APICaller +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.web.reactive.function.client.WebClient + +@Configuration +class APICallerConfig +{ + @Bean + fun getAPICall() = + APICaller( + webClientBuilder = WebClient.builder() + ) +} \ No newline at end of file diff --git a/src/main/kotlin/com/hrv/mart/orderlibrary/model/query/OrderData.kt b/src/main/kotlin/com/hrv/mart/orderlibrary/model/query/OrderData.kt new file mode 100644 index 0000000..117e31f --- /dev/null +++ b/src/main/kotlin/com/hrv/mart/orderlibrary/model/query/OrderData.kt @@ -0,0 +1,36 @@ +package com.hrv.mart.orderlibrary.model.query + +import java.time.LocalDate +import java.time.format.DateTimeFormatter +import java.util.* + +data class OrderDate ( + val year: Int, + val month: Int, + val day: Int, +) { + fun parseToString(isStarting: Boolean): String { + val time = + if (isStarting) { + "00:00:00" + } + else { + "23:59:59" + } + return LocalDate.of(year, month, day).toString() + ":${time}" + } + companion object { + fun getMaxDate() = + toOrderDate(LocalDate.now()) + fun getMinDate() = + toOrderDate(LocalDate.MIN) + fun getDateTimeFormat() = + DateTimeFormatter.ofPattern("yyyy-MM-dd:HH:mm:ss", Locale.ROOT) + private fun toOrderDate(date: LocalDate) = + OrderDate( + year = maxOf(date.year, 1), + month = date.month.value, + day = date.dayOfMonth + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hrv/mart/orderlibrary/model/query/OrderQuery.kt b/src/main/kotlin/com/hrv/mart/orderlibrary/model/query/OrderQuery.kt new file mode 100644 index 0000000..89de374 --- /dev/null +++ b/src/main/kotlin/com/hrv/mart/orderlibrary/model/query/OrderQuery.kt @@ -0,0 +1,22 @@ +package com.hrv.mart.orderlibrary.model.query + +import com.hrv.mart.orderlibrary.model.Status +import org.springframework.data.domain.Sort + +data class OrderQuery ( + val status: List = listOf( + Status.SHIPPED, + Status.PROCESS, + Status.PLACED, + Status.CANCELLED + ), + val startingDate: OrderDate = OrderDate.getMinDate(), + val endingDate: OrderDate = OrderDate.getMaxDate(), + val sortInDecreasingDateOrder: Boolean = true +) { + fun getSortingOrder() = + if (this.sortInDecreasingDateOrder) + Sort.Direction.DESC + else + Sort.Direction.ASC +} \ No newline at end of file diff --git a/src/main/kotlin/com/hrv/mart/orderlibrary/repository/OrderRepository.kt b/src/main/kotlin/com/hrv/mart/orderlibrary/repository/OrderRepository.kt new file mode 100644 index 0000000..09f3f9d --- /dev/null +++ b/src/main/kotlin/com/hrv/mart/orderlibrary/repository/OrderRepository.kt @@ -0,0 +1,50 @@ +package com.hrv.mart.orderlibrary.repository + +import com.hrv.mart.apicall.APICaller +import com.hrv.mart.custompageable.model.Pageable +import com.hrv.mart.custompageable.model.QueryParams +import com.hrv.mart.orderlibrary.model.OrderResponse +import com.hrv.mart.orderlibrary.model.query.OrderQuery +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value +import org.springframework.http.server.reactive.ServerHttpResponse +import org.springframework.stereotype.Repository + +@Repository +class OrderRepository ( + @Value("\${hrv.mart.orderUrl}") + private val orderUrl: String, + @Autowired + private val apiCaller: APICaller +) +{ + fun getUserOrder(userId: String, queryParams: QueryParams, response: ServerHttpResponse) = + apiCaller + .getData( + "${orderUrl}/${userId}${queryParams.getQueryParamForURL()}", + response = response, + responseClassType = Pageable::class.java + ) + .map { + it as OrderResponse + } + fun getOrderByUserIDAndOrderId(userId: String, orderId: String, response: ServerHttpResponse) = + apiCaller + .getData( + "${orderUrl}/${userId}/${orderId}", + response = response, + responseClassType = OrderResponse::class.java + ) + fun getOrderByApplyingFilter( + orderQueryParams: OrderQuery, + queryParam: QueryParams, + response: ServerHttpResponse + ) = + apiCaller + .postRequest( + orderUrl, + Pageable::class.java, + orderQueryParams::class.java, + response + ) +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 191e215..578758f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,4 @@ -spring.kafka.producer.bootstrap-servers: localhost:9092 -spring.kafka.producer.key-serializer: org.apache.kafka.common.serialization.StringSerializer -spring.kafka.producer.value-serializer: org.springframework.kafka.support.serializer.JsonSerializer \ No newline at end of file +spring.kafka.producer.bootstrap-servers=${KAFKA_SERVER} +spring.kafka.producer.key-serializer= org.apache.kafka.common.serialization.StringSerializer +spring.kafka.producer.value-serializer= org.springframework.kafka.support.serializer.JsonSerializer +hrv.mart.orderUrl=${ORDER_URL} \ No newline at end of file