use rincon_core::api::method::{Method, Operation, Parameters, Prepare, RpcReturnType};
use rincon_core::arango::protocol::{FIELD_CODE, FIELD_ID, FIELD_RESULT,
PARAM_EXCLUDE_SYSTEM, PATH_API_COLLECTION, PATH_PROPERTIES, PATH_RENAME,
PATH_REVISION};
#[cfg(feature = "cluster")]
use rincon_core::arango::protocol::PARAM_WAIT_FOR_SYNC_REPLICATION;
use super::types::*;
#[allow(missing_copy_implementations)]
#[derive(Debug, Clone, PartialEq)]
pub struct ListCollections {
exclude_system: bool
}
#[cfg_attr(feature = "cargo-clippy", allow(new_without_default_derive))]
impl ListCollections {
pub fn new() -> Self {
ListCollections {
exclude_system: true,
}
}
pub fn including_system() -> Self {
ListCollections {
exclude_system: false,
}
}
pub fn set_exclude_system(&mut self, exclude: bool) {
self.exclude_system = exclude;
}
pub fn is_exclude_system(&self) -> bool {
self.exclude_system
}
}
impl Method for ListCollections {
type Result = Vec<Collection>;
const RETURN_TYPE: RpcReturnType = RpcReturnType {
result_field: Some(FIELD_RESULT),
code_field: Some(FIELD_CODE),
};
}
impl Prepare for ListCollections {
type Content = ();
fn operation(&self) -> Operation {
Operation::Read
}
fn path(&self) -> String {
String::from(PATH_API_COLLECTION)
}
fn parameters(&self) -> Parameters {
let mut params = Parameters::with_capacity(1);
if self.exclude_system {
params.insert(PARAM_EXCLUDE_SYSTEM, true);
}
params
}
fn header(&self) -> Parameters {
Parameters::empty()
}
fn content(&self) -> Option<&Self::Content> {
None
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateCollection {
collection: NewCollection,
#[cfg(feature = "cluster")]
wait_for_sync_replication: bool,
}
impl CreateCollection {
pub fn new(collection: NewCollection) -> Self {
CreateCollection {
collection,
#[cfg(feature = "cluster")]
wait_for_sync_replication: true,
}
}
pub fn with_name<N>(name: N) -> Self
where N: Into<String>
{
CreateCollection {
collection: NewCollection::with_name(name),
#[cfg(feature = "cluster")]
wait_for_sync_replication: true,
}
}
pub fn documents_with_name<N>(name: N) -> Self
where N: Into<String>
{
CreateCollection {
collection: NewCollection::documents_with_name(name),
#[cfg(feature = "cluster")]
wait_for_sync_replication: true,
}
}
pub fn edges_with_name<N>(name: N) -> Self
where N: Into<String>
{
CreateCollection {
collection: NewCollection::edges_with_name(name),
#[cfg(feature = "cluster")]
wait_for_sync_replication: true,
}
}
#[cfg(feature = "cluster")]
pub fn set_wait_for_sync_replication(&mut self, wait_for_sync_replication: bool) {
self.wait_for_sync_replication = wait_for_sync_replication;
}
pub fn collection(&self) -> &NewCollection {
&self.collection
}
#[cfg(feature = "cluster")]
pub fn is_wait_for_sync_replication(&self) -> bool {
self.wait_for_sync_replication
}
}
impl Method for CreateCollection {
type Result = BasicCollectionProperties;
const RETURN_TYPE: RpcReturnType = RpcReturnType {
result_field: None,
code_field: Some(FIELD_CODE),
};
}
impl Prepare for CreateCollection {
type Content = NewCollection;
fn operation(&self) -> Operation {
Operation::Create
}
fn path(&self) -> String {
String::from(PATH_API_COLLECTION)
}
#[cfg(not(feature = "cluster"))]
fn parameters(&self) -> Parameters {
Parameters::empty()
}
#[cfg(feature = "cluster")]
fn parameters(&self) -> Parameters {
let mut params = Parameters::with_capacity(1);
if !self.wait_for_sync_replication {
params.insert(PARAM_WAIT_FOR_SYNC_REPLICATION, 0);
}
params
}
fn header(&self) -> Parameters {
Parameters::empty()
}
fn content(&self) -> Option<&Self::Content> {
Some(&self.collection)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct DropCollection {
name: String,
system: bool,
}
impl DropCollection {
pub fn with_name<N>(name: N) -> Self
where N: Into<String>
{
DropCollection {
name: name.into(),
system: false,
}
}
pub fn system_with_name<N>(name: N) -> Self
where N: Into<String>
{
DropCollection {
name: name.into(),
system: true,
}
}
pub fn set_system(&mut self, system: bool) {
self.system = system;
}
pub fn name(&self) -> &str {
&self.name
}
pub fn is_system(&self) -> bool {
self.system
}
}
impl Method for DropCollection {
type Result = String;
const RETURN_TYPE: RpcReturnType = RpcReturnType {
result_field: Some(FIELD_ID),
code_field: Some(FIELD_CODE),
};
}
impl Prepare for DropCollection {
type Content = ();
fn operation(&self) -> Operation {
Operation::Delete
}
fn path(&self) -> String {
String::from(PATH_API_COLLECTION)
+ "/" + &self.name
}
fn parameters(&self) -> Parameters {
Parameters::empty()
}
fn header(&self) -> Parameters {
Parameters::empty()
}
fn content(&self) -> Option<&Self::Content> {
None
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetCollection {
name: String,
}
impl GetCollection {
pub fn new(name: String) -> Self {
GetCollection {
name,
}
}
pub fn with_name<N>(name: N) -> Self
where N: Into<String>
{
GetCollection {
name: name.into(),
}
}
pub fn name(&self) -> &str {
&self.name
}
}
impl Method for GetCollection {
type Result = Collection;
const RETURN_TYPE: RpcReturnType = RpcReturnType {
result_field: None,
code_field: Some(FIELD_CODE),
};
}
impl Prepare for GetCollection {
type Content = ();
fn operation(&self) -> Operation {
Operation::Read
}
fn path(&self) -> String {
String::from(PATH_API_COLLECTION)
+ "/" + &self.name
}
fn parameters(&self) -> Parameters {
Parameters::empty()
}
fn header(&self) -> Parameters {
Parameters::empty()
}
fn content(&self) -> Option<&Self::Content> {
None
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetCollectionRevision {
name: String,
}
impl GetCollectionRevision {
pub fn new(name: String) -> Self {
GetCollectionRevision {
name,
}
}
pub fn with_name<N>(name: N) -> Self
where N: Into<String>
{
GetCollectionRevision {
name: name.into(),
}
}
pub fn name(&self) -> &str {
&self.name
}
}
impl Method for GetCollectionRevision {
type Result = CollectionRevision;
const RETURN_TYPE: RpcReturnType = RpcReturnType {
result_field: None,
code_field: Some(FIELD_CODE),
};
}
impl Prepare for GetCollectionRevision {
type Content = ();
fn operation(&self) -> Operation {
Operation::Read
}
fn path(&self) -> String {
String::from(PATH_API_COLLECTION)
+ "/" + &self.name + PATH_REVISION
}
fn parameters(&self) -> Parameters {
Parameters::empty()
}
fn header(&self) -> Parameters {
Parameters::empty()
}
fn content(&self) -> Option<&Self::Content> {
None
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetCollectionProperties {
name: String,
}
impl GetCollectionProperties {
pub fn new(name: String) -> Self {
GetCollectionProperties {
name,
}
}
pub fn with_name<N>(name: N) -> Self
where N: Into<String>
{
GetCollectionProperties {
name: name.into(),
}
}
pub fn name(&self) -> &str {
&self.name
}
}
impl Method for GetCollectionProperties {
type Result = CollectionProperties;
const RETURN_TYPE: RpcReturnType = RpcReturnType {
result_field: None,
code_field: Some(FIELD_CODE),
};
}
impl Prepare for GetCollectionProperties {
type Content = ();
fn operation(&self) -> Operation {
Operation::Read
}
fn path(&self) -> String {
String::from(PATH_API_COLLECTION)
+ "/" + &self.name + PATH_PROPERTIES
}
fn parameters(&self) -> Parameters {
Parameters::empty()
}
fn header(&self) -> Parameters {
Parameters::empty()
}
fn content(&self) -> Option<&Self::Content> {
None
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ChangeCollectionProperties {
name: String,
updates: CollectionPropertiesUpdate,
}
impl ChangeCollectionProperties {
pub fn new(name: String, updates: CollectionPropertiesUpdate) -> Self {
ChangeCollectionProperties {
name,
updates,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn updates(&self) -> &CollectionPropertiesUpdate {
&self.updates
}
}
impl Method for ChangeCollectionProperties {
type Result = CollectionProperties;
const RETURN_TYPE: RpcReturnType = RpcReturnType {
result_field: None,
code_field: Some(FIELD_CODE),
};
}
impl Prepare for ChangeCollectionProperties {
type Content = CollectionPropertiesUpdate;
fn operation(&self) -> Operation {
Operation::Replace
}
fn path(&self) -> String {
String::from(PATH_API_COLLECTION)
+ "/" + &self.name + PATH_PROPERTIES
}
fn parameters(&self) -> Parameters {
Parameters::empty()
}
fn header(&self) -> Parameters {
Parameters::empty()
}
fn content(&self) -> Option<&Self::Content> {
Some(&self.updates)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct RenameCollection {
name: String,
rename_to: RenameTo,
}
impl RenameCollection {
pub fn new(name: String, rename_to: RenameTo) -> Self {
RenameCollection {
name,
rename_to,
}
}
pub fn with_name<N>(name: N) -> RenameCollectionBuilder
where N: Into<String>
{
RenameCollectionBuilder {
collection_name: name.into(),
}
}
}
impl Method for RenameCollection {
type Result = Collection;
const RETURN_TYPE: RpcReturnType = RpcReturnType {
result_field: None,
code_field: Some(FIELD_CODE),
};
}
impl Prepare for RenameCollection {
type Content = RenameTo;
fn operation(&self) -> Operation {
Operation::Replace
}
fn path(&self) -> String {
String::from(PATH_API_COLLECTION)
+ "/" + &self.name
+ PATH_RENAME
}
fn parameters(&self) -> Parameters {
Parameters::empty()
}
fn header(&self) -> Parameters {
Parameters::empty()
}
fn content(&self) -> Option<&Self::Content> {
Some(&self.rename_to)
}
}
#[derive(Debug)]
pub struct RenameCollectionBuilder {
collection_name: String,
}
impl RenameCollectionBuilder {
#[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))]
pub fn to_name<N>(self, name: N) -> RenameCollection
where N: Into<String>
{
RenameCollection {
name: self.collection_name,
rename_to: RenameTo::new(name),
}
}
}