2024-12-04 23:17:19 +03:00
|
|
|
use chrono::{DateTime, Utc};
|
2024-12-02 23:56:43 +03:00
|
|
|
use serde::{Deserialize, Serialize};
|
2024-12-15 04:30:39 +03:00
|
|
|
|
|
|
|
use crate::database::post;
|
2024-12-02 23:56:43 +03:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub struct Post {
|
2024-12-04 23:17:19 +03:00
|
|
|
pub creation_time: DateTime<Utc>,
|
2024-12-15 04:30:39 +03:00
|
|
|
pub user_id: i64,
|
2024-12-02 23:56:43 +03:00
|
|
|
pub post: String,
|
|
|
|
}
|
2024-12-15 04:30:39 +03:00
|
|
|
|
|
|
|
impl Post {
|
2025-01-20 03:10:42 +03:00
|
|
|
pub async fn create(user_id: &i64, post: &String) -> Result<Post, sqlx::Error> {
|
|
|
|
post::create(user_id, post).await
|
2024-12-15 04:30:39 +03:00
|
|
|
}
|
|
|
|
|
2025-01-27 17:54:57 +03:00
|
|
|
pub async fn read(user_id: &i64, creation_time: &DateTime<Utc>) -> Result<Post, sqlx::Error> {
|
|
|
|
post::read(user_id, creation_time).await
|
2024-12-15 04:30:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn update(
|
|
|
|
user_id: &i64,
|
2025-01-27 17:54:57 +03:00
|
|
|
creation_time: &DateTime<Utc>,
|
2024-12-15 04:30:39 +03:00
|
|
|
post: &String,
|
|
|
|
) -> Result<Post, sqlx::Error> {
|
2025-01-27 17:54:57 +03:00
|
|
|
post::update(user_id, creation_time, post).await
|
2024-12-15 04:30:39 +03:00
|
|
|
}
|
|
|
|
|
2025-01-27 17:54:57 +03:00
|
|
|
pub async fn delete(user_id: &i64, creation_time: &DateTime<Utc>) -> Result<Post, sqlx::Error> {
|
|
|
|
post::delete(user_id, creation_time).await
|
2024-12-15 04:30:39 +03:00
|
|
|
}
|
|
|
|
|
2025-01-20 03:10:42 +03:00
|
|
|
pub async fn read_all() -> Result<Vec<Post>, sqlx::Error> {
|
|
|
|
post::read_all().await
|
2024-12-15 04:30:39 +03:00
|
|
|
}
|
|
|
|
|
2025-01-20 03:10:42 +03:00
|
|
|
pub async fn read_all_for_user(user_id: &i64) -> Result<Vec<Post>, sqlx::Error> {
|
|
|
|
post::read_all_for_user(user_id).await
|
2024-12-15 04:30:39 +03:00
|
|
|
}
|
|
|
|
}
|