rust_forum/src/feature/post.rs

42 lines
1.1 KiB
Rust
Raw Normal View History

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 {
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
}
pub async fn read(creation_time: &DateTime<Utc>) -> Result<Post, sqlx::Error> {
post::read(creation_time).await
2024-12-15 04:30:39 +03:00
}
pub async fn update(
creation_time: &DateTime<Utc>,
user_id: &i64,
post: &String,
) -> Result<Post, sqlx::Error> {
post::update(creation_time, user_id, post).await
2024-12-15 04:30:39 +03:00
}
pub async fn delete(creation_time: &DateTime<Utc>) -> Result<Post, sqlx::Error> {
post::delete(creation_time).await
2024-12-15 04:30:39 +03:00
}
pub async fn read_all() -> Result<Vec<Post>, sqlx::Error> {
post::read_all().await
2024-12-15 04:30:39 +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
}
}