From 2e23c7919fde6e9f94bbbefb99998cfe4cb07200 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 22 Mar 2024 19:47:36 +0100 Subject: [PATCH] Removed the concept of down & upvotes --- client-solid/src/Util/api.ts | 2 - ...e476c59530888879fd84de0a6116b3aa99641.json | 40 +++++++++++++ ...4a204ddf3d75be6666fca3624deb35c0aaa97.json | 14 +---- ...337fffccc32dc87a17a40c67c3c1c7e163e63.json | 60 ------------------- ...10789ca27ba7919ceba0881134ee3e40cfb7.json} | 18 +----- ...82ead87ff0b1504135f64165cdc35352db5b.json} | 26 ++++---- server/migrations/0002_posts_table.sql | 2 - server/migrations/0003_comments_table.sql | 2 - server/src/db.rs | 6 +- server/src/types/comment.rs | 4 -- server/src/types/post.rs | 4 -- 11 files changed, 58 insertions(+), 120 deletions(-) create mode 100644 server/.sqlx/query-1bc374be695ed5237e460b08d69e476c59530888879fd84de0a6116b3aa99641.json delete mode 100644 server/.sqlx/query-3560895233b2af755be5c55ce01337fffccc32dc87a17a40c67c3c1c7e163e63.json rename server/.sqlx/{query-2ec6780ea09d3cd14aeb87aeb97d93ff9a46e71d75f7e00d6c990fd3585ed866.json => query-371366128df3138dce5b63ff4fb010789ca27ba7919ceba0881134ee3e40cfb7.json} (59%) rename server/.sqlx/{query-f2463f3ff911698f3e841c631e8b8609408eaa32f0dcc7fb70c029339613cd07.json => query-745713958bdfdf0f5e9fd086dda582ead87ff0b1504135f64165cdc35352db5b.json} (68%) diff --git a/client-solid/src/Util/api.ts b/client-solid/src/Util/api.ts index 095bfe6..be6d0f9 100644 --- a/client-solid/src/Util/api.ts +++ b/client-solid/src/Util/api.ts @@ -40,8 +40,6 @@ export interface PublicComment { id: number; parent_post_id: number; parent_comment_id: number | null; - upvotes: number; - downvotes: number; content: string; created_at: string; updated_at: string; diff --git a/server/.sqlx/query-1bc374be695ed5237e460b08d69e476c59530888879fd84de0a6116b3aa99641.json b/server/.sqlx/query-1bc374be695ed5237e460b08d69e476c59530888879fd84de0a6116b3aa99641.json new file mode 100644 index 0000000..85d82ea --- /dev/null +++ b/server/.sqlx/query-1bc374be695ed5237e460b08d69e476c59530888879fd84de0a6116b3aa99641.json @@ -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" +} diff --git a/server/.sqlx/query-1cff76615ce5fb26bd9fbb23cbe4a204ddf3d75be6666fca3624deb35c0aaa97.json b/server/.sqlx/query-1cff76615ce5fb26bd9fbb23cbe4a204ddf3d75be6666fca3624deb35c0aaa97.json index ee38c27..3b7d137 100644 --- a/server/.sqlx/query-1cff76615ce5fb26bd9fbb23cbe4a204ddf3d75be6666fca3624deb35c0aaa97.json +++ b/server/.sqlx/query-1cff76615ce5fb26bd9fbb23cbe4a204ddf3d75be6666fca3624deb35c0aaa97.json @@ -20,21 +20,11 @@ }, { "ordinal": 3, - "name": "upvotes", - "type_info": "Int4" - }, - { - "ordinal": 4, - "name": "downvotes", - "type_info": "Int4" - }, - { - "ordinal": 5, "name": "created_at", "type_info": "Timestamp" }, { - "ordinal": 6, + "ordinal": 4, "name": "updated_at", "type_info": "Timestamp" } @@ -47,8 +37,6 @@ false, false, false, - false, - false, false ] }, diff --git a/server/.sqlx/query-3560895233b2af755be5c55ce01337fffccc32dc87a17a40c67c3c1c7e163e63.json b/server/.sqlx/query-3560895233b2af755be5c55ce01337fffccc32dc87a17a40c67c3c1c7e163e63.json deleted file mode 100644 index d269c15..0000000 --- a/server/.sqlx/query-3560895233b2af755be5c55ce01337fffccc32dc87a17a40c67c3c1c7e163e63.json +++ /dev/null @@ -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" -} diff --git a/server/.sqlx/query-2ec6780ea09d3cd14aeb87aeb97d93ff9a46e71d75f7e00d6c990fd3585ed866.json b/server/.sqlx/query-371366128df3138dce5b63ff4fb010789ca27ba7919ceba0881134ee3e40cfb7.json similarity index 59% rename from server/.sqlx/query-2ec6780ea09d3cd14aeb87aeb97d93ff9a46e71d75f7e00d6c990fd3585ed866.json rename to server/.sqlx/query-371366128df3138dce5b63ff4fb010789ca27ba7919ceba0881134ee3e40cfb7.json index 877e58f..182a34e 100644 --- a/server/.sqlx/query-2ec6780ea09d3cd14aeb87aeb97d93ff9a46e71d75f7e00d6c990fd3585ed866.json +++ b/server/.sqlx/query-371366128df3138dce5b63ff4fb010789ca27ba7919ceba0881134ee3e40cfb7.json @@ -1,6 +1,6 @@ { "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": { "columns": [ { @@ -15,21 +15,11 @@ }, { "ordinal": 2, - "name": "upvotes", - "type_info": "Int4" - }, - { - "ordinal": 3, - "name": "downvotes", - "type_info": "Int4" - }, - { - "ordinal": 4, "name": "created_at", "type_info": "Timestamp" }, { - "ordinal": 5, + "ordinal": 3, "name": "updated_at", "type_info": "Timestamp" } @@ -41,13 +31,11 @@ ] }, "nullable": [ - false, - false, false, false, false, false ] }, - "hash": "2ec6780ea09d3cd14aeb87aeb97d93ff9a46e71d75f7e00d6c990fd3585ed866" + "hash": "371366128df3138dce5b63ff4fb010789ca27ba7919ceba0881134ee3e40cfb7" } diff --git a/server/.sqlx/query-f2463f3ff911698f3e841c631e8b8609408eaa32f0dcc7fb70c029339613cd07.json b/server/.sqlx/query-745713958bdfdf0f5e9fd086dda582ead87ff0b1504135f64165cdc35352db5b.json similarity index 68% rename from server/.sqlx/query-f2463f3ff911698f3e841c631e8b8609408eaa32f0dcc7fb70c029339613cd07.json rename to server/.sqlx/query-745713958bdfdf0f5e9fd086dda582ead87ff0b1504135f64165cdc35352db5b.json index 15dc272..a34c398 100644 --- a/server/.sqlx/query-f2463f3ff911698f3e841c631e8b8609408eaa32f0dcc7fb70c029339613cd07.json +++ b/server/.sqlx/query-745713958bdfdf0f5e9fd086dda582ead87ff0b1504135f64165cdc35352db5b.json @@ -1,41 +1,38 @@ { "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": { "columns": [ { "ordinal": 0, "name": "id", - "type_info": "Int8" + "type_info": "Int4" }, { "ordinal": 1, + "name": "parent_post_id", + "type_info": "Int8" + }, + { + "ordinal": 2, "name": "content", "type_info": "Text" }, - { - "ordinal": 2, - "name": "upvotes", - "type_info": "Int4" - }, { "ordinal": 3, - "name": "downvotes", - "type_info": "Int4" - }, - { - "ordinal": 4, "name": "created_at", "type_info": "Timestamp" }, { - "ordinal": 5, + "ordinal": 4, "name": "updated_at", "type_info": "Timestamp" } ], "parameters": { "Left": [ + "Int8", + "Int8", "Int8" ] }, @@ -44,9 +41,8 @@ false, false, false, - false, false ] }, - "hash": "f2463f3ff911698f3e841c631e8b8609408eaa32f0dcc7fb70c029339613cd07" + "hash": "745713958bdfdf0f5e9fd086dda582ead87ff0b1504135f64165cdc35352db5b" } diff --git a/server/migrations/0002_posts_table.sql b/server/migrations/0002_posts_table.sql index 5042a86..2ab5280 100644 --- a/server/migrations/0002_posts_table.sql +++ b/server/migrations/0002_posts_table.sql @@ -2,8 +2,6 @@ CREATE TABLE IF NOT EXISTS posts ( id BIGSERIAL PRIMARY KEY, user_id BIGINT 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, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users (id) diff --git a/server/migrations/0003_comments_table.sql b/server/migrations/0003_comments_table.sql index 5eb8049..d0cbfc7 100644 --- a/server/migrations/0003_comments_table.sql +++ b/server/migrations/0003_comments_table.sql @@ -4,8 +4,6 @@ CREATE TABLE IF NOT EXISTS comments ( -- parent_comment_id BIGINT, author_user_id BIGINT 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, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (parent_post_id) REFERENCES posts (id), diff --git a/server/src/db.rs b/server/src/db.rs index 1c83492..4216809 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -39,7 +39,7 @@ pub async fn db_get_comments( ) -> Vec { sqlx::query_as!( 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", parent_post_id, 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 { sqlx::query_as!( 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, 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 { sqlx::query_as!( 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 ) .fetch_one(pool) diff --git a/server/src/types/comment.rs b/server/src/types/comment.rs index 70fe32a..0b01d8b 100644 --- a/server/src/types/comment.rs +++ b/server/src/types/comment.rs @@ -16,8 +16,6 @@ pub struct Comment { pub parent_post_id: i64, pub parent_comment_id: Option, pub author_user_id: i64, - pub upvotes: i32, - pub downvotes: i32, pub content: String, pub created_at: chrono::NaiveDateTime, pub updated_at: chrono::NaiveDateTime, @@ -28,8 +26,6 @@ pub struct Comment { pub struct PublicComment { pub id: i64, pub parent_post_id: i64, - pub upvotes: i32, - pub downvotes: i32, pub content: String, pub created_at: chrono::NaiveDateTime, pub updated_at: chrono::NaiveDateTime, diff --git a/server/src/types/post.rs b/server/src/types/post.rs index 5ac4885..2940486 100644 --- a/server/src/types/post.rs +++ b/server/src/types/post.rs @@ -15,8 +15,6 @@ pub struct Post { pub id: i64, pub user_id: i64, pub content: String, - pub upvotes: i64, - pub downvotes: i64, pub created_at: chrono::NaiveDateTime, pub updated_at: chrono::NaiveDateTime, } @@ -26,8 +24,6 @@ pub struct Post { pub struct PublicPost { pub id: i64, pub content: String, - pub upvotes: i64, - pub downvotes: i64, #[serde(rename = "createdAt")] pub created_at: chrono::NaiveDateTime, #[serde(rename = "updatedAt")]