Skip to content

Commit

Permalink
-Orders Route Enhancement (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhubaibKhan4 committed Jun 20, 2024
1 parent f9b5a96 commit e1c3e5a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface OrderDao {
deliveryDate: String
): Order?

suspend fun getAllOrders(): List<Order>
suspend fun getAllOrdersByUserId(id:Int): List<Order>
suspend fun getOrderById(id: Long): Order?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class OrderRepository : OrderDao {
return rowToResult(statement?.resultedValues?.get(0)!!)
}

override suspend fun getAllOrders(): List<Order> {
return DatabaseFactory.dbQuery {
OrderTable.selectAll().mapNotNull { rowToResult(it) }
}
}

override suspend fun getAllOrdersByUserId(id: Int): List<Order> {
return DatabaseFactory.dbQuery {
OrderTable.select { OrderTable.userId eq id }
Expand Down
19 changes: 19 additions & 0 deletions src/main/kotlin/com/example/plugins/Routes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2173,5 +2173,24 @@ fun Route.order(
)
}
}
get("v1/order") {

try {
val order = db.getAllOrders()
if (order != null) {
call.respond(HttpStatusCode.OK, order)
} else {
call.respond(
status = HttpStatusCode.NotFound,
"No Orders Found Yet."
)
}
} catch (e: Exception) {
call.respond(
status = HttpStatusCode.InternalServerError,
"Error While Fetching Order: ${e.message}"
)
}
}

}
Binary file added upload/products/promotions/flexi-store.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e1c3e5a

Please sign in to comment.