mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
feat(global) compatibility milestone
This commit is contained in:
19 files changed
+347
-119
No files matched your search
@@ -12,7 +12,7 @@ use axum::{
|
||||
use chrono::NaiveDate;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::{query_as, FromRow, PgPool};
|
||||
use sqlx::{FromRow, PgPool, query_as};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(FromRow, Serialize)]
|
||||
|
||||
@@ -28,7 +28,7 @@ struct SelectedPost {
|
||||
category: String,
|
||||
tags: Vec<String>,
|
||||
content: String,
|
||||
metadata: Value,
|
||||
metadata: Option<Value>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, FromRow)]
|
||||
|
||||
@@ -7,19 +7,19 @@ use sqlx::{FromRow, PgPool, query_as};
|
||||
#[derive(FromRow)]
|
||||
struct DBPaginationRow {
|
||||
page_count: i32,
|
||||
total_count: i64,
|
||||
post_count: i64,
|
||||
}
|
||||
|
||||
struct PaginationResponse {
|
||||
page_count: i32,
|
||||
total_count: i64,
|
||||
post_count: i64,
|
||||
}
|
||||
|
||||
impl From<DBPaginationRow> for PaginationResponse {
|
||||
fn from(value: DBPaginationRow) -> Self {
|
||||
Self {
|
||||
page_count: value.page_count,
|
||||
total_count: value.total_count,
|
||||
post_count: value.post_count,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ impl From<PaginationResponse> for Value {
|
||||
fn from(value: PaginationResponse) -> Self {
|
||||
json!({
|
||||
"page_count": value.page_count,
|
||||
"total_count": value.total_count
|
||||
"post_count": value.post_count
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -36,9 +36,9 @@ impl From<PaginationResponse> for Value {
|
||||
pub async fn handler(State(db_connection): State<PgPool>) -> Response<String> {
|
||||
match query_as::<_, DBPaginationRow>(
|
||||
r#"
|
||||
SELECT
|
||||
SELECT
|
||||
cast(ceil(count(*) / cast($1 AS FLOAT)) AS INTEGER) AS page_count,
|
||||
count(*) AS total_count
|
||||
count(*) AS post_count
|
||||
FROM posts;
|
||||
"#,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user