comment, interaction db
This commit is contained in:
parent
ee9015c1e3
commit
60d18771d7
17 changed files with 184 additions and 32 deletions
|
@ -1 +1,76 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use sqlx::{Pool, Postgres};
|
||||
|
||||
use crate::feature::comment::Comment;
|
||||
|
||||
pub async fn create(
|
||||
post_creation_time: DateTime<Utc>,
|
||||
creation_time: DateTime<Utc>,
|
||||
commenter_id: i64,
|
||||
comment: &String,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Comment, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Comment,
|
||||
r#"
|
||||
INSERT INTO "comment"(post_creation_time, creation_time, commenter_id, comment)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING *
|
||||
"#,
|
||||
post_creation_time,
|
||||
creation_time,
|
||||
commenter_id,
|
||||
comment,
|
||||
)
|
||||
.fetch_one(database_connection)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn read(
|
||||
creation_time: DateTime<Utc>,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Comment, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Comment,
|
||||
r#"
|
||||
SELECT * FROM "comment" WHERE "creation_time" = $1
|
||||
"#,
|
||||
creation_time
|
||||
)
|
||||
.fetch_one(database_connection)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn update(
|
||||
creation_time: DateTime<Utc>,
|
||||
comment: &String,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Comment, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Comment,
|
||||
r#"
|
||||
UPDATE "comment" SET "comment" = $1 WHERE "creation_time" = $2
|
||||
RETURNING *
|
||||
"#,
|
||||
comment,
|
||||
creation_time
|
||||
)
|
||||
.fetch_one(database_connection)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete(
|
||||
creation_time: DateTime<Utc>,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Comment, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Comment,
|
||||
r#"
|
||||
DELETE FROM "comment" where "creation_time" = $1
|
||||
RETURNING *
|
||||
"#,
|
||||
creation_time
|
||||
)
|
||||
.fetch_one(database_connection)
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -1 +1,69 @@
|
|||
use sqlx::{Pool, Postgres};
|
||||
|
||||
use crate::feature::interaction::Interaction;
|
||||
|
||||
pub async fn create(
|
||||
name: &String,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Interaction, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Interaction,
|
||||
r#"
|
||||
INSERT INTO "interaction"(name)
|
||||
VALUES ($1)
|
||||
RETURNING *
|
||||
"#,
|
||||
name,
|
||||
)
|
||||
.fetch_one(database_connection)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn read(
|
||||
name: &String,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Interaction, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Interaction,
|
||||
r#"
|
||||
SELECT * FROM "interaction" WHERE "name" = $1
|
||||
"#,
|
||||
name
|
||||
)
|
||||
.fetch_one(database_connection)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn update(
|
||||
id: i64,
|
||||
name: &String,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Interaction, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Interaction,
|
||||
r#"
|
||||
UPDATE "interaction" SET "name" = $1 WHERE "id" = $2
|
||||
RETURNING *
|
||||
"#,
|
||||
name,
|
||||
id
|
||||
)
|
||||
.fetch_one(database_connection)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete(
|
||||
id: i64,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Interaction, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Interaction,
|
||||
r#"
|
||||
DELETE FROM "interaction" where "id" = $1
|
||||
RETURNING *
|
||||
"#,
|
||||
id
|
||||
)
|
||||
.fetch_one(database_connection)
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ pub async fn delete(
|
|||
sqlx::query_as!(
|
||||
Post,
|
||||
r#"
|
||||
DELETE FROM "post" where creation_time = $1
|
||||
DELETE FROM "post" where "creation_time" = $1
|
||||
RETURNING *
|
||||
"#,
|
||||
creation_time
|
||||
|
|
|
@ -56,7 +56,7 @@ pub async fn delete(id: i64, database_connection: &Pool<Postgres>) -> Result<Rol
|
|||
sqlx::query_as!(
|
||||
Role,
|
||||
r#"
|
||||
DELETE FROM "role" where id = $1
|
||||
DELETE FROM "role" where "id" = $1
|
||||
RETURNING *
|
||||
"#,
|
||||
id
|
||||
|
|
|
@ -65,7 +65,7 @@ pub async fn delete(id: i64, database_connection: &Pool<Postgres>) -> Result<Use
|
|||
sqlx::query_as!(
|
||||
User,
|
||||
r#"
|
||||
DELETE FROM "user" where id = $1
|
||||
DELETE FROM "user" where "id" = $1
|
||||
RETURNING *
|
||||
"#,
|
||||
id
|
||||
|
|
|
@ -1 +1,8 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
|
||||
pub struct Comment {
|
||||
pub post_creation_time: DateTime<Utc>,
|
||||
pub creation_time: DateTime<Utc>,
|
||||
pub commenter_id: i64,
|
||||
pub comment: String,
|
||||
}
|
||||
|
|
|
@ -1,22 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
enum InteractionType {
|
||||
Like,
|
||||
Dislike,
|
||||
Heart,
|
||||
Confetti,
|
||||
Plus,
|
||||
Minus,
|
||||
Rocket,
|
||||
Smile,
|
||||
Laugh,
|
||||
Sad,
|
||||
Shrug,
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Interaction {
|
||||
post_id: String,
|
||||
user_id: String,
|
||||
interaction_type: InteractionType,
|
||||
pub struct Interaction {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue