mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-27 15:40:36 +08:00
http: Move querystring structs into own module
This commit is contained in:
@@ -25,6 +25,7 @@ use radicle::Profile;
|
||||
|
||||
mod error;
|
||||
mod json;
|
||||
pub(crate) mod query;
|
||||
mod v1;
|
||||
|
||||
use crate::api::error::Error;
|
||||
@@ -154,87 +155,6 @@ async fn root_handler() -> impl IntoResponse {
|
||||
Json(response)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PaginationQuery {
|
||||
#[serde(default)]
|
||||
pub show: RepoQuery,
|
||||
pub page: Option<usize>,
|
||||
pub per_page: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum RepoQuery {
|
||||
All,
|
||||
#[default]
|
||||
Pinned,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RawQuery {
|
||||
pub mime: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CobsQuery<T> {
|
||||
pub page: Option<usize>,
|
||||
pub per_page: Option<usize>,
|
||||
pub status: Option<T>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PoliciesQuery {
|
||||
/// The NID from which to fetch from after tracking a repo.
|
||||
pub from: Option<NodeId>,
|
||||
pub scope: Option<Scope>,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum IssueStatus {
|
||||
Closed,
|
||||
#[default]
|
||||
Open,
|
||||
All,
|
||||
}
|
||||
|
||||
impl IssueStatus {
|
||||
pub fn matches(&self, issue: &issue::State) -> bool {
|
||||
match self {
|
||||
Self::Open => matches!(issue, issue::State::Open),
|
||||
Self::Closed => matches!(issue, issue::State::Closed { .. }),
|
||||
Self::All => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum PatchStatus {
|
||||
#[default]
|
||||
Open,
|
||||
Draft,
|
||||
Archived,
|
||||
Merged,
|
||||
All,
|
||||
}
|
||||
|
||||
impl PatchStatus {
|
||||
pub fn matches(&self, patch: &patch::State) -> bool {
|
||||
match self {
|
||||
Self::Open => matches!(patch, patch::State::Open { .. }),
|
||||
Self::Draft => matches!(patch, patch::State::Draft),
|
||||
Self::Archived => matches!(patch, patch::State::Archived),
|
||||
Self::Merged => matches!(patch, patch::State::Merged { .. }),
|
||||
Self::All => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod search {
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use radicle::cob::{issue, patch};
|
||||
use radicle::node::policy::Scope;
|
||||
use radicle::node::NodeId;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PaginationQuery {
|
||||
#[serde(default)]
|
||||
pub show: RepoQuery,
|
||||
pub page: Option<usize>,
|
||||
pub per_page: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum RepoQuery {
|
||||
All,
|
||||
#[default]
|
||||
Pinned,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RawQuery {
|
||||
pub mime: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CobsQuery<T> {
|
||||
pub page: Option<usize>,
|
||||
pub per_page: Option<usize>,
|
||||
pub status: Option<T>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PoliciesQuery {
|
||||
/// The NID from which to fetch from after tracking a repo.
|
||||
pub from: Option<NodeId>,
|
||||
pub scope: Option<Scope>,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum IssueStatus {
|
||||
Closed,
|
||||
#[default]
|
||||
Open,
|
||||
All,
|
||||
}
|
||||
|
||||
impl IssueStatus {
|
||||
pub fn matches(&self, issue: &issue::State) -> bool {
|
||||
match self {
|
||||
Self::Open => matches!(issue, issue::State::Open),
|
||||
Self::Closed => matches!(issue, issue::State::Closed { .. }),
|
||||
Self::All => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum PatchStatus {
|
||||
#[default]
|
||||
Open,
|
||||
Draft,
|
||||
Archived,
|
||||
Merged,
|
||||
All,
|
||||
}
|
||||
|
||||
impl PatchStatus {
|
||||
pub fn matches(&self, patch: &patch::State) -> bool {
|
||||
match self {
|
||||
Self::Open => matches!(patch, patch::State::Open { .. }),
|
||||
Self::Draft => matches!(patch, patch::State::Draft),
|
||||
Self::Archived => matches!(patch, patch::State::Archived),
|
||||
Self::Merged => matches!(patch, patch::State::Merged { .. }),
|
||||
Self::All => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,8 @@ use radicle::identity::Did;
|
||||
use radicle::storage::ReadStorage;
|
||||
|
||||
use crate::api::error::Error;
|
||||
use crate::api::{Context, PaginationQuery, RepoQuery};
|
||||
use crate::api::query::{PaginationQuery, RepoQuery};
|
||||
use crate::api::Context;
|
||||
use crate::axum_extra::{Path, Query};
|
||||
|
||||
pub fn router(ctx: Context) -> Router {
|
||||
|
||||
@@ -18,8 +18,9 @@ use radicle::storage::{ReadRepository, ReadStorage, RemoteRepository};
|
||||
|
||||
use crate::api;
|
||||
use crate::api::error::Error;
|
||||
use crate::api::query::{CobsQuery, PaginationQuery, RepoQuery};
|
||||
use crate::api::search::{SearchQueryString, SearchResult};
|
||||
use crate::api::{CobsQuery, Context, PaginationQuery, RepoQuery};
|
||||
use crate::api::Context;
|
||||
use crate::axum_extra::{cached_response, immutable_response, Path, Query};
|
||||
|
||||
const MAX_BODY_LIMIT: usize = 4_194_304;
|
||||
@@ -569,7 +570,7 @@ async fn readme_handler(
|
||||
async fn issues_handler(
|
||||
State(ctx): State<Context>,
|
||||
Path(rid): Path<RepoId>,
|
||||
Query(qs): Query<CobsQuery<api::IssueStatus>>,
|
||||
Query(qs): Query<CobsQuery<api::query::IssueStatus>>,
|
||||
) -> impl IntoResponse {
|
||||
let (repo, _) = ctx.repo(rid)?;
|
||||
let CobsQuery {
|
||||
@@ -623,7 +624,7 @@ async fn issue_handler(
|
||||
async fn patches_handler(
|
||||
State(ctx): State<Context>,
|
||||
Path(rid): Path<RepoId>,
|
||||
Query(qs): Query<CobsQuery<api::PatchStatus>>,
|
||||
Query(qs): Query<CobsQuery<api::query::PatchStatus>>,
|
||||
) -> impl IntoResponse {
|
||||
let (repo, _) = ctx.repo(rid)?;
|
||||
let CobsQuery {
|
||||
|
||||
@@ -15,7 +15,7 @@ use radicle::profile::Profile;
|
||||
use radicle::storage::{ReadRepository, ReadStorage};
|
||||
use radicle_surf::{Oid, Repository};
|
||||
|
||||
use crate::api::RawQuery;
|
||||
use crate::api::query::RawQuery;
|
||||
use crate::axum_extra::Path;
|
||||
use crate::error::RawError as Error;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user