2023-05-08 01:25:22 +00:00
|
|
|
use axum::{
|
|
|
|
extract::{Path, State},
|
|
|
|
Json,
|
|
|
|
};
|
|
|
|
use sqlx::PgPool;
|
|
|
|
|
2023-05-10 03:46:42 +00:00
|
|
|
use crate::error::{Error, Result};
|
|
|
|
use crate::models::feed::{create_feed, get_feed, delete_feed, CreateFeed, Feed};
|
2023-05-08 01:25:22 +00:00
|
|
|
|
2023-05-10 03:46:42 +00:00
|
|
|
pub async fn get(State(pool): State<PgPool>, Path(id): Path<i32>) -> Result<Json<Feed>> {
|
|
|
|
Ok(Json(get_feed(&pool, id).await?))
|
2023-05-08 01:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn post(
|
|
|
|
State(pool): State<PgPool>,
|
|
|
|
Json(payload): Json<CreateFeed>,
|
|
|
|
) -> Result<Json<Feed>, Error> {
|
2023-05-10 03:46:42 +00:00
|
|
|
Ok(Json(create_feed(&pool, payload).await?))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn delete(State(pool): State<PgPool>, Path(id): Path<i32>) -> Result<()> {
|
|
|
|
delete_feed(&pool, id).await
|
2023-05-08 01:25:22 +00:00
|
|
|
}
|