mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 00:31:33 +10:00
feat(collections): Added all internal collections commands
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -1,21 +1,81 @@
|
||||
use std::sync::Mutex;
|
||||
|
||||
use reqwest::blocking::Client;
|
||||
use url::Url;
|
||||
|
||||
use crate::{error::remote_access_error::RemoteAccessError, games::{collections::collection::CollectionObject, library::Game}, remote::{auth::generate_authorization_header, requests::make_request}, AppState};
|
||||
use crate::{database::db::DatabaseImpls, error::remote_access_error::RemoteAccessError, remote::{auth::generate_authorization_header, requests::make_request}, DB};
|
||||
|
||||
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();
|
||||
Ok(response.json()?)
|
||||
}
|
||||
|
||||
return Ok(res)
|
||||
#[tauri::command]
|
||||
pub fn fetch_collection(id: String) -> Result<Collection, RemoteAccessError> {
|
||||
let client = Client::new();
|
||||
let response = make_request(&client, &["/api/v1/client/collection/", &id], &[], |r| {
|
||||
r.header("Authorization", generate_authorization_header())
|
||||
})?
|
||||
.send()?;
|
||||
|
||||
Ok(response.json()?)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn create_collection(name: String) -> Result<String, RemoteAccessError> {
|
||||
let client = Client::new();
|
||||
let base_url = DB.fetch_base_url();
|
||||
|
||||
let base_url = Url::parse(&format!("{}/api/v1/client/collection/", base_url))?;
|
||||
|
||||
let response = client
|
||||
.post(base_url)
|
||||
.header("Authorization", generate_authorization_header())
|
||||
.json(&{name})
|
||||
.send()?;
|
||||
Ok(response.json()?)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn add_game_to_collection(name: String) -> Result<(), RemoteAccessError> {
|
||||
let client = Client::new();
|
||||
let url = Url::parse(&format!("{}/api/v1/client/collection/{}/entry/", DB.fetch_base_url(), name))?;
|
||||
|
||||
client
|
||||
.post(url)
|
||||
.header("Authorization", generate_authorization_header())
|
||||
.send()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn delete_collection(id: String) -> Result<bool, RemoteAccessError> {
|
||||
let client = Client::new();
|
||||
let base_url = Url::parse(&format!("{}/api/v1/client/collection/{}", DB.fetch_base_url(), id))?;
|
||||
|
||||
let response = client
|
||||
.delete(base_url)
|
||||
.header("Authorization", generate_authorization_header())
|
||||
.send()?;
|
||||
|
||||
Ok(response.json()?)
|
||||
}
|
||||
#[tauri::command]
|
||||
pub fn delete_game_in_collection(id: String) -> Result<(), RemoteAccessError> {
|
||||
let client = Client::new();
|
||||
let base_url = Url::parse(&format!("{}/api/v1/client/collection/{}/entry", DB.fetch_base_url(), id))?;
|
||||
|
||||
client
|
||||
.delete(base_url)
|
||||
.header("Authorization", generate_authorization_header())
|
||||
.json(&{id})
|
||||
.send()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -25,7 +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::collections::commands::{add_game_to_collection, create_collection, delete_collection, delete_game_in_collection, fetch_collection, fetch_collections};
|
||||
use games::commands::{
|
||||
fetch_game, fetch_game_status, fetch_game_verion_options, fetch_library, uninstall_game,
|
||||
};
|
||||
@ -251,6 +251,11 @@ pub fn run() {
|
||||
fetch_game_verion_options,
|
||||
// Collections
|
||||
fetch_collections,
|
||||
fetch_collection,
|
||||
create_collection,
|
||||
add_game_to_collection,
|
||||
delete_collection,
|
||||
delete_game_in_collection,
|
||||
// Downloads
|
||||
download_game,
|
||||
move_download_in_queue,
|
||||
|
||||
Reference in New Issue
Block a user