Skip to content
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(cat-gateway): Add stub endpoints to minimally work with norns 1/2 #1055

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
555d198
feat: initial endpoints
apskhem Oct 24, 2024
7e27d6f
chore: fmtfix
apskhem Oct 24, 2024
a8e4614
fix: fund path
apskhem Oct 24, 2024
1b18582
chore: style
apskhem Oct 25, 2024
63a38cf
feat: settings dto
apskhem Oct 25, 2024
96cb81c
chore: fmtfix
apskhem Oct 25, 2024
9efbe7e
feat: proposals and fund
apskhem Oct 25, 2024
3251b9d
Merge branch 'main' into feat/norns-endpoints-stub
apskhem Oct 28, 2024
6779df9
feat: complete proposal dto
apskhem Oct 28, 2024
5cf088f
feat: review dto
apskhem Oct 28, 2024
740fc22
chore: fmtfix
apskhem Oct 28, 2024
8ab2ae5
Merge branch 'main' into feat/norns-endpoints-stub
apskhem Oct 29, 2024
89a9239
chore: lintfix
apskhem Oct 29, 2024
bda32de
chore: cspell fix
apskhem Oct 29, 2024
97ba07a
Merge branch 'main' into feat/norns-endpoints-stub
apskhem Oct 30, 2024
4170626
Merge branch 'main' into feat/norns-endpoints-stub
stevenj Nov 1, 2024
875ee00
Merge branch 'main' into feat/norns-endpoints-stub
apskhem Nov 4, 2024
408868f
refactor: move response dtos to legacy objects
apskhem Nov 4, 2024
9eed447
Merge branch 'main' into feat/norns-endpoints-stub
apskhem Nov 5, 2024
3e7e4cb
Merge branch 'main' into feat/norns-endpoints-stub
dtscalac Nov 5, 2024
7fd9c04
chore: lintfix
apskhem Nov 5, 2024
e38c243
Merge branch 'main' into feat/norns-endpoints-stub
apskhem Nov 5, 2024
55b4ac1
Merge branch 'main' into feat/norns-endpoints-stub
stevenj Nov 5, 2024
1c8613e
Merge branch 'main' into feat/norns-endpoints-stub
apskhem Nov 7, 2024
eee866e
docs: partial lintfix
apskhem Nov 7, 2024
616228f
Merge branch 'main' into feat/norns-endpoints-stub
apskhem Nov 17, 2024
d226eeb
Merge branch 'main' into feat/norns-endpoints-stub
apskhem Nov 21, 2024
83a3b76
docs: partial objects
apskhem Nov 25, 2024
589044e
docs: most of objects
apskhem Nov 25, 2024
c958c1e
feat: vote history object
apskhem Nov 26, 2024
8189602
fix: add omit files
apskhem Nov 26, 2024
a62987b
fix: finalize spectral rules
apskhem Nov 26, 2024
cacf3c6
chore: remove tmp just target
apskhem Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions catalyst-gateway/bin/src/service/api/legacy/v0/fund_get.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Implementation of the GET /setting endpoint
use poem_openapi::{payload::Json, ApiResponse};

use crate::service::common::{objects::legacy::fund::Fund, responses::WithErrorResponses};

/// Endpoint responses
#[derive(ApiResponse)]
pub(crate) enum Responses {
/// The default success response.
#[oai(status = 200)]
Ok(Json<Fund>),
}

/// All responses
pub(crate) type AllResponses = WithErrorResponses<Responses>;

/// The service endpoint
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint() -> AllResponses {
Responses::Ok(Json(Fund::default())).into()
}
110 changes: 108 additions & 2 deletions catalyst-gateway/bin/src/service/api/legacy/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
//! `v0` Endpoints
use poem_openapi::{payload::Binary, OpenApi};
use poem_openapi::{
param::Path,
payload::{Binary, Json},
OpenApi,
};

use crate::service::{
common::{auth::none::NoAuthorization, tags::ApiTags},
common::{
auth::none::NoAuthorization, objects::legacy::vote_history::VoteHistoryItem, tags::ApiTags,
},
utilities::middleware::schema_validation::schema_version_validation,
};

mod fund_get;
mod message_post;
mod plans_get;
mod proposal_by_id_get;
mod proposals_get;
mod proposals_post;
mod review_by_proposal_id_get;
mod settings_get;

