Removed the concept of down & upvotes
This commit is contained in:
parent
84defa703e
commit
2e23c7919f
11 changed files with 58 additions and 120 deletions
|
@ -40,8 +40,6 @@ export interface PublicComment {
|
||||||
id: number;
|
id: number;
|
||||||
parent_post_id: number;
|
parent_post_id: number;
|
||||||
parent_comment_id: number | null;
|
parent_comment_id: number | null;
|
||||||
upvotes: number;
|
|
||||||
downvotes: number;
|
|
||||||
content: string;
|
content: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "SELECT id, content, created_at, updated_at FROM posts WHERE id = $1",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "id",
|
||||||
|
"type_info": "Int8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 1,
|
||||||
|
"name": "content",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 2,
|
||||||
|
"name": "created_at",
|
||||||
|
"type_info": "Timestamp"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 3,
|
||||||
|
"name": "updated_at",
|
||||||
|
"type_info": "Timestamp"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "1bc374be695ed5237e460b08d69e476c59530888879fd84de0a6116b3aa99641"
|
||||||
|
}
|
|
@ -20,21 +20,11 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ordinal": 3,
|
"ordinal": 3,
|
||||||
"name": "upvotes",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "downvotes",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "created_at",
|
"name": "created_at",
|
||||||
"type_info": "Timestamp"
|
"type_info": "Timestamp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ordinal": 6,
|
"ordinal": 4,
|
||||||
"name": "updated_at",
|
"name": "updated_at",
|
||||||
"type_info": "Timestamp"
|
"type_info": "Timestamp"
|
||||||
}
|
}
|
||||||
|
@ -47,8 +37,6 @@
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT id, parent_post_id, upvotes, downvotes, content, created_at, updated_at\n FROM comments WHERE parent_post_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "parent_post_id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "upvotes",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "downvotes",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "content",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "created_at",
|
|
||||||
"type_info": "Timestamp"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 6,
|
|
||||||
"name": "updated_at",
|
|
||||||
"type_info": "Timestamp"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Int8",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "3560895233b2af755be5c55ce01337fffccc32dc87a17a40c67c3c1c7e163e63"
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "SELECT id, content, upvotes, downvotes, created_at, updated_at FROM posts ORDER BY created_at DESC LIMIT $1 OFFSET $2",
|
"query": "SELECT id, content, created_at, updated_at FROM posts ORDER BY created_at DESC LIMIT $1 OFFSET $2",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
|
@ -15,21 +15,11 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ordinal": 2,
|
"ordinal": 2,
|
||||||
"name": "upvotes",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "downvotes",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "created_at",
|
"name": "created_at",
|
||||||
"type_info": "Timestamp"
|
"type_info": "Timestamp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ordinal": 5,
|
"ordinal": 3,
|
||||||
"name": "updated_at",
|
"name": "updated_at",
|
||||||
"type_info": "Timestamp"
|
"type_info": "Timestamp"
|
||||||
}
|
}
|
||||||
|
@ -41,13 +31,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "2ec6780ea09d3cd14aeb87aeb97d93ff9a46e71d75f7e00d6c990fd3585ed866"
|
"hash": "371366128df3138dce5b63ff4fb010789ca27ba7919ceba0881134ee3e40cfb7"
|
||||||
}
|
}
|
|
@ -1,41 +1,38 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "SELECT id, content, upvotes, downvotes, created_at, updated_at FROM posts WHERE id = $1",
|
"query": "SELECT id, parent_post_id, content, created_at, updated_at\n FROM comments WHERE parent_post_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
"ordinal": 0,
|
"ordinal": 0,
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"type_info": "Int8"
|
"type_info": "Int4"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ordinal": 1,
|
"ordinal": 1,
|
||||||
|
"name": "parent_post_id",
|
||||||
|
"type_info": "Int8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 2,
|
||||||
"name": "content",
|
"name": "content",
|
||||||
"type_info": "Text"
|
"type_info": "Text"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "upvotes",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ordinal": 3,
|
"ordinal": 3,
|
||||||
"name": "downvotes",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "created_at",
|
"name": "created_at",
|
||||||
"type_info": "Timestamp"
|
"type_info": "Timestamp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ordinal": 5,
|
"ordinal": 4,
|
||||||
"name": "updated_at",
|
"name": "updated_at",
|
||||||
"type_info": "Timestamp"
|
"type_info": "Timestamp"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Left": [
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"Int8",
|
||||||
"Int8"
|
"Int8"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -44,9 +41,8 @@
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "f2463f3ff911698f3e841c631e8b8609408eaa32f0dcc7fb70c029339613cd07"
|
"hash": "745713958bdfdf0f5e9fd086dda582ead87ff0b1504135f64165cdc35352db5b"
|
||||||
}
|
}
|
|
@ -2,8 +2,6 @@ CREATE TABLE IF NOT EXISTS posts (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
user_id BIGINT NOT NULL,
|
user_id BIGINT NOT NULL,
|
||||||
content TEXT NOT NULL,
|
content TEXT NOT NULL,
|
||||||
upvotes INTEGER NOT NULL DEFAULT 0,
|
|
||||||
downvotes INTEGER NOT NULL DEFAULT 0,
|
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (user_id) REFERENCES users (id)
|
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||||
|
|
|
@ -4,8 +4,6 @@ CREATE TABLE IF NOT EXISTS comments (
|
||||||
-- parent_comment_id BIGINT,
|
-- parent_comment_id BIGINT,
|
||||||
author_user_id BIGINT NOT NULL,
|
author_user_id BIGINT NOT NULL,
|
||||||
content TEXT NOT NULL,
|
content TEXT NOT NULL,
|
||||||
upvotes INTEGER NOT NULL DEFAULT 0,
|
|
||||||
downvotes INTEGER NOT NULL DEFAULT 0,
|
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (parent_post_id) REFERENCES posts (id),
|
FOREIGN KEY (parent_post_id) REFERENCES posts (id),
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub async fn db_get_comments(
|
||||||
) -> Vec<PublicComment> {
|
) -> Vec<PublicComment> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
PublicComment,
|
PublicComment,
|
||||||
"SELECT id, parent_post_id, upvotes, downvotes, content, created_at, updated_at
|
"SELECT id, parent_post_id, content, created_at, updated_at
|
||||||
FROM comments WHERE parent_post_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3",
|
FROM comments WHERE parent_post_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3",
|
||||||
parent_post_id,
|
parent_post_id,
|
||||||
limit,
|
limit,
|
||||||
|
@ -54,7 +54,7 @@ pub async fn db_get_comments(
|
||||||
pub async fn db_get_latest_posts(pool: &PgPool, limit: i64, offset: i64) -> Vec<PublicPost> {
|
pub async fn db_get_latest_posts(pool: &PgPool, limit: i64, offset: i64) -> Vec<PublicPost> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
PublicPost,
|
PublicPost,
|
||||||
"SELECT id, content, upvotes, downvotes, created_at, updated_at FROM posts ORDER BY created_at DESC LIMIT $1 OFFSET $2",
|
"SELECT id, content, created_at, updated_at FROM posts ORDER BY created_at DESC LIMIT $1 OFFSET $2",
|
||||||
limit,
|
limit,
|
||||||
offset
|
offset
|
||||||
)
|
)
|
||||||
|
@ -67,7 +67,7 @@ pub async fn db_get_latest_posts(pool: &PgPool, limit: i64, offset: i64) -> Vec<
|
||||||
pub async fn db_get_post(id: i64, pool: &PgPool) -> Option<PublicPost> {
|
pub async fn db_get_post(id: i64, pool: &PgPool) -> Option<PublicPost> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
PublicPost,
|
PublicPost,
|
||||||
"SELECT id, content, upvotes, downvotes, created_at, updated_at FROM posts WHERE id = $1",
|
"SELECT id, content, created_at, updated_at FROM posts WHERE id = $1",
|
||||||
id
|
id
|
||||||
)
|
)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
|
|
|
@ -16,8 +16,6 @@ pub struct Comment {
|
||||||
pub parent_post_id: i64,
|
pub parent_post_id: i64,
|
||||||
pub parent_comment_id: Option<i64>,
|
pub parent_comment_id: Option<i64>,
|
||||||
pub author_user_id: i64,
|
pub author_user_id: i64,
|
||||||
pub upvotes: i32,
|
|
||||||
pub downvotes: i32,
|
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub created_at: chrono::NaiveDateTime,
|
pub created_at: chrono::NaiveDateTime,
|
||||||
pub updated_at: chrono::NaiveDateTime,
|
pub updated_at: chrono::NaiveDateTime,
|
||||||
|
@ -28,8 +26,6 @@ pub struct Comment {
|
||||||
pub struct PublicComment {
|
pub struct PublicComment {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub parent_post_id: i64,
|
pub parent_post_id: i64,
|
||||||
pub upvotes: i32,
|
|
||||||
pub downvotes: i32,
|
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub created_at: chrono::NaiveDateTime,
|
pub created_at: chrono::NaiveDateTime,
|
||||||
pub updated_at: chrono::NaiveDateTime,
|
pub updated_at: chrono::NaiveDateTime,
|
||||||
|
|
|
@ -15,8 +15,6 @@ pub struct Post {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub user_id: i64,
|
pub user_id: i64,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub upvotes: i64,
|
|
||||||
pub downvotes: i64,
|
|
||||||
pub created_at: chrono::NaiveDateTime,
|
pub created_at: chrono::NaiveDateTime,
|
||||||
pub updated_at: chrono::NaiveDateTime,
|
pub updated_at: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
@ -26,8 +24,6 @@ pub struct Post {
|
||||||
pub struct PublicPost {
|
pub struct PublicPost {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub upvotes: i64,
|
|
||||||
pub downvotes: i64,
|
|
||||||
#[serde(rename = "createdAt")]
|
#[serde(rename = "createdAt")]
|
||||||
pub created_at: chrono::NaiveDateTime,
|
pub created_at: chrono::NaiveDateTime,
|
||||||
#[serde(rename = "updatedAt")]
|
#[serde(rename = "updatedAt")]
|
||||||
|
|
Loading…
Reference in a new issue