mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 16:51:18 +10:00
fix(collections): Ensured that all internal collection commands use and send the correct data
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
|
use serde_json::json;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{database::db::DatabaseImpls, error::remote_access_error::RemoteAccessError, remote::{auth::generate_authorization_header, requests::make_request}, DB};
|
use crate::{database::db::DatabaseImpls, error::remote_access_error::RemoteAccessError, remote::{auth::generate_authorization_header, requests::make_request}, DB};
|
||||||
@ -17,9 +18,9 @@ pub fn fetch_collections() -> Result<Collections, RemoteAccessError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn fetch_collection(id: String) -> Result<Collection, RemoteAccessError> {
|
pub fn fetch_collection(collection_id: String) -> Result<Collection, RemoteAccessError> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let response = make_request(&client, &["/api/v1/client/collection/", &id], &[], |r| {
|
let response = make_request(&client, &["/api/v1/client/collection/", &collection_id], &[], |r| {
|
||||||
r.header("Authorization", generate_authorization_header())
|
r.header("Authorization", generate_authorization_header())
|
||||||
})?
|
})?
|
||||||
.send()?;
|
.send()?;
|
||||||
@ -28,42 +29,39 @@ pub fn fetch_collection(id: String) -> Result<Collection, RemoteAccessError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn create_collection(name: String) -> Result<(), RemoteAccessError> {
|
pub fn create_collection(name: String) -> Result<Collection, RemoteAccessError> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let base_url = DB.fetch_base_url();
|
let base_url = DB.fetch_base_url();
|
||||||
|
|
||||||
let base_url = Url::parse(&format!("{}api/v1/client/collection/", base_url))?;
|
let base_url = Url::parse(&format!("{}api/v1/client/collection/", base_url))?;
|
||||||
|
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.post(base_url)
|
.post(base_url)
|
||||||
.header("Authorization", generate_authorization_header())
|
.header("Authorization", generate_authorization_header())
|
||||||
.json(&{name});
|
.json(&json!({"name": name}))
|
||||||
|
.send()?;
|
||||||
|
|
||||||
println!("{:?}", response);
|
Ok(response.json()?)
|
||||||
|
|
||||||
|
|
||||||
println!("{}", response.send()?.text().unwrap());
|
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn add_game_to_collection(name: String) -> Result<(), RemoteAccessError> {
|
pub fn add_game_to_collection(collection_id: String, game_id: String) -> Result<(), RemoteAccessError> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let url = Url::parse(&format!("{}api/v1/client/collection/{}/entry/", DB.fetch_base_url(), name))?;
|
let url = Url::parse(&format!("{}api/v1/client/collection/{}/entry/", DB.fetch_base_url(), collection_id))?;
|
||||||
|
|
||||||
let response = client
|
client
|
||||||
.post(url)
|
.post(url)
|
||||||
.header("Authorization", generate_authorization_header())
|
.header("Authorization", generate_authorization_header())
|
||||||
|
.json(&json!({"id": game_id}))
|
||||||
.send()?;
|
.send()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn delete_collection(id: String) -> Result<bool, RemoteAccessError> {
|
pub fn delete_collection(collection_id: String) -> Result<bool, RemoteAccessError> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let base_url = Url::parse(&format!("{}api/v1/client/collection/{}", DB.fetch_base_url(), id))?;
|
let base_url = Url::parse(&format!("{}api/v1/client/collection/{}", DB.fetch_base_url(), collection_id))?;
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.delete(base_url)
|
.delete(base_url)
|
||||||
@ -73,14 +71,14 @@ pub fn delete_collection(id: String) -> Result<bool, RemoteAccessError> {
|
|||||||
Ok(response.json()?)
|
Ok(response.json()?)
|
||||||
}
|
}
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn delete_game_in_collection(id: String) -> Result<(), RemoteAccessError> {
|
pub fn delete_game_in_collection(collection_id: String, game_id: String) -> Result<(), RemoteAccessError> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let base_url = Url::parse(&format!("{}api/v1/client/collection/{}/entry", DB.fetch_base_url(), id))?;
|
let base_url = Url::parse(&format!("{}api/v1/client/collection/{}/entry", DB.fetch_base_url(), collection_id))?;
|
||||||
|
|
||||||
client
|
client
|
||||||
.delete(base_url)
|
.delete(base_url)
|
||||||
.header("Authorization", generate_authorization_header())
|
.header("Authorization", generate_authorization_header())
|
||||||
.json(&{id})
|
.json(&json!({"id": game_id}))
|
||||||
.send()?;
|
.send()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user