postgres via sqlx - workable?
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use axum::{
|
||||
extract::{Query, Request},
|
||||
extract::{Query, Request, State},
|
||||
response::{IntoResponse, Redirect, Response},
|
||||
};
|
||||
use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
database::{self},
|
||||
MnemoState,
|
||||
error::CompositeError,
|
||||
logs::LogEntry,
|
||||
users::{User, auth::UserAuthenticate},
|
||||
@@ -19,22 +19,22 @@ pub struct PageQuery {
|
||||
}
|
||||
|
||||
pub async fn page(
|
||||
State(state): State<MnemoState>,
|
||||
Query(query): Query<PageQuery>,
|
||||
req: Request,
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = match User::authenticate(req.headers())? {
|
||||
let mut tx = state.pool.begin().await?;
|
||||
let u = match User::authenticate(&mut *tx, req.headers()).await? {
|
||||
Some(u) => u,
|
||||
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||
};
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let page = query.page.unwrap_or(1).max(1);
|
||||
let per_page = 20;
|
||||
let offset = (page - 1) * per_page;
|
||||
|
||||
let logs = LogEntry::get_chronological_offset(&tx, offset, per_page)?;
|
||||
let total_logs = LogEntry::total_count(&tx)?;
|
||||
let logs = LogEntry::get_chronological_offset(&mut *tx, offset, per_page).await?;
|
||||
let total_logs = LogEntry::total_count(&mut *tx).await?;
|
||||
let total_pages = (total_logs as f64 / per_page as f64).ceil() as i64;
|
||||
|
||||
Ok(base(
|
||||
@@ -42,7 +42,7 @@ pub async fn page(
|
||||
html!(
|
||||
(nav(Some(&u), req.uri().path()))
|
||||
|
||||
@if true {//let Ok(true) = u.has_permission(&tx, Permission::BrowseServerLogs) {
|
||||
@if true {//let Ok(true) = u.has_permission(&mut *tx, Permission::BrowseServerLogs) {
|
||||
div class="max-w-4xl mx-auto px-2" {
|
||||
div class="my-4" {
|
||||
p class="flex items-center gap-2" {
|
||||
|
||||
Reference in New Issue
Block a user