2026-03-17 20:42:51 +01:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use sqlx::{FromRow, PgPool};
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize, FromRow)]
|
|
|
|
|
pub struct PhotographerProfile {
|
|
|
|
|
pub id: Uuid,
|
2026-04-12 23:21:11 +02:00
|
|
|
pub user_role_profile_id: Uuid,
|
|
|
|
|
pub specialties: Vec<String>,
|
|
|
|
|
pub camera_brands: Vec<String>,
|
|
|
|
|
pub studio_available: bool,
|
|
|
|
|
pub outdoor_shoots: bool,
|
|
|
|
|
pub travel_radius_km: Option<i32>,
|
|
|
|
|
pub starting_price_inr: Option<i32>,
|
2026-03-17 20:42:51 +01:00
|
|
|
pub created_at: DateTime<Utc>,
|
|
|
|
|
pub updated_at: DateTime<Utc>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct UpsertPhotographerProfilePayload {
|
2026-04-12 23:21:11 +02:00
|
|
|
pub specialties: Vec<String>,
|
|
|
|
|
pub camera_brands: Vec<String>,
|
|
|
|
|
pub studio_available: bool,
|
|
|
|
|
pub outdoor_shoots: bool,
|
|
|
|
|
pub travel_radius_km: Option<i32>,
|
|
|
|
|
pub starting_price_inr: Option<i32>,
|
2026-03-17 20:42:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct PhotographerRepository;
|
|
|
|
|
|
|
|
|
|
impl PhotographerRepository {
|
2026-04-12 23:21:11 +02:00
|
|
|
pub async fn get_by_user_role_id(pool: &PgPool, user_role_profile_id: Uuid) -> Result<Option<PhotographerProfile>, sqlx::Error> {
|
2026-04-09 07:40:15 +02:00
|
|
|
sqlx::query_as::<_, PhotographerProfile>(
|
2026-04-12 23:21:11 +02:00
|
|
|
r#"SELECT id, user_role_profile_id, specialties, camera_brands,
|
|
|
|
|
studio_available, outdoor_shoots, travel_radius_km,
|
|
|
|
|
starting_price_inr,
|
|
|
|
|
created_at, updated_at
|
|
|
|
|
FROM photographer_profiles WHERE user_role_profile_id = $1"#,
|
2026-04-09 07:40:15 +02:00
|
|
|
)
|
2026-04-12 23:21:11 +02:00
|
|
|
.bind(user_role_profile_id)
|
2026-04-09 07:40:15 +02:00
|
|
|
.fetch_optional(pool)
|
|
|
|
|
.await
|
2026-03-17 20:42:51 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-12 23:21:11 +02:00
|
|
|
pub async fn upsert(pool: &PgPool, user_role_profile_id: Uuid, p: UpsertPhotographerProfilePayload) -> Result<PhotographerProfile, sqlx::Error> {
|
2026-04-09 07:40:15 +02:00
|
|
|
sqlx::query_as::<_, PhotographerProfile>(
|
2026-04-12 23:21:11 +02:00
|
|
|
r#"INSERT INTO photographer_profiles (user_role_profile_id, specialties, camera_brands,
|
|
|
|
|
studio_available, outdoor_shoots, travel_radius_km, starting_price_inr)
|
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
|
|
|
ON CONFLICT (user_role_profile_id) DO UPDATE SET
|
|
|
|
|
specialties = COALESCE(EXCLUDED.specialties, photographer_profiles.specialties),
|
|
|
|
|
camera_brands = COALESCE(EXCLUDED.camera_brands, photographer_profiles.camera_brands),
|
|
|
|
|
studio_available = EXCLUDED.studio_available,
|
|
|
|
|
outdoor_shoots = EXCLUDED.outdoor_shoots,
|
|
|
|
|
travel_radius_km = EXCLUDED.travel_radius_km,
|
|
|
|
|
starting_price_inr = EXCLUDED.starting_price_inr,
|
|
|
|
|
updated_at = NOW()
|
|
|
|
|
RETURNING id, user_role_profile_id, specialties, camera_brands,
|
|
|
|
|
studio_available, outdoor_shoots, travel_radius_km,
|
|
|
|
|
starting_price_inr, created_at, updated_at"#,
|
2026-04-09 07:40:15 +02:00
|
|
|
)
|
2026-04-12 23:21:11 +02:00
|
|
|
.bind(user_role_profile_id)
|
|
|
|
|
.bind(&p.specialties)
|
|
|
|
|
.bind(&p.camera_brands)
|
|
|
|
|
.bind(p.studio_available)
|
|
|
|
|
.bind(p.outdoor_shoots)
|
|
|
|
|
.bind(p.travel_radius_km)
|
|
|
|
|
.bind(p.starting_price_inr)
|
2026-04-09 07:40:15 +02:00
|
|
|
.fetch_one(pool)
|
|
|
|
|
.await
|
2026-03-17 20:42:51 +01:00
|
|
|
}
|
|
|
|
|
}
|