fix(client): fixing pool CRUD operations
This commit is contained in:
parent
e14c1b48fa
commit
6b20a89c1e
4 changed files with 37 additions and 31 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
|
@ -949,15 +949,6 @@ dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "progress"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "17b820305721858696053a7fd0215cfeeee16ecaaf96b7a209945428e02f1c44"
|
|
||||||
dependencies = [
|
|
||||||
"terminal_size",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.36"
|
version = "1.0.36"
|
||||||
|
|
@ -1404,7 +1395,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "szurubooru-client"
|
name = "szurubooru-client"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
@ -1430,7 +1421,6 @@ dependencies = [
|
||||||
name = "szurubooru-integration-test"
|
name = "szurubooru-integration-test"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"progress",
|
|
||||||
"szurubooru-client",
|
"szurubooru-client",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
@ -1450,16 +1440,6 @@ dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "terminal_size"
|
|
||||||
version = "0.1.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.63"
|
version = "1.0.63"
|
||||||
|
|
|
||||||
|
|
@ -1084,7 +1084,7 @@ impl<'a> SzurubooruRequest<'a> {
|
||||||
create_update_pool: &CreateUpdatePool,
|
create_update_pool: &CreateUpdatePool,
|
||||||
) -> SzurubooruResult<PoolResource> {
|
) -> SzurubooruResult<PoolResource> {
|
||||||
let path = format!("/pool/{pool_id}");
|
let path = format!("/pool/{pool_id}");
|
||||||
self.do_request(Method::POST, &path, None, Some(create_update_pool))
|
self.do_request(Method::PUT, &path, None, Some(create_update_pool))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1097,10 +1097,12 @@ impl<'a> SzurubooruRequest<'a> {
|
||||||
|
|
||||||
/// Deletes existing pool. All posts in the pool will only have their relation to the pool
|
/// Deletes existing pool. All posts in the pool will only have their relation to the pool
|
||||||
/// removed.
|
/// removed.
|
||||||
pub async fn delete_pool(&self, pool_id: u32) -> SzurubooruResult<()> {
|
pub async fn delete_pool(&self, pool_id: u32, version: u32) -> SzurubooruResult<()> {
|
||||||
let path = format!("/pool/{pool_id}");
|
let path = format!("/pool/{pool_id}");
|
||||||
self.do_request(Method::DELETE, &path, None, None::<&String>)
|
let version_obj = ResourceVersion { version };
|
||||||
|
self.do_request::<Value, _, _>(Method::DELETE, &path, None, Some(&version_obj))
|
||||||
.await
|
.await
|
||||||
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes source pool and merges all of its posts with the target pool. Other pool properties
|
/// Removes source pool and merges all of its posts with the target pool. Other pool properties
|
||||||
|
|
|
||||||
|
|
@ -360,21 +360,27 @@ pub struct CreateUpdatePost {
|
||||||
/// created. Tags created automatically have no implications, no suggestions, one name and
|
/// created. Tags created automatically have no implications, no suggestions, one name and
|
||||||
/// their category is set to the first tag category found
|
/// their category is set to the first tag category found
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
pub tags: Vec<String>,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub tags: Option<Vec<String>>,
|
||||||
/// Required field, represents the SFW/NSFW state of a post
|
/// Required field, represents the SFW/NSFW state of a post
|
||||||
pub safety: PostSafety,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub safety: Option<PostSafety>,
|
||||||
/// The origin of the post's content
|
/// The origin of the post's content
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub source: Option<String>,
|
pub source: Option<String>,
|
||||||
/// The IDs of related posts
|
/// The IDs of related posts
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
pub relations: Vec<u32>,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub relations: Option<Vec<u32>>,
|
||||||
/// Notes to be displayed on the post
|
/// Notes to be displayed on the post
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
pub notes: Vec<NoteResource>,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub notes: Option<Vec<NoteResource>>,
|
||||||
/// Flags relevant to the post. If omitted they will be auto-detected
|
/// Flags relevant to the post. If omitted they will be auto-detected
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
pub flags: Vec<String>,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub flags: Option<Vec<String>>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
/// The URL to download the content from
|
/// The URL to download the content from
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
|
|
@ -515,16 +521,20 @@ pub struct CreateUpdateUser {
|
||||||
pub version: Option<u32>,
|
pub version: Option<u32>,
|
||||||
/// The username
|
/// The username
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
/// The user's password
|
/// The user's password
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub password: Option<String>,
|
pub password: Option<String>,
|
||||||
/// The user's desired rank, if not given will default to `default_rank` in the server's
|
/// The user's desired rank, if not given will default to `default_rank` in the server's
|
||||||
/// configuration
|
/// configuration
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub rank: Option<UserRank>,
|
pub rank: Option<UserRank>,
|
||||||
/// The user avatar style, Gravatar or Manual
|
/// The user avatar style, Gravatar or Manual
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub avatar_style: Option<UserAvatarStyle>,
|
pub avatar_style: Option<UserAvatarStyle>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -570,15 +580,19 @@ pub struct UserAuthTokenResource {
|
||||||
pub struct CreateUpdateUserAuthToken {
|
pub struct CreateUpdateUserAuthToken {
|
||||||
/// Resource version. See [versioning](ResourceVersion)
|
/// Resource version. See [versioning](ResourceVersion)
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[builder(default)]
|
||||||
pub version: Option<u32>,
|
pub version: Option<u32>,
|
||||||
/// Whether the token is still valid for authentication
|
/// Whether the token is still valid for authentication
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[builder(default)]
|
||||||
pub enabled: Option<bool>,
|
pub enabled: Option<bool>,
|
||||||
/// A note that describes the token
|
/// A note that describes the token
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[builder(default)]
|
||||||
pub note: Option<String>,
|
pub note: Option<String>,
|
||||||
/// Time when the token expires
|
/// Time when the token expires
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[builder(default)]
|
||||||
pub expiration_time: Option<DateTime<Utc>>,
|
pub expiration_time: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -731,16 +745,25 @@ pub struct PoolResource {
|
||||||
pub struct CreateUpdatePool {
|
pub struct CreateUpdatePool {
|
||||||
/// Resource version. See [versioning](ResourceVersion)
|
/// Resource version. See [versioning](ResourceVersion)
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[builder(default)]
|
||||||
pub version: Option<u32>,
|
pub version: Option<u32>,
|
||||||
/// Names and aliases for this pool. When creating a new pool the first name in this list
|
/// Names and aliases for this pool. When creating a new pool the first name in this list
|
||||||
/// is used as the pool name
|
/// is used as the pool name
|
||||||
|
#[builder(default)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub names: Option<Vec<String>>,
|
pub names: Option<Vec<String>>,
|
||||||
/// Pool category that this pool belongs to. Must already exist
|
/// Pool category that this pool belongs to. Must already exist
|
||||||
|
#[builder(default)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub category: Option<String>,
|
pub category: Option<String>,
|
||||||
/// Markdown string describing this pool
|
/// Markdown string describing this pool
|
||||||
|
#[builder(default)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
/// A list of posts that belong to this pool. The server will throw an error if one of these
|
/// A list of posts that belong to this pool. The server will throw an error if one of these
|
||||||
/// post IDs doesn't exist
|
/// post IDs doesn't exist
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[builder(default)]
|
||||||
pub posts: Option<Vec<u32>>,
|
pub posts: Option<Vec<u32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -827,12 +850,14 @@ pub struct CommentResource {
|
||||||
/// .unwrap();
|
/// .unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
pub struct CreateUpdateComment {
|
pub struct CreateUpdateComment {
|
||||||
|
#[builder(default)]
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
/// Resource version. See [versioning](ResourceVersion)
|
/// Resource version. See [versioning](ResourceVersion)
|
||||||
/// Omitted when creating a new comment
|
/// Omitted when creating a new comment
|
||||||
pub version: Option<u32>,
|
pub version: Option<u32>,
|
||||||
/// The text of the comment
|
/// The text of the comment
|
||||||
pub text: String,
|
pub text: String,
|
||||||
|
#[builder(default)]
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
/// The post the comment should be attached to. Only used when creating a new comment
|
/// The post the comment should be attached to. Only used when creating a new comment
|
||||||
pub post_id: Option<u32>,
|
pub post_id: Option<u32>,
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
progress = "0.2.0"
|
szurubooru-client = { path = "../szurubooru-client" }
|
||||||
szurubooru-client = { version = "0.1.0", path = "../szurubooru-client" }
|
|
||||||
tokio = { version = "1.39.2", features = ["full", "test-util", "tracing"] }
|
tokio = { version = "1.39.2", features = ["full", "test-util", "tracing"] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue