some fixes
This commit is contained in:
@@ -404,6 +404,23 @@ struct PublishedPageRow {
|
||||
updated_at: String,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, FromRow)]
|
||||
struct PostgresPublishedPageRow {
|
||||
token: String,
|
||||
pad_id: Option<i64>,
|
||||
note_id: Option<i64>,
|
||||
allow_task_updates: bool,
|
||||
title: String,
|
||||
content: String,
|
||||
updated_at: String,
|
||||
}
|
||||
|
||||
impl From<PostgresPublishedPageRow> for PublishedPage {
|
||||
fn from(value: PostgresPublishedPageRow) -> Self {
|
||||
Self { token: value.token, pad_id: value.pad_id, note_id: value.note_id, allow_task_updates: value.allow_task_updates, title: value.title, content: value.content, updated_at: value.updated_at }
|
||||
}
|
||||
}
|
||||
impl From<PublishedPageRow> for PublishedPage {
|
||||
fn from(value: PublishedPageRow) -> Self {
|
||||
Self {
|
||||
@@ -453,40 +470,47 @@ pub async fn publish_note(pool: &Database, note_id: i64) -> Result<String, sqlx:
|
||||
}
|
||||
|
||||
pub async fn find_published_page(pool: &Database, token: &str) -> Result<Option<PublishedPage>, sqlx::Error> {
|
||||
if pool.kind() == DatabaseKind::Postgres {
|
||||
return Ok(sqlx::query_as::<_, PostgresPublishedPageRow>(queries::Q021_POSTGRES)
|
||||
.bind(token).fetch_optional(pool.pool()).await?.map(Into::into));
|
||||
}
|
||||
Ok(sqlx::query_as::<_, PublishedPageRow>(queries::get(pool.kind(), queries::Q021))
|
||||
.bind(token)
|
||||
.fetch_optional(pool.pool())
|
||||
.await?
|
||||
.map(Into::into))
|
||||
.bind(token).fetch_optional(pool.pool()).await?.map(Into::into))
|
||||
}
|
||||
|
||||
pub async fn pad_public_task_updates(pool: &Database, pad_id: i64) -> Result<bool, sqlx::Error> {
|
||||
if pool.kind() == DatabaseKind::Postgres {
|
||||
return Ok(sqlx::query_scalar::<_, bool>(queries::Q044_POSTGRES)
|
||||
.bind(pad_id).fetch_optional(pool.pool()).await?.unwrap_or(false));
|
||||
}
|
||||
let value = sqlx::query_scalar::<_, i64>(queries::get(pool.kind(), queries::Q044))
|
||||
.bind(pad_id)
|
||||
.fetch_optional(pool.pool())
|
||||
.await?
|
||||
.unwrap_or(0);
|
||||
.bind(pad_id).fetch_optional(pool.pool()).await?.unwrap_or(0);
|
||||
Ok(value != 0)
|
||||
}
|
||||
|
||||
pub async fn note_public_task_updates(pool: &Database, note_id: i64) -> Result<bool, sqlx::Error> {
|
||||
if pool.kind() == DatabaseKind::Postgres {
|
||||
return Ok(sqlx::query_scalar::<_, bool>(queries::Q045_POSTGRES)
|
||||
.bind(note_id).fetch_optional(pool.pool()).await?.unwrap_or(false));
|
||||
}
|
||||
let value = sqlx::query_scalar::<_, i64>(queries::get(pool.kind(), queries::Q045))
|
||||
.bind(note_id)
|
||||
.fetch_optional(pool.pool())
|
||||
.await?
|
||||
.unwrap_or(0);
|
||||
.bind(note_id).fetch_optional(pool.pool()).await?.unwrap_or(0);
|
||||
Ok(value != 0)
|
||||
}
|
||||
|
||||
pub async fn set_pad_public_task_updates(pool: &Database, pad_id: i64, allow: bool) -> Result<(), sqlx::Error> {
|
||||
publish_pad(pool, pad_id).await?;
|
||||
sqlx::query(queries::get(pool.kind(), queries::Q040)).bind(if allow { 1i64 } else { 0i64 }).bind(pad_id).execute(pool.pool()).await?;
|
||||
let mut query = sqlx::query(queries::get(pool.kind(), queries::Q040));
|
||||
query = if pool.kind() == DatabaseKind::Postgres { query.bind(allow) } else { query.bind(if allow { 1i64 } else { 0i64 }) };
|
||||
query.bind(pad_id).execute(pool.pool()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_note_public_task_updates(pool: &Database, note_id: i64, allow: bool) -> Result<(), sqlx::Error> {
|
||||
publish_note(pool, note_id).await?;
|
||||
sqlx::query(queries::get(pool.kind(), queries::Q041)).bind(if allow { 1i64 } else { 0i64 }).bind(note_id).execute(pool.pool()).await?;
|
||||
let mut query = sqlx::query(queries::get(pool.kind(), queries::Q041));
|
||||
query = if pool.kind() == DatabaseKind::Postgres { query.bind(allow) } else { query.bind(if allow { 1i64 } else { 0i64 }) };
|
||||
query.bind(note_id).execute(pool.pool()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user