Skip to main content

agentics_persistence/repositories/
pioneer_codes.rs

1use sqlx::PgPool;
2
3use crate::db;
4use crate::repositories::{
5    CreatePioneerCodeInput, PioneerCodeRecord, PioneerCodeUseRecord, RevokePioneerCodeOutcome,
6};
7use agentics_domain::models::ids::PioneerCodeId;
8use agentics_error::Result;
9
10#[derive(Debug, Clone, Copy)]
11pub struct PioneerCodesRepository<'a> {
12    pub(super) pool: &'a PgPool,
13}
14
15impl PioneerCodesRepository<'_> {
16    pub async fn create(&self, input: &CreatePioneerCodeInput) -> Result<PioneerCodeRecord> {
17        db::pioneer_codes::create_pioneer_code(self.pool, input).await
18    }
19
20    pub async fn list(&self) -> Result<Vec<PioneerCodeRecord>> {
21        db::pioneer_codes::list_pioneer_codes(self.pool).await
22    }
23
24    pub async fn detail(
25        &self,
26        id: &PioneerCodeId,
27    ) -> Result<(PioneerCodeRecord, Vec<PioneerCodeUseRecord>)> {
28        db::pioneer_codes::get_pioneer_code_detail(self.pool, id).await
29    }
30
31    pub async fn revoke(&self, id: &PioneerCodeId) -> Result<RevokePioneerCodeOutcome> {
32        db::pioneer_codes::revoke_pioneer_code(self.pool, id).await
33    }
34}