diff --git a/desktop/src-tauri/src/games/collections/collection.rs b/desktop/src-tauri/src/games/collections/collection.rs new file mode 100644 index 00000000..673c0d6d --- /dev/null +++ b/desktop/src-tauri/src/games/collections/collection.rs @@ -0,0 +1,24 @@ +use serde::{Deserialize, Serialize}; + +use crate::games::library::Game; + +pub type Collections = Vec; + +#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[serde(rename_all = "camelCase")] +pub struct Collection { + id: String, + name: String, + is_default: bool, + user_id: String, + entries: Vec +} + +#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[serde(rename_all = "camelCase")] +pub struct CollectionObject { + collection_id: String, + game_id: String, + game: Game, +} + diff --git a/desktop/src-tauri/src/games/collections/commands.rs b/desktop/src-tauri/src/games/collections/commands.rs new file mode 100644 index 00000000..19d7fdf4 --- /dev/null +++ b/desktop/src-tauri/src/games/collections/commands.rs @@ -0,0 +1,21 @@ +use std::sync::Mutex; + +use reqwest::blocking::Client; + +use crate::{error::remote_access_error::RemoteAccessError, games::{collections::collection::CollectionObject, library::Game}, remote::{auth::generate_authorization_header, requests::make_request}, AppState}; + +use super::collection::{Collection, Collections}; + +#[tauri::command] +pub fn fetch_collections() -> Result { + println!("Fetching collection"); + let client = Client::new(); + let response = make_request(&client, &["/api/v1/client/collection"], &[], |r| { + r.header("Authorization", generate_authorization_header()) + })? + .send()?; + + let res = response.json().unwrap(); + + return Ok(res) +} \ No newline at end of file diff --git a/desktop/src-tauri/src/games/collections/mod.rs b/desktop/src-tauri/src/games/collections/mod.rs new file mode 100644 index 00000000..ea3baf68 --- /dev/null +++ b/desktop/src-tauri/src/games/collections/mod.rs @@ -0,0 +1,2 @@ +pub mod commands; +pub mod collection; \ No newline at end of file diff --git a/desktop/src-tauri/src/games/library.rs b/desktop/src-tauri/src/games/library.rs index bfb4445e..1e1509f4 100644 --- a/desktop/src-tauri/src/games/library.rs +++ b/desktop/src-tauri/src/games/library.rs @@ -24,7 +24,7 @@ pub struct FetchGameStruct { status: GameStatusWithTransient, } -#[derive(Serialize, Deserialize, Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug, Default)] #[serde(rename_all = "camelCase")] pub struct Game { id: String, diff --git a/desktop/src-tauri/src/games/mod.rs b/desktop/src-tauri/src/games/mod.rs index 65c5c6b0..8b13190f 100644 --- a/desktop/src-tauri/src/games/mod.rs +++ b/desktop/src-tauri/src/games/mod.rs @@ -2,3 +2,4 @@ pub mod commands; pub mod downloads; pub mod library; pub mod state; +pub mod collections; \ No newline at end of file diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs index e134fcf5..8e5edbfa 100644 --- a/desktop/src-tauri/src/lib.rs +++ b/desktop/src-tauri/src/lib.rs @@ -25,6 +25,7 @@ use download_manager::commands::{ }; use download_manager::download_manager::DownloadManager; use download_manager::download_manager_builder::DownloadManagerBuilder; +use games::collections::commands::fetch_collections; use games::commands::{ fetch_game, fetch_game_status, fetch_game_verion_options, fetch_library, uninstall_game, }; @@ -248,6 +249,8 @@ pub fn run() { fetch_download_dir_stats, fetch_game_status, fetch_game_verion_options, + // Collections + fetch_collections, // Downloads download_game, move_download_in_queue,