implement default destination for boats

This commit is contained in:
2023-11-09 08:56:08 +01:00
parent ed0989e2a1
commit 715fae59fc
7 changed files with 26 additions and 13 deletions

View File

@ -13,6 +13,7 @@ pub struct Boat {
pub owner: Option<i64>,
pub year_built: Option<i64>,
pub boatbuilder: Option<String>,
pub default_destination: Option<String>,
#[serde(default = "bool::default")]
default_shipmaster_only_steering: bool,
#[serde(default = "bool::default")]
@ -21,7 +22,7 @@ pub struct Boat {
external: bool,
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum BoatDamage {
None,
@ -29,7 +30,7 @@ pub enum BoatDamage {
Locked,
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct BoatWithDetails {
#[serde(flatten)]
boat: Boat,
@ -44,6 +45,7 @@ pub struct BoatToAdd<'r> {
pub year_built: Option<i64>,
pub boatbuilder: Option<&'r str>,
pub default_shipmaster_only_steering: bool,
pub default_destination: Option<&'r str>,
pub skull: bool,
pub external: bool,
pub location_id: Option<i64>,
@ -57,6 +59,7 @@ pub struct BoatToUpdate<'r> {
pub year_built: Option<i64>,
pub boatbuilder: Option<&'r str>,
pub default_shipmaster_only_steering: bool,
pub default_destination: Option<&'r str>,
pub skull: bool,
pub external: bool,
pub location_id: i64,
@ -138,7 +141,7 @@ impl Boat {
let boats = sqlx::query_as!(
Boat,
"
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external
FROM boat
ORDER BY amount_seats DESC
"
@ -158,7 +161,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, skull, external
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external
FROM boat
WHERE owner is null or owner = ?
ORDER BY amount_seats DESC
@ -172,7 +175,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, skull, external
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external
FROM boat
WHERE owner = ? OR (owner is null and amount_seats = 1)
ORDER BY amount_seats DESC
@ -191,7 +194,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, skull, external
SELECT boat.id, boat.name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external
FROM boat
INNER JOIN location ON boat.location_id = location.id
WHERE location.name=?
@ -208,12 +211,13 @@ 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, 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) VALUES (?,?,?,?,?,?,?,?,?,?)",
boat.name,
boat.amount_seats,
boat.year_built,
boat.boatbuilder,
boat.default_shipmaster_only_steering,
boat.default_destination,
boat.skull,
boat.external,
boat.location_id,
@ -226,12 +230,13 @@ 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=?, 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=? WHERE id=?",
boat.name,
boat.amount_seats,
boat.year_built,
boat.boatbuilder,
boat.default_shipmaster_only_steering,
boat.default_destination,
boat.skull,
boat.external,
boat.location_id,