Lines
0 %
Functions
Branches
100 %
use crate::{
auth::Claims,
data::Data,
data_format::{Rejection, Report, ReviewRequest, ReviewType, Task},
error::{Error, Result},
};
use actix_web::web::{self, Json, Payload};
use futures_util::stream::StreamExt;
use std::collections::BTreeMap;
pub async fn get_selectors(data: web::Data<Data>) -> Json<Vec<String>> {
Json(data.selectors().to_vec())
}
pub async fn get_review_types(data: web::Data<Data>) -> Json<BTreeMap<String, ReviewType>> {
Json(data.review_types().clone())
pub async fn get_requests(
claims: Claims,
data: web::Data<Data>,
) -> Json<BTreeMap<String, ReviewRequest>> {
Json(data.get_requests(&claims).await)
/// Add a request for service coming in via the web form.
/// The submitter should receive a receipt of their request via mail.
pub async fn add_request(data: web::Data<Data>, body: Payload) -> Result<Json<()>> {
let bytes = get_bytes(body).await?;
let _request = data.add_request(&bytes).await?;
Ok(Json(()))
pub async fn get_rejections(
) -> Json<BTreeMap<String, Rejection>> {
Json(data.get_rejections(&claims).await)
pub async fn add_rejection(data: web::Data<Data>, body: Payload) -> Result<Json<()>> {
let _rejection = data.add_rejection(&bytes).await?;
pub async fn get_tasks(data: web::Data<Data>) -> Json<BTreeMap<String, Task>> {
Json(data.tasks().await)
/// Add a task for a partner to handle a request.
/// A mail should be sent to the partner that a task has been added.
pub async fn add_task(claims: Claims, data: web::Data<Data>, body: Payload) -> Result<Json<()>> {
// check that the request comes from a selector
if data.is_selector(&claims) {
let _task = data.add_task(&data.config, &bytes).await?;
} else {
return Err(Error::Msg("You are not allowed to add a task.".into()));
pub async fn get_reports(data: web::Data<Data>) -> Json<BTreeMap<String, Report>> {
Json(data.reports().await)
pub async fn add_report(claims: Claims, data: web::Data<Data>, body: Payload) -> Result<Json<()>> {
let _report = data.add_report(&bytes, &claims).await?;
pub async fn add_file(data: web::Data<Data>, body: Payload) -> Result<Json<String>> {
let name = data.add_file(&bytes).await?;
Ok(Json(name))
async fn get_bytes(mut body: Payload) -> Result<Vec<u8>> {
let mut bytes = web::BytesMut::new();
while let Some(item) = body.next().await {
bytes.extend_from_slice(&item?);
Ok(bytes.to_vec())