Skip to content

Commit

Permalink
Controller facility join date
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeo committed Sep 17, 2024
1 parent aa3017d commit d1dc175
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion vzdv-tasks/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![deny(unsafe_code)]

use anyhow::{Context, Result};
use chrono::Months;
use chrono::{DateTime, Months};
use clap::Parser;
use log::{debug, error, info};
use sqlx::{sqlite::SqliteRow, Row, SqlitePool};
Expand Down Expand Up @@ -80,6 +80,7 @@ async fn update_controller_record(db: &SqlitePool, controller: &RosterMember) ->
}
};

let facility_join = DateTime::parse_from_rfc3339(&controller.facility_join)?;
// update record
sqlx::query(sql::UPSERT_USER_TASK)
.bind(controller.cid)
Expand All @@ -90,6 +91,7 @@ async fn update_controller_record(db: &SqlitePool, controller: &RosterMember) ->
.bind(&controller.facility)
// controller will be on the roster since that's what the VATSIM API is showing
.bind(true)
.bind(facility_join)
.bind(roles.join(","))
.execute(db)
.await?;
Expand Down
10 changes: 7 additions & 3 deletions vzdv/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Controller {
pub home_facility: String,
pub is_on_roster: bool,
pub roles: String,
pub join_date: Option<DateTime<Utc>>,
pub loa_until: Option<DateTime<Utc>>,
}

Expand Down Expand Up @@ -139,6 +140,7 @@ CREATE TABLE controller (
home_facility TEXT,
is_on_roster INTEGER,
roles TEXT,
join_date TEXT,
loa_until TEXT
) STRICT;
Expand Down Expand Up @@ -249,16 +251,17 @@ WHERE

pub const UPSERT_USER_TASK: &str = "
INSERT INTO controller
(id, cid, first_name, last_name, email, rating, home_facility, is_on_roster, roles)
(id, cid, first_name, last_name, email, rating, home_facility, is_on_roster, join_date, roles)
VALUES
(NULL, $1, $2, $3, $4, $5, $6, $7, $8)
(NULL, $1, $2, $3, $4, $5, $6, $7, $8, $9)
ON CONFLICT(cid) DO UPDATE SET
first_name=excluded.first_name,
last_name=excluded.last_name,
email=excluded.email,
rating=excluded.rating,
home_facility=excluded.home_facility,
is_on_roster=excluded.is_on_roster,
join_date=excluded.join_date,
roles=excluded.roles
WHERE
cid=excluded.cid
Expand All @@ -269,7 +272,8 @@ pub const GET_ALL_CONTROLLERS_ON_ROSTER: &str = "SELECT * FROM controller WHERE
pub const GET_ALL_CONTROLLER_CIDS: &str = "SELECT cid FROM controller";
pub const GET_ALL_ROSTER_CONTROLLER_CIDS: &str =
"SELECT cid FROM controller WHERE is_on_roster=TRUE";
pub const UPDATE_REMOVED_FROM_ROSTER: &str = "UPDATE controller SET is_on_roster=0 WHERE cid=$1";
pub const UPDATE_REMOVED_FROM_ROSTER: &str =
"UPDATE controller SET is_on_roster=0, home_facility='', join_date=NULL WHERE cid=$1";
pub const GET_CONTROLLER_BY_CID: &str = "SELECT * FROM controller WHERE cid=$1";
pub const GET_CONTROLLER_CIDS_AND_NAMES: &str = "SELECT cid, first_name, last_name from controller";
pub const GET_ATM_AND_DATM: &str = "SELECT * FROM controller WHERE roles LIKE '%ATM%'";
Expand Down

0 comments on commit d1dc175

Please sign in to comment.