Skip to content

Commit 64fa6de

Browse files
refactor(db): move product feedback store ownership
Signed-off-by: tornquist <[email protected]>
1 parent 849b817 commit 64fa6de

3 files changed

Lines changed: 46 additions & 20 deletions

File tree

‎crates/buzz-db/src/lib.rs‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,25 +1335,6 @@ impl Db {
13351335
Ok(result.rows_affected())
13361336
}
13371337

1338-
/// Sidecar an accepted product-feedback event, idempotent by event id.
1339-
#[datastore_span(name = "insert_product_feedback", system = "postgresql")]
1340-
pub async fn insert_product_feedback(
1341-
&self,
1342-
community: CommunityId,
1343-
feedback: product_feedback::NewProductFeedback<'_>,
1344-
) -> Result<Uuid> {
1345-
product_feedback::insert(&self.pool, community, feedback).await
1346-
}
1347-
1348-
/// List product feedback across the deployment, newest first.
1349-
#[datastore_span(name = "list_product_feedback", system = "postgresql")]
1350-
pub async fn list_product_feedback(
1351-
&self,
1352-
limit: i64,
1353-
) -> Result<Vec<product_feedback::ProductFeedbackRecord>> {
1354-
product_feedback::list(&self.pool, limit).await
1355-
}
1356-
13571338
/// Insert a tenant-scoped NIP-56 report row, idempotent by report event id.
13581339
#[datastore_span(name = "insert_moderation_report", system = "postgresql")]
13591340
pub async fn insert_moderation_report(

‎crates/buzz-db/src/product_feedback.rs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
//! Feedback retains its source [`CommunityId`] as provenance, but is not a
44
//! community moderation concern and is never inserted into the events table.
55
6+
use buzz_datastore_tracing::datastore_span;
67
use chrono::{DateTime, Utc};
78
use serde::Serialize;
89
use sqlx::{PgPool, Row as _};
910
use uuid::Uuid;
1011

11-
use crate::{error::Result, CommunityId};
12+
use crate::{error::Result, CommunityId, Db};
1213

1314
/// Validated fields from an accepted product-feedback event.
1415
#[derive(Debug, Clone)]
@@ -117,6 +118,24 @@ pub async fn list(pool: &PgPool, limit: i64) -> Result<Vec<ProductFeedbackRecord
117118
.collect()
118119
}
119120

121+
impl Db {
122+
/// Sidecar an accepted product-feedback event, idempotent by event id.
123+
#[datastore_span(name = "insert_product_feedback", system = "postgresql")]
124+
pub async fn insert_product_feedback(
125+
&self,
126+
community: CommunityId,
127+
feedback: NewProductFeedback<'_>,
128+
) -> Result<Uuid> {
129+
insert(&self.pool, community, feedback).await
130+
}
131+
132+
/// List product feedback across the deployment, newest first.
133+
#[datastore_span(name = "list_product_feedback", system = "postgresql")]
134+
pub async fn list_product_feedback(&self, limit: i64) -> Result<Vec<ProductFeedbackRecord>> {
135+
list(&self.pool, limit).await
136+
}
137+
}
138+
120139
#[cfg(test)]
121140
mod tests {
122141
use super::*;

‎crates/buzz-db/tests/store_ownership.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,32 @@ fn relay_invite_store_has_single_ownership() {
9393
}
9494
}
9595

96+
#[test]
97+
fn product_feedback_store_has_single_ownership() {
98+
let root = include_str!("../src/lib.rs");
99+
let store = include_str!("../src/product_feedback.rs");
100+
101+
for method in ["insert_product_feedback", "list_product_feedback"] {
102+
let signature = format!("pub async fn {method}(");
103+
assert_eq!(count(root, &signature), 0, "{method} remains in lib.rs");
104+
assert_eq!(
105+
count(store, &signature),
106+
1,
107+
"{method} must be singly owned by product_feedback.rs"
108+
);
109+
let span = format!("name = \"{method}\"");
110+
assert_eq!(count(store, &span), 1, "{method} span is not unique");
111+
}
112+
113+
for ty in [
114+
"pub struct NewProductFeedback",
115+
"pub struct ProductFeedbackRecord",
116+
] {
117+
assert_eq!(count(root, ty), 0, "{ty} remains in lib.rs");
118+
assert_eq!(count(store, ty), 1, "{ty} is not singly owned");
119+
}
120+
}
121+
96122
#[test]
97123
fn channel_and_membership_stores_have_single_ownership() {
98124
let root = include_str!("../src/lib.rs");

0 commit comments

Comments
 (0)