added autogenerated rust server code
This commit is contained in:
parent
e3cc07061c
commit
0246f22e3e
22
Cargo.toml
22
Cargo.toml
|
@ -6,15 +6,9 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# for web server
|
||||
rocket = { version = "0.5.0", features = ["json", "uuid"] }
|
||||
rocket_dyn_templates = { version = "0.1.0", features = ["handlebars", "tera"] }
|
||||
# for json serialization
|
||||
serde = "1.0.196"
|
||||
|
||||
# for random number generation
|
||||
rand = "0.8.5"
|
||||
# for json serialization
|
||||
serde_json = "1.0.113"
|
||||
# for uuid generation
|
||||
uuid = { version = "1.7.0", features = ["serde", "v4"] }
|
||||
# for command line arguments
|
||||
|
@ -23,5 +17,17 @@ structopt = "0.3.23"
|
|||
csv = "1.1.6"
|
||||
clap = { version = "4.3.24", features = ["derive"] }
|
||||
|
||||
|
||||
stv-rs = "0.3.0"
|
||||
|
||||
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_yaml = "0.7"
|
||||
serde_json = "1.0"
|
||||
base64 = "~0.7.0"
|
||||
futures = "0.1.16"
|
||||
hyper = "0.11.6"
|
||||
url = "1.5"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio-core = "*"
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# Authorization
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**to_date** | **String** | | [optional] [default to null]
|
||||
**from_date** | **String** | | [optional] [default to null]
|
||||
**user** | **String** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# Credentials
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**username** | **String** | | [optional] [default to null]
|
||||
**password** | **String** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
# \DefaultApi
|
||||
|
||||
All URIs are relative to *https://localhost/api*
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
[**auth_login_post**](DefaultApi.md#auth_login_post) | **Post** /auth/login | Authenticate user
|
||||
[**auth_token_post**](DefaultApi.md#auth_token_post) | **Post** /auth/token | Generate authentication token for another user
|
||||
[**elections_all_get**](DefaultApi.md#elections_all_get) | **Get** /elections/all | Get all existing elections
|
||||
[**elections_create_post**](DefaultApi.md#elections_create_post) | **Post** /elections/create | Create new election
|
||||
[**elections_id_get**](DefaultApi.md#elections_id_get) | **Get** /elections/{id} | Get all existing elections
|
||||
[**elections_id_post**](DefaultApi.md#elections_id_post) | **Post** /elections/{id} | Vote in exsisting election
|
||||
|
||||
|
||||
# **auth_login_post**
|
||||
> ::models::InlineResponse200 auth_login_post(ctx, credentials)
|
||||
Authenticate user
|
||||
|
||||
### Required Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**ctx** | **context.Context** | context containing the authentication | nil if no authentication
|
||||
**credentials** | [**Credentials**](Credentials.md)| |
|
||||
|
||||
### Return type
|
||||
|
||||
[**::models::InlineResponse200**](inline_response_200.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[JWT](../README.md#JWT)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json
|
||||
- **Accept**: application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **auth_token_post**
|
||||
> ::models::InlineResponse2001 auth_token_post(ctx, authorization, token)
|
||||
Generate authentication token for another user
|
||||
|
||||
### Required Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**ctx** | **context.Context** | context containing the authentication | nil if no authentication
|
||||
**authorization** | **String**| Your authorization token |
|
||||
**token** | [**Authorization**](Authorization.md)| |
|
||||
|
||||
### Return type
|
||||
|
||||
[**::models::InlineResponse2001**](inline_response_200_1.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[JWT](../README.md#JWT)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json
|
||||
- **Accept**: application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **elections_all_get**
|
||||
> ::models::ElectionList elections_all_get(ctx, authorization)
|
||||
Get all existing elections
|
||||
|
||||
### Required Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**ctx** | **context.Context** | context containing the authentication | nil if no authentication
|
||||
**authorization** | **String**| Your authorization token |
|
||||
|
||||
### Return type
|
||||
|
||||
[**::models::ElectionList**](ElectionList.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[JWT](../README.md#JWT)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json
|
||||
- **Accept**: application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **elections_create_post**
|
||||
> ::models::Election elections_create_post(ctx, authorization, election)
|
||||
Create new election
|
||||
|
||||
### Required Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**ctx** | **context.Context** | context containing the authentication | nil if no authentication
|
||||
**authorization** | **String**| Your authorization token |
|
||||
**election** | [**Election**](Election.md)| |
|
||||
|
||||
### Return type
|
||||
|
||||
[**::models::Election**](Election.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[JWT](../README.md#JWT)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json
|
||||
- **Accept**: application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **elections_id_get**
|
||||
> ::models::Election elections_id_get(ctx, authorization, id)
|
||||
Get all existing elections
|
||||
|
||||
### Required Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**ctx** | **context.Context** | context containing the authentication | nil if no authentication
|
||||
**authorization** | **String**| Your authorization token |
|
||||
**id** | **String**| |
|
||||
|
||||
### Return type
|
||||
|
||||
[**::models::Election**](Election.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[JWT](../README.md#JWT)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json
|
||||
- **Accept**: application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **elections_id_post**
|
||||
> ::models::Vote elections_id_post(ctx, authorization, election)
|
||||
Vote in exsisting election
|
||||
|
||||
### Required Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**ctx** | **context.Context** | context containing the authentication | nil if no authentication
|
||||
**authorization** | **String**| Your authorization token |
|
||||
**election** | [**Vote**](Vote.md)| |
|
||||
|
||||
### Return type
|
||||
|
||||
[**::models::Vote**](Vote.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
[JWT](../README.md#JWT)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json
|
||||
- **Accept**: application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
# Election
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**id** | **String** | | [optional] [default to null]
|
||||
**username** | **String** | | [optional] [default to null]
|
||||
**name** | **String** | | [optional] [default to null]
|
||||
**description** | **String** | | [optional] [default to null]
|
||||
**start_date** | **String** | | [optional] [default to null]
|
||||
**end_date** | **String** | | [optional] [default to null]
|
||||
**items** | [**Vec<::models::ElectionItem>**](ElectionItem.md) | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# ElectionItem
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**id** | **String** | | [optional] [default to null]
|
||||
**name** | **String** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# ElectionList
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# InlineResponse200
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**token** | **String** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# InlineResponse2001
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**token** | **String** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
# User
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**id** | **String** | | [optional] [default to null]
|
||||
**username** | **String** | | [optional] [default to null]
|
||||
**password** | **String** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
# Vote
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**authorization** | [***::models::Authorization**](Authorization.md) | | [optional] [default to null]
|
||||
**userid** | **String** | | [optional] [default to null]
|
||||
**data** | [**Vec<::models::VoteItem>**](VoteItem.md) | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# VoteItem
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**item** | [***::models::ElectionItem**](ElectionItem.md) | | [optional] [default to null]
|
||||
**value** | **f32** | | [optional] [default to null]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use hyper;
|
||||
use super::configuration::Configuration;
|
||||
|
||||
pub struct APIClient<C: hyper::client::Connect> {
|
||||
configuration: Rc<Configuration<C>>,
|
||||
default_api: Box<::apis::DefaultApi>,
|
||||
}
|
||||
|
||||
impl<C: hyper::client::Connect> APIClient<C> {
|
||||
pub fn new(configuration: Configuration<C>) -> APIClient<C> {
|
||||
let rc = Rc::new(configuration);
|
||||
|
||||
APIClient {
|
||||
configuration: rc.clone(),
|
||||
default_api: Box::new(::apis::DefaultApiClient::new(rc.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_api(&self) -> &::apis::DefaultApi{
|
||||
self.default_api.as_ref()
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
use hyper;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct Configuration<C: hyper::client::Connect> {
|
||||
pub base_path: String,
|
||||
pub user_agent: Option<String>,
|
||||
pub client: hyper::client::Client<C>,
|
||||
pub basic_auth: Option<BasicAuth>,
|
||||
pub oauth_access_token: Option<String>,
|
||||
pub api_key: Option<ApiKey>,
|
||||
// TODO: take an oauth2 token source, similar to the go one
|
||||
}
|
||||
|
||||
pub type BasicAuth = (String, Option<String>);
|
||||
|
||||
pub struct ApiKey {
|
||||
pub prefix: Option<String>,
|
||||
pub key: String,
|
||||
}
|
||||
|
||||
impl<C: hyper::client::Connect> Configuration<C> {
|
||||
pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
|
||||
Configuration {
|
||||
base_path: "https://localhost/api".to_owned(),
|
||||
user_agent: Some("Swagger-Codegen/0.0.1/rust".to_owned()),
|
||||
client: client,
|
||||
basic_auth: None,
|
||||
oauth_access_token: None,
|
||||
api_key: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,480 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
use hyper::header::UserAgent;
|
||||
|
||||
use super::{Error, configuration};
|
||||
|
||||
pub struct DefaultApiClient<C: hyper::client::Connect> {
|
||||
configuration: Rc<configuration::Configuration<C>>,
|
||||
}
|
||||
|
||||
impl<C: hyper::client::Connect> DefaultApiClient<C> {
|
||||
pub fn new(configuration: Rc<configuration::Configuration<C>>) -> DefaultApiClient<C> {
|
||||
DefaultApiClient {
|
||||
configuration: configuration,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DefaultApi {
|
||||
fn auth_login_post(&self, credentials: ::models::Credentials) -> Box<Future<Item = ::models::InlineResponse200, Error = Error<serde_json::Value>>>;
|
||||
fn auth_token_post(&self, authorization: &str, token: ::models::Authorization) -> Box<Future<Item = ::models::InlineResponse2001, Error = Error<serde_json::Value>>>;
|
||||
fn elections_all_get(&self, authorization: &str) -> Box<Future<Item = ::models::ElectionList, Error = Error<serde_json::Value>>>;
|
||||
fn elections_create_post(&self, authorization: &str, election: ::models::Election) -> Box<Future<Item = ::models::Election, Error = Error<serde_json::Value>>>;
|
||||
fn elections_id_get(&self, authorization: &str, id: &str) -> Box<Future<Item = ::models::Election, Error = Error<serde_json::Value>>>;
|
||||
fn elections_id_post(&self, authorization: &str, election: ::models::Vote) -> Box<Future<Item = ::models::Vote, Error = Error<serde_json::Value>>>;
|
||||
}
|
||||
|
||||
|
||||
impl<C: hyper::client::Connect>DefaultApi for DefaultApiClient<C> {
|
||||
fn auth_login_post(&self, credentials: ::models::Credentials) -> Box<Future<Item = ::models::InlineResponse200, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref apikey) = configuration.api_key {
|
||||
let key = apikey.key.clone();
|
||||
let val = match apikey.prefix {
|
||||
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||
None => key,
|
||||
};
|
||||
auth_headers.insert("Authorization".to_owned(), val);
|
||||
};
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/auth/login?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
let serialized = serde_json::to_string(&credentials).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::InlineResponse200, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
fn auth_token_post(&self, authorization: &str, token: ::models::Authorization) -> Box<Future<Item = ::models::InlineResponse2001, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref apikey) = configuration.api_key {
|
||||
let key = apikey.key.clone();
|
||||
let val = match apikey.prefix {
|
||||
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||
None => key,
|
||||
};
|
||||
auth_headers.insert("Authorization".to_owned(), val);
|
||||
};
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/auth/token?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
{
|
||||
let mut headers = req.headers_mut();
|
||||
headers.set_raw("Authorization", authorization);
|
||||
}
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
let serialized = serde_json::to_string(&token).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::InlineResponse2001, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
fn elections_all_get(&self, authorization: &str) -> Box<Future<Item = ::models::ElectionList, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref apikey) = configuration.api_key {
|
||||
let key = apikey.key.clone();
|
||||
let val = match apikey.prefix {
|
||||
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||
None => key,
|
||||
};
|
||||
auth_headers.insert("Authorization".to_owned(), val);
|
||||
};
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/elections/all?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
{
|
||||
let mut headers = req.headers_mut();
|
||||
headers.set_raw("Authorization", authorization);
|
||||
}
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::ElectionList, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
fn elections_create_post(&self, authorization: &str, election: ::models::Election) -> Box<Future<Item = ::models::Election, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref apikey) = configuration.api_key {
|
||||
let key = apikey.key.clone();
|
||||
let val = match apikey.prefix {
|
||||
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||
None => key,
|
||||
};
|
||||
auth_headers.insert("Authorization".to_owned(), val);
|
||||
};
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/elections/create?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
{
|
||||
let mut headers = req.headers_mut();
|
||||
headers.set_raw("Authorization", authorization);
|
||||
}
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
let serialized = serde_json::to_string(&election).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::Election, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
fn elections_id_get(&self, authorization: &str, id: &str) -> Box<Future<Item = ::models::Election, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref apikey) = configuration.api_key {
|
||||
let key = apikey.key.clone();
|
||||
let val = match apikey.prefix {
|
||||
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||
None => key,
|
||||
};
|
||||
auth_headers.insert("Authorization".to_owned(), val);
|
||||
};
|
||||
let method = hyper::Method::Get;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/elections/{id}?{}", configuration.base_path, query_string, id=id);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
{
|
||||
let mut headers = req.headers_mut();
|
||||
headers.set_raw("Authorization", authorization);
|
||||
}
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::Election, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
fn elections_id_post(&self, authorization: &str, election: ::models::Vote) -> Box<Future<Item = ::models::Vote, Error = Error<serde_json::Value>>> {
|
||||
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
|
||||
|
||||
let mut auth_headers = HashMap::<String, String>::new();
|
||||
let mut auth_query = HashMap::<String, String>::new();
|
||||
if let Some(ref apikey) = configuration.api_key {
|
||||
let key = apikey.key.clone();
|
||||
let val = match apikey.prefix {
|
||||
Some(ref prefix) => format!("{} {}", prefix, key),
|
||||
None => key,
|
||||
};
|
||||
auth_headers.insert("Authorization".to_owned(), val);
|
||||
};
|
||||
let method = hyper::Method::Post;
|
||||
|
||||
let query_string = {
|
||||
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
|
||||
for (key, val) in &auth_query {
|
||||
query.append_pair(key, val);
|
||||
}
|
||||
query.finish()
|
||||
};
|
||||
let uri_str = format!("{}/elections/{id}?{}", configuration.base_path, query_string);
|
||||
|
||||
// TODO(farcaller): handle error
|
||||
// if let Err(e) = uri {
|
||||
// return Box::new(futures::future::err(e));
|
||||
// }
|
||||
let mut uri: hyper::Uri = uri_str.parse().unwrap();
|
||||
|
||||
let mut req = hyper::Request::new(method, uri);
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
{
|
||||
let mut headers = req.headers_mut();
|
||||
headers.set_raw("Authorization", authorization);
|
||||
}
|
||||
|
||||
for (key, val) in auth_headers {
|
||||
req.headers_mut().set_raw(key, val);
|
||||
}
|
||||
|
||||
let serialized = serde_json::to_string(&election).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
|
||||
req.set_body(serialized);
|
||||
|
||||
// send request
|
||||
Box::new(
|
||||
configuration.client.request(req)
|
||||
.map_err(|e| Error::from(e))
|
||||
.and_then(|resp| {
|
||||
let status = resp.status();
|
||||
resp.body().concat2()
|
||||
.and_then(move |body| Ok((status, body)))
|
||||
.map_err(|e| Error::from(e))
|
||||
})
|
||||
.and_then(|(status, body)| {
|
||||
if status.is_success() {
|
||||
Ok(body)
|
||||
} else {
|
||||
Err(Error::from((status, &*body)))
|
||||
}
|
||||
})
|
||||
.and_then(|body| {
|
||||
let parsed: Result<::models::Vote, _> = serde_json::from_slice(&body);
|
||||
parsed.map_err(|e| Error::from(e))
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
use hyper;
|
||||
use serde;
|
||||
use serde_json;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error<T> {
|
||||
Hyper(hyper::Error),
|
||||
Serde(serde_json::Error),
|
||||
ApiError(ApiError<T>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ApiError<T> {
|
||||
pub code: hyper::StatusCode,
|
||||
pub content: Option<T>,
|
||||
}
|
||||
|
||||
impl<'de, T> From<(hyper::StatusCode, &'de [u8])> for Error<T>
|
||||
where T: serde::Deserialize<'de> {
|
||||
fn from(e: (hyper::StatusCode, &'de [u8])) -> Self {
|
||||
if e.1.len() == 0 {
|
||||
return Error::ApiError(ApiError{
|
||||
code: e.0,
|
||||
content: None,
|
||||
});
|
||||
}
|
||||
match serde_json::from_slice::<T>(e.1) {
|
||||
Ok(t) => Error::ApiError(ApiError{
|
||||
code: e.0,
|
||||
content: Some(t),
|
||||
}),
|
||||
Err(e) => {
|
||||
Error::from(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<hyper::Error> for Error<T> {
|
||||
fn from(e: hyper::Error) -> Self {
|
||||
return Error::Hyper(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<serde_json::Error> for Error<T> {
|
||||
fn from(e: serde_json::Error) -> Self {
|
||||
return Error::Serde(e)
|
||||
}
|
||||
}
|
||||
|
||||
use super::models::*;
|
||||
|
||||
mod default_api;
|
||||
pub use self::default_api::{ DefaultApi, DefaultApiClient };
|
||||
|
||||
pub mod configuration;
|
||||
pub mod client;
|
|
@ -0,0 +1,11 @@
|
|||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
extern crate hyper;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate futures;
|
||||
extern crate url;
|
||||
|
||||
pub mod apis;
|
||||
pub mod models;
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Authorization {
|
||||
#[serde(rename = "to_date")]
|
||||
to_date: Option<String>,
|
||||
#[serde(rename = "from_date")]
|
||||
from_date: Option<String>,
|
||||
#[serde(rename = "user")]
|
||||
user: Option<String>
|
||||
}
|
||||
|
||||
impl Authorization {
|
||||
pub fn new() -> Authorization {
|
||||
Authorization {
|
||||
to_date: None,
|
||||
from_date: None,
|
||||
user: None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_to_date(&mut self, to_date: String) {
|
||||
self.to_date = Some(to_date);
|
||||
}
|
||||
|
||||
pub fn with_to_date(mut self, to_date: String) -> Authorization {
|
||||
self.to_date = Some(to_date);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn to_date(&self) -> Option<&String> {
|
||||
self.to_date.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_to_date(&mut self) {
|
||||
self.to_date = None;
|
||||
}
|
||||
|
||||
pub fn set_from_date(&mut self, from_date: String) {
|
||||
self.from_date = Some(from_date);
|
||||
}
|
||||
|
||||
pub fn with_from_date(mut self, from_date: String) -> Authorization {
|
||||
self.from_date = Some(from_date);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn from_date(&self) -> Option<&String> {
|
||||
self.from_date.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_from_date(&mut self) {
|
||||
self.from_date = None;
|
||||
}
|
||||
|
||||
pub fn set_user(&mut self, user: String) {
|
||||
self.user = Some(user);
|
||||
}
|
||||
|
||||
pub fn with_user(mut self, user: String) -> Authorization {
|
||||
self.user = Some(user);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user(&self) -> Option<&String> {
|
||||
self.user.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_user(&mut self) {
|
||||
self.user = None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Credentials {
|
||||
#[serde(rename = "username")]
|
||||
username: Option<String>,
|
||||
#[serde(rename = "password")]
|
||||
password: Option<String>
|
||||
}
|
||||
|
||||
impl Credentials {
|
||||
pub fn new() -> Credentials {
|
||||
Credentials {
|
||||
username: None,
|
||||
password: None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_username(&mut self, username: String) {
|
||||
self.username = Some(username);
|
||||
}
|
||||
|
||||
pub fn with_username(mut self, username: String) -> Credentials {
|
||||
self.username = Some(username);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn username(&self) -> Option<&String> {
|
||||
self.username.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_username(&mut self) {
|
||||
self.username = None;
|
||||
}
|
||||
|
||||
pub fn set_password(&mut self, password: String) {
|
||||
self.password = Some(password);
|
||||
}
|
||||
|
||||
pub fn with_password(mut self, password: String) -> Credentials {
|
||||
self.password = Some(password);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn password(&self) -> Option<&String> {
|
||||
self.password.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_password(&mut self) {
|
||||
self.password = None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Election {
|
||||
#[serde(rename = "id")]
|
||||
id: Option<String>,
|
||||
#[serde(rename = "username")]
|
||||
username: Option<String>,
|
||||
#[serde(rename = "name")]
|
||||
name: Option<String>,
|
||||
#[serde(rename = "description")]
|
||||
description: Option<String>,
|
||||
#[serde(rename = "start_date")]
|
||||
start_date: Option<String>,
|
||||
#[serde(rename = "end_date")]
|
||||
end_date: Option<String>,
|
||||
#[serde(rename = "items")]
|
||||
items: Option<Vec<::models::ElectionItem>>
|
||||
}
|
||||
|
||||
impl Election {
|
||||
pub fn new() -> Election {
|
||||
Election {
|
||||
id: None,
|
||||
username: None,
|
||||
name: None,
|
||||
description: None,
|
||||
start_date: None,
|
||||
end_date: None,
|
||||
items: None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_id(&mut self, id: String) {
|
||||
self.id = Some(id);
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: String) -> Election {
|
||||
self.id = Some(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<&String> {
|
||||
self.id.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_id(&mut self) {
|
||||
self.id = None;
|
||||
}
|
||||
|
||||
pub fn set_username(&mut self, username: String) {
|
||||
self.username = Some(username);
|
||||
}
|
||||
|
||||
pub fn with_username(mut self, username: String) -> Election {
|
||||
self.username = Some(username);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn username(&self) -> Option<&String> {
|
||||
self.username.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_username(&mut self) {
|
||||
self.username = None;
|
||||
}
|
||||
|
||||
pub fn set_name(&mut self, name: String) {
|
||||
self.name = Some(name);
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: String) -> Election {
|
||||
self.name = Some(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<&String> {
|
||||
self.name.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_name(&mut self) {
|
||||
self.name = None;
|
||||
}
|
||||
|
||||
pub fn set_description(&mut self, description: String) {
|
||||
self.description = Some(description);
|
||||
}
|
||||
|
||||
pub fn with_description(mut self, description: String) -> Election {
|
||||
self.description = Some(description);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn description(&self) -> Option<&String> {
|
||||
self.description.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_description(&mut self) {
|
||||
self.description = None;
|
||||
}
|
||||
|
||||
pub fn set_start_date(&mut self, start_date: String) {
|
||||
self.start_date = Some(start_date);
|
||||
}
|
||||
|
||||
pub fn with_start_date(mut self, start_date: String) -> Election {
|
||||
self.start_date = Some(start_date);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn start_date(&self) -> Option<&String> {
|
||||
self.start_date.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_start_date(&mut self) {
|
||||
self.start_date = None;
|
||||
}
|
||||
|
||||
pub fn set_end_date(&mut self, end_date: String) {
|
||||
self.end_date = Some(end_date);
|
||||
}
|
||||
|
||||
pub fn with_end_date(mut self, end_date: String) -> Election {
|
||||
self.end_date = Some(end_date);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn end_date(&self) -> Option<&String> {
|
||||
self.end_date.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_end_date(&mut self) {
|
||||
self.end_date = None;
|
||||
}
|
||||
|
||||
pub fn set_items(&mut self, items: Vec<::models::ElectionItem>) {
|
||||
self.items = Some(items);
|
||||
}
|
||||
|
||||
pub fn with_items(mut self, items: Vec<::models::ElectionItem>) -> Election {
|
||||
self.items = Some(items);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn items(&self) -> Option<&Vec<::models::ElectionItem>> {
|
||||
self.items.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_items(&mut self) {
|
||||
self.items = None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ElectionItem {
|
||||
#[serde(rename = "id")]
|
||||
id: Option<String>,
|
||||
#[serde(rename = "name")]
|
||||
name: Option<String>
|
||||
}
|
||||
|
||||
impl ElectionItem {
|
||||
pub fn new() -> ElectionItem {
|
||||
ElectionItem {
|
||||
id: None,
|
||||
name: None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_id(&mut self, id: String) {
|
||||
self.id = Some(id);
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: String) -> ElectionItem {
|
||||
self.id = Some(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<&String> {
|
||||
self.id.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_id(&mut self) {
|
||||
self.id = None;
|
||||
}
|
||||
|
||||
pub fn set_name(&mut self, name: String) {
|
||||
self.name = Some(name);
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: String) -> ElectionItem {
|
||||
self.name = Some(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<&String> {
|
||||
self.name.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_name(&mut self) {
|
||||
self.name = None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ElectionList {
|
||||
}
|
||||
|
||||
impl ElectionList {
|
||||
pub fn new() -> ElectionList {
|
||||
ElectionList {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InlineResponse200 {
|
||||
#[serde(rename = "token")]
|
||||
token: Option<String>
|
||||
}
|
||||
|
||||
impl InlineResponse200 {
|
||||
pub fn new() -> InlineResponse200 {
|
||||
InlineResponse200 {
|
||||
token: None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_token(&mut self, token: String) {
|
||||
self.token = Some(token);
|
||||
}
|
||||
|
||||
pub fn with_token(mut self, token: String) -> InlineResponse200 {
|
||||
self.token = Some(token);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn token(&self) -> Option<&String> {
|
||||
self.token.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_token(&mut self) {
|
||||
self.token = None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InlineResponse2001 {
|
||||
#[serde(rename = "token")]
|
||||
token: Option<String>
|
||||
}
|
||||
|
||||
impl InlineResponse2001 {
|
||||
pub fn new() -> InlineResponse2001 {
|
||||
InlineResponse2001 {
|
||||
token: None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_token(&mut self, token: String) {
|
||||
self.token = Some(token);
|
||||
}
|
||||
|
||||
pub fn with_token(mut self, token: String) -> InlineResponse2001 {
|
||||
self.token = Some(token);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn token(&self) -> Option<&String> {
|
||||
self.token.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_token(&mut self) {
|
||||
self.token = None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
mod authorization;
|
||||
pub use self::authorization::Authorization;
|
||||
mod credentials;
|
||||
pub use self::credentials::Credentials;
|
||||
mod election;
|
||||
pub use self::election::Election;
|
||||
mod election_item;
|
||||
pub use self::election_item::ElectionItem;
|
||||
mod election_list;
|
||||
pub use self::election_list::ElectionList;
|
||||
mod inline_response_200;
|
||||
pub use self::inline_response_200::InlineResponse200;
|
||||
mod inline_response_200_1;
|
||||
pub use self::inline_response_200_1::InlineResponse2001;
|
||||
mod user;
|
||||
pub use self::user::User;
|
||||
mod vote;
|
||||
pub use self::vote::Vote;
|
||||
mod vote_item;
|
||||
pub use self::vote_item::VoteItem;
|
||||
|
||||
// TODO(farcaller): sort out files
|
||||
pub struct File;
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
#[serde(rename = "id")]
|
||||
id: Option<String>,
|
||||
#[serde(rename = "username")]
|
||||
username: Option<String>,
|
||||
#[serde(rename = "password")]
|
||||
password: Option<String>
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn new() -> User {
|
||||
User {
|
||||
id: None,
|
||||
username: None,
|
||||
password: None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_id(&mut self, id: String) {
|
||||
self.id = Some(id);
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: String) -> User {
|
||||
self.id = Some(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<&String> {
|
||||
self.id.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_id(&mut self) {
|
||||
self.id = None;
|
||||
}
|
||||
|
||||
pub fn set_username(&mut self, username: String) {
|
||||
self.username = Some(username);
|
||||
}
|
||||
|
||||
pub fn with_username(mut self, username: String) -> User {
|
||||
self.username = Some(username);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn username(&self) -> Option<&String> {
|
||||
self.username.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_username(&mut self) {
|
||||
self.username = None;
|
||||
}
|
||||
|
||||
pub fn set_password(&mut self, password: String) {
|
||||
self.password = Some(password);
|
||||
}
|
||||
|
||||
pub fn with_password(mut self, password: String) -> User {
|
||||
self.password = Some(password);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn password(&self) -> Option<&String> {
|
||||
self.password.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_password(&mut self) {
|
||||
self.password = None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Vote {
|
||||
#[serde(rename = "authorization")]
|
||||
authorization: Option<::models::Authorization>,
|
||||
#[serde(rename = "userid")]
|
||||
userid: Option<String>,
|
||||
#[serde(rename = "data")]
|
||||
data: Option<Vec<::models::VoteItem>>
|
||||
}
|
||||
|
||||
impl Vote {
|
||||
pub fn new() -> Vote {
|
||||
Vote {
|
||||
authorization: None,
|
||||
userid: None,
|
||||
data: None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_authorization(&mut self, authorization: ::models::Authorization) {
|
||||
self.authorization = Some(authorization);
|
||||
}
|
||||
|
||||
pub fn with_authorization(mut self, authorization: ::models::Authorization) -> Vote {
|
||||
self.authorization = Some(authorization);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn authorization(&self) -> Option<&::models::Authorization> {
|
||||
self.authorization.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_authorization(&mut self) {
|
||||
self.authorization = None;
|
||||
}
|
||||
|
||||
pub fn set_userid(&mut self, userid: String) {
|
||||
self.userid = Some(userid);
|
||||
}
|
||||
|
||||
pub fn with_userid(mut self, userid: String) -> Vote {
|
||||
self.userid = Some(userid);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn userid(&self) -> Option<&String> {
|
||||
self.userid.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_userid(&mut self) {
|
||||
self.userid = None;
|
||||
}
|
||||
|
||||
pub fn set_data(&mut self, data: Vec<::models::VoteItem>) {
|
||||
self.data = Some(data);
|
||||
}
|
||||
|
||||
pub fn with_data(mut self, data: Vec<::models::VoteItem>) -> Vote {
|
||||
self.data = Some(data);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn data(&self) -> Option<&Vec<::models::VoteItem>> {
|
||||
self.data.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_data(&mut self) {
|
||||
self.data = None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* vote-rs API
|
||||
*
|
||||
* API for conducting electronic voting
|
||||
*
|
||||
* OpenAPI spec version: 0.0.1
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct VoteItem {
|
||||
#[serde(rename = "item")]
|
||||
item: Option<::models::ElectionItem>,
|
||||
#[serde(rename = "value")]
|
||||
value: Option<f32>
|
||||
}
|
||||
|
||||
impl VoteItem {
|
||||
pub fn new() -> VoteItem {
|
||||
VoteItem {
|
||||
item: None,
|
||||
value: None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_item(&mut self, item: ::models::ElectionItem) {
|
||||
self.item = Some(item);
|
||||
}
|
||||
|
||||
pub fn with_item(mut self, item: ::models::ElectionItem) -> VoteItem {
|
||||
self.item = Some(item);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn item(&self) -> Option<&::models::ElectionItem> {
|
||||
self.item.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_item(&mut self) {
|
||||
self.item = None;
|
||||
}
|
||||
|
||||
pub fn set_value(&mut self, value: f32) {
|
||||
self.value = Some(value);
|
||||
}
|
||||
|
||||
pub fn with_value(mut self, value: f32) -> VoteItem {
|
||||
self.value = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn value(&self) -> Option<&f32> {
|
||||
self.value.as_ref()
|
||||
}
|
||||
|
||||
pub fn reset_value(&mut self) {
|
||||
self.value = None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -8,7 +8,6 @@ use std::path::Path;
|
|||
|
||||
|
||||
|
||||
|
||||
use stv_rs::parse::parse_election;
|
||||
use stv_rs::meek::stv_droop;
|
||||
use stv_rs::types::Election;
|
||||
|
@ -29,9 +28,6 @@ pub fn blt_to_string_results(blt: String) -> String {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Ballot {
|
||||
weight: i32,
|
||||
|
@ -85,7 +81,10 @@ pub fn election_data_to_blt(election_data: ElectionData) -> String {
|
|||
return blt;
|
||||
}
|
||||
|
||||
|
||||
pub fn csv_to_election_data(csv: &str, num_seats: i32, title: String) -> ElectionData {
|
||||
//TODO: use a proper csv parser, instead of splitting by delimiter
|
||||
|
||||
//read the csv file and convert it to a ballot
|
||||
let delimiter = ",";
|
||||
|
||||
|
@ -139,7 +138,6 @@ pub fn csv_to_election_data(csv: &str, num_seats: i32, title: String) -> Electio
|
|||
}
|
||||
ballots.push(ballot);
|
||||
}
|
||||
|
||||
//deduplicate the ballots
|
||||
let mut deduped_ballots: Vec<Ballot> = Vec::new();
|
||||
for ballot in ballots {
|
||||
|
@ -155,7 +153,6 @@ pub fn csv_to_election_data(csv: &str, num_seats: i32, title: String) -> Electio
|
|||
}
|
||||
}
|
||||
ballots = deduped_ballots;
|
||||
|
||||
let election_data = ElectionData {
|
||||
num_candidates: num_candidates,
|
||||
num_seats: num_seats,
|
||||
|
|
Loading…
Reference in New Issue