use std::sync::Arc;
use anyhow::Context;
use kr::make_ctx;
use salvo::{handler, Depot, Request};
use validator::Validate;
use infra::{
core::AppState,
status::{api_err::ApiErr, ApiResult},
};
use crate::service::{
self,
greeter::{ReqHello, RespHello},
};
#[handler]
pub async fn hello(depot: &mut Depot, req: &mut Request) -> ApiResult<RespHello> {
let params = req
.parse_json::<ReqHello>()
.await
.with_context(|| make_ctx("request body parsed failed"))?;
if let Err(e) = params.validate() {
return Err(ApiErr::Params(e.to_string()));
}
let ctx = depot.obtain::<Arc<AppState>>().unwrap();
// let iden = depot.obtain::<Identity>().unwrap();
service::greeter::hello(ctx, params).await
}