mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-10 20:42:10 +10:00
feat(collections): Added fetch_collections function
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
24
src-tauri/src/games/collections/collection.rs
Normal file
24
src-tauri/src/games/collections/collection.rs
Normal 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,
|
||||
}
|
||||
|
||||
21
src-tauri/src/games/collections/commands.rs
Normal file
21
src-tauri/src/games/collections/commands.rs
Normal 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)
|
||||
}
|
||||
2
src-tauri/src/games/collections/mod.rs
Normal file
2
src-tauri/src/games/collections/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod commands;
|
||||
pub mod collection;
|
||||
@ -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,
|
||||
|
||||
@ -2,3 +2,4 @@ pub mod commands;
|
||||
pub mod downloads;
|
||||
pub mod library;
|
||||
pub mod state;
|
||||
pub mod collections;
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user