Files
crawlnicle/src/handlers/api/entry.rs
Tyler Hallada 15364ee861 Working apalis cron and worker with 0.6.0-rc.5
Also renamed `pool` variables throughout codebase to `db` for clarity.
2024-08-21 01:16:01 -04:00

24 lines
515 B
Rust

use axum::{
extract::{Path, State},
Json,
};
use sqlx::PgPool;
use crate::error::Error;
use crate::models::entry::{CreateEntry, Entry};
use crate::uuid::Base62Uuid;
pub async fn get(
State(db): State<PgPool>,
Path(id): Path<Base62Uuid>,
) -> Result<Json<Entry>, Error> {
Ok(Json(Entry::get(&db, id.as_uuid()).await?))
}
pub async fn post(
State(db): State<PgPool>,
Json(payload): Json<CreateEntry>,
) -> Result<Json<Entry>, Error> {
Ok(Json(Entry::create(&db, payload).await?))
}