Skip to content

Commit

Permalink
size and offset check
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed Dec 12, 2024
1 parent 0d7d54f commit 11b5c07
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
9 changes: 7 additions & 2 deletions backend/app/api/v1/endpoints/cpt/cptJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,21 @@ async def jobs(
except Exception as e:
print(f"Error fetching data for product {product}: {e}")

jobsCount = totalJobs
# The total is determined by summing the counts of all products and is included in the response.
# However, during pagination, if the count of any product drops to zero,
# the total becomes lower than the actual value, which is undesirable.

# on first hit, totalJobs is 0
if totalJobs == 0:
for product in total_dict:
total += int(total_dict[product])
totalJobs = total
jobsCount = total
response = {
"startDate": start_date.__str__(),
"endDate": end_date.__str__(),
"results": results_df.to_dict("records"),
"total": totalJobs,
"total": jobsCount,
"offset": offset + size,
}

Expand Down
3 changes: 1 addition & 2 deletions backend/app/api/v1/endpoints/cpt/maps/hce.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ....commons.hce import getData
from datetime import date

import pandas as pd

################################################################
# This will return a Dictionary from HCE required by the CPT
Expand All @@ -16,7 +16,6 @@
# "version"
# "testName"
################################################################
import pandas as pd


async def hceMapper(start_datetime: date, end_datetime: date, size: int, offset: int):
Expand Down
12 changes: 5 additions & 7 deletions backend/app/api/v1/endpoints/ocm/ocmJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ async def jobs(
status_code=422,
)

if not offset:
offset = 0

if not offset and not size:
size = 10000
offset = 0

if offset and not size:
raise HTTPException(400, f"offset {offset} specified without size")
elif not offset and not size:
size = 10000
offset = 0
elif not offset:
offset = 0

results = await getData(start_date, end_date, size, offset, "ocm.elasticsearch")

Expand Down
10 changes: 5 additions & 5 deletions backend/app/api/v1/endpoints/ocp/ocpJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ async def jobs(
status_code=422,
)

if not offset:
offset = 0
if not offset and not size:
size = 10000
offset = 0
if offset and not size:
raise HTTPException(400, f"offset {offset} specified without size")
elif not offset and not size:
size = 10000
offset = 0
elif not offset:
offset = 0

results = await getData(start_date, end_date, size, offset, "ocp.elasticsearch")
jobs = []
Expand Down
12 changes: 5 additions & 7 deletions backend/app/api/v1/endpoints/quay/quayJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ async def jobs(
status_code=422,
)

if not offset:
offset = 0

if not offset and not size:
size = 10000
offset = 0

if offset and not size:
raise HTTPException(400, f"offset {offset} specified without size")
elif not offset and not size:
size = 10000
offset = 0
elif not offset:
offset = 0

results = await getData(start_date, end_date, size, offset, "quay.elasticsearch")

Expand Down

0 comments on commit 11b5c07

Please sign in to comment.