Working user and link list, (big)restructure

This is now a workspace consisting of:
  * the pslink app (a wasm frontend for the admin interface)
  * the pslink binary
  * shared - modules for communication between the two above.
This commit is contained in:
2021-08-12 15:48:02 +02:00
committed by dietrich
parent 1611cfb9a2
commit fc9b18141f
60 changed files with 2238 additions and 396 deletions
+27
View File
@@ -0,0 +1,27 @@
use std::ops::Deref;
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize, Debug, Default)]
pub struct Filter {
pub sieve: String,
}
impl Deref for Filter {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.sieve
}
}
#[derive(Clone, Deserialize, Serialize, PartialEq, Eq, Debug)]
pub enum Ordering {
Ascending,
Descending,
}
#[derive(Clone, Deserialize, Serialize, Debug)]
pub struct Operation<T, V> {
pub column: T,
pub value: V,
}
+31
View File
@@ -0,0 +1,31 @@
use enum_map::{Enum, EnumMap};
use serde::{Deserialize, Serialize};
use super::general::{Filter, Operation, Ordering};
/// A generic list returntype containing the User and a Vec containing e.g. Links or Users
#[derive(Clone, Deserialize, Serialize, Debug)]
pub struct LinkRequestForm {
pub filter: EnumMap<LinkOverviewColumns, Filter>,
pub order: Option<Operation<LinkOverviewColumns, Ordering>>,
pub amount: usize,
}
impl Default for LinkRequestForm {
fn default() -> Self {
Self {
filter: EnumMap::default(),
order: None,
amount: 20,
}
}
}
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq, Hash, Enum)]
pub enum LinkOverviewColumns {
Code,
Description,
Target,
Author,
Statistics,
}
+3
View File
@@ -0,0 +1,3 @@
pub mod general;
pub mod links;
pub mod users;
+28
View File
@@ -0,0 +1,28 @@
use enum_map::{Enum, EnumMap};
use serde::{Deserialize, Serialize};
use super::general::{Filter, Operation, Ordering};
#[derive(Clone, Deserialize, Serialize, Debug)]
pub struct UserRequestForm {
pub filter: EnumMap<UserOverviewColumns, Filter>,
pub order: Option<Operation<UserOverviewColumns, Ordering>>,
pub amount: usize,
}
impl Default for UserRequestForm {
fn default() -> Self {
Self {
filter: EnumMap::default(),
order: None,
amount: 20,
}
}
}
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq, Hash, Enum)]
pub enum UserOverviewColumns {
Id,
Email,
Username,
}
+46
View File
@@ -0,0 +1,46 @@
use serde::{Deserialize, Serialize};
/// A generic list returntype containing the User and a Vec containing e.g. Links or Users
#[derive(Clone, Deserialize, Serialize)]
pub struct ListWithOwner<T> {
pub user: User,
pub list: Vec<T>,
}
/// A link together with its author and its click-count.
#[derive(Clone, Deserialize, Serialize, Debug)]
pub struct FullLink {
pub link: Link,
pub user: User,
pub clicks: Count,
}
#[derive(PartialEq, Serialize, Deserialize, Clone, Debug)]
pub struct User {
pub id: i64,
pub username: String,
pub email: String,
pub password: String,
pub role: i64,
pub language: String,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Link {
pub id: i64,
pub title: String,
pub target: String,
pub code: String,
pub author: i64,
pub created_at: chrono::NaiveDateTime,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Count {
pub number: i32,
}
#[derive(Serialize, Debug)]
pub struct Click {
pub id: i64,
pub link: i64,
pub created_at: chrono::NaiveDateTime,
}
+2
View File
@@ -0,0 +1,2 @@
pub mod apirequests;
pub mod datatypes;