|
|
|
@ -20,7 +20,7 @@ pub async fn list_for_user(
|
|
|
|
) -> Result<Vec<Synthesis>, AppError> {
|
|
|
|
) -> Result<Vec<Synthesis>, AppError> {
|
|
|
|
let rows = sqlx::query_as::<_, Synthesis>(
|
|
|
|
let rows = sqlx::query_as::<_, Synthesis>(
|
|
|
|
r#"
|
|
|
|
r#"
|
|
|
|
SELECT id, user_id, week, sections, status, created_at
|
|
|
|
SELECT id, user_id, week, sections, status, created_at, job_id
|
|
|
|
FROM syntheses
|
|
|
|
FROM syntheses
|
|
|
|
WHERE user_id = $1
|
|
|
|
WHERE user_id = $1
|
|
|
|
ORDER BY created_at DESC
|
|
|
|
ORDER BY created_at DESC
|
|
|
|
@ -42,7 +42,7 @@ pub async fn list_for_user(
|
|
|
|
pub async fn get_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Synthesis>, AppError> {
|
|
|
|
pub async fn get_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Synthesis>, AppError> {
|
|
|
|
let row = sqlx::query_as::<_, Synthesis>(
|
|
|
|
let row = sqlx::query_as::<_, Synthesis>(
|
|
|
|
r#"
|
|
|
|
r#"
|
|
|
|
SELECT id, user_id, week, sections, status, created_at
|
|
|
|
SELECT id, user_id, week, sections, status, created_at, job_id
|
|
|
|
FROM syntheses
|
|
|
|
FROM syntheses
|
|
|
|
WHERE id = $1
|
|
|
|
WHERE id = $1
|
|
|
|
"#,
|
|
|
|
"#,
|
|
|
|
@ -64,7 +64,7 @@ pub async fn get_by_id_for_user(
|
|
|
|
) -> Result<Option<Synthesis>, AppError> {
|
|
|
|
) -> Result<Option<Synthesis>, AppError> {
|
|
|
|
let row = sqlx::query_as::<_, Synthesis>(
|
|
|
|
let row = sqlx::query_as::<_, Synthesis>(
|
|
|
|
r#"
|
|
|
|
r#"
|
|
|
|
SELECT id, user_id, week, sections, status, created_at
|
|
|
|
SELECT id, user_id, week, sections, status, created_at, job_id
|
|
|
|
FROM syntheses
|
|
|
|
FROM syntheses
|
|
|
|
WHERE id = $1 AND user_id = $2
|
|
|
|
WHERE id = $1 AND user_id = $2
|
|
|
|
"#,
|
|
|
|
"#,
|
|
|
|
@ -86,17 +86,19 @@ pub async fn create(
|
|
|
|
user_id: Uuid,
|
|
|
|
user_id: Uuid,
|
|
|
|
week: &str,
|
|
|
|
week: &str,
|
|
|
|
sections_json: &serde_json::Value,
|
|
|
|
sections_json: &serde_json::Value,
|
|
|
|
|
|
|
|
job_id: Uuid,
|
|
|
|
) -> Result<Synthesis, AppError> {
|
|
|
|
) -> Result<Synthesis, AppError> {
|
|
|
|
let row = sqlx::query_as::<_, Synthesis>(
|
|
|
|
let row = sqlx::query_as::<_, Synthesis>(
|
|
|
|
r#"
|
|
|
|
r#"
|
|
|
|
INSERT INTO syntheses (user_id, week, sections, status)
|
|
|
|
INSERT INTO syntheses (user_id, week, sections, status, job_id)
|
|
|
|
VALUES ($1, $2, $3, 'completed')
|
|
|
|
VALUES ($1, $2, $3, 'completed', $4)
|
|
|
|
RETURNING id, user_id, week, sections, status, created_at
|
|
|
|
RETURNING id, user_id, week, sections, status, created_at, job_id
|
|
|
|
"#,
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.bind(user_id)
|
|
|
|
.bind(user_id)
|
|
|
|
.bind(week)
|
|
|
|
.bind(week)
|
|
|
|
.bind(sections_json)
|
|
|
|
.bind(sections_json)
|
|
|
|
|
|
|
|
.bind(job_id)
|
|
|
|
.fetch_one(pool)
|
|
|
|
.fetch_one(pool)
|
|
|
|
.await?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|