/// `v0` API Endpoints
pub(crate) struct V0Api;
Expand Down Expand Up @@ -41,4 +54,97 @@ impl V0Api {
async fn plans_get(&self, _auth: NoAuthorization) -> plans_get::AllResponses {
plans_get::endpoint().await
}

/// Get settings.
apskhem marked this conversation as resolved.
Show resolved Hide resolved
///
/// Get settings information including fees detail.
#[oai(
path = "/settings",
method = "get",
operation_id = "GetSettings",
deprecated = true
)]
async fn settings_get(&self, _auth: NoAuthorization) -> settings_get::AllResponses {
settings_get::endpoint().await
}

/// Get fund.
///
/// Get fund information.
#[oai(
path = "/fund/",
method = "get",
operation_id = "GetFund",
deprecated = true
)]
async fn fund_get(&self, _auth: NoAuthorization) -> fund_get::AllResponses {
fund_get::endpoint().await
}

/// Get list of proposals.
///
/// Get list of proposals and the proposal's detail.
#[oai(
path = "/proposals",
method = "get",
operation_id = "GetProposals",
deprecated = true
)]
async fn proposals_get(&self, _auth: NoAuthorization) -> proposals_get::AllResponses {
proposals_get::endpoint().await
}

/// Get list of proposals.
///
/// Get list of proposals according to the filter options.
/// This is a POST method, only to send the filter data over the HTTP body.
#[oai(
path = "/proposals",
method = "post",
operation_id = "GetProposalsByFilter",
deprecated = true
)]
async fn proposals_post(
&self, message: Json<Vec<VoteHistoryItem>>, _auth: NoAuthorization,
) -> proposals_post::AllResponses {
proposals_post::endpoint(message.0).await
}

/// Get a proposal.
///
/// Get a proposal filtering by its identifier.
#[oai(
path = "/proposals/:id",
method = "get",
operation_id = "ShowProposalById",
deprecated = true
)]
async fn proposal_by_id_get(
&self,
/// The proposal identifier to be retrieved.
#[oai(validator(max_length = 256, min_length = 0, pattern = "[A-Za-z0-9_-]"))]
id: Path<String>,
_auth: NoAuthorization,
) -> proposal_by_id_get::AllResponses {
proposal_by_id_get::endpoint(id.0).await
}

