You've already forked AstralRinth
* typos :help_me: * (part 1/?) massive cleanup to make the code more Rust-ic and cut down heap allocations. * (part 2/?) massive cleanup to make the code more Rust-ic and cut down heap allocations. * (part 3/?) cut down some pretty major heap allocations here - more Bytes and BytesMuts, less Vec<u8>s also I don't really understand why you need to `to_vec` when you don't really use it again afterwards * (part 4/?) deduplicate error handling in backblaze logic * (part 5/?) fixes, cleanups, refactors, and reformatting * (part 6/?) cleanups and refactors * remove loads of `as_str` in types that already are `Display` * Revert "remove loads of `as_str` in types that already are `Display`" This reverts commit 4f974310cfb167ceba03001d81388db4f0fbb509. * reformat and move routes util to the util module * use streams * Run prepare + formatting issues Co-authored-by: Jai A <jaiagr+gpg@pm.me> Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
54 lines
1.4 KiB
Rust
54 lines
1.4 KiB
Rust
use super::ApiError;
|
|
use crate::database;
|
|
use crate::models::projects::ProjectStatus;
|
|
use crate::util::auth::check_is_moderator_from_headers;
|
|
use actix_web::{get, web, HttpRequest, HttpResponse};
|
|
use serde::Deserialize;
|
|
use sqlx::PgPool;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct ResultCount {
|
|
#[serde(default = "default_count")]
|
|
pub count: i16,
|
|
}
|
|
|
|
fn default_count() -> i16 {
|
|
100
|
|
}
|
|
|
|
#[get("projects")]
|
|
pub async fn get_projects(
|
|
req: HttpRequest,
|
|
pool: web::Data<PgPool>,
|
|
count: web::Query<ResultCount>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
check_is_moderator_from_headers(req.headers(), &**pool).await?;
|
|
|
|
use futures::stream::TryStreamExt;
|
|
|
|
let project_ids = sqlx::query!(
|
|
"
|
|
SELECT id FROM mods
|
|
WHERE status = (
|
|
SELECT id FROM statuses WHERE status = $1
|
|
)
|
|
ORDER BY updated ASC
|
|
LIMIT $2;
|
|
",
|
|
ProjectStatus::Processing.as_str(),
|
|
count.count as i64
|
|
)
|
|
.fetch_many(&**pool)
|
|
.try_filter_map(|e| async { Ok(e.right().map(|m| database::models::ProjectId(m.id))) })
|
|
.try_collect::<Vec<database::models::ProjectId>>()
|
|
.await?;
|
|
|
|
let projects: Vec<_> = database::Project::get_many_full(project_ids, &**pool)
|
|
.await?
|
|
.into_iter()
|
|
.map(crate::models::projects::Project::from)
|
|
.collect();
|
|
|
|
Ok(HttpResponse::Ok().json(projects))
|
|
}
|