mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
feat(backend/database/post) add first_update
This commit is contained in:
4 files changed
+39
-23
No files matched your search
+13
-11
@@ -1,18 +1,20 @@
|
|||||||
CREATE TABLE IF NOT EXISTS Post
|
CREATE TABLE IF NOT EXISTS Post
|
||||||
(
|
(
|
||||||
post_id UUID PRIMARY KEY,
|
post_id UUID PRIMARY KEY,
|
||||||
title VARCHAR(255) NOT NULL,
|
title VARCHAR(255) NOT NULL,
|
||||||
summary TEXT NOT NULL,
|
summary TEXT NOT NULL,
|
||||||
content TEXT NOT NULL,
|
content TEXT NOT NULL,
|
||||||
last_update TIMESTAMP
|
last_update TIMESTAMP,
|
||||||
|
first_update TIMESTAMP NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
drop table if exists post;
|
drop table if exists post;
|
||||||
|
|
||||||
INSERT INTO Post (post_id, title, summary, content, last_update)
|
INSERT INTO Post (post_id, title, summary, content, last_update, first_update)
|
||||||
VALUES ($1, $2, $3, $4, $5)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
ON CONFLICT (post_id)
|
ON CONFLICT (post_id)
|
||||||
DO UPDATE SET title = excluded.title,
|
DO UPDATE SET title = excluded.title,
|
||||||
summary = excluded.summary,
|
summary = excluded.summary,
|
||||||
content = excluded.content,
|
content = excluded.content,
|
||||||
last_update = excluded.last_update
|
last_update = excluded.last_update,
|
||||||
|
first_update = excluded.first_update
|
||||||
@@ -49,11 +49,12 @@ pub async fn refresh(
|
|||||||
r##"
|
r##"
|
||||||
CREATE TABLE IF NOT EXISTS Post
|
CREATE TABLE IF NOT EXISTS Post
|
||||||
(
|
(
|
||||||
post_id UUID PRIMARY KEY,
|
post_id UUID PRIMARY KEY,
|
||||||
title VARCHAR(255) NOT NULL,
|
title VARCHAR(255) NOT NULL,
|
||||||
summary TEXT NOT NULL,
|
summary TEXT NOT NULL,
|
||||||
content TEXT NOT NULL,
|
content TEXT NOT NULL,
|
||||||
last_update TIMESTAMP
|
last_update TIMESTAMP,
|
||||||
|
first_update TIMESTAMP NOT NULL
|
||||||
);
|
);
|
||||||
"##,
|
"##,
|
||||||
)
|
)
|
||||||
@@ -81,13 +82,15 @@ CREATE TABLE IF NOT EXISTS Tag
|
|||||||
// table Post
|
// table Post
|
||||||
match query(
|
match query(
|
||||||
r##"
|
r##"
|
||||||
INSERT INTO Post (post_id, title, summary, content, last_update)
|
INSERT INTO Post (post_id, title, summary, content, last_update, first_update)
|
||||||
VALUES ($1, $2, $3, $4, $5)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
ON CONFLICT (post_id)
|
ON CONFLICT (post_id)
|
||||||
DO UPDATE SET title = excluded.title,
|
DO UPDATE SET title = excluded.title,
|
||||||
summary = excluded.summary,
|
summary = excluded.summary,
|
||||||
content = excluded.content,
|
content = excluded.content,
|
||||||
last_update = excluded.last_update
|
last_update = excluded.last_update,
|
||||||
|
first_update = excluded.first_update
|
||||||
|
|
||||||
"##,
|
"##,
|
||||||
)
|
)
|
||||||
.bind(post.post_id)
|
.bind(post.post_id)
|
||||||
@@ -95,6 +98,7 @@ ON CONFLICT (post_id)
|
|||||||
.bind(post.summary)
|
.bind(post.summary)
|
||||||
.bind(&post.content)
|
.bind(&post.content)
|
||||||
.bind(post.last_update)
|
.bind(post.last_update)
|
||||||
|
.bind(post.first_update)
|
||||||
.execute(&db_connection)
|
.execute(&db_connection)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ pub struct Post {
|
|||||||
pub summary: String,
|
pub summary: String,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub last_update: NaiveDateTime,
|
pub last_update: NaiveDateTime,
|
||||||
|
pub first_update: NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ use std::error::Error;
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use chrono::{NaiveDateTime, Utc};
|
use chrono::{NaiveDate, NaiveDateTime, Utc};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::markdown::meta::parse_meta;
|
use crate::markdown::meta::parse_meta;
|
||||||
@@ -44,12 +44,21 @@ impl Post {
|
|||||||
Utc::now().naive_utc()
|
Utc::now().naive_utc()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let first_update: NaiveDateTime = match meta.get("date") {
|
||||||
|
None => Utc::now().naive_utc(),
|
||||||
|
Some(date) => NaiveDateTime::from(
|
||||||
|
NaiveDate::parse_from_str(date, "%Y-%m-%d%z")
|
||||||
|
.expect("Failed to parse first_update time"),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Post {
|
Ok(Post {
|
||||||
post_id: Uuid::new_v4(),
|
post_id: Uuid::new_v4(),
|
||||||
title,
|
title,
|
||||||
summary,
|
summary,
|
||||||
content: md_content,
|
content: md_content,
|
||||||
last_update,
|
last_update,
|
||||||
|
first_update,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user