All checks were successful
build-and-release / build (developers) (push) Successful in 1m42s
build-and-release / build (companies) (push) Successful in 1m48s
build-and-release / build (catering-services) (push) Successful in 1m55s
build-and-release / build (cron) (push) Successful in 2m4s
build-and-release / build (customers) (push) Successful in 2m26s
build-and-release / build (employees) (push) Successful in 1m24s
build-and-release / build (fitness-trainers) (push) Successful in 1m37s
build-and-release / build (gateway) (push) Successful in 1m38s
build-and-release / build (graphic-designers) (push) Successful in 1m54s
build-and-release / build (jobs) (push) Successful in 1m48s
build-and-release / build (leads) (push) Successful in 1m40s
build-and-release / build (job-seekers) (push) Successful in 2m52s
build-and-release / build (photographers) (push) Successful in 1m50s
build-and-release / build (payments) (push) Successful in 2m16s
build-and-release / build (makeup-artists) (push) Successful in 2m48s
build-and-release / build (tutors) (push) Successful in 2m16s
build-and-release / build (social-media-managers) (push) Successful in 2m42s
build-and-release / build (ugc-content-creators) (push) Successful in 2m36s
build-and-release / build (video-editors) (push) Successful in 2m19s
build-and-release / build (users) (push) Successful in 5m10s
Adds a DB-trigger-generated reference_number (NXT-{TYPE}-{YY}-{000001}) to
verifications, support_tickets, payments, job_applications, lead_requests,
and users, replacing raw UUIDs shown to customers/admins. Also fixes
verification-status endpoint to return uploaded documents (previously
omitted, so documents never appeared after submission), and adds a
reference-number lookup endpoint for the AI support assistant.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
118 lines
3.1 KiB
Rust
118 lines
3.1 KiB
Rust
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use sqlx::{FromRow, PgPool};
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Debug, Serialize, Deserialize, FromRow)]
|
|
pub struct Application {
|
|
pub id: Uuid,
|
|
pub reference_number: String,
|
|
pub job_id: Uuid,
|
|
pub applicant_user_id: Uuid,
|
|
pub cover_note: Option<String>,
|
|
pub status: String,
|
|
pub applied_at: DateTime<Utc>,
|
|
pub updated_at: DateTime<Utc>,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub struct CreateApplicationPayload {
|
|
pub job_id: Uuid,
|
|
pub applicant_user_id: Uuid,
|
|
pub cover_note: Option<String>,
|
|
}
|
|
|
|
pub struct ApplicationRepository;
|
|
|
|
impl ApplicationRepository {
|
|
pub async fn create(
|
|
pool: &PgPool,
|
|
payload: CreateApplicationPayload,
|
|
) -> Result<Application, sqlx::Error> {
|
|
let app = sqlx::query_as::<_, Application>(
|
|
r#"
|
|
INSERT INTO job_applications (job_id, applicant_user_id, cover_note)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING *
|
|
"#,
|
|
)
|
|
.bind(payload.job_id)
|
|
.bind(payload.applicant_user_id)
|
|
.bind(payload.cover_note)
|
|
.fetch_one(pool)
|
|
.await?;
|
|
|
|
Ok(app)
|
|
}
|
|
|
|
pub async fn get_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Application>, sqlx::Error> {
|
|
sqlx::query_as::<_, Application>("SELECT * FROM job_applications WHERE id = $1")
|
|
.bind(id)
|
|
.fetch_optional(pool)
|
|
.await
|
|
}
|
|
|
|
pub async fn list_by_job_id(
|
|
pool: &PgPool,
|
|
job_id: Uuid,
|
|
status: Option<String>,
|
|
page: i64,
|
|
limit: i64,
|
|
) -> Result<Vec<Application>, sqlx::Error> {
|
|
let offset = (page - 1) * limit;
|
|
let apps = sqlx::query_as::<_, Application>(
|
|
r#"
|
|
SELECT * FROM job_applications
|
|
WHERE job_id = $1 AND ($2::VARCHAR IS NULL OR status = $2)
|
|
ORDER BY applied_at DESC
|
|
LIMIT $3 OFFSET $4
|
|
"#,
|
|
)
|
|
.bind(job_id)
|
|
.bind(status)
|
|
.bind(limit)
|
|
.bind(offset)
|
|
.fetch_all(pool)
|
|
.await?;
|
|
|
|
Ok(apps)
|
|
}
|
|
|
|
pub async fn list_by_user_id(
|
|
pool: &PgPool,
|
|
applicant_user_id: Uuid,
|
|
page: i64,
|
|
limit: i64,
|
|
) -> Result<Vec<Application>, sqlx::Error> {
|
|
let offset = (page - 1) * limit;
|
|
let apps = sqlx::query_as::<_, Application>(
|
|
r#"
|
|
SELECT * FROM job_applications
|
|
WHERE applicant_user_id = $1
|
|
ORDER BY applied_at DESC
|
|
LIMIT $2 OFFSET $3
|
|
"#,
|
|
)
|
|
.bind(applicant_user_id)
|
|
.bind(limit)
|
|
.bind(offset)
|
|
.fetch_all(pool)
|
|
.await?;
|
|
Ok(apps)
|
|
}
|
|
|
|
pub async fn update_status(
|
|
pool: &PgPool,
|
|
id: Uuid,
|
|
status: &str,
|
|
) -> Result<Application, sqlx::Error> {
|
|
let app = sqlx::query_as::<_, Application>(
|
|
"UPDATE job_applications SET status = $1, updated_at = NOW() WHERE id = $2 RETURNING *",
|
|
)
|
|
.bind(status)
|
|
.bind(id)
|
|
.fetch_one(pool)
|
|
.await?;
|
|
Ok(app)
|
|
}
|
|
}
|