implement first draft of switching handoperatable boats
This commit is contained in:
@ -21,6 +21,8 @@ pub struct Boat {
|
||||
pub boatbuilder: Option<String>,
|
||||
pub default_destination: Option<String>,
|
||||
#[serde(default = "bool::default")]
|
||||
convert_handoperated_possible: bool,
|
||||
#[serde(default = "bool::default")]
|
||||
default_shipmaster_only_steering: bool,
|
||||
#[serde(default = "bool::default")]
|
||||
skull: bool,
|
||||
@ -53,6 +55,7 @@ pub struct BoatToAdd<'r> {
|
||||
pub year_built: Option<i64>,
|
||||
pub boatbuilder: Option<&'r str>,
|
||||
pub default_shipmaster_only_steering: bool,
|
||||
pub convert_handoperated_possible: bool,
|
||||
pub default_destination: Option<&'r str>,
|
||||
pub skull: bool,
|
||||
pub external: bool,
|
||||
@ -69,6 +72,7 @@ pub struct BoatToUpdate<'r> {
|
||||
pub default_shipmaster_only_steering: bool,
|
||||
pub default_destination: Option<&'r str>,
|
||||
pub skull: bool,
|
||||
pub convert_handoperated_possible: bool,
|
||||
pub external: bool,
|
||||
pub location_id: i64,
|
||||
pub owner: Option<i64>,
|
||||
@ -189,7 +193,7 @@ AND date('now') BETWEEN start_date AND end_date;",
|
||||
let boats = sqlx::query_as!(
|
||||
Boat,
|
||||
"
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted, convert_handoperated_possible
|
||||
FROM boat
|
||||
WHERE deleted=false
|
||||
ORDER BY amount_seats DESC
|
||||
@ -218,7 +222,8 @@ SELECT
|
||||
b.default_destination,
|
||||
b.skull,
|
||||
b.external,
|
||||
b.deleted
|
||||
b.deleted,
|
||||
b.convert_handoperated_possible
|
||||
FROM
|
||||
boat AS b
|
||||
WHERE
|
||||
@ -244,7 +249,7 @@ ORDER BY
|
||||
sqlx::query_as!(
|
||||
Boat,
|
||||
"
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted, convert_handoperated_possible
|
||||
FROM boat
|
||||
WHERE owner is null or owner = ?
|
||||
ORDER BY amount_seats DESC
|
||||
@ -258,7 +263,7 @@ ORDER BY amount_seats DESC
|
||||
sqlx::query_as!(
|
||||
Boat,
|
||||
"
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted, convert_handoperated_possible
|
||||
FROM boat
|
||||
WHERE owner = ? OR (owner is null and amount_seats = 1)
|
||||
ORDER BY amount_seats DESC
|
||||
@ -276,7 +281,7 @@ ORDER BY amount_seats DESC
|
||||
.unwrap();
|
||||
let boats_in_ottensheim = sqlx::query_as!(
|
||||
Boat,
|
||||
"SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted
|
||||
"SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted, convert_handoperated_possible
|
||||
FROM boat
|
||||
WHERE owner is null and location_id = ?
|
||||
ORDER BY amount_seats DESC
|
||||
@ -295,7 +300,7 @@ ORDER BY amount_seats DESC
|
||||
let boats = sqlx::query_as!(
|
||||
Boat,
|
||||
"
|
||||
SELECT boat.id, boat.name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted
|
||||
SELECT boat.id, boat.name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted, convert_handoperated_possible
|
||||
FROM boat
|
||||
INNER JOIN location ON boat.location_id = location.id
|
||||
WHERE location.name=?
|
||||
@ -312,7 +317,7 @@ ORDER BY amount_seats DESC
|
||||
|
||||
pub async fn create(db: &SqlitePool, boat: BoatToAdd<'_>) -> Result<(), String> {
|
||||
sqlx::query!(
|
||||
"INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, location_id, owner) VALUES (?,?,?,?,?,?,?,?,?,?)",
|
||||
"INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, location_id, owner, convert_handoperated_possible) VALUES (?,?,?,?,?,?,?,?,?,?,?)",
|
||||
boat.name,
|
||||
boat.amount_seats,
|
||||
boat.year_built,
|
||||
@ -322,7 +327,8 @@ ORDER BY amount_seats DESC
|
||||
boat.skull,
|
||||
boat.external,
|
||||
boat.location_id,
|
||||
boat.owner
|
||||
boat.owner,
|
||||
boat.convert_handoperated_possible
|
||||
)
|
||||
.execute(db)
|
||||
.await.map_err(|e| e.to_string())?;
|
||||
@ -331,7 +337,7 @@ ORDER BY amount_seats DESC
|
||||
|
||||
pub async fn update(&self, db: &SqlitePool, boat: BoatToUpdate<'_>) -> Result<(), String> {
|
||||
sqlx::query!(
|
||||
"UPDATE boat SET name=?, amount_seats=?, year_built=?, boatbuilder=?, default_shipmaster_only_steering=?, default_destination=?, skull=?, external=?, location_id=?, owner=? WHERE id=?",
|
||||
"UPDATE boat SET name=?, amount_seats=?, year_built=?, boatbuilder=?, default_shipmaster_only_steering=?, default_destination=?, skull=?, external=?, location_id=?, owner=?, convert_handoperated_possible=? WHERE id=?",
|
||||
boat.name,
|
||||
boat.amount_seats,
|
||||
boat.year_built,
|
||||
@ -342,6 +348,7 @@ ORDER BY amount_seats DESC
|
||||
boat.external,
|
||||
boat.location_id,
|
||||
boat.owner,
|
||||
boat.convert_handoperated_possible,
|
||||
self.id
|
||||
)
|
||||
.execute(db)
|
||||
|
Reference in New Issue
Block a user