diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-21 21:10:22 +0300 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-21 21:10:22 +0300 |
| commit | 934fb31059da10fa843d96a10c37f181eaa89456 (patch) | |
| tree | 452b36bdd1e286e68381607f15742695afec0f60 /src/users.rs | |
| parent | 30f50e5b31294abd75c4b629970ad4865108738d (diff) | |
feat: add weather pooler and config
Diffstat (limited to 'src/users.rs')
| -rw-r--r-- | src/users.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/users.rs b/src/users.rs index 43f190d..dad24bc 100644 --- a/src/users.rs +++ b/src/users.rs @@ -20,6 +20,16 @@ pub enum UserRole { Admin, } +#[derive(Debug, Serialize, Deserialize, FromRow, Clone, PartialEq, ToSchema)] +pub struct UserWithLocation { + pub id: i64, + pub user_id: String, + pub role: UserRole, + pub location_id: i64, + pub latitude: f64, + pub longitude: f64, +} + pub struct UserRepository<'a> { pub db: &'a sqlx::SqlitePool, } @@ -79,6 +89,17 @@ impl<'a> UserRepository<'a> { Ok(()) } + pub async fn list_users_with_locations(&self) -> Result<Vec<UserWithLocation>, sqlx::Error> { + sqlx::query_as::<_, UserWithLocation>( + "SELECT u.id, u.user_id, u.role, l.id as location_id, l.latitude, l.longitude + FROM users u + LEFT JOIN locations l ON u.id = l.user_id + WHERE l.id IS NOT NULL", + ) + .fetch_all(self.db) + .await + } + pub async fn any_admin_exists(&self) -> Result<bool, sqlx::Error> { let count: (i64,) = sqlx::query_as("SELECT COUNT(*) FROM users WHERE role = ?") .bind(UserRole::Admin) |
