1
Fork 0

turtle info endpoint

This commit is contained in:
Andy Killorin 2023-12-17 02:20:18 -06:00
parent 721ffeb765
commit 3f5a258ea9
Signed by: ank
GPG key ID: B6241CA3B552BCA4

View file

@ -63,7 +63,7 @@ impl Direction {
}
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
struct Turtle {
name: Name,
fuel: usize,
@ -111,9 +111,10 @@ async fn main() -> Result<(), Error> {
.route("/turtle/new", post(create_turtle))
.route("/turtle/update/:id", post(command))
.route("/turtle/client.lua", get(client))
.route("/turtle/control/:id/setGoal", post(set_goal))
.route("/turtle/setGoal/:id", post(set_goal))
.route("/turtle/info/:id", get(turtle_info))
.route("/turtle/updateAll", get(update_turtles))
.route("/flush", get(flush))
.route("/updateTurtles", get(update_turtles))
.with_state(state.clone());
let listener = tokio::net::TcpListener::bind("0.0.0.0:48228").await.unwrap();
@ -221,6 +222,15 @@ async fn update_turtles(
"ACK"
}
async fn turtle_info(
Path(id): Path<u32>,
State(state): State<SharedControl>,
) -> Json<Turtle> {
let state = &mut state.read().await;
Json(state.turtles[id as usize].clone())
}
async fn command(
Path(id): Path<u32>,
State(state): State<SharedControl>,