Skip to content

Commit 6b6609f

Browse files
committed
Add limit and offset to job endpont
1 parent f448133 commit 6b6609f

File tree

9 files changed

+93
-4
lines changed

9 files changed

+93
-4
lines changed

rfd-api-spec.json

+18
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,24 @@
720720
"summary": "List all jobs for a RFD",
721721
"operationId": "list_jobs",
722722
"parameters": [
723+
{
724+
"in": "query",
725+
"name": "limit",
726+
"schema": {
727+
"nullable": true,
728+
"type": "integer",
729+
"format": "int64"
730+
}
731+
},
732+
{
733+
"in": "query",
734+
"name": "offset",
735+
"schema": {
736+
"nullable": true,
737+
"type": "integer",
738+
"format": "int64"
739+
}
740+
},
723741
{
724742
"in": "query",
725743
"name": "rfd",

rfd-api/src/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,12 @@ impl RfdContext {
819819
&self,
820820
caller: &Caller<RfdPermission>,
821821
filter: Option<JobFilter>,
822+
pagination: &ListPagination,
822823
) -> ResourceResult<Vec<Job>, StoreError> {
823824
let mut jobs = JobStore::list(
824825
&*self.storage,
825826
filter.map(|filter| vec![filter]).unwrap_or_default(),
826-
&ListPagination::default().limit(UNLIMITED),
827+
pagination,
827828
)
828829
.await
829830
.tap_err(|err| tracing::error!(?err, "Failed to lookup jobs"))

rfd-api/src/endpoints/job.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ use serde::Deserialize;
99
use trace_request::trace_request;
1010
use tracing::instrument;
1111
use v_api::{response::client_error, ApiContext};
12-
use v_model::permissions::Caller;
12+
use v_model::{permissions::Caller, storage::ListPagination};
1313

1414
use crate::{context::RfdContext, permissions::RfdPermission};
1515

16+
use super::UNLIMITED;
17+
1618
// Read Endpoints
1719

1820
#[derive(Debug, Deserialize, JsonSchema)]
1921
struct ListJobsQuery {
2022
rfd: String,
23+
limit: Option<i64>,
24+
offset: Option<i64>,
2125
}
2226

2327
/// List all jobs for a RFD
@@ -50,6 +54,9 @@ async fn list_jobs_op(
5054
.list_jobs(
5155
caller,
5256
Some(JobFilter::default().rfd(Some(vec![rfd_number]))),
57+
&ListPagination::default()
58+
.limit(query.limit.unwrap_or(UNLIMITED))
59+
.offset(query.offset.unwrap_or(0)),
5360
)
5461
.await?;
5562
Ok(HttpResponseOk(jobs))

rfd-api/src/endpoints/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5+
pub static UNLIMITED: i64 = 9999999;
6+
57
pub mod job;
68
pub mod rfd;
79
pub mod webhook;

rfd-cli/src/generated/cli.rs

+20
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,18 @@ impl<T: CliConfig> Cli<T> {
465465

466466
pub fn cli_list_jobs() -> ::clap::Command {
467467
::clap::Command::new("")
468+
.arg(
469+
::clap::Arg::new("limit")
470+
.long("limit")
471+
.value_parser(::clap::value_parser!(i64))
472+
.required(false),
473+
)
474+
.arg(
475+
::clap::Arg::new("offset")
476+
.long("offset")
477+
.value_parser(::clap::value_parser!(i64))
478+
.required(false),
479+
)
468480
.arg(
469481
::clap::Arg::new("rfd")
470482
.long("rfd")
@@ -2121,6 +2133,14 @@ impl<T: CliConfig> Cli<T> {
21212133

21222134
pub async fn execute_list_jobs(&self, matches: &::clap::ArgMatches) -> anyhow::Result<()> {
21232135
let mut request = self.client.list_jobs();
2136+
if let Some(value) = matches.get_one::<i64>("limit") {
2137+
request = request.limit(value.clone());
2138+
}
2139+
2140+
if let Some(value) = matches.get_one::<i64>("offset") {
2141+
request = request.offset(value.clone());
2142+
}
2143+
21242144
if let Some(value) = matches.get_one::<::std::string::String>("rfd") {
21252145
request = request.rfd(value.clone());
21262146
}

rfd-sdk/src/generated/sdk.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -13490,6 +13490,8 @@ impl Client {
1349013490
///
1349113491
/// ```ignore
1349213492
/// let response = client.list_jobs()
13493+
/// .limit(limit)
13494+
/// .offset(offset)
1349313495
/// .rfd(rfd)
1349413496
/// .send()
1349513497
/// .await;
@@ -15709,17 +15711,43 @@ pub mod builder {
1570915711
#[derive(Debug, Clone)]
1571015712
pub struct ListJobs<'a> {
1571115713
client: &'a super::Client,
15714+
limit: Result<Option<i64>, String>,
15715+
offset: Result<Option<i64>, String>,
1571215716
rfd: Result<::std::string::String, String>,
1571315717
}
1571415718

1571515719
impl<'a> ListJobs<'a> {
1571615720
pub fn new(client: &'a super::Client) -> Self {
1571715721
Self {
1571815722
client: client,
15723+
limit: Ok(None),
15724+
offset: Ok(None),
1571915725
rfd: Err("rfd was not initialized".to_string()),
1572015726
}
1572115727
}
1572215728

15729+
pub fn limit<V>(mut self, value: V) -> Self
15730+
where
15731+
V: std::convert::TryInto<i64>,
15732+
{
15733+
self.limit = value
15734+
.try_into()
15735+
.map(Some)
15736+
.map_err(|_| "conversion to `i64` for limit failed".to_string());
15737+
self
15738+
}
15739+
15740+
pub fn offset<V>(mut self, value: V) -> Self
15741+
where
15742+
V: std::convert::TryInto<i64>,
15743+
{
15744+
self.offset = value
15745+
.try_into()
15746+
.map(Some)
15747+
.map_err(|_| "conversion to `i64` for offset failed".to_string());
15748+
self
15749+
}
15750+
1572315751
pub fn rfd<V>(mut self, value: V) -> Self
1572415752
where
1572515753
V: std::convert::TryInto<::std::string::String>,
@@ -15734,7 +15762,14 @@ pub mod builder {
1573415762
pub async fn send(
1573515763
self,
1573615764
) -> Result<ResponseValue<::std::vec::Vec<types::Job>>, Error<types::Error>> {
15737-
let Self { client, rfd } = self;
15765+
let Self {
15766+
client,
15767+
limit,
15768+
offset,
15769+
rfd,
15770+
} = self;
15771+
let limit = limit.map_err(Error::InvalidRequest)?;
15772+
let offset = offset.map_err(Error::InvalidRequest)?;
1573815773
let rfd = rfd.map_err(Error::InvalidRequest)?;
1573915774
let url = format!("{}/job", client.baseurl,);
1574015775
#[allow(unused_mut)]
@@ -15745,6 +15780,8 @@ pub mod builder {
1574515780
::reqwest::header::ACCEPT,
1574615781
::reqwest::header::HeaderValue::from_static("application/json"),
1574715782
)
15783+
.query(&progenitor_client::QueryParam::new("limit", &limit))
15784+
.query(&progenitor_client::QueryParam::new("offset", &offset))
1574815785
.query(&progenitor_client::QueryParam::new("rfd", &rfd))
1574915786
.build()?;
1575015787
let result = client.client.execute(request).await;

rfd-ts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oxide/rfd.ts",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "TypeScript client for the RFD API",
55
"engines": {
66
"node": ">=18"

rfd-ts/src/Api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ export interface DeleteGroupPathParams {
615615
}
616616

617617
export interface ListJobsQueryParams {
618+
limit?: number
619+
offset?: number
618620
rfd: string
619621
}
620622

rfd-ts/src/validate.ts

+2
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,8 @@ export const ListJobsParams = z.preprocess(
884884
z.object({
885885
path: z.object({}),
886886
query: z.object({
887+
limit: z.number().optional(),
888+
offset: z.number().optional(),
887889
rfd: z.string(),
888890
}),
889891
}),

0 commit comments

Comments
 (0)