-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding pagination on orders-api when we getting all orders #152
Merged
+301
−68
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4d0116c
Adding pagination on orders-api when we getting all orders
jurabek a2880ac
fixing the unit tests
jurabek 5bb28b2
fixing the fetchAll not returning all items
jurabek e422d01
fixing checkout consumer issue: still some issues
jurabek 9ebc2b3
Orders page in the dashboard app
jurabek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
14 changes: 14 additions & 0 deletions
14
...end/services/order-api/src/main/java/org/jurabek/restaurant/order/api/dtos/OrdersDto.java
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,14 @@ | ||
package org.jurabek.restaurant.order.api.dtos; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class OrdersDto { | ||
private List<OrderDto> orders; | ||
private Long total; | ||
private Integer offset; | ||
private Integer limit; | ||
} |
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
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
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
35 changes: 35 additions & 0 deletions
35
src/backend/services/web.admin/dashboard-app/src/app/(dashboard)/orders/order-table-row.tsx
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,35 @@ | ||
import { Button } from "@/components/ui/button"; | ||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; | ||
import { TableCell, TableRow } from "@/components/ui/table"; | ||
import { calculateTotalPrice, Order } from "@/lib/types/order"; | ||
import { MoreHorizontal } from "lucide-react"; | ||
|
||
export function OrderRow({ order }: { order: Order }) { | ||
return ( | ||
<TableRow> | ||
<TableCell className="font-medium">{order.orderedDate.toString()}</TableCell> | ||
<TableCell className="font-medium">{calculateTotalPrice(order)}</TableCell> | ||
<TableCell className="font-medium">{order.cartId}</TableCell> | ||
<TableCell className="font-medium">{order.checkoutId}</TableCell> | ||
<TableCell> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button aria-haspopup="true" size="icon" variant="ghost"> | ||
<MoreHorizontal className="h-4 w-4" /> | ||
<span className="sr-only">Toggle menu</span> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="end"> | ||
<DropdownMenuLabel>Actions</DropdownMenuLabel> | ||
<DropdownMenuItem>Edit</DropdownMenuItem> | ||
<DropdownMenuItem> | ||
<form action={() => {}}> | ||
<button type="submit">Delete</button> | ||
</form> | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</TableCell> | ||
</TableRow> | ||
); | ||
} |
109 changes: 109 additions & 0 deletions
109
src/backend/services/web.admin/dashboard-app/src/app/(dashboard)/orders/orders-table.tsx
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,109 @@ | ||
"use client"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { | ||
Table, | ||
TableBody, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "@/components/ui/table"; | ||
import { Order } from "@/lib/types/order"; | ||
import { ChevronLeft, ChevronRight } from "lucide-react"; | ||
import { useRouter } from "next/navigation"; | ||
import { OrderRow } from "./order-table-row"; | ||
|
||
export function OrdersTable({ | ||
orders, | ||
offset, | ||
totalProducts, | ||
productsPerPage, | ||
}: { | ||
orders: Order[]; | ||
offset: number; | ||
totalProducts: number; | ||
productsPerPage: number; | ||
}) { | ||
let router = useRouter(); | ||
function prevPage() { | ||
router.back(); | ||
} | ||
|
||
function nextPage() { | ||
router.push(`/orders?offset=${offset}`, { scroll: false }); | ||
} | ||
|
||
return ( | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>Orders</CardTitle> | ||
<CardDescription>View all orders.</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<Table> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead>Order Date</TableHead> | ||
<TableHead className="hidden md:table-cell"> | ||
Total Price | ||
</TableHead> | ||
<TableHead className="hidden md:table-cell">Cart ID</TableHead> | ||
<TableHead className="hidden md:table-cell"> | ||
Checkout ID | ||
</TableHead> | ||
<TableHead> | ||
<span className="sr-only">Actions</span> | ||
</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{orders.map((order) => ( | ||
<OrderRow key={order.id} order={order} /> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</CardContent> | ||
<CardFooter> | ||
<form className="flex items-center w-full justify-between"> | ||
<div className="text-xs text-muted-foreground"> | ||
Showing{" "} | ||
<strong> | ||
{Math.min(offset - productsPerPage, totalProducts) + 1}-{offset} | ||
</strong>{" "} | ||
of <strong>{totalProducts}</strong> products | ||
</div> | ||
<div className="flex"> | ||
<Button | ||
formAction={prevPage} | ||
variant="ghost" | ||
size="sm" | ||
type="submit" | ||
disabled={offset === productsPerPage} | ||
> | ||
<ChevronLeft className="mr-2 h-4 w-4" /> | ||
Prev | ||
</Button> | ||
<Button | ||
formAction={nextPage} | ||
variant="ghost" | ||
size="sm" | ||
type="submit" | ||
disabled={offset + productsPerPage > totalProducts} | ||
> | ||
Next | ||
<ChevronRight className="ml-2 h-4 w-4" /> | ||
</Button> | ||
</div> | ||
</form> | ||
</CardFooter> | ||
</Card> | ||
); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/backend/services/web.admin/dashboard-app/src/app/(dashboard)/orders/page.tsx
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,31 @@ | ||
import { fetchOrders } from "@/lib/fetch"; | ||
import { OrdersTable } from "./orders-table"; | ||
|
||
export default async function OrdersPage({ | ||
searchParams, | ||
}: { | ||
searchParams: { q: string; offset: string }; | ||
}) { | ||
const search = searchParams.q ?? ""; | ||
const offset = searchParams.offset ?? 0; | ||
const productsPerPage = 10; | ||
|
||
const { | ||
orders, | ||
total, | ||
offset: currOffset, | ||
} = await fetchOrders(Number(offset), productsPerPage); | ||
|
||
const newOffset = currOffset + productsPerPage; | ||
|
||
return ( | ||
<div> | ||
<OrdersTable | ||
orders={orders} | ||
offset={newOffset} | ||
totalProducts={total} | ||
productsPerPage={productsPerPage} | ||
/> | ||
</div> | ||
); | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/backend/services/web.admin/dashboard-app/src/lib/types/order.ts
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,32 @@ | ||
import * as z from "zod"; | ||
|
||
export const OrderItemSchema = z.object({ | ||
"id": z.string(), | ||
"unitPrice": z.number(), | ||
"units": z.number(), | ||
"productId": z.number(), | ||
"productName": z.null(), | ||
}); | ||
export type OrderItem = z.infer<typeof OrderItemSchema>; | ||
|
||
export const OrderSchema = z.object({ | ||
"id": z.string(), | ||
"orderedDate": z.coerce.date(), | ||
"cartId": z.string(), | ||
"transactionId": z.string(), | ||
"checkoutId": z.string(), | ||
"orderItems": z.array(OrderItemSchema), | ||
}); | ||
export type Order = z.infer<typeof OrderSchema>; | ||
|
||
export const OrdersSchema = z.object({ | ||
"orders": z.array(OrderSchema), | ||
"total": z.number(), | ||
"offset": z.number(), | ||
"limit": z.number(), | ||
}); | ||
export type Orders = z.infer<typeof OrdersSchema>; | ||
|
||
export function calculateTotalPrice(order: Order): number { | ||
return order.orderItems.reduce((total, item) => total + item.unitPrice, 0); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkout-api not getting ready during container start while Kafka broker is loading