Skip to content

Commit

Permalink
refactor: Move all legacy endpoints and corresponding types under the…
Browse files Browse the repository at this point in the history
… `legacy` mod (#258)

* move registration, v0 and v1 endpoints impl to the legacy mod

* update test endpoint

* move common objects to the legacy mod

* move event-db types and quries to the legacy mod
  • Loading branch information
Mr-Leshiy authored Feb 19, 2024
1 parent 97f675a commit 1f7ec0f
Show file tree
Hide file tree
Showing 54 changed files with 79 additions and 51 deletions.
4 changes: 4 additions & 0 deletions catalyst-gateway/bin/src/event_db/legacy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! Legacy event db queries and types
pub(crate) mod queries;
pub(crate) mod types;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_trait::async_trait;

use crate::event_db::{
error::Error,
types::{
legacy::types::{
ballot::{
Ballot, BallotType, GroupVotePlans, ObjectiveBallots, ObjectiveChoices, ProposalBallot,
VotePlan,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chrono::{NaiveDateTime, Utc};

use crate::event_db::{
error::Error,
types::event::{
legacy::types::event::{
Event, EventDetails, EventGoal, EventId, EventRegistration, EventSchedule, EventSummary,
VotingPowerAlgorithm, VotingPowerSettings,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_trait::async_trait;

use crate::event_db::{
error::Error,
types::{
legacy::types::{
event::EventId,
objective::{
Objective, ObjectiveDetails, ObjectiveId, ObjectiveSummary, ObjectiveType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_trait::async_trait;

use crate::event_db::{
error::Error,
types::{
legacy::types::{
event::EventId,
objective::ObjectiveId,
proposal::{Proposal, ProposalDetails, ProposalId, ProposalSummary, ProposerDetails},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_trait::async_trait;

use crate::event_db::{
error::Error,
types::{
legacy::types::{
event::EventId,
objective::ObjectiveId,
proposal::ProposalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_trait::async_trait;
use chrono::{NaiveDateTime, Utc};

use crate::event_db::{
types::{
legacy::types::{
event::EventId,
registration::{Delegation, Delegator, RewardAddress, Voter, VoterGroupId, VoterInfo},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_trait::async_trait;
use chrono::{NaiveDateTime, Utc};

use crate::event_db::{
types::{
legacy::types::{
event::{EventId, EventSummary},
objective::{ObjectiveId, ObjectiveSummary, ObjectiveType},
proposal::{ProposalId, ProposalSummary},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use async_trait::async_trait;
use chrono::{NaiveDateTime, Utc};

use crate::event_db::{
types::vit_ss::{
legacy::types::vit_ss::{
challenge::{Challenge, ChallengeHighlights},
fund::{Fund, FundNextInfo, FundStageDates, FundWithNext},
goal::Goal,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Ballot types
use super::{objective::ObjectiveId, proposal::ProposalId};
use crate::event_db::types::registration::VoterGroupId;
use crate::event_db::legacy::types::registration::VoterGroupId;

#[derive(Debug, Clone, PartialEq, Eq)]
/// Objective Choices
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Objective Types
use serde_json::Value;

use crate::event_db::types::registration::VoterGroupId;
use crate::event_db::legacy::types::registration::VoterGroupId;

#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
3 changes: 1 addition & 2 deletions catalyst-gateway/bin/src/event_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use tokio_postgres::NoTls;

mod config_table;
pub(crate) mod error;
pub(crate) mod queries;
pub(crate) mod legacy;
pub(crate) mod schema_check;
pub(crate) mod types;

/// Database URL Environment Variable name.
/// eg: "`postgres://catalyst-dev:CHANGE_ME@localhost/CatalystDev`"
Expand Down
13 changes: 13 additions & 0 deletions catalyst-gateway/bin/src/service/api/legacy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Legacy endpoints
pub(crate) use registration::RegistrationApi;
pub(crate) use v0::V0Api;
pub(crate) use v1::V1Api;

mod registration;
mod v0;
mod v1;

/// Legacy endpoints API
#[allow(dead_code)]
pub(crate) type LegacyApi = (RegistrationApi, V0Api, V1Api);
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use poem_openapi::{
use crate::{
service::{
common::{
objects::{
objects::legacy::{
event_id::EventId, voter_registration::VoterRegistration,
voting_public_key::VotingPublicKey,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use poem_extensions::{response, UniResponse::T200};
use poem_openapi::payload::{Binary, Json};

use crate::service::common::{
objects::fragments_processing_summary::FragmentsProcessingSummary,
objects::legacy::fragments_processing_summary::FragmentsProcessingSummary,
responses::{
resp_2xx::OK,
resp_4xx::BadRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use poem_openapi::payload::Json;

use crate::{
service::common::{
objects::vote_plan::VotePlan,
objects::legacy::vote_plan::VotePlan,
responses::{
resp_2xx::OK,
resp_4xx::BadRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use poem_openapi::{param::Path, payload::Json};

use crate::{
service::common::{
objects::account_votes::{AccountId, AccountVote},
objects::legacy::account_votes::{AccountId, AccountVote},
responses::{
resp_2xx::OK,
resp_4xx::BadRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use poem_extensions::{response, UniResponse::T200};
use poem_openapi::payload::Json;

use crate::service::common::{
objects::{
objects::legacy::{
fragments_batch::FragmentsBatch, fragments_processing_summary::FragmentsProcessingSummary,
},
responses::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use poem_extensions::{response, UniResponse::T200};
use poem_openapi::payload::Json;

use crate::service::common::{
objects::{fragment_status::FragmentStatus, fragments_processing_summary::FragmentId},
objects::legacy::{fragment_status::FragmentStatus, fragments_processing_summary::FragmentId},
responses::{
resp_2xx::OK,
resp_4xx::BadRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use poem_openapi::{
use crate::{
service::{
common::{
objects::{
objects::legacy::{
account_votes::AccountId, fragments_batch::FragmentsBatch,
fragments_processing_summary::FragmentId,
},
Expand Down
16 changes: 8 additions & 8 deletions catalyst-gateway/bin/src/service/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@ use std::net::IpAddr;

use gethostname::gethostname;
use health::HealthApi;
use legacy::LegacyApi;
use local_ip_address::list_afinet_netifas;
use poem_openapi::{ContactObject, LicenseObject, OpenApiService, ServerObject};
use registration::RegistrationApi;
use test_endpoints::TestApi;
use v0::V0Api;
use v1::V1Api;

use crate::settings::{DocsSettings, API_URL_PREFIX};

mod health;
mod registration;
mod legacy;
mod test_endpoints;
mod v0;
mod v1;

/// The name of the API
const API_TITLE: &str = "Catalyst Gateway";
Expand Down Expand Up @@ -62,9 +58,13 @@ const TERMS_OF_SERVICE: &str =
/// Create the `OpenAPI` definition
pub(crate) fn mk_api(
hosts: Vec<String>, settings: &DocsSettings,
) -> OpenApiService<(TestApi, HealthApi, RegistrationApi, V0Api, V1Api), ()> {
) -> OpenApiService<(TestApi, HealthApi, LegacyApi), ()> {
let mut service = OpenApiService::new(
(TestApi, HealthApi, RegistrationApi, V0Api, V1Api),
(
TestApi,
HealthApi,
(legacy::RegistrationApi, legacy::V0Api, legacy::V1Api),
),
API_TITLE,
API_VERSION,
)
Expand Down
8 changes: 7 additions & 1 deletion catalyst-gateway/bin/src/service/api/test_endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ use poem_openapi::{
OpenApi,
};

use crate::{service::common::tags::ApiTags, state::State};
use crate::{
service::{
common::tags::ApiTags, utilities::middleware::schema_validation::schema_version_validation,
},
state::State,
};

/// Test API Endpoints
pub(crate) struct TestApi;
Expand All @@ -23,6 +28,7 @@ impl TestApi {
path = "/test/:id/test/:action",
method = "get",
operation_id = "testGet",
transform = "schema_version_validation",
deprecated
)]
/// Test Get API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ impl Example for EventId {
}
}

impl From<EventId> for crate::event_db::types::event::EventId {
impl From<EventId> for crate::event_db::legacy::types::event::EventId {
fn from(event_id: EventId) -> Self {
crate::event_db::types::event::EventId(event_id.0)
crate::event_db::legacy::types::event::EventId(event_id.0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use poem_openapi::{types::Example, Object, Union};

use crate::service::common::objects::{block::BlockDate, hash::Hash};
use crate::service::common::objects::legacy::{block::BlockDate, hash::Hash};

#[derive(Object)]
#[oai(example = false)]
Expand Down
16 changes: 16 additions & 0 deletions catalyst-gateway/bin/src/service/common/objects/legacy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! Legacy objects
pub(crate) mod account_votes;
pub(crate) mod block;
pub(crate) mod delegate_public_key;
pub(crate) mod event_id;
pub(crate) mod fragment_status;
pub(crate) mod fragments_batch;
pub(crate) mod fragments_processing_summary;
pub(crate) mod hash;
pub(crate) mod stake_public_key;
pub(crate) mod vote_plan;
pub(crate) mod voter_group_id;
pub(crate) mod voter_info;
pub(crate) mod voter_registration;
pub(crate) mod voting_public_key;
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ impl Example for VoterGroupId {
}
}

impl TryFrom<crate::event_db::types::registration::VoterGroupId> for VoterGroupId {
impl TryFrom<crate::event_db::legacy::types::registration::VoterGroupId> for VoterGroupId {
type Error = String;

fn try_from(
value: crate::event_db::types::registration::VoterGroupId,
value: crate::event_db::legacy::types::registration::VoterGroupId,
) -> Result<Self, Self::Error> {
match value.0.as_str() {
"rep" => Ok(Self::Rep),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ impl Example for VoterInfo {
}
}

impl TryFrom<crate::event_db::types::registration::VoterInfo> for VoterInfo {
impl TryFrom<crate::event_db::legacy::types::registration::VoterInfo> for VoterInfo {
type Error = String;

fn try_from(
value: crate::event_db::types::registration::VoterInfo,
value: crate::event_db::legacy::types::registration::VoterInfo,
) -> Result<Self, Self::Error> {
Ok(Self {
voting_power: value.voting_power,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ impl Example for VoterRegistration {
}
}

impl TryFrom<crate::event_db::types::registration::Voter> for VoterRegistration {
impl TryFrom<crate::event_db::legacy::types::registration::Voter> for VoterRegistration {
type Error = String;

fn try_from(value: crate::event_db::types::registration::Voter) -> Result<Self, Self::Error> {
fn try_from(
value: crate::event_db::legacy::types::registration::Voter,
) -> Result<Self, Self::Error> {
Ok(Self {
voter_info: value.info.try_into()?,
as_at: value.as_at,
Expand Down
16 changes: 2 additions & 14 deletions catalyst-gateway/bin/src/service/common/objects/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
//! This module contains common and re-usable objects.
pub(crate) mod account_votes;
pub(crate) mod block;
pub(crate) mod delegate_public_key;
pub(crate) mod event_id;
pub(crate) mod fragment_status;
pub(crate) mod fragments_batch;
pub(crate) mod fragments_processing_summary;
pub(crate) mod hash;
pub(crate) mod stake_public_key;
pub(crate) mod vote_plan;
pub(crate) mod voter_group_id;
pub(crate) mod voter_info;
pub(crate) mod voter_registration;
pub(crate) mod voting_public_key;
pub(crate) mod legacy;

0 comments on commit 1f7ec0f

Please sign in to comment.