/// Get proposal reviews.
///
/// Get proposal reviews by proposal identifier.
#[oai(
path = "/reviews/:proposal_id",
method = "get",
operation_id = "GetReviewByProposalId",
deprecated = true
)]
async fn review_by_proposal_id_get(
&self,
/// The proposal identifier to retrieve the reviews.
#[oai(validator(max_length = 256, min_length = 0, pattern = "[A-Za-z0-9_-]"))]
proposal_id: Path<String>,
_auth: NoAuthorization,
) -> review_by_proposal_id_get::AllResponses {
review_by_proposal_id_get::endpoint(proposal_id.0).await
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Implementation of the GET /setting endpoint
use poem_openapi::{payload::Json, ApiResponse};

use crate::service::common::{objects::legacy::proposal::Proposal, responses::WithErrorResponses};

/// Endpoint responses
#[derive(ApiResponse)]
pub(crate) enum Responses {
/// The default success response.
#[oai(status = 200)]
Ok(Json<Proposal>),
}

/// All responses
pub(crate) type AllResponses = WithErrorResponses<Responses>;

/// The service endpoint
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint(_id: String) -> AllResponses {
Responses::Ok(Json(Proposal::default())).into()
}
21 changes: 21 additions & 0 deletions catalyst-gateway/bin/src/service/api/legacy/v0/proposals_get.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Implementation of the GET /setting endpoint
use poem_openapi::{payload::Json, ApiResponse};

use crate::service::common::{objects::legacy::proposal::Proposal, responses::WithErrorResponses};

/// Endpoint responses
#[derive(ApiResponse)]
pub(crate) enum Responses {
/// The default success response.
#[oai(status = 200)]
Ok(Json<Vec<Proposal>>),
}

/// All responses
pub(crate) type AllResponses = WithErrorResponses<Responses>;

/// The service endpoint
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint() -> AllResponses {
Responses::Ok(Json(Default::default())).into()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! Implementation of the GET /setting endpoint
use poem_openapi::{payload::Json, ApiResponse};

use super::VoteHistoryItem;
use crate::service::common::{objects::legacy::proposal::Proposal, responses::WithErrorResponses};

/// Endpoint responses
#[derive(ApiResponse)]
pub(crate) enum Responses {
/// The default success response.
#[oai(status = 200)]
Ok(Json<Vec<Proposal>>),
}

/// All responses
pub(crate) type AllResponses = WithErrorResponses<Responses>;

/// The service endpoint
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint(_message: Vec<VoteHistoryItem>) -> AllResponses {
Responses::Ok(Json(Vec::new())).into()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Implementation of the GET /setting endpoint
use std::collections::HashMap;

use poem_openapi::{payload::Json, ApiResponse};

use crate::service::common::{objects::legacy::review::Review, responses::WithErrorResponses};

/// Endpoint responses
#[derive(ApiResponse)]
pub(crate) enum Responses {
/// The default success response.
#[oai(status = 200)]
Ok(Json<HashMap<String, Review>>),
}

/// All responses
pub(crate) type AllResponses = WithErrorResponses<Responses>;

/// The service endpoint
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint(_id: String) -> AllResponses {
Responses::Ok(Json(HashMap::default())).into()
}
23 changes: 23 additions & 0 deletions catalyst-gateway/bin/src/service/api/legacy/v0/settings_get.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Implementation of the GET /setting endpoint
use poem_openapi::{payload::Json, ApiResponse};

use crate::service::common::{
objects::legacy::settings_info::SettingsInfo, responses::WithErrorResponses,
};

/// Endpoint responses
#[derive(ApiResponse)]
pub(crate) enum Responses {
/// The default success response.
#[oai(status = 200)]
Ok(Json<SettingsInfo>),
}

/// All responses
pub(crate) type AllResponses = WithErrorResponses<Responses>;

/// The service endpoint
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint() -> AllResponses {
Responses::Ok(Json(SettingsInfo::default())).into()
}
11 changes: 11 additions & 0 deletions catalyst-gateway/bin/src/service/common/objects/legacy/fund.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Define the Fund

use poem_openapi::Object;

/// The fund information object.
#[allow(clippy::missing_docs_in_private_items)]
#[derive(Object, Default)]
pub(crate) struct Fund {
#[oai(validator(max_length = 256, min_length = 0, pattern = "[A-Za-z0-9_-]"))]
id: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ pub(crate) mod event_id;
pub(crate) mod fragment_status;
pub(crate) mod fragments_batch;
pub(crate) mod fragments_processing_summary;
pub(crate) mod fund;
pub(crate) mod hash;
pub(crate) mod proposal;
pub(crate) mod review;
pub(crate) mod settings_info;
pub(crate) mod stake_public_key;
pub(crate) mod vote_history;
pub(crate) mod vote_plan;
pub(crate) mod voter_group_id;
pub(crate) mod voter_info;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! Define the Proposal

use std::collections::HashMap;

use poem_openapi::Object;

/// The proposal object.
#[allow(clippy::missing_docs_in_private_items)]
#[allow(clippy::struct_field_names)]
#[derive(Object, Default)]
pub(crate) struct Proposal {
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
internal_id: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
chain_voteplan_id: String,
#[oai(validator(minimum(value = "0"), maximum(value = "4294967295")))]
chain_proposal_index: u32,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
chain_vote_encryption_key: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
chain_voteplan_payload: String,
#[oai(validator(
max_length = 32767,
min_length = 0,
pattern = "[\\s\\S]",
max_properties = 100,
min_properties = 0
))]
chain_vote_options: HashMap<String, String>,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
proposal_public_key: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
fund_id: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
proposal_summary: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
proposal_importance: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
proposal_title: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
proposal_goal: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
proposal_url: String,
#[oai(validator(minimum(value = "0"), maximum(value = "4294967295")))]
proposal_funds: u32,
#[oai(validator(minimum(value = "0"), maximum(value = "4294967295")))]
reviews_count: u32,
#[oai(validator(minimum(value = "0"), maximum(value = "4294967295")))]
proposal_impact_score: u32,
#[oai]
proposer: Option<Proposer>,
}

/// The proposer object.
#[allow(clippy::missing_docs_in_private_items)]
#[derive(Object, Default)]
pub(crate) struct Proposer {
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
proposer_name: String,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Define the Review

use poem_openapi::Object;

/// The proposal review object from a reviewer.
#[allow(clippy::missing_docs_in_private_items)]
#[derive(Object, Default)]
pub(crate) struct Review {
#[oai(validator(max_length = 256, min_length = 0, pattern = "[A-Za-z0-9_-]"))]
id: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
assessor: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
impact_alignment_note: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
impact_alignment_rating_given: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
auditability_note: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
auditability_rating_given: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
feasibility_note: String,
#[oai(validator(max_length = 32767, min_length = 0, pattern = "[\\s\\S]"))]
feasibility_rating_given: String,
}
Loading