feat: Process events with conductor object
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
a73111b36f
commit
96cd918dfe
1 changed files with 4 additions and 10 deletions
|
@ -19,6 +19,8 @@ use std::collections::HashMap;
|
||||||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use libconductor::{Conductor, EventType};
|
||||||
|
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::AppCtx;
|
use crate::AppCtx;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
@ -42,23 +44,15 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(post_event);
|
cfg.service(post_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
enum EventType {
|
|
||||||
NewHostname(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_web_codegen_const_routes::post(path = "API_V1_ROUTES.webhook.post_event")]
|
#[actix_web_codegen_const_routes::post(path = "API_V1_ROUTES.webhook.post_event")]
|
||||||
async fn post_event(ctx: AppCtx, payload: web::Json<EventType>) -> ServiceResult<impl Responder> {
|
async fn post_event(ctx: AppCtx, payload: web::Json<EventType>) -> ServiceResult<impl Responder> {
|
||||||
|
ctx.conductor.process(payload.into_inner()).await;
|
||||||
Ok(HttpResponse::Created())
|
Ok(HttpResponse::Created())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use actix_web::{
|
use actix_web::{http::StatusCode, test, App};
|
||||||
http::{header, StatusCode},
|
|
||||||
test, App,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue