Skip to content

Commit e28fa79

Browse files
committed
fix(task): pagination begins at 1
1 parent 8d3cbe9 commit e28fa79

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

internal/server/api/task.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ func (r *Task) getHistory(c *fiber.Ctx) error {
5252
}
5353

5454
limit := c.QueryInt("limit", 10)
55-
page := c.QueryInt("page", 0)
56-
if limit < 1 || page < 0 {
55+
page := c.QueryInt("page", 1)
56+
if limit < 1 || page < 1 {
5757
return fiber.ErrBadRequest
5858
}
5959

6060
tasks, err := r.task.GetHistory(c.Context(), dto.TaskFilter{
6161
TaskUID: uid,
6262
Result: result,
6363
Limit: limit,
64-
Offset: page * limit,
64+
Offset: (page - 1) * limit,
6565
})
6666
if err != nil {
6767
return err

ui/src/lib/api/task.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function useTaskGetAll() {
2929
export function useTaskGetHistory(filter?: TaskHistoryFilter) {
3030
const { data, isLoading, fetchNextPage, isFetchingNextPage, hasNextPage, error, refetch, isFetching } = useInfiniteQuery({
3131
queryKey: ["task_history", JSON.stringify(filter)],
32-
queryFn: async ({ pageParam = 0 }) => {
32+
queryFn: async ({ pageParam = 1 }) => {
3333
const queryParams = new URLSearchParams({
3434
page: pageParam.toString(),
3535
limit: PAGE_LIMIT.toString(),
@@ -46,7 +46,7 @@ export function useTaskGetHistory(filter?: TaskHistoryFilter) {
4646
const url = `${ENDPOINT}/history?${queryParams.toString()}`;
4747
return (await apiGet(url, convertTaskHistoryToModel)).data;
4848
},
49-
initialPageParam: 0,
49+
initialPageParam: 1,
5050
getNextPageParam: (lastPage, allPages) => {
5151
return lastPage.length < PAGE_LIMIT ? undefined : allPages.length + 1;
5252
},

0 commit comments

Comments
 (0)