smart-house-web: бэкенд

This commit is contained in:
15 changed files with 758 additions and 12 deletions

View File

@@ -0,0 +1,21 @@
use std::collections::HashMap;
use axum::{Json, extract::State, http::StatusCode};
use crate::Room;
pub async fn get_rooms(
State(server_state): State<super::ServerState>,
) -> Json<HashMap<String, Room>> {
server_state.read().await.get_rooms().clone().into()
}
pub async fn post_rooms(
State(server_state): State<super::ServerState>,
Json(map): Json<HashMap<String, Room>>,
) -> StatusCode {
for (name, room) in map.into_iter() {
server_state.write().await.add_room(name, room);
}
StatusCode::CREATED
}