-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: get config-versions api #248
Open
mahatoankitkumar
wants to merge
1
commit into
main
Choose a base branch
from
feat/get-snapshots
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod handlers; | ||
pub use handlers::endpoints; |
50 changes: 50 additions & 0 deletions
50
crates/context_aware_config/src/api/config_versions/handlers.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::{ | ||
db::{models::ConfigVersion, schema::config_versions}, | ||
types::{PaginatedResponse, QueryFilters}, | ||
}; | ||
|
||
extern crate base64; | ||
use service_utils::service::types::DbConnection; | ||
|
||
use superposition_types::result as superposition; | ||
|
||
use actix_web::{ | ||
get, | ||
web::{Json, Query}, | ||
Scope, | ||
}; | ||
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl}; | ||
|
||
pub fn endpoints() -> Scope { | ||
Scope::new("").service(get) | ||
} | ||
|
||
#[get("")] | ||
async fn get( | ||
db_conn: DbConnection, | ||
filters: Query<QueryFilters>, | ||
) -> superposition::Result<Json<PaginatedResponse<ConfigVersion>>> { | ||
let DbConnection(mut conn) = db_conn; | ||
|
||
let n_version: i64 = config_versions::dsl::config_versions | ||
.count() | ||
.get_result(&mut conn)?; | ||
let mut builder = config_versions::dsl::config_versions | ||
.into_boxed() | ||
.order(config_versions::dsl::created_at.desc()); | ||
if let Some(limit) = filters.count { | ||
builder = builder.limit(limit); | ||
} | ||
if let Some(page) = filters.page { | ||
let offset = (page - 1) * filters.count.unwrap_or(10); | ||
builder = builder.offset(offset); | ||
} | ||
let limit = filters.count.unwrap_or(10); | ||
let config_versions: Vec<ConfigVersion> = builder.load(&mut conn)?; | ||
let total_pages = (n_version as f64 / limit as f64).ceil() as i64; | ||
Ok(Json(PaginatedResponse { | ||
total_pages, | ||
total_items: n_version, | ||
data: config_versions, | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ pub mod api; | |
pub mod db; | ||
pub mod helpers; | ||
pub mod middlewares; | ||
pub mod types; | ||
pub mod validation_functions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Deserialize)] | ||
pub struct QueryFilters { | ||
pub count: Option<i64>, | ||
pub page: Option<i64>, | ||
} | ||
|
||
#[derive(Serialize, Debug, Clone, Deserialize)] | ||
pub struct PaginatedResponse<T> { | ||
pub total_pages: i64, | ||
pub total_items: i64, | ||
pub data: Vec<T>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we move this to
superposition_types
in some new file for such common utility types as it might be useful for experimentation as well for list experiments