Skip to content

Commit

Permalink
Split out pdfs
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Dec 21, 2024
1 parent ef9f0ef commit 6b9b132
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
25 changes: 23 additions & 2 deletions rfd-api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use rfd_data::{
use rfd_github::{GitHubError, GitHubNewRfdNumber, GitHubRfdRepo};
use rfd_model::{
schema_ext::{ContentFormat, Visibility},
storage::{JobStore, RfdFilter, RfdMetaStore, RfdStorage, RfdStore},
CommitSha, FileSha, Job, NewJob, Rfd, RfdId, RfdMeta, RfdRevision, RfdRevisionId,
storage::{JobStore, RfdFilter, RfdMetaStore, RfdPdfFilter, RfdPdfStore, RfdStorage, RfdStore},
CommitSha, FileSha, Job, NewJob, Rfd, RfdId, RfdMeta, RfdPdf, RfdRevision, RfdRevisionId,
};
use rsa::{
pkcs1::{DecodeRsaPrivateKey, EncodeRsaPrivateKey},
Expand Down Expand Up @@ -491,6 +491,27 @@ impl RfdContext {
self.view_rfd_revision(caller, rfd_number, None).await
}

#[instrument(skip(self, caller))]
pub async fn view_rfd_pdfs(
&self,
caller: &Caller<RfdPermission>,
rfd_number: i32,
revision: Option<RfdRevisionIdentifier>,
) -> ResourceResult<Vec<RfdPdf>, StoreError> {
let rfd = self.get_rfd_meta(caller, rfd_number, revision).await?;
let pdfs = RfdPdfStore::list(
&*self.storage,
vec![RfdPdfFilter::default()
.rfd(Some(vec![rfd.id]))
.rfd_revision(Some(vec![rfd.content.id]))],
&ListPagination::unlimited(),
)
.await
.to_resource_result()?;

Ok(pdfs)
}

#[instrument(skip(self, caller, content))]
pub async fn update_rfd_content(
&self,
Expand Down
19 changes: 14 additions & 5 deletions rfd-api/src/endpoints/rfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rfd_data::{
};
use rfd_model::{
schema_ext::{ContentFormat, Visibility},
Rfd, RfdRevisionId,
Rfd, RfdPdf, RfdRevisionId,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -141,7 +141,7 @@ pub async fn view_rfd(
pub async fn view_rfd_pdf(
rqctx: RequestContext<RfdContext>,
path: Path<RfdPathParams>,
) -> Result<HttpResponseOk<RfdWithContent>, HttpError> {
) -> Result<HttpResponseOk<Vec<RfdPdf>>, HttpError> {
let ctx = rqctx.context();
let caller = ctx.v_ctx().get_caller(&rqctx).await?;
let path = path.into_inner();
Expand Down Expand Up @@ -225,7 +225,7 @@ pub async fn view_rfd_revision(
pub async fn view_rfd_revision_pdf(
rqctx: RequestContext<RfdContext>,
path: Path<RfdRevisionPathParams>,
) -> Result<HttpResponseOk<RfdWithContent>, HttpError> {
) -> Result<HttpResponseOk<Vec<RfdPdf>>, HttpError> {
let ctx = rqctx.context();
let caller = ctx.v_ctx().get_caller(&rqctx).await?;
let path = path.into_inner();
Expand Down Expand Up @@ -384,8 +384,17 @@ async fn view_rfd_pdf_op(
caller: &Caller<RfdPermission>,
number: String,
revision: Option<RfdRevisionIdentifier>,
) -> Result<HttpResponseOk<RfdWithContent>, HttpError> {
unimplemented!()
) -> Result<HttpResponseOk<Vec<RfdPdf>>, HttpError> {
if let Ok(rfd_number) = number.parse::<i32>() {
Ok(HttpResponseOk(
ctx.view_rfd_pdfs(caller, rfd_number, revision).await?,
))
} else {
Err(client_error(
ClientErrorStatusCode::BAD_REQUEST,
"Malformed RFD number",
))
}
}

#[instrument(skip(ctx, caller), fields(caller = ?caller.id), err(Debug))]
Expand Down

0 comments on commit 6b9b132

Please sign in to comment.