-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
8 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/hrv/mart/orderlibrary/config/APICallerConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/main/kotlin/com/hrv/mart/orderlibrary/model/query/OrderData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/hrv/mart/orderlibrary/model/query/OrderQuery.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/com/hrv/mart/orderlibrary/repository/OrderRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |