Skip to content

Commit

Permalink
Sketch out wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Dec 21, 2024
1 parent 182c2b6 commit 7489d1a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 16 deletions.
12 changes: 11 additions & 1 deletion rfd-api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use rfd_github::{GitHubError, GitHubNewRfdNumber, GitHubRfdRepo};
use rfd_model::{
schema_ext::{ContentFormat, Visibility},
storage::{JobStore, RfdFilter, RfdMetaStore, RfdPdfFilter, RfdPdfStore, RfdStorage, RfdStore},
CommitSha, FileSha, Job, NewJob, Rfd, RfdId, RfdMeta, RfdPdf, RfdRevision, RfdRevisionId,
CommitSha, FileSha, Job, NewJob, Rfd, RfdComment, RfdId, RfdMeta, RfdPdf, RfdRevision,
RfdRevisionId,
};
use rsa::{
pkcs1::{DecodeRsaPrivateKey, EncodeRsaPrivateKey},
Expand Down Expand Up @@ -512,6 +513,15 @@ impl RfdContext {
Ok(pdfs)
}

pub async fn view_rfd_comments(
&self,
caller: &Caller<RfdPermission>,
rfd_number: i32,
revision: Option<RfdRevisionIdentifier>,
) -> ResourceResult<Vec<RfdComment>, StoreError> {
unimplemented!()
}

#[instrument(skip(self, caller, content))]
pub async fn update_rfd_content(
&self,
Expand Down
30 changes: 22 additions & 8 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, RfdPdf, RfdRevisionId,
Rfd, RfdComment, RfdPdf, RfdRevisionId,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -175,8 +175,11 @@ pub async fn view_rfd_attr(
pub async fn view_rfd_comments(
rqctx: RequestContext<RfdContext>,
path: Path<RfdPathParams>,
) -> Result<HttpResponseOk<()>, HttpError> {
unimplemented!()
) -> Result<HttpResponseOk<Vec<RfdComment>>, HttpError> {
let ctx = rqctx.context();
let caller = ctx.v_ctx().get_caller(&rqctx).await?;
let path = path.into_inner();
view_rfd_comments_op(ctx, &caller, path.number, None).await
}

// Specific RFD revision endpoints
Expand Down Expand Up @@ -266,8 +269,11 @@ pub async fn view_rfd_revision_attr(
pub async fn view_rfd_revision_comments(
rqctx: RequestContext<RfdContext>,
path: Path<RfdRevisionPathParams>,
) -> Result<HttpResponseOk<()>, HttpError> {
unimplemented!()
) -> Result<HttpResponseOk<Vec<RfdComment>>, HttpError> {
let ctx = rqctx.context();
let caller = ctx.v_ctx().get_caller(&rqctx).await?;
let path = path.into_inner();
view_rfd_comments_op(ctx, &caller, path.number, Some(path.revision.into())).await
}

#[derive(Debug, Deserialize, JsonSchema)]
Expand Down Expand Up @@ -406,7 +412,7 @@ async fn view_rfd_attr_op(
attr: RfdAttrName,
) -> Result<HttpResponseOk<RfdAttr>, HttpError> {
if let Ok(rfd_number) = number.parse::<i32>() {
let rfd = ctx.view_rfd(caller, rfd_number, None).await?;
let rfd = ctx.view_rfd(caller, rfd_number, revision).await?;
let content = match rfd.format {
ContentFormat::Asciidoc => RfdContent::Asciidoc(RfdAsciidoc::new(rfd.content)),
ContentFormat::Markdown => RfdContent::Markdown(RfdMarkdown::new(rfd.content)),
Expand All @@ -427,8 +433,16 @@ async fn view_rfd_comments_op(
caller: &Caller<RfdPermission>,
number: String,
revision: Option<RfdRevisionIdentifier>,
) -> Result<HttpResponseOk<RfdWithContent>, HttpError> {
unimplemented!()
) -> Result<HttpResponseOk<Vec<RfdComment>>, HttpError> {
if let Ok(rfd_number) = number.parse::<i32>() {
let comments = ctx.view_rfd_comments(caller, rfd_number, revision).await?;
Ok(HttpResponseOk(comments))
} else {
Err(client_error(
ClientErrorStatusCode::BAD_REQUEST,
"Malformed RFD number",
))
}
}

#[instrument(skip(ctx, caller), fields(caller = ?caller.id), err(Debug))]
Expand Down
2 changes: 1 addition & 1 deletion rfd-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl TypedUuidKind for RfdCommentId {
pub struct RfdComment {
pub id: TypedUuid<RfdCommentId>,
pub rfd_id: TypedUuid<RfdId>,
pub comment_user_id: TypedUuid<RfdCommentUserId>,
pub comment_user: RfdCommentUser,
pub external_id: Option<i32>,
pub node_id: String,
pub discussion_number: Option<i32>,
Expand Down
44 changes: 42 additions & 2 deletions rfd-model/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use std::fmt::Debug;
use v_model::storage::{ListPagination, StoreError};

use crate::{
schema_ext::PdfSource, CommitSha, Job, NewJob, NewRfd, NewRfdPdf, NewRfdRevision, Rfd, RfdId,
RfdMeta, RfdPdf, RfdPdfId, RfdRevision, RfdRevisionId, RfdRevisionMeta,
schema_ext::PdfSource, CommitSha, Job, NewJob, NewRfd, NewRfdComment, NewRfdCommentUser,
NewRfdPdf, NewRfdRevision, Rfd, RfdComment, RfdCommentId, RfdCommentUser, RfdCommentUserId,
RfdId, RfdMeta, RfdPdf, RfdPdfId, RfdRevision, RfdRevisionId, RfdRevisionMeta,
};

#[cfg(feature = "mock")]
Expand Down Expand Up @@ -308,3 +309,42 @@ pub trait JobStore {
async fn start(&self, id: i32) -> Result<Option<Job>, StoreError>;
async fn complete(&self, id: i32) -> Result<Option<Job>, StoreError>;
}

#[cfg_attr(feature = "mock", automock)]
#[async_trait]
pub trait RfdCommentUserStore {
async fn upsert(
&self,
new_rfd_comment_user: NewRfdCommentUser,
) -> Result<RfdCommentUser, StoreError>;
}

#[derive(Debug, Default)]
pub struct RfdCommentFilter {
pub rfd: Option<Vec<TypedUuid<RfdId>>>,
pub user: Option<Vec<TypedUuid<RfdCommentUserId>>>,
}

impl RfdCommentFilter {
pub fn rfd(mut self, rfd: Option<Vec<TypedUuid<RfdId>>>) -> Self {
self.rfd = rfd;
self
}

pub fn user(mut self, user: Option<Vec<TypedUuid<RfdCommentUserId>>>) -> Self {
self.user = user;
self
}
}

#[cfg_attr(feature = "mock", automock)]
#[async_trait]
pub trait RfdCommentStore {
async fn list(
&self,
filters: Vec<RfdCommentFilter>,
pagination: &ListPagination,
) -> Result<Vec<Job>, StoreError>;
async fn upsert(&self, new_rfd_comment: NewRfdComment) -> Result<RfdComment, StoreError>;
async fn delete(&self, id: &TypedUuid<RfdCommentId>) -> Result<Option<RfdComment>, StoreError>;
}
39 changes: 35 additions & 4 deletions rfd-model/src/storage/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ use crate::{
schema::{job, rfd, rfd_pdf, rfd_revision},
schema_ext::Visibility,
storage::StoreError,
Job, NewJob, NewRfd, NewRfdPdf, NewRfdRevision, Rfd, RfdId, RfdMeta, RfdPdf, RfdPdfId,
RfdRevision, RfdRevisionId, RfdRevisionMeta,
Job, NewJob, NewRfd, NewRfdComment, NewRfdCommentUser, NewRfdPdf, NewRfdRevision, Rfd,
RfdComment, RfdCommentId, RfdCommentUser, RfdId, RfdMeta, RfdPdf, RfdPdfId, RfdRevision,
RfdRevisionId, RfdRevisionMeta,
};

use super::{
JobFilter, JobStore, ListPagination, RfdFilter, RfdMetaStore, RfdPdfFilter, RfdPdfStore,
RfdRevisionFilter, RfdRevisionMetaStore, RfdRevisionStore, RfdStore,
JobFilter, JobStore, ListPagination, RfdCommentFilter, RfdCommentStore, RfdCommentUserStore,
RfdFilter, RfdMetaStore, RfdPdfFilter, RfdPdfStore, RfdRevisionFilter, RfdRevisionMetaStore,
RfdRevisionStore, RfdStore,
};

#[async_trait]
Expand Down Expand Up @@ -748,6 +750,35 @@ impl JobStore for PostgresStore {
}
}

#[async_trait]
impl RfdCommentUserStore for PostgresStore {
async fn upsert(
&self,
new_rfd_comment_user: NewRfdCommentUser,

Check warning on line 757 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `new_rfd_comment_user`

Check warning on line 757 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `new_rfd_comment_user`

Check warning on line 757 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `new_rfd_comment_user`

Check warning on line 757 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `new_rfd_comment_user`
) -> Result<RfdCommentUser, StoreError> {
unimplemented!()
}
}

#[async_trait]
impl RfdCommentStore for PostgresStore {
async fn list(
&self,
filters: Vec<RfdCommentFilter>,

Check warning on line 767 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `filters`

Check warning on line 767 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `filters`

Check warning on line 767 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `filters`

Check warning on line 767 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `filters`
pagination: &ListPagination,

Check warning on line 768 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `pagination`

Check warning on line 768 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `pagination`

Check warning on line 768 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `pagination`

Check warning on line 768 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `pagination`
) -> Result<Vec<Job>, StoreError> {
unimplemented!()
}

async fn upsert(&self, new_rfd_comment: NewRfdComment) -> Result<RfdComment, StoreError> {

Check warning on line 773 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `new_rfd_comment`

Check warning on line 773 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `new_rfd_comment`

Check warning on line 773 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `new_rfd_comment`

Check warning on line 773 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `new_rfd_comment`
unimplemented!()
}

async fn delete(&self, id: &TypedUuid<RfdCommentId>) -> Result<Option<RfdComment>, StoreError> {

Check warning on line 777 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `id`

Check warning on line 777 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `id`

Check warning on line 777 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `id`

Check warning on line 777 in rfd-model/src/storage/postgres.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `id`
unimplemented!()
}
}

fn flatten_predicates<T>(
predicates: Vec<Vec<Box<dyn BoxableExpression<T, Pg, SqlType = Bool>>>>,
) -> Option<Box<dyn BoxableExpression<T, Pg, SqlType = Bool>>>
Expand Down

0 comments on commit 7489d1a

Please sign in to comment.