Add feed model, link items to feeds
This commit is contained in:
19
src/handlers/feed.rs
Normal file
19
src/handlers/feed.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
Json,
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::models::feed::{create_feed, get_feed, CreateFeed, Feed};
|
||||
|
||||
pub async fn get(State(pool): State<PgPool>, Path(id): Path<i32>) -> Result<Json<Feed>, Error> {
|
||||
Ok(Json(get_feed(pool, id).await?))
|
||||
}
|
||||
|
||||
pub async fn post(
|
||||
State(pool): State<PgPool>,
|
||||
Json(payload): Json<CreateFeed>,
|
||||
) -> Result<Json<Feed>, Error> {
|
||||
Ok(Json(create_feed(pool, payload).await?))
|
||||
}
|
||||
9
src/handlers/feeds.rs
Normal file
9
src/handlers/feeds.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use axum::{extract::State, Json};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::models::feed::{get_feeds, Feed};
|
||||
|
||||
pub async fn get(State(pool): State<PgPool>) -> Result<Json<Vec<Feed>>, Error> {
|
||||
Ok(Json(get_feeds(pool).await?))
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
use axum::{extract::{State, Path}, Json};
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
Json,
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::models::item::{create_item, get_item, CreateItem, Item};
|
||||
|
||||
pub async fn get(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<i32>,
|
||||
) -> Result<Json<Item>, Error> {
|
||||
pub async fn get(State(pool): State<PgPool>, Path(id): Path<i32>) -> Result<Json<Item>, Error> {
|
||||
Ok(Json(get_item(pool, id).await?))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
pub mod feed;
|
||||
pub mod feeds;
|
||||
pub mod item;
|
||||
pub mod items;
|
||||
|
||||
Reference in New Issue
Block a user