mirror of
https://codeberg.org/Mo8it/git-webhook-client
synced 2024-11-21 11:06:32 +00:00
Simplify crate imports
This commit is contained in:
parent
42d97b5959
commit
539c15e221
3 changed files with 11 additions and 9 deletions
|
@ -9,7 +9,9 @@ use std::sync::Arc;
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use crate::{db, errors, extractors::ValidatedJson, mailer, states, templates, webhook};
|
use crate::{
|
||||||
|
db, errors::AppError, extractors::ValidatedJson, mailer::Mailer, states, templates, webhook,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct IndexQuery {
|
pub struct IndexQuery {
|
||||||
|
@ -19,7 +21,7 @@ pub struct IndexQuery {
|
||||||
pub async fn index(
|
pub async fn index(
|
||||||
State(db): State<Arc<states::DB>>,
|
State(db): State<Arc<states::DB>>,
|
||||||
query: Query<IndexQuery>,
|
query: Query<IndexQuery>,
|
||||||
) -> Result<Response, errors::AppError> {
|
) -> Result<Response, AppError> {
|
||||||
let id = match query.id {
|
let id = match query.id {
|
||||||
Some(id) if id != 0 => id,
|
Some(id) if id != 0 => id,
|
||||||
Some(_) => return Err("id=0 not allowed!".into()),
|
Some(_) => return Err("id=0 not allowed!".into()),
|
||||||
|
@ -38,9 +40,9 @@ pub async fn index(
|
||||||
pub async fn trigger(
|
pub async fn trigger(
|
||||||
State(db): State<Arc<states::DB>>,
|
State(db): State<Arc<states::DB>>,
|
||||||
State(state_config): State<Arc<states::StateConfig>>,
|
State(state_config): State<Arc<states::StateConfig>>,
|
||||||
State(mailer): State<Arc<mailer::Mailer>>,
|
State(mailer): State<Arc<Mailer>>,
|
||||||
ValidatedJson(json): ValidatedJson,
|
ValidatedJson(json): ValidatedJson,
|
||||||
) -> Result<Response, errors::AppError> {
|
) -> Result<Response, AppError> {
|
||||||
info!("Trigger called");
|
info!("Trigger called");
|
||||||
|
|
||||||
let repo = json
|
let repo = json
|
||||||
|
|
|
@ -2,7 +2,7 @@ use anyhow::Result;
|
||||||
use axum::extract::FromRef;
|
use axum::extract::FromRef;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{config, db, mailer};
|
use crate::{config, db, mailer::Mailer};
|
||||||
|
|
||||||
pub struct DB {
|
pub struct DB {
|
||||||
pub pool: db::DBPool,
|
pub pool: db::DBPool,
|
||||||
|
@ -41,12 +41,12 @@ impl StateConfig {
|
||||||
#[derive(Clone, FromRef)]
|
#[derive(Clone, FromRef)]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub config: Arc<StateConfig>,
|
pub config: Arc<StateConfig>,
|
||||||
pub mailer: Arc<mailer::Mailer>,
|
pub mailer: Arc<Mailer>,
|
||||||
pub db: Arc<DB>,
|
pub db: Arc<DB>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
pub fn build(config: config::Config, mailer: mailer::Mailer) -> Result<Self> {
|
pub fn build(config: config::Config, mailer: Mailer) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
config: Arc::new(StateConfig::from(config)),
|
config: Arc::new(StateConfig::from(config)),
|
||||||
mailer: Arc::new(mailer),
|
mailer: Arc::new(mailer),
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use std::{process::Command, sync::Arc};
|
use std::{process::Command, sync::Arc};
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
|
||||||
use crate::{config, db, mailer, states};
|
use crate::{config, db, mailer::Mailer, states};
|
||||||
|
|
||||||
pub struct TaskContext {
|
pub struct TaskContext {
|
||||||
pub hook: config::Hook,
|
pub hook: config::Hook,
|
||||||
pub hook_log_id: i32,
|
pub hook_log_id: i32,
|
||||||
pub hook_log_link: String,
|
pub hook_log_link: String,
|
||||||
pub db: Arc<states::DB>,
|
pub db: Arc<states::DB>,
|
||||||
pub mailer: Arc<mailer::Mailer>,
|
pub mailer: Arc<Mailer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(context: TaskContext) {
|
pub async fn run(context: TaskContext) {
|
||||||
|
|
Loading…
Reference in a new issue