smart-house-web: бэкенд
This commit is contained in:
21
smart-house-web/backend/src/server/house.rs
Normal file
21
smart-house-web/backend/src/server/house.rs
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user