Going somewhere... but no idea where.
This commit is contained in:
1 parent
0bbe716d8d
commit
89597dcac2
7 files changed
+110
-10
No files matched your search
@@ -13,6 +13,7 @@
|
||||
|
||||
<body>
|
||||
|
||||
<div hx-headers='{"myHeader": "My Value"}'>
|
||||
|
||||
<nav class="uk-navbar-container" uk-navbar>
|
||||
<div class="uk-navbar-left">
|
||||
@@ -38,6 +39,8 @@
|
||||
</div>
|
||||
<div class="uk-width-1-6@m"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -4,9 +4,22 @@
|
||||
|
||||
{% block body %}
|
||||
|
||||
overview
|
||||
|
||||
{% for i in [{'a': 90}, 2, 3] %}
|
||||
lll {{ i }}
|
||||
<table class="uk-table uk-table-divider uk-table-striped uk-table-hover uk-table-small">
|
||||
<caption>Users</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th> <th>Name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{%for user in users.content%}
|
||||
<tr>
|
||||
<td> {{ user.id }}</td>
|
||||
<td> {{ user.name }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
+7
-2
@@ -1,7 +1,8 @@
|
||||
use rusqlite::{Connection, params, Result, Row, Transaction};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::db::_external_id::{Id, UserId};
|
||||
use crate::util::{CustomResult, Error};
|
||||
use rusqlite::{params, Connection, Result, Row, Transaction};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct User {
|
||||
@@ -14,6 +15,10 @@ impl User {
|
||||
pub fn id(&self) -> UserId {
|
||||
UserId::from_id(self.id)
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_user(tx: &Transaction, name: &String, public_key: &String) -> CustomResult<User> {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
use rusqlite::Connection;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::db::external_id::UserId;
|
||||
use crate::db::users::{list_users, User};
|
||||
use crate::util::CustomResult;
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct Page<T> where T: Serialize {
|
||||
total_number_of_page: usize,
|
||||
current_page_number: usize,
|
||||
content: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T> Page<T> where T: Serialize{
|
||||
pub fn all_of(data: Vec<T>) -> Page<T>{
|
||||
Page{
|
||||
total_number_of_page: 0,
|
||||
current_page_number: 10,
|
||||
content: data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct UserDTO {
|
||||
name: String,
|
||||
id: String, // todo: should be of type UserId
|
||||
}
|
||||
|
||||
impl UserDTO {
|
||||
fn from_entity(user: &User) -> UserDTO {
|
||||
return UserDTO { name: user.get_name(), id: user.id().to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UserService<'a> {
|
||||
conn: &'a Connection,
|
||||
}
|
||||
|
||||
impl UserService<'_> {
|
||||
pub fn new(conn: &Connection) -> UserService {
|
||||
UserService { conn }
|
||||
}
|
||||
|
||||
pub fn list_users(self) -> CustomResult<Page<UserDTO>> {
|
||||
let users = list_users(self.conn)?.iter().map(UserDTO::from_entity).collect();
|
||||
let ret = Page::all_of(users);
|
||||
return Ok(ret)
|
||||
}
|
||||
}
|
||||
@@ -1 +1,19 @@
|
||||
use rusqlite::Connection;
|
||||
|
||||
use crate::services::_users::UserService;
|
||||
|
||||
mod _transactions;
|
||||
mod _users;
|
||||
|
||||
pub struct ServiceFactory<'a> {
|
||||
conn: &'a Connection,
|
||||
}
|
||||
|
||||
impl ServiceFactory<'_> {
|
||||
pub fn new(conn: &Connection) -> ServiceFactory {
|
||||
ServiceFactory { conn }
|
||||
}
|
||||
pub fn get_user_service(&self) -> UserService {
|
||||
UserService::new(self.conn)
|
||||
}
|
||||
}
|
||||
+12
-3
@@ -5,8 +5,10 @@ use clap::builder::TypedValueParser;
|
||||
use log::info;
|
||||
use minijinja::context;
|
||||
use serde::Deserialize;
|
||||
use crate::db::users::list_users;
|
||||
|
||||
use crate::events::Event;
|
||||
use crate::services::ServiceFactory;
|
||||
use crate::util::SQLiteConnectionFactory;
|
||||
use crate::webui::MiniJinjaRenderer;
|
||||
|
||||
@@ -21,8 +23,16 @@ pub async fn actions(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Resp
|
||||
}
|
||||
|
||||
#[actix_web::get("/overview")]
|
||||
pub async fn overview(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Responder> {
|
||||
tmpl_env.render("overview.html", ())
|
||||
pub async fn overview(tmpl_env: MiniJinjaRenderer,
|
||||
connFactory: web::Data<SQLiteConnectionFactory>) -> actix_web::Result<impl Responder> {
|
||||
let conn = connFactory.readonly().unwrap(); // todo; to proper 500
|
||||
let service_factory = ServiceFactory::new(& conn);
|
||||
let user_service = service_factory.get_user_service();
|
||||
let users = user_service.list_users().unwrap();
|
||||
let ctx = context! {
|
||||
users => users,
|
||||
};
|
||||
tmpl_env.render("overview.html", ctx)
|
||||
}
|
||||
|
||||
#[actix_web::get("/partials/overview/submit_button")]
|
||||
@@ -42,7 +52,6 @@ pub async fn actions_partials(
|
||||
_req: HttpRequest,
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
query: web::Query<HashMap<String, String>>,
|
||||
connFactory: web::Data<SQLiteConnectionFactory>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let event_type = query
|
||||
.get("event_type")
|
||||
|
||||
+1
-1
@@ -27,6 +27,6 @@ pub async fn event_processor_loop(conFact: SQLiteConnectionFactory,
|
||||
pub async fn bob() -> CustomResult<()> {
|
||||
loop {
|
||||
sleep(Duration::from_millis(1000)).await;
|
||||
println!("100 ms have elapsed");
|
||||
// println!("100 ms have elapsed");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user