monorepo/otg/core/src/library.rs

47 lines
1.4 KiB
Rust
Raw Normal View History

2024-03-22 02:39:28 +00:00
/*
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
2024-03-22 03:48:48 +00:00
This file is part of On the Grid.
2024-03-22 02:39:28 +00:00
2024-03-22 03:48:48 +00:00
On the Grid is free software: you can redistribute it and/or modify it under the terms of the GNU
2024-03-22 02:39:28 +00:00
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
2024-03-22 03:48:48 +00:00
On the Grid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
2024-03-22 02:39:28 +00:00
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
2024-03-22 03:48:48 +00:00
You should have received a copy of the GNU General Public License along with On the Grid. If not, see <https://www.gnu.org/licenses/>.
2024-03-22 02:39:28 +00:00
*/
use crate::Core;
2024-03-22 02:39:28 +00:00
use serde::{Deserialize, Serialize};
use sgf::GameRecord;
2024-03-22 02:39:28 +00:00
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum LibraryRequest {
ListGames,
2024-03-22 02:39:28 +00:00
}
#[derive(Clone, Debug)]
2024-03-22 02:39:28 +00:00
pub enum LibraryResponse {
Games(Vec<GameRecord>),
2024-03-22 02:39:28 +00:00
}
async fn handle_list_games(model: &Core) -> LibraryResponse {
let library = model.library();
match *library {
Some(ref library) => {
2024-03-23 18:41:35 +00:00
let info = library.all_games().cloned().collect::<Vec<GameRecord>>();
2024-03-22 02:39:28 +00:00
LibraryResponse::Games(info)
}
None => LibraryResponse::Games(vec![]),
}
}
pub async fn handle(model: &Core, request: LibraryRequest) -> LibraryResponse {
match request {
LibraryRequest::ListGames => handle_list_games(model).await,
}
}