Skip to content

Commit

Permalink
More wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Dec 21, 2024
1 parent 7489d1a commit e7726ed
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 19 deletions.
17 changes: 15 additions & 2 deletions rfd-api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use rfd_data::{
use rfd_github::{GitHubError, GitHubNewRfdNumber, GitHubRfdRepo};
use rfd_model::{
schema_ext::{ContentFormat, Visibility},
storage::{JobStore, RfdFilter, RfdMetaStore, RfdPdfFilter, RfdPdfStore, RfdStorage, RfdStore},
storage::{
JobStore, RfdCommentFilter, RfdCommentStore, RfdFilter, RfdMetaStore, RfdPdfFilter,
RfdPdfStore, RfdStorage, RfdStore,
},
CommitSha, FileSha, Job, NewJob, Rfd, RfdComment, RfdId, RfdMeta, RfdPdf, RfdRevision,
RfdRevisionId,
};
Expand Down Expand Up @@ -519,7 +522,17 @@ impl RfdContext {
rfd_number: i32,
revision: Option<RfdRevisionIdentifier>,
) -> ResourceResult<Vec<RfdComment>, StoreError> {
unimplemented!()
let rfd = self.get_rfd_meta(caller, rfd_number, revision).await?;
let comments = RfdCommentStore::list(
&*self.storage,
vec![RfdCommentFilter::default()
.rfd(Some(vec![rfd.id]))
.comment_created_before(Some(rfd.content.committed_at))],
&ListPagination::unlimited(),
)
.await
.to_resource_result()?;
Ok(comments)
}

#[instrument(skip(self, caller, content))]
Expand Down
58 changes: 53 additions & 5 deletions rfd-model/src/storage/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ use std::sync::Arc;
use v_model::storage::StoreError;

use crate::{
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, MockJobStore, MockRfdMetaStore, MockRfdPdfStore,
MockRfdRevisionMetaStore, MockRfdRevisionStore, MockRfdStore, RfdFilter, RfdMetaStore,
RfdPdfFilter, RfdPdfStore, RfdRevisionFilter, RfdRevisionMetaStore, RfdRevisionStore, RfdStore,
JobFilter, JobStore, ListPagination, MockJobStore, MockRfdCommentStore,
MockRfdCommentUserStore, MockRfdMetaStore, MockRfdPdfStore, MockRfdRevisionMetaStore,
MockRfdRevisionStore, MockRfdStore, RfdCommentFilter, RfdCommentStore, RfdCommentUserStore,
RfdFilter, RfdMetaStore, RfdPdfFilter, RfdPdfStore, RfdRevisionFilter, RfdRevisionMetaStore,
RfdRevisionStore, RfdStore,
};

pub struct MockStorage {
Expand All @@ -25,6 +28,8 @@ pub struct MockStorage {
pub rfd_revision_meta_store: Option<Arc<MockRfdRevisionMetaStore>>,
pub rfd_pdf_store: Option<Arc<MockRfdPdfStore>>,
pub job_store: Option<Arc<MockJobStore>>,
pub rfd_comment_user_store: Option<Arc<MockRfdCommentUserStore>>,
pub rfd_comment_store: Option<Arc<MockRfdCommentStore>>,
}

impl MockStorage {
Expand All @@ -36,6 +41,8 @@ impl MockStorage {
rfd_revision_meta_store: None,
rfd_pdf_store: None,
job_store: None,
rfd_comment_user_store: None,
rfd_comment_store: None,
}
}
}
Expand Down Expand Up @@ -234,3 +241,44 @@ impl JobStore for MockStorage {
self.job_store.as_ref().unwrap().complete(id).await
}
}

#[async_trait]
impl RfdCommentUserStore for MockStorage {
async fn upsert(
&self,
new_rfd_comment_user: NewRfdCommentUser,
) -> Result<RfdCommentUser, StoreError> {
self.rfd_comment_user_store
.as_ref()
.unwrap()
.upsert(new_rfd_comment_user)
.await
}
}

