added images to project route, datasource
This commit is contained in:
@@ -7,7 +7,7 @@ impl ProjectsDatasource {
|
|||||||
pub async fn get_all(pool: &Pool<Postgres>) -> Result<Vec<Project>, sqlx::Error> {
|
pub async fn get_all(pool: &Pool<Postgres>) -> Result<Vec<Project>, sqlx::Error> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Project,
|
Project,
|
||||||
"SELECT project_id, title, repo, summary, description, tech, wip, created_at FROM projects p WHERE deleted_at IS NULL ORDER BY p.created_at DESC"
|
"SELECT p.project_id, title, repo, summary, description, tech, wip, p.created_at, COALESCE(array_agg(pi.url) FILTER (WHERE pi.url IS NOT NULL), '{}') as images FROM projects p LEFT JOIN project_images pi ON p.project_id = pi.project_id AND pi.deleted_at IS NULL WHERE p.deleted_at IS NULL GROUP BY p.project_id, p.title, p.repo, p.summary, p.description, p.tech, p.wip, p.created_at ORDER BY p.created_at DESC"
|
||||||
)
|
)
|
||||||
.fetch_all(pool)
|
.fetch_all(pool)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ pub struct Project {
|
|||||||
#[serde(serialize_with = "serialize_datetime")]
|
#[serde(serialize_with = "serialize_datetime")]
|
||||||
#[serde(deserialize_with = "deserialize_datetime")]
|
#[serde(deserialize_with = "deserialize_datetime")]
|
||||||
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
|
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
|
pub images: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ProjectsRoute;
|
pub struct ProjectsRoute;
|
||||||
|
|||||||
Reference in New Issue
Block a user