botx_api_framework/integration/actix/
notification_result_handler.rs1use std::sync::Arc;
2
3use actix_web::{web::{Data, self}, post, Responder, HttpResponse, http::{header::ContentType, self}, error};
4use anthill_di::DependencyContext;
5use async_lock::RwLock;
6use botx_api::{api::result::ExpressResult, bot::models::{NotificationCallbackRequestOk, NotificationCallbackRequestError}};
7
8use crate::contexts::{BotXApiFrameworkContext, NotificationContext};
9
10#[post("/notification/callback")]
11pub async fn notification_callback(request: web::Json<ExpressResult<NotificationCallbackRequestOk, NotificationCallbackRequestError>>, ioc_ctx: Data<DependencyContext>) -> impl Responder {
12 if request.0.is_ok() {
13 log::debug!("{:#?}", request);
14 } else {
15 log::error!("{:#?}", request);
16 }
17
18 let req = &request.0;
19
20 let sync_id = match req {
21 ExpressResult::<NotificationCallbackRequestOk, NotificationCallbackRequestError>::Ok(res) => res.sync_id.clone(),
22 ExpressResult::<NotificationCallbackRequestOk, NotificationCallbackRequestError>::Err(err) => err.sync_id.clone(),
23 };
24
25 if let Ok(notification_context) = ioc_ctx.resolve::<Arc<RwLock<NotificationContext>>>().await {
26 notification_context.write().await.event(sync_id);
27 }
28
29 let context = ioc_ctx.resolve::<BotXApiFrameworkContext>().await.expect("Контекст фреймворка не может быть получен из ioc");
30
31 context.process_notification_result(request.0).await;
32
33 HttpResponse::Ok()
34}