Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Fix QueryParams for VTN server
Browse files Browse the repository at this point in the history
  • Loading branch information
pohlm01 committed Jun 10, 2024
1 parent b435313 commit e34da18
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/vtn/api/program.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::cmp::min;
use std::collections::hash_map::Entry;

use axum::extract::{Path, State};
use axum::Json;
use chrono::Utc;
use reqwest::StatusCode;
use serde::Deserialize;
use tracing::trace;
use tracing::{debug, trace};
use validator::Validate;

use openadr::wire::program::{ProgramContent, ProgramId};
Expand Down Expand Up @@ -34,10 +35,12 @@ pub async fn get_all(
Err(err) => Some(Err(err)),
})
.collect::<Result<Vec<_>, AppError>>()?;

trace!("filtered programs: {:?}", programs);

Ok(Json(
programs
.get(query_params.skip as usize..(query_params.skip + query_params.limit) as usize)
.get(query_params.skip as usize..min((query_params.skip + query_params.limit) as usize, programs.len()))
.unwrap_or(&[])
.to_vec(),
))
Expand Down Expand Up @@ -67,6 +70,7 @@ pub async fn add(
Json(new_program): Json<ProgramContent>,
) -> Result<(StatusCode, Json<Program>), AppError> {
let program = Program::new(new_program);
debug!("created program with name '{}' and id '{}'", program.content.program_name, program.id);
state
.programs
.write()
Expand Down

0 comments on commit e34da18

Please sign in to comment.