feat(collections): Added fetch_collections function

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2025-03-11 10:46:16 +11:00
parent 639d3b4630
commit 9614af7f03
6 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,24 @@
use serde::{Deserialize, Serialize};
use crate::games::library::Game;
pub type Collections = Vec<Collection>;
#[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<CollectionObject>
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct CollectionObject {
collection_id: String,
game_id: String,
game: Game,
}

View File

@ -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<Collections, RemoteAccessError> {
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)
}

View File

@ -0,0 +1,2 @@
pub mod commands;
pub mod collection;

View File

@ -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,

View File

@ -2,3 +2,4 @@ pub mod commands;
pub mod downloads;
pub mod library;
pub mod state;
pub mod collections;

View File

@ -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,