Skip to content

Commit

Permalink
Add order endpoints (#16)
Browse files Browse the repository at this point in the history
* Add api call

* add custom pageable

* Update workflow

* Add orderurl in application.properties

* Add config for api call

* Add model for query

* Added repository
  • Loading branch information
Harsh3305 authored Jul 4, 2023
1 parent 8aa25be commit 4377051
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<KotlinCompile> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
)
}
36 changes: 36 additions & 0 deletions src/main/kotlin/com/hrv/mart/orderlibrary/model/query/OrderData.kt
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Original file line number Diff line number Diff line change
@@ -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<Status> = 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
}
Original file line number Diff line number Diff line change
@@ -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
)
}
7 changes: 4 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
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}

0 comments on commit 4377051

Please sign in to comment.