Skip to content

Commit

Permalink
fix: replace API string durations with milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
SupernaviX committed Oct 31, 2024
1 parent eb8112c commit a9ec46e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 54 deletions.
31 changes: 24 additions & 7 deletions firefly-cardanoconnect/src/routes/streams.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::time::Duration;

use axum::extract::{Path, Query};
use axum::{extract::State, Json};
use firefly_server::apitypes::{ApiDuration, ApiError, ApiResult, NoContent};
use firefly_server::apitypes::{ApiError, ApiResult, NoContent};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand All @@ -15,6 +17,14 @@ fn example_opt_batch_size() -> Option<usize> {
Some(example_batch_size())
}

fn example_batch_timeout_ms() -> u64 {
500
}

fn example_opt_batch_timeout_ms() -> Option<u64> {
Some(example_batch_timeout_ms())
}

fn example_from_block() -> Option<String> {
Some("earliest".into())
}
Expand All @@ -25,7 +35,8 @@ pub struct CreateStreamRequest {
pub name: String,
#[schemars(example = "example_batch_size")]
pub batch_size: usize,
pub batch_timeout: ApiDuration,
#[schemars(example = "example_batch_timeout_ms")]
pub batch_timeout_ms: u64,
}

#[derive(Deserialize, JsonSchema)]
Expand All @@ -39,7 +50,8 @@ pub struct StreamPathParameters {
pub struct UpdateStreamRequest {
#[schemars(example = "example_opt_batch_size")]
pub batch_size: Option<usize>,
pub batch_timeout: Option<ApiDuration>,
#[schemars(example = "example_opt_batch_timeout_ms")]
pub batch_timeout_ms: Option<u64>,
}

#[derive(Serialize, JsonSchema)]
Expand All @@ -49,15 +61,16 @@ pub struct EventStream {
pub name: String,
#[schemars(example = "example_batch_size")]
pub batch_size: usize,
pub batch_timeout: ApiDuration,
#[schemars(example = "example_batch_timeout_ms")]
pub batch_timeout_ms: u64,
}
impl From<Stream> for EventStream {
fn from(value: Stream) -> Self {
Self {
id: value.id.into(),
name: value.name,
batch_size: value.batch_size,
batch_timeout: value.batch_timeout.into(),
batch_timeout_ms: value.batch_timeout.as_millis() as u64,
}
}
}
Expand Down Expand Up @@ -111,7 +124,11 @@ pub async fn create_stream(
Json(req): Json<CreateStreamRequest>,
) -> ApiResult<Json<EventStream>> {
let stream = stream_manager
.create_stream(&req.name, req.batch_size, req.batch_timeout.into())
.create_stream(
&req.name,
req.batch_size,
Duration::from_millis(req.batch_timeout_ms),
)
.await?;
Ok(Json(stream.into()))
}
Expand Down Expand Up @@ -151,7 +168,7 @@ pub async fn update_stream(
) -> ApiResult<Json<EventStream>> {
let id = stream_id.into();
let batch_size = req.batch_size;
let batch_timeout = req.batch_timeout.map(|d| d.into());
let batch_timeout = req.batch_timeout_ms.map(Duration::from_millis);
let stream = stream_manager
.update_stream(&id, batch_size, batch_timeout)
.await?;
Expand Down
2 changes: 0 additions & 2 deletions firefly-server/src/apitypes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod duration;
mod error;
mod no_content;

pub use duration::ApiDuration;
pub use error::{ApiError, ApiResult, Context, ToAnyhow};
pub use no_content::NoContent;
45 changes: 0 additions & 45 deletions firefly-server/src/apitypes/duration.rs

This file was deleted.

0 comments on commit a9ec46e

Please sign in to comment.