dcache/src/network/api.rs

55 lines
1.7 KiB
Rust

use actix_web::post;
use actix_web::web;
use actix_web::web::Data;
use actix_web::Responder;
use openraft::error::CheckIsLeaderError;
use openraft::error::Infallible;
use openraft::error::RaftError;
use openraft::BasicNode;
use web::Json;
use crate::app::ExampleApp;
use crate::store::ExampleRequest;
use crate::ExampleNodeId;
/**
* Application API
*
* This is where you place your application, you can use the example below to create your
* API. The current implementation:
*
* - `POST - /write` saves a value in a key and sync the nodes.
* - `POST - /read` attempt to find a value from a given key.
*/
#[post("/write")]
pub async fn write(
app: Data<ExampleApp>,
req: Json<ExampleRequest>,
) -> actix_web::Result<impl Responder> {
let response = app.raft.client_write(req.0).await;
Ok(Json(response))
}
// AddVisitor(AddVisitor),
// AddCaptcha(AddCaptcha),
// RenameCaptcha(RenameCaptcha),
// RemoveCaptcha(RemoveCaptcha),
//#[post("/post")]
//pub async fn read(app: Data<ExampleApp>, req: Json<String>) -> actix_web::Result<impl Responder> {
// let state_machine = app.store.state_machine.read().await;
// let key = req.0;
// let value = state_machine.data.get(&key).cloned();
//
// let res: Result<String, Infallible> = Ok(value.unwrap_or_default());
// Ok(Json(res))
//}
//
//#[post("/visitor/add")]
//pub async fn add_visitor(app: Data<ExampleApp>, req: Json<String>) -> actix_web::Result<impl Responder> {
// let state_machine = app.store.state_machine.read().await;
// let key = req.0;
// let value = state_machine.data.get(&key).cloned();
//
// let res: Result<String, Infallible> = Ok(value.unwrap_or_default());
// Ok(Json(res))
//}