Skip to main content

systemprompt_users/repository/banned_ip/
mod.rs

1//! Persistence for IP bans.
2//!
3//! [`BannedIpRepository`] reads and writes the `banned_ips` table, supporting
4//! temporary and permanent bans with offense metadata. Ban inputs are carried
5//! by [`BanIpParams`] / [`BanIpWithMetadataParams`] with a [`BanDuration`], and
6//! lookups return [`BannedIp`].
7
8mod listing;
9mod queries;
10mod types;
11
12use std::sync::Arc;
13
14use crate::error::Result;
15use sqlx::PgPool;
16use systemprompt_database::DbPool;
17
18pub use types::{BanDuration, BanIpParams, BanIpWithMetadataParams, BannedIp};
19
20#[derive(Clone, Debug)]
21pub struct BannedIpRepository {
22    pool: Arc<PgPool>,
23    write_pool: Arc<PgPool>,
24}
25
26impl BannedIpRepository {
27    pub fn new(db: &DbPool) -> Result<Self> {
28        let pool = db.pool_arc()?;
29        let write_pool = db.write_pool_arc()?;
30        Ok(Self { pool, write_pool })
31    }
32
33    pub fn from_pool(pool: Arc<PgPool>) -> Self {
34        let write_pool = Arc::clone(&pool);
35        Self { pool, write_pool }
36    }
37}