#[async_trait]
impl RfdCommentStore for MockStorage {
async fn list(
&self,
filters: Vec<RfdCommentFilter>,
pagination: &ListPagination,
) -> Result<Vec<RfdComment>, StoreError> {
self.rfd_comment_store
.as_ref()
.unwrap()
.list(filters, pagination)
.await
}

async fn upsert(&self, new_rfd_comment: NewRfdComment) -> Result<RfdComment, StoreError> {
self.rfd_comment_store
.as_ref()
.unwrap()
.upsert(new_rfd_comment)
.await
}

async fn delete(&self, id: &TypedUuid<RfdCommentId>) -> Result<Option<RfdComment>, StoreError> {
self.rfd_comment_store.as_ref().unwrap().delete(id).await
}
}
23 changes: 12 additions & 11 deletions rfd-model/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

pub use async_bb8_diesel::{ConnectionError, PoolError};
use async_trait::async_trait;
use chrono::{DateTime, Utc};
pub use diesel::result::Error as DbError;
#[cfg(feature = "mock")]
use mockall::automock;
Expand All @@ -28,6 +29,8 @@ pub trait RfdStorage:
+ RfdRevisionMetaStore
+ RfdPdfStore
+ JobStore
+ RfdCommentUserStore
+ RfdCommentStore
+ Send
+ Sync
+ 'static
Expand All @@ -40,6 +43,8 @@ impl<T> RfdStorage for T where
+ RfdRevisionMetaStore
+ RfdPdfStore
+ JobStore
+ RfdCommentUserStore
+ RfdCommentStore
+ Send
+ Sync
+ 'static
Expand Down Expand Up @@ -175,11 +180,6 @@ pub trait RfdRevisionStore {
filters: Vec<RfdRevisionFilter>,
pagination: &ListPagination,
) -> Result<Vec<RfdRevision>, StoreError>;
// async fn list_unique_rfd(
// &self,
// filters: Vec<RfdRevisionFilter>,
// pagination: &ListPagination,
// ) -> Result<Vec<RfdRevision>, StoreError>;
async fn upsert(&self, new_revision: NewRfdRevision) -> Result<RfdRevision, StoreError>;
async fn delete(
&self,
Expand All @@ -200,11 +200,6 @@ pub trait RfdRevisionMetaStore {
filters: Vec<RfdRevisionFilter>,
pagination: &ListPagination,
) -> Result<Vec<RfdRevisionMeta>, StoreError>;
// async fn list_unique_rfd(
// &self,
// filter: RfdRevisionFilter,
// pagination: &ListPagination,
// ) -> Result<Vec<RfdRevisionMeta>, StoreError>;
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -323,6 +318,7 @@ pub trait RfdCommentUserStore {
pub struct RfdCommentFilter {
pub rfd: Option<Vec<TypedUuid<RfdId>>>,
pub user: Option<Vec<TypedUuid<RfdCommentUserId>>>,
pub comment_created_before: Option<DateTime<Utc>>,
}

impl RfdCommentFilter {
Expand All @@ -335,6 +331,11 @@ impl RfdCommentFilter {
self.user = user;
self
}

pub fn comment_created_before(mut self, comment_created_before: Option<DateTime<Utc>>) -> Self {
self.comment_created_before = comment_created_before;
self
}
}

#[cfg_attr(feature = "mock", automock)]
Expand All @@ -344,7 +345,7 @@ pub trait RfdCommentStore {
&self,
filters: Vec<RfdCommentFilter>,
pagination: &ListPagination,
) -> Result<Vec<Job>, StoreError>;
) -> Result<Vec<RfdComment>, StoreError>;
async fn upsert(&self, new_rfd_comment: NewRfdComment) -> Result<RfdComment, StoreError>;
async fn delete(&self, id: &TypedUuid<RfdCommentId>) -> Result<Option<RfdComment>, StoreError>;
}
2 changes: 1 addition & 1 deletion rfd-model/src/storage/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ impl RfdCommentStore for PostgresStore {
&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> {
) -> Result<Vec<RfdComment>, StoreError> {
unimplemented!()
}

Expand Down

0 comments on commit e7726ed

Please sign in to comment.