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//!
8//! Copyright (c) systemprompt.io — Business Source License 1.1.
9//! See <https://systemprompt.io> for licensing details.
10
11mod listing;
12mod queries;
13mod types;
14
15use std::sync::Arc;
16
17use sqlx::PgPool;
18use systemprompt_database::DbPool;
19
20pub use types::{BanDuration, BanIpParams, BanIpWithMetadataParams, BannedIp};
21
22#[derive(Clone, Debug)]
23pub struct BannedIpRepository {
24    pool: Arc<PgPool>,
25    write_pool: Arc<PgPool>,
26}
27
28impl BannedIpRepository {
29    pub fn new(db: &DbPool) -> Self {
30        let pool = db.pool();
31        let write_pool = db.write_pool();
32        Self { pool, write_pool }
33    }
34
35    pub fn from_pool(pool: Arc<PgPool>) -> Self {
36        let write_pool = Arc::clone(&pool);
37        Self { pool, write_pool }
38    }
39}