diff --git a/migrations/20241204225128_create_role_table.up.sql b/migrations/20241204225128_create_role_table.up.sql index e33fee9..a6e7d53 100644 --- a/migrations/20241204225128_create_role_table.up.sql +++ b/migrations/20241204225128_create_role_table.up.sql @@ -4,6 +4,6 @@ CREATE TABLE IF NOT EXISTS "role"( name VARCHAR(16) NOT NULL UNIQUE ); -INSERT INTO "role"(id, name) VALUES (0, 'Ahmet Kaan Gümüş'); -INSERT INTO "role"(id, name) VALUES (1, 'Founder'); -INSERT INTO "role"(id, name) VALUES (2, 'Normal'); +INSERT INTO "role"(id, name) VALUES (0, 'Ahmet Kaan Gümüş') ON CONFLICT(id) DO UPDATE SET "name" = 'Ahmet Kaan Gümüş'; +INSERT INTO "role"(id, name) VALUES (1, 'Founder') ON CONFLICT(id) DO UPDATE SET "name" = 'Founder'; +INSERT INTO "role"(id, name) VALUES (2, 'Normal') ON CONFLICT(id) DO UPDATE SET "name" = 'Normal'; diff --git a/src/database/comment.rs b/src/database/comment.rs index 48654a0..5f52ec4 100644 --- a/src/database/comment.rs +++ b/src/database/comment.rs @@ -73,7 +73,7 @@ pub async fn delete( .await } -pub async fn read_all( +pub async fn read_all_for_post( post_creation_time: DateTime, database_connection: &Pool, ) -> Result, sqlx::Error> { @@ -86,4 +86,4 @@ pub async fn read_all( ) .fetch_all(database_connection) .await -} \ No newline at end of file +} diff --git a/src/database/comment_interaction.rs b/src/database/comment_interaction.rs index e0f00e4..a2559c6 100644 --- a/src/database/comment_interaction.rs +++ b/src/database/comment_interaction.rs @@ -73,7 +73,7 @@ pub async fn delete( .await } -pub async fn read_all( +pub async fn read_all_for_comment( comment_creation_time: &DateTime, database_connection: &Pool, ) -> Result, sqlx::Error> { @@ -86,4 +86,4 @@ pub async fn read_all( ) .fetch_all(database_connection) .await -} \ No newline at end of file +} diff --git a/src/database/post.rs b/src/database/post.rs index 0200f0e..416d1e4 100644 --- a/src/database/post.rs +++ b/src/database/post.rs @@ -73,9 +73,7 @@ pub async fn delete( .await } -pub async fn read_all( - database_connection: &Pool, -) -> Result, sqlx::Error> { +pub async fn read_all(database_connection: &Pool) -> Result, sqlx::Error> { sqlx::query_as!( Post, r#" @@ -99,4 +97,4 @@ pub async fn read_all_for_user( ) .fetch_all(database_connection) .await -} \ No newline at end of file +} diff --git a/src/database/post_interaction.rs b/src/database/post_interaction.rs index b2e08a0..aacf0f5 100644 --- a/src/database/post_interaction.rs +++ b/src/database/post_interaction.rs @@ -73,7 +73,7 @@ pub async fn delete( .await } -pub async fn read_all( +pub async fn read_all_for_post( post_creation_time: &DateTime, database_connection: &Pool, ) -> Result, sqlx::Error> { @@ -86,4 +86,4 @@ pub async fn read_all( ) .fetch_all(database_connection) .await -} \ No newline at end of file +} diff --git a/src/database/user.rs b/src/database/user.rs index a92efc7..e4ac816 100644 --- a/src/database/user.rs +++ b/src/database/user.rs @@ -73,3 +73,29 @@ pub async fn delete(id: i64, database_connection: &Pool) -> Result) -> Result, sqlx::Error> { + sqlx::query_as!( + User, + r#" + SELECT * FROM "user" + "#, + ) + .fetch_all(database_connection) + .await +} + +pub async fn read_all_for_role( + role_id: i64, + database_connection: &Pool, +) -> Result, sqlx::Error> { + sqlx::query_as!( + User, + r#" + SELECT * FROM "user" WHERE "role_id" = $1 + "#, + role_id + ) + .fetch_all(database_connection) + .await +}