Skip to content

Commit

Permalink
Rename the custom context in the minimal example
Browse files Browse the repository at this point in the history
  • Loading branch information
spencewenski committed May 12, 2024
1 parent 332dee1 commit 078a6b8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/minimal/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use roadster::service::registry::ServiceRegistry;
use roadster::service::worker::sidekiq::app_worker::AppWorker;
use roadster::service::worker::sidekiq::service::SidekiqWorkerService;

use crate::app_state::AppState;
use crate::app_state::CustomAppContext;
use crate::cli::AppCli;
use crate::controller;
use crate::worker::example::ExampleWorker;
Expand All @@ -19,7 +19,7 @@ pub struct App;

#[async_trait]
impl RoadsterApp for App {
type State = AppState;
type State = CustomAppContext;
type Cli = AppCli;
type M = Migrator;

Expand Down
8 changes: 4 additions & 4 deletions examples/minimal/src/app_state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// We need to use the disallowed `roadster::app_context::AppContext` type in this module in order
// to implement the required traits used to convert it to/from `AppState`.
#![allow(clippy::disallowed_types)]
use roadster::app_context::AppContext;

pub type AppState = ();
pub type CustomAppContext = ();

pub type AppState = AppContext<CustomAppContext>;
6 changes: 3 additions & 3 deletions examples/minimal/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use roadster::app_context::AppContext;
use roadster::cli::RunCommand;

use crate::app::App;
use crate::app_state::AppState;
use crate::app_state::CustomAppContext;

/// Minimal Example: Commands specific to managing the `minimal` app are provided in the CLI
/// as well. Subcommands not listed under the `roadster` subcommand are specific to `minimal`.
Expand All @@ -23,7 +23,7 @@ impl RunCommand<App> for AppCli {
&self,
app: &App,
cli: &AppCli,
context: &AppContext<AppState>,
context: &AppContext<CustomAppContext>,
) -> anyhow::Result<bool> {
if let Some(command) = self.command.as_ref() {
command.run(app, cli, context).await
Expand All @@ -45,7 +45,7 @@ impl RunCommand<App> for AppCommand {
&self,
_app: &App,
_cli: &AppCli,
_context: &AppContext<AppState>,
_context: &AppContext<CustomAppContext>,
) -> anyhow::Result<bool> {
Ok(false)
}
Expand Down
7 changes: 2 additions & 5 deletions examples/minimal/src/controller/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use aide::axum::ApiRouter;
use aide::transform::TransformOperation;
use axum::extract::State;
use axum::Json;
use roadster::app_context::AppContext;
use roadster::controller::build_path;
use roadster::service::worker::sidekiq::app_worker::AppWorker;
use roadster::view::app_error::AppError;
Expand All @@ -16,7 +15,7 @@ use tracing::instrument;
const BASE: &str = "/example";
const TAG: &str = "Example";

pub fn routes(parent: &str) -> ApiRouter<AppContext<AppState>> {
pub fn routes(parent: &str) -> ApiRouter<AppState> {
let root = build_path(parent, BASE);

ApiRouter::new().api_route(&root, get_with(example_get, example_get_docs))
Expand All @@ -27,9 +26,7 @@ pub fn routes(parent: &str) -> ApiRouter<AppContext<AppState>> {
pub struct ExampleResponse {}

#[instrument(skip_all)]
async fn example_get(
State(state): State<AppContext<AppState>>,
) -> Result<Json<ExampleResponse>, AppError> {
async fn example_get(State(state): State<AppState>) -> Result<Json<ExampleResponse>, AppError> {
ExampleWorker::enqueue(&state, "Example".to_string()).await?;
Ok(Json(ExampleResponse {}))
}
Expand Down
3 changes: 1 addition & 2 deletions examples/minimal/src/controller/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::app_state::AppState;
use aide::axum::ApiRouter;
use roadster::app_context::AppContext;

pub mod example;

pub fn routes(parent: &str) -> ApiRouter<AppContext<AppState>> {
pub fn routes(parent: &str) -> ApiRouter<AppState> {
ApiRouter::new().merge(example::routes(parent))
}
3 changes: 1 addition & 2 deletions examples/minimal/src/worker/example.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::app::App;
use crate::app_state::AppState;
use async_trait::async_trait;
use roadster::app_context::AppContext;
use roadster::service::worker::sidekiq::app_worker::AppWorker;
use sidekiq::Worker;
use tracing::{info, instrument};
Expand All @@ -19,7 +18,7 @@ impl Worker<String> for ExampleWorker {

#[async_trait]
impl AppWorker<App, String> for ExampleWorker {
fn build(_context: &AppContext<AppState>) -> Self {
fn build(_context: &AppState) -> Self {
Self {}
}
}

0 comments on commit 078a6b8

Please sign in to comment.