implement user handling for trips
This commit is contained in:
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO trips_to_trips_types\n (trip_id, trip_type_id)\n VALUES\n (?, ?)\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 2
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "0e8a12e168d8ff41005b2b5a1356ef5dc39339291572005e2a9278fb28113a2b"
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "\n INSERT INTO trips_items\n (\n item_id,\n trip_id,\n pick,\n pack,\n ready,\n new\n )\n VALUES (?, ?, ?, ?, ?, ?)\n ",
|
"query": "\n INSERT INTO trips_items\n (\n item_id,\n trip_id,\n pick,\n pack,\n ready,\n new,\n user_id\n )\n VALUES (?, ?, ?, ?, ?, ?, ?)\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 6
|
"Right": 7
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "86eb9fd598fbbb50b32ea7eae3151bfd8a83639c8b70301f5d5aeef19ae9462c"
|
"hash": "12167f7d6f8b1bfc5f37c214b089a5196039e6845598b8b22852b7665bcd5c0c"
|
||||||
}
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "\n SELECT\n i_item.id AS item_id\n FROM inventory_items AS i_item\n LEFT JOIN (\n SELECT t_item.item_id as item_id\n FROM trips_items AS t_item\n WHERE t_item.trip_id = ?\n ) AS t_item\n ON t_item.item_id = i_item.id\n WHERE t_item.item_id IS NULL\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "item_id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "1994305e1521fe1f5f927ad28e21c9cab8a25598b19e1c9038dae9092fe18f1f"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO trips\n (id, name, date_start, date_end, state)\n VALUES\n (?, ?, ?, ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 5
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "259757f1bb08f0c366371202c75b8555b878290b8a5a68564ec3e8b3d8e7ed01"
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "\n SELECT\n category.id as category_id,\n category.name as category_name,\n category.description AS category_description,\n inner.trip_id AS trip_id,\n inner.item_id AS item_id,\n inner.item_name AS item_name,\n inner.item_description AS item_description,\n inner.item_weight AS item_weight,\n inner.item_is_picked AS item_is_picked,\n inner.item_is_packed AS item_is_packed,\n inner.item_is_ready AS item_is_ready,\n inner.item_is_new AS item_is_new\n FROM inventory_items_categories AS category\n LEFT JOIN (\n SELECT\n trip.trip_id AS trip_id,\n category.id as category_id,\n category.name as category_name,\n category.description as category_description,\n item.id as item_id,\n item.name as item_name,\n item.description as item_description,\n item.weight as item_weight,\n trip.pick as item_is_picked,\n trip.pack as item_is_packed,\n trip.ready as item_is_ready,\n trip.new as item_is_new\n FROM trips_items as trip\n INNER JOIN inventory_items as item\n ON item.id = trip.item_id\n INNER JOIN inventory_items_categories as category\n ON category.id = item.category_id\n WHERE trip.trip_id = ?\n ) AS inner\n ON inner.category_id = category.id\n ",
|
"query": "\n SELECT\n category.id as category_id,\n category.name as category_name,\n category.description AS category_description,\n inner.trip_id AS trip_id,\n inner.item_id AS item_id,\n inner.item_name AS item_name,\n inner.item_description AS item_description,\n inner.item_weight AS item_weight,\n inner.item_is_picked AS item_is_picked,\n inner.item_is_packed AS item_is_packed,\n inner.item_is_ready AS item_is_ready,\n inner.item_is_new AS item_is_new\n FROM inventory_items_categories AS category\n LEFT JOIN (\n SELECT\n trip.trip_id AS trip_id,\n category.id as category_id,\n category.name as category_name,\n category.description as category_description,\n item.id as item_id,\n item.name as item_name,\n item.description as item_description,\n item.weight as item_weight,\n trip.pick as item_is_picked,\n trip.pack as item_is_packed,\n trip.ready as item_is_ready,\n trip.new as item_is_new,\n trip.user_id as user_id\n FROM trips_items as trip\n INNER JOIN inventory_items as item\n ON item.id = trip.item_id\n INNER JOIN inventory_items_categories as category\n ON category.id = item.category_id\n WHERE trip.trip_id = ? AND trip.user_id = ?\n ) AS inner\n ON inner.category_id = category.id\n WHERE category.user_id = ?\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 1
|
"Right": 3
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
false,
|
||||||
@@ -82,5 +82,5 @@
|
|||||||
true
|
true
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "a417bf136b8f79339a21fda10518c781d0d2bfc8c3fc99353d1956dfad9f5ac8"
|
"hash": "2793ec31c3345d77a824314bffa8a53cee248ac310fa620c272af1514f9ae951"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "SELECT\n id,\n name,\n CAST (date_start AS TEXT) date_start,\n CAST (date_end AS TEXT) date_end,\n state,\n location,\n temp_min,\n temp_max,\n comment\n FROM trips\n WHERE id = ?",
|
"query": "SELECT\n id,\n name,\n CAST (date_start AS TEXT) date_start,\n CAST (date_end AS TEXT) date_end,\n state,\n location,\n temp_min,\n temp_max,\n comment\n FROM trips\n WHERE user_id = ?",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -64,5 +64,5 @@
|
|||||||
true
|
true
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "999fe09a6a095ac0ee7b3e3c38a6f2008641e03f9344f31bf9f8eb16a47403da"
|
"hash": "4753028574932a6b8d118deb65a930a1592512178477d210acfce662c857cf65"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "\n SELECT\n category.id as category_id,\n category.name as category_name,\n category.description AS category_description,\n inner.trip_id AS trip_id,\n inner.item_id AS item_id,\n inner.item_name AS item_name,\n inner.item_description AS item_description,\n inner.item_weight AS item_weight,\n inner.item_is_picked AS item_is_picked,\n inner.item_is_packed AS item_is_packed,\n inner.item_is_ready AS item_is_ready,\n inner.item_is_new AS item_is_new\n FROM inventory_items_categories AS category\n LEFT JOIN (\n SELECT\n trip.trip_id AS trip_id,\n category.id as category_id,\n category.name as category_name,\n category.description as category_description,\n item.id as item_id,\n item.name as item_name,\n item.description as item_description,\n item.weight as item_weight,\n trip.pick as item_is_picked,\n trip.pack as item_is_packed,\n trip.ready as item_is_ready,\n trip.new as item_is_new\n FROM trips_items as trip\n INNER JOIN inventory_items as item\n ON item.id = trip.item_id\n INNER JOIN inventory_items_categories as category\n ON category.id = item.category_id\n WHERE trip.trip_id = ?\n ) AS inner\n ON inner.category_id = category.id\n WHERE category.id = ?\n ",
|
"query": "\n SELECT\n category.id as category_id,\n category.name as category_name,\n category.description AS category_description,\n inner.trip_id AS trip_id,\n inner.item_id AS item_id,\n inner.item_name AS item_name,\n inner.item_description AS item_description,\n inner.item_weight AS item_weight,\n inner.item_is_picked AS item_is_picked,\n inner.item_is_packed AS item_is_packed,\n inner.item_is_ready AS item_is_ready,\n inner.item_is_new AS item_is_new\n FROM inventory_items_categories AS category\n LEFT JOIN (\n SELECT\n trip.trip_id AS trip_id,\n category.id as category_id,\n category.name as category_name,\n category.description as category_description,\n item.id as item_id,\n item.name as item_name,\n item.description as item_description,\n item.weight as item_weight,\n trip.pick as item_is_picked,\n trip.pack as item_is_packed,\n trip.ready as item_is_ready,\n trip.new as item_is_new\n FROM trips_items as trip\n INNER JOIN inventory_items as item\n ON item.id = trip.item_id\n INNER JOIN inventory_items_categories as category\n ON category.id = item.category_id\n WHERE \n trip.trip_id = ?\n AND trip.user_id = ?\n ) AS inner\n ON inner.category_id = category.id\n WHERE category.id = ?\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 2
|
"Right": 3
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
false,
|
||||||
@@ -82,5 +82,5 @@
|
|||||||
true
|
true
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "343addb4024192688590b6b1228b9fdc554e2bbcc7e7300d8ca04cc4f23087d0"
|
"hash": "4878a57b32697b1f18e3d2bf58d34b1ad5d05976eec3432406a3d8ddf92d8b94"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "\n SELECT\n CAST(IFNULL(SUM(i_item.weight), 0) AS INTEGER) AS total_weight\n FROM trips AS trip\n INNER JOIN trips_items AS t_item\n ON t_item.trip_id = trip.id\n INNER JOIN inventory_items AS i_item\n ON t_item.item_id = i_item.id\n WHERE\n trip.id = ?\n AND t_item.pick = true\n ",
|
"query": "\n SELECT\n CAST(IFNULL(SUM(i_item.weight), 0) AS INTEGER) AS total_weight\n FROM trips AS trip\n INNER JOIN trips_items AS t_item\n ON t_item.trip_id = trip.id\n INNER JOIN inventory_items AS i_item\n ON t_item.item_id = i_item.id\n WHERE\n trip.id = ? AND trip.user_id = ?\n AND t_item.pick = true\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -10,11 +10,11 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 1
|
"Right": 2
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "cc70d7a392a0283fec1896acba805f5c2a527537b8faa22d1c69306017b9c465"
|
"hash": "48c563fdbc8ca0dbe14726eda25a18780c6c416eda63b246daa75c5ff318331d"
|
||||||
}
|
}
|
||||||
12
rust/.sqlx/query-4e24e535cc7c0dc0de572be4295ec187d7ad3742cb85371550bdaed2b780d7f5.json
generated
Normal file
12
rust/.sqlx/query-4e24e535cc7c0dc0de572be4295ec187d7ad3742cb85371550bdaed2b780d7f5.json
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "INSERT INTO trips_types\n (id, name, user_id)\n VALUES\n (?, ?, ?)",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 3
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "4e24e535cc7c0dc0de572be4295ec187d7ad3742cb85371550bdaed2b780d7f5"
|
||||||
|
}
|
||||||
12
rust/.sqlx/query-5b1ddabd48e5407dae74a2f01eb2dbc3712ac4c2dcf48b90b6ec4ee8900ec2ef.json
generated
Normal file
12
rust/.sqlx/query-5b1ddabd48e5407dae74a2f01eb2dbc3712ac4c2dcf48b90b6ec4ee8900ec2ef.json
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "INSERT INTO\n trips_to_trips_types (trip_id, trip_type_id)\n SELECT trips.id as trip_id, trips_types.id as trip_type_id\n FROM trips\n INNER JOIN trips_types\n WHERE\n trips.id = ?\n AND trips.user_id = ?\n AND trips_types.id = ?\n AND trips_types.user_id = ?",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 4
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "5b1ddabd48e5407dae74a2f01eb2dbc3712ac4c2dcf48b90b6ec4ee8900ec2ef"
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "UPDATE trips_types\n SET name = ?\n WHERE id = ?",
|
"query": "UPDATE trips_types\n SET name = ?\n WHERE id = ? and user_id = ?",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 2
|
"Right": 3
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "92ca05be21a4c05bf26f8a1655bbb8d9f1ece322abff5395ecacde3f6e28fdf7"
|
"hash": "5d27eb20c0f6c80bec63192b2ab89827bcf2b75fa75af1ce238530377e25d7bd"
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "UPDATE trips\n SET state = ?\n WHERE id = ?",
|
"query": "UPDATE trips\n SET state = ?\n WHERE id = ? and user_id = ?",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 2
|
"Right": 3
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "3356a9ab2f217e3daf101644667c9d84f1547e0c72ab779e2f3aebb628a78034"
|
"hash": "6aa1ef65325521e8b2655445f8bf227a77ef1a24c8fcf722bf8e49beb8c7ba83"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "\n SELECT\n t_item.item_id AS id,\n t_item.pick AS picked,\n t_item.pack AS packed,\n t_item.ready AS ready,\n t_item.new AS new,\n i_item.name AS name,\n i_item.description AS description,\n i_item.weight AS weight,\n i_item.category_id AS category_id\n FROM trips_items AS t_item\n INNER JOIN inventory_items AS i_item\n ON i_item.id = t_item.item_id\n WHERE t_item.item_id = ?\n AND t_item.trip_id = ?\n ",
|
"query": "\n SELECT\n t_item.item_id AS id,\n t_item.pick AS picked,\n t_item.pack AS packed,\n t_item.ready AS ready,\n t_item.new AS new,\n i_item.name AS name,\n i_item.description AS description,\n i_item.weight AS weight,\n i_item.category_id AS category_id\n FROM trips_items AS t_item\n INNER JOIN inventory_items AS i_item\n ON i_item.id = t_item.item_id\n WHERE t_item.item_id = ?\n AND t_item.trip_id = ?\n AND t_item.user_id = ?\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 2
|
"Right": 3
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
false,
|
||||||
@@ -64,5 +64,5 @@
|
|||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "16c1a8c70c0778528502dcf1067f5b23d8fc8aaa6d61385b79bac4224a78d703"
|
"hash": "6fd3243228d59a7ac2266f0c181a78e7e7a312e101bdd9846123ee4de7c4751a"
|
||||||
}
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM trips_to_trips_types AS ttt\n WHERE ttt.trip_id = ?\n AND ttt.trip_type_id = ?\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 2
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "82395724cd85d8b57ce50a64f49386435fbebc83f18db53ab8650b29414e40fb"
|
|
||||||
}
|
|
||||||
12
rust/.sqlx/query-85c45093fb8d01ea07cb2f9ec94613b8117a437f07e22b0e8204687f8485b872.json
generated
Normal file
12
rust/.sqlx/query-85c45093fb8d01ea07cb2f9ec94613b8117a437f07e22b0e8204687f8485b872.json
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "INSERT INTO trips\n (id, name, date_start, date_end, state, user_id)\n VALUES\n (?, ?, ?, ?, ?, ?)",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 6
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "85c45093fb8d01ea07cb2f9ec94613b8117a437f07e22b0e8204687f8485b872"
|
||||||
|
}
|
||||||
20
rust/.sqlx/query-a5bedc046d5a4fd900903675794e7c3d8202d3876a26505cd26be7ceeb10d06d.json
generated
Normal file
20
rust/.sqlx/query-a5bedc046d5a4fd900903675794e7c3d8202d3876a26505cd26be7ceeb10d06d.json
generated
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "\n SELECT\n i_item.id AS item_id\n FROM inventory_items AS i_item\n LEFT JOIN (\n SELECT t_item.item_id AS item_id, t_item.user_id AS user_id\n FROM trips_items AS t_item\n WHERE t_item.trip_id = ? AND t_item.user_id = ?\n ) AS t_item\n ON t_item.item_id = i_item.id\n WHERE t_item.item_id IS NULL AND i_item.user_id = ?",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "item_id",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 3
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "a5bedc046d5a4fd900903675794e7c3d8202d3876a26505cd26be7ceeb10d06d"
|
||||||
|
}
|
||||||
12
rust/.sqlx/query-b22e5d91f70638d4ed3b1592c661e470a0d80493e13478393f357da417a0208b.json
generated
Normal file
12
rust/.sqlx/query-b22e5d91f70638d4ed3b1592c661e470a0d80493e13478393f357da417a0208b.json
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "DELETE FROM trips_to_trips_types AS ttt\n WHERE ttt.trip_id = ?\n AND ttt.trip_type_id = ?\n AND EXISTS(SELECT * FROM trips WHERE id = ? AND user_id = ?)\n AND EXISTS(SELECT * FROM trips_types WHERE id = ? AND user_id = ?)\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 6
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "b22e5d91f70638d4ed3b1592c661e470a0d80493e13478393f357da417a0208b"
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "SELECT\n id,\n name\n FROM trips_types",
|
"query": "SELECT\n id,\n name\n FROM trips_types\n WHERE user_id = ?",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -15,12 +15,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 0
|
"Right": 1
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
false,
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "1eb9a8fdb9412753592f48a9267c97042aeaf6691546efae894e5d34ee92f34b"
|
"hash": "b36287d1b8c7905fb5fe6f8e9c73ca6f63b79252471ce4621d8692771e6fd3cc"
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "UPDATE trips\n SET comment = ?\n WHERE id = ?",
|
"query": "UPDATE trips\n SET comment = ?\n WHERE id = ? AND user_id = ?",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 2
|
"Right": 3
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "a5cdb8a6d5850326815efd460c0b42dda02a4ea32713ec89beceb38cd24321d5"
|
"hash": "baea696b94b2f73ec46c645ed4f7ed355fab4bb37a56b9061bc37f3f053703cb"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "SELECT\n id,\n name,\n CAST (date_start AS TEXT) date_start,\n CAST (date_end AS TEXT) date_end,\n state,\n location,\n temp_min,\n temp_max,\n comment\n FROM trips",
|
"query": "SELECT\n id,\n name,\n CAST (date_start AS TEXT) date_start,\n CAST (date_end AS TEXT) date_end,\n state,\n location,\n temp_min,\n temp_max,\n comment\n FROM trips\n WHERE id = ? and user_id = ?",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 0
|
"Right": 2
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
false,
|
||||||
@@ -64,5 +64,5 @@
|
|||||||
true
|
true
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "6df16058d577c24a2aaaae71b2c3fd94ddf24e1ced343f3ea20872f0692a9ada"
|
"hash": "c1c2a52d3de684ac473206fa348ee792afe635b41eea4d32db30ac9775794520"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "SQLite",
|
"db_name": "SQLite",
|
||||||
"query": "\n SELECT\n type.id as id,\n type.name as name,\n inner.id IS NOT NULL AS active\n FROM trips_types AS type\n LEFT JOIN (\n SELECT type.id as id, type.name as name\n FROM trips as trip\n INNER JOIN trips_to_trips_types as ttt\n ON ttt.trip_id = trip.id\n INNER JOIN trips_types AS type\n ON type.id == ttt.trip_type_id\n WHERE trip.id = ?\n ) AS inner\n ON inner.id = type.id\n ",
|
"query": "\n SELECT\n type.id as id,\n type.name as name,\n inner.id IS NOT NULL AS active\n FROM trips_types AS type\n LEFT JOIN (\n SELECT type.id as id, trip.user_id as user_id\n FROM trips as trip\n INNER JOIN trips_to_trips_types as ttt\n ON ttt.trip_id = trip.id\n INNER JOIN trips_types AS type\n ON type.id == ttt.trip_type_id\n WHERE trip.id = ? AND trip.user_id = ?\n ) AS inner\n ON inner.id = type.id\n WHERE type.user_id = ?\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Right": 1
|
"Right": 3
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
false,
|
false,
|
||||||
@@ -28,5 +28,5 @@
|
|||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "1f08e9bebf51aab9cabff2a5c79211233a686e9ef9f96ea5c036fbba8f6b06d5"
|
"hash": "dd3f7d321b59961e4ab8a8c0946de1aff32eae0c645e9c544b48926f7ca16a66"
|
||||||
}
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO trips_types\n (id, name)\n VALUES\n (?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 2
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "ded3be1c8894a64e3b5f749461db7261d9224abb8a54da980db8262733d08205"
|
|
||||||
}
|
|
||||||
38
rust/migrations/20230820193229_add_user_to_trips.sql
Normal file
38
rust/migrations/20230820193229_add_user_to_trips.sql
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
-- CREATE TABLE "trips_tmp" (
|
||||||
|
-- id VARCHAR(36) NOT NULL,
|
||||||
|
-- name TEXT NOT NULL,
|
||||||
|
-- date_start DATE NOT NULL,
|
||||||
|
-- date_end DATE NOT NULL,
|
||||||
|
-- location TEXT,
|
||||||
|
-- state VARCHAR(8) NOT NULL,
|
||||||
|
-- user_id VARCHAR(36) NOT NULL,
|
||||||
|
-- comment TEXT,
|
||||||
|
-- temp_min INTEGER,
|
||||||
|
-- temp_max INTEGER,
|
||||||
|
-- PRIMARY KEY (id),
|
||||||
|
-- FOREIGN KEY (user_id) REFERENCES users(id),
|
||||||
|
-- UNIQUE (name)
|
||||||
|
-- );
|
||||||
|
|
||||||
|
CREATE TABLE "trips_items_tmp" (
|
||||||
|
item_id VARCHAR(36) NOT NULL,
|
||||||
|
trip_id VARCHAR(36) NOT NULL,
|
||||||
|
pick BOOLEAN NOT NULL,
|
||||||
|
pack BOOLEAN NOT NULL,
|
||||||
|
ready BOOLEAN NOT NULL,
|
||||||
|
new BOOLEAN NOT NULL,
|
||||||
|
user_id VARCHAR(36) NOT NULL,
|
||||||
|
PRIMARY KEY (item_id, trip_id),
|
||||||
|
FOREIGN KEY(item_id) REFERENCES "inventory_items" (id),
|
||||||
|
FOREIGN KEY(trip_id) REFERENCES "trips" (id),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- INSERT INTO trips_tmp SELECT *, (SELECT id FROM users LIMIT 1) as user_id FROM trips;
|
||||||
|
INSERT INTO trips_items_tmp SELECT *, (SELECT id FROM users LIMIT 1) as user_id FROM trips_items;
|
||||||
|
|
||||||
|
-- DROP TABLE trips;
|
||||||
|
DROP TABLE trips_items;
|
||||||
|
|
||||||
|
-- ALTER TABLE trips_tmp RENAME TO trips;
|
||||||
|
ALTER TABLE trips_items_tmp RENAME TO trips_items;
|
||||||
21
rust/migrations/20230820194457_add_user_to_trips2.sql
Normal file
21
rust/migrations/20230820194457_add_user_to_trips2.sql
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
CREATE TABLE "trips_tmp" (
|
||||||
|
id VARCHAR(36) NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
date_start DATE NOT NULL,
|
||||||
|
date_end DATE NOT NULL,
|
||||||
|
location TEXT,
|
||||||
|
state VARCHAR(8) NOT NULL,
|
||||||
|
comment TEXT,
|
||||||
|
temp_min INTEGER,
|
||||||
|
temp_max INTEGER,
|
||||||
|
user_id VARCHAR(36) NOT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE (name),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO trips_tmp SELECT *, (SELECT id FROM users LIMIT 1) as user_id FROM trips;
|
||||||
|
|
||||||
|
DROP TABLE trips;
|
||||||
|
|
||||||
|
ALTER TABLE trips_tmp RENAME TO trips;
|
||||||
13
rust/migrations/20230820200039_add_user_to_trips_types.sql
Normal file
13
rust/migrations/20230820200039_add_user_to_trips_types.sql
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
CREATE TABLE "trips_types_tmp" (
|
||||||
|
id VARCHAR(36) NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
user_id VARCHAR(36) NOT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE (name)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO trips_types_tmp SELECT *, (SELECT id FROM users LIMIT 1) as user_id FROM trips_types;
|
||||||
|
|
||||||
|
DROP TABLE trips_types;
|
||||||
|
|
||||||
|
ALTER TABLE trips_types_tmp RENAME TO trips_types;
|
||||||
10
rust/query.sql
Normal file
10
rust/query.sql
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
INSERT INTO
|
||||||
|
trips_to_trips_types (trip_id, trip_type_id)
|
||||||
|
SELECT trips.id as trip_id, trips_types.id as trip_type_id
|
||||||
|
FROM trips
|
||||||
|
INNER JOIN trips_types
|
||||||
|
WHERE
|
||||||
|
trips.id = "629ac022-d715-4dfa-9a53-56ffd0be36f3"
|
||||||
|
AND trips.user_id = "f981b589-4ed4-42e7-85f0-453961849fc4"
|
||||||
|
AND trips_types.id = "bdcc58ee-0f09-4fea-ab76-50f3e118228e"
|
||||||
|
AND trips_types.user_id = "f981b589-4ed4-42e7-85f0-453961849fc4"
|
||||||
@@ -6,6 +6,8 @@ use super::{
|
|||||||
inventory,
|
inventory,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::Context;
|
||||||
|
|
||||||
use futures::{TryFutureExt, TryStreamExt};
|
use futures::{TryFutureExt, TryStreamExt};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_variant::to_variant_name;
|
use serde_variant::to_variant_name;
|
||||||
@@ -126,12 +128,14 @@ impl TripCategory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find(
|
pub async fn find(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
trip_id: Uuid,
|
trip_id: Uuid,
|
||||||
category_id: Uuid,
|
category_id: Uuid,
|
||||||
) -> Result<Option<TripCategory>, Error> {
|
) -> Result<Option<TripCategory>, Error> {
|
||||||
let mut category: Option<TripCategory> = None;
|
let mut category: Option<TripCategory> = None;
|
||||||
|
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let trip_id_param = trip_id.to_string();
|
let trip_id_param = trip_id.to_string();
|
||||||
let category_id_param = category_id.to_string();
|
let category_id_param = category_id.to_string();
|
||||||
|
|
||||||
@@ -170,12 +174,15 @@ impl TripCategory {
|
|||||||
ON item.id = trip.item_id
|
ON item.id = trip.item_id
|
||||||
INNER JOIN inventory_items_categories as category
|
INNER JOIN inventory_items_categories as category
|
||||||
ON category.id = item.category_id
|
ON category.id = item.category_id
|
||||||
WHERE trip.trip_id = ?
|
WHERE
|
||||||
|
trip.trip_id = ?
|
||||||
|
AND trip.user_id = ?
|
||||||
) AS inner
|
) AS inner
|
||||||
ON inner.category_id = category.id
|
ON inner.category_id = category.id
|
||||||
WHERE category.id = ?
|
WHERE category.id = ?
|
||||||
",
|
",
|
||||||
trip_id_param,
|
trip_id_param,
|
||||||
|
user_id,
|
||||||
category_id_param
|
category_id_param
|
||||||
)
|
)
|
||||||
.fetch(pool)
|
.fetch(pool)
|
||||||
@@ -280,10 +287,12 @@ impl TryFrom<DbTripsItemsRow> for TripItem {
|
|||||||
|
|
||||||
impl TripItem {
|
impl TripItem {
|
||||||
pub async fn find(
|
pub async fn find(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
trip_id: Uuid,
|
trip_id: Uuid,
|
||||||
item_id: Uuid,
|
item_id: Uuid,
|
||||||
) -> Result<Option<Self>, Error> {
|
) -> Result<Option<Self>, Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let item_id_param = item_id.to_string();
|
let item_id_param = item_id.to_string();
|
||||||
let trip_id_param = trip_id.to_string();
|
let trip_id_param = trip_id.to_string();
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
@@ -304,9 +313,11 @@ impl TripItem {
|
|||||||
ON i_item.id = t_item.item_id
|
ON i_item.id = t_item.item_id
|
||||||
WHERE t_item.item_id = ?
|
WHERE t_item.item_id = ?
|
||||||
AND t_item.trip_id = ?
|
AND t_item.trip_id = ?
|
||||||
|
AND t_item.user_id = ?
|
||||||
",
|
",
|
||||||
item_id_param,
|
item_id_param,
|
||||||
trip_id_param,
|
trip_id_param,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.fetch_optional(pool)
|
.fetch_optional(pool)
|
||||||
.await?
|
.await?
|
||||||
@@ -315,22 +326,26 @@ impl TripItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_state(
|
pub async fn set_state(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
trip_id: Uuid,
|
trip_id: Uuid,
|
||||||
item_id: Uuid,
|
item_id: Uuid,
|
||||||
key: TripItemStateKey,
|
key: TripItemStateKey,
|
||||||
value: bool,
|
value: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let result = sqlx::query(&format!(
|
let result = sqlx::query(&format!(
|
||||||
"UPDATE trips_items
|
"UPDATE trips_items
|
||||||
SET {key} = ?
|
SET {key} = ?
|
||||||
WHERE trip_id = ?
|
WHERE trip_id = ?
|
||||||
AND item_id = ?",
|
AND item_id = ?
|
||||||
|
AND user_id = ?",
|
||||||
key = to_variant_name(&key).unwrap()
|
key = to_variant_name(&key).unwrap()
|
||||||
))
|
))
|
||||||
.bind(value)
|
.bind(value)
|
||||||
.bind(trip_id.to_string())
|
.bind(trip_id.to_string())
|
||||||
.bind(item_id.to_string())
|
.bind(item_id.to_string())
|
||||||
|
.bind(user_id)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -342,7 +357,7 @@ impl TripItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct DbTripRow {
|
pub struct DbTripRow {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub date_start: String,
|
pub date_start: String,
|
||||||
@@ -409,34 +424,8 @@ pub(crate) struct DbTripWeightRow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Trip {
|
impl Trip {
|
||||||
pub async fn all(pool: &sqlx::Pool<sqlx::Sqlite>) -> Result<Vec<Trip>, Error> {
|
pub async fn all(ctx: &Context, pool: &sqlx::Pool<sqlx::Sqlite>) -> Result<Vec<Trip>, Error> {
|
||||||
sqlx::query_as!(
|
let user_id = ctx.user.id.to_string();
|
||||||
DbTripRow,
|
|
||||||
"SELECT
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
CAST (date_start AS TEXT) date_start,
|
|
||||||
CAST (date_end AS TEXT) date_end,
|
|
||||||
state,
|
|
||||||
location,
|
|
||||||
temp_min,
|
|
||||||
temp_max,
|
|
||||||
comment
|
|
||||||
FROM trips",
|
|
||||||
)
|
|
||||||
.fetch(pool)
|
|
||||||
.map_ok(|row| row.try_into())
|
|
||||||
.try_collect::<Vec<Result<Trip, Error>>>()
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.collect::<Result<Vec<Trip>, Error>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find(
|
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
|
||||||
trip_id: Uuid,
|
|
||||||
) -> Result<Option<Self>, Error> {
|
|
||||||
let trip_id_param = trip_id.to_string();
|
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
DbTripRow,
|
DbTripRow,
|
||||||
"SELECT
|
"SELECT
|
||||||
@@ -450,8 +439,40 @@ impl Trip {
|
|||||||
temp_max,
|
temp_max,
|
||||||
comment
|
comment
|
||||||
FROM trips
|
FROM trips
|
||||||
WHERE id = ?",
|
WHERE user_id = ?",
|
||||||
trip_id_param
|
user_id
|
||||||
|
)
|
||||||
|
.fetch(pool)
|
||||||
|
.map_ok(|row| row.try_into())
|
||||||
|
.try_collect::<Vec<Result<Trip, Error>>>()
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.collect::<Result<Vec<Trip>, Error>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn find(
|
||||||
|
ctx: &Context,
|
||||||
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
|
trip_id: Uuid,
|
||||||
|
) -> Result<Option<Self>, Error> {
|
||||||
|
let trip_id_param = trip_id.to_string();
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
|
sqlx::query_as!(
|
||||||
|
DbTripRow,
|
||||||
|
"SELECT
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
CAST (date_start AS TEXT) date_start,
|
||||||
|
CAST (date_end AS TEXT) date_end,
|
||||||
|
state,
|
||||||
|
location,
|
||||||
|
temp_min,
|
||||||
|
temp_max,
|
||||||
|
comment
|
||||||
|
FROM trips
|
||||||
|
WHERE id = ? and user_id = ?",
|
||||||
|
trip_id_param,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.fetch_optional(pool)
|
.fetch_optional(pool)
|
||||||
.await?
|
.await?
|
||||||
@@ -460,10 +481,12 @@ impl Trip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_type_remove(
|
pub async fn trip_type_remove(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
type_id: Uuid,
|
type_id: Uuid,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let id_param = id.to_string();
|
let id_param = id.to_string();
|
||||||
let type_id_param = type_id.to_string();
|
let type_id_param = type_id.to_string();
|
||||||
|
|
||||||
@@ -471,9 +494,15 @@ impl Trip {
|
|||||||
"DELETE FROM trips_to_trips_types AS ttt
|
"DELETE FROM trips_to_trips_types AS ttt
|
||||||
WHERE ttt.trip_id = ?
|
WHERE ttt.trip_id = ?
|
||||||
AND ttt.trip_type_id = ?
|
AND ttt.trip_type_id = ?
|
||||||
|
AND EXISTS(SELECT * FROM trips WHERE id = ? AND user_id = ?)
|
||||||
|
AND EXISTS(SELECT * FROM trips_types WHERE id = ? AND user_id = ?)
|
||||||
",
|
",
|
||||||
id_param,
|
id_param,
|
||||||
type_id_param,
|
type_id_param,
|
||||||
|
id_param,
|
||||||
|
user_id,
|
||||||
|
type_id_param,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -482,20 +511,31 @@ impl Trip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_type_add(
|
pub async fn trip_type_add(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
type_id: Uuid,
|
type_id: Uuid,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
|
// TODO user handling?
|
||||||
let trip_id_param = id.to_string();
|
let trip_id_param = id.to_string();
|
||||||
let type_id_param = type_id.to_string();
|
let type_id_param = type_id.to_string();
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO trips_to_trips_types
|
"INSERT INTO
|
||||||
(trip_id, trip_type_id)
|
trips_to_trips_types (trip_id, trip_type_id)
|
||||||
VALUES
|
SELECT trips.id as trip_id, trips_types.id as trip_type_id
|
||||||
(?, ?)
|
FROM trips
|
||||||
",
|
INNER JOIN trips_types
|
||||||
|
WHERE
|
||||||
|
trips.id = ?
|
||||||
|
AND trips.user_id = ?
|
||||||
|
AND trips_types.id = ?
|
||||||
|
AND trips_types.user_id = ?",
|
||||||
trip_id_param,
|
trip_id_param,
|
||||||
|
user_id,
|
||||||
type_id_param,
|
type_id_param,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -504,17 +544,20 @@ impl Trip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_state(
|
pub async fn set_state(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
new_state: &TripState,
|
new_state: &TripState,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let trip_id_param = id.to_string();
|
let trip_id_param = id.to_string();
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"UPDATE trips
|
"UPDATE trips
|
||||||
SET state = ?
|
SET state = ?
|
||||||
WHERE id = ?",
|
WHERE id = ? and user_id = ?",
|
||||||
new_state,
|
new_state,
|
||||||
trip_id_param,
|
trip_id_param,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -523,17 +566,20 @@ impl Trip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_comment(
|
pub async fn set_comment(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
new_comment: &str,
|
new_comment: &str,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let trip_id_param = id.to_string();
|
let trip_id_param = id.to_string();
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"UPDATE trips
|
"UPDATE trips
|
||||||
SET comment = ?
|
SET comment = ?
|
||||||
WHERE id = ?",
|
WHERE id = ? AND user_id = ?",
|
||||||
new_comment,
|
new_comment,
|
||||||
trip_id_param,
|
trip_id_param,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -542,19 +588,22 @@ impl Trip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_attribute(
|
pub async fn set_attribute(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
trip_id: Uuid,
|
trip_id: Uuid,
|
||||||
attribute: TripAttribute,
|
attribute: TripAttribute,
|
||||||
value: &str,
|
value: &str,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let result = sqlx::query(&format!(
|
let result = sqlx::query(&format!(
|
||||||
"UPDATE trips
|
"UPDATE trips
|
||||||
SET {attribute} = ?
|
SET {attribute} = ?
|
||||||
WHERE id = ?",
|
WHERE id = ? AND user_id = ?",
|
||||||
attribute = to_variant_name(&attribute).unwrap()
|
attribute = to_variant_name(&attribute).unwrap()
|
||||||
))
|
))
|
||||||
.bind(value)
|
.bind(value)
|
||||||
.bind(trip_id.to_string())
|
.bind(trip_id.to_string())
|
||||||
|
.bind(user_id)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -566,11 +615,13 @@ impl Trip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn save(
|
pub async fn save(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
name: &str,
|
name: &str,
|
||||||
date_start: time::Date,
|
date_start: time::Date,
|
||||||
date_end: time::Date,
|
date_end: time::Date,
|
||||||
) -> Result<Uuid, Error> {
|
) -> Result<Uuid, Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let id = Uuid::new_v4();
|
let id = Uuid::new_v4();
|
||||||
let id_param = id.to_string();
|
let id_param = id.to_string();
|
||||||
let date_start = date_start.format(consts::DATE_FORMAT)?;
|
let date_start = date_start.format(consts::DATE_FORMAT)?;
|
||||||
@@ -580,14 +631,15 @@ impl Trip {
|
|||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO trips
|
"INSERT INTO trips
|
||||||
(id, name, date_start, date_end, state)
|
(id, name, date_start, date_end, state, user_id)
|
||||||
VALUES
|
VALUES
|
||||||
(?, ?, ?, ?, ?)",
|
(?, ?, ?, ?, ?, ?)",
|
||||||
id_param,
|
id_param,
|
||||||
name,
|
name,
|
||||||
date_start,
|
date_start,
|
||||||
date_end,
|
date_end,
|
||||||
trip_state,
|
trip_state,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -596,9 +648,11 @@ impl Trip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_total_picked_weight(
|
pub async fn find_total_picked_weight(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
trip_id: Uuid,
|
trip_id: Uuid,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let trip_id_param = trip_id.to_string();
|
let trip_id_param = trip_id.to_string();
|
||||||
let weight = sqlx::query_as!(
|
let weight = sqlx::query_as!(
|
||||||
DbTripWeightRow,
|
DbTripWeightRow,
|
||||||
@@ -611,10 +665,11 @@ impl Trip {
|
|||||||
INNER JOIN inventory_items AS i_item
|
INNER JOIN inventory_items AS i_item
|
||||||
ON t_item.item_id = i_item.id
|
ON t_item.item_id = i_item.id
|
||||||
WHERE
|
WHERE
|
||||||
trip.id = ?
|
trip.id = ? AND trip.user_id = ?
|
||||||
AND t_item.pick = true
|
AND t_item.pick = true
|
||||||
",
|
",
|
||||||
trip_id_param
|
trip_id_param,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
.map_ok(|row| row.total_weight.unwrap() as i64)
|
.map_ok(|row| row.total_weight.unwrap() as i64)
|
||||||
@@ -650,7 +705,12 @@ impl Trip {
|
|||||||
.sum::<i64>()
|
.sum::<i64>()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn load_trips_types(&mut self, pool: &sqlx::Pool<sqlx::Sqlite>) -> Result<(), Error> {
|
pub async fn load_trips_types(
|
||||||
|
&mut self,
|
||||||
|
ctx: &Context,
|
||||||
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let id = self.id.to_string();
|
let id = self.id.to_string();
|
||||||
let types = sqlx::query!(
|
let types = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -660,17 +720,20 @@ impl Trip {
|
|||||||
inner.id IS NOT NULL AS active
|
inner.id IS NOT NULL AS active
|
||||||
FROM trips_types AS type
|
FROM trips_types AS type
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT type.id as id, type.name as name
|
SELECT type.id as id, trip.user_id as user_id
|
||||||
FROM trips as trip
|
FROM trips as trip
|
||||||
INNER JOIN trips_to_trips_types as ttt
|
INNER JOIN trips_to_trips_types as ttt
|
||||||
ON ttt.trip_id = trip.id
|
ON ttt.trip_id = trip.id
|
||||||
INNER JOIN trips_types AS type
|
INNER JOIN trips_types AS type
|
||||||
ON type.id == ttt.trip_type_id
|
ON type.id == ttt.trip_type_id
|
||||||
WHERE trip.id = ?
|
WHERE trip.id = ? AND trip.user_id = ?
|
||||||
) AS inner
|
) AS inner
|
||||||
ON inner.id = type.id
|
ON inner.id = type.id
|
||||||
|
WHERE type.user_id = ?
|
||||||
",
|
",
|
||||||
id
|
id,
|
||||||
|
user_id,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.fetch(pool)
|
.fetch(pool)
|
||||||
.map_ok(|row| -> Result<TripType, Error> {
|
.map_ok(|row| -> Result<TripType, Error> {
|
||||||
@@ -695,6 +758,7 @@ impl Trip {
|
|||||||
|
|
||||||
pub async fn sync_trip_items_with_inventory(
|
pub async fn sync_trip_items_with_inventory(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
// we need to get all items that are part of the inventory but not
|
// we need to get all items that are part of the inventory but not
|
||||||
@@ -708,6 +772,7 @@ impl Trip {
|
|||||||
// * if the trip is new, we have to make these new items prominently
|
// * if the trip is new, we have to make these new items prominently
|
||||||
// visible so the user knows that there might be new items to
|
// visible so the user knows that there might be new items to
|
||||||
// consider
|
// consider
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let trip_id = self.id.to_string();
|
let trip_id = self.id.to_string();
|
||||||
let unsynced_items: Vec<Uuid> = sqlx::query!(
|
let unsynced_items: Vec<Uuid> = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -715,14 +780,15 @@ impl Trip {
|
|||||||
i_item.id AS item_id
|
i_item.id AS item_id
|
||||||
FROM inventory_items AS i_item
|
FROM inventory_items AS i_item
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT t_item.item_id as item_id
|
SELECT t_item.item_id AS item_id, t_item.user_id AS user_id
|
||||||
FROM trips_items AS t_item
|
FROM trips_items AS t_item
|
||||||
WHERE t_item.trip_id = ?
|
WHERE t_item.trip_id = ? AND t_item.user_id = ?
|
||||||
) AS t_item
|
) AS t_item
|
||||||
ON t_item.item_id = i_item.id
|
ON t_item.item_id = i_item.id
|
||||||
WHERE t_item.item_id IS NULL
|
WHERE t_item.item_id IS NULL AND i_item.user_id = ?",
|
||||||
",
|
trip_id,
|
||||||
trip_id
|
user_id,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.fetch(pool)
|
.fetch(pool)
|
||||||
.map_ok(|row| -> Result<Uuid, Error> { Ok(Uuid::try_parse(&row.item_id)?) })
|
.map_ok(|row| -> Result<Uuid, Error> { Ok(Uuid::try_parse(&row.item_id)?) })
|
||||||
@@ -748,9 +814,10 @@ impl Trip {
|
|||||||
pick,
|
pick,
|
||||||
pack,
|
pack,
|
||||||
ready,
|
ready,
|
||||||
new
|
new,
|
||||||
|
user_id
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
",
|
",
|
||||||
item_id,
|
item_id,
|
||||||
trip_id,
|
trip_id,
|
||||||
@@ -758,6 +825,7 @@ impl Trip {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
mark_as_new,
|
mark_as_new,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -768,11 +836,16 @@ impl Trip {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn load_categories(&mut self, pool: &sqlx::Pool<sqlx::Sqlite>) -> Result<(), Error> {
|
pub async fn load_categories(
|
||||||
|
&mut self,
|
||||||
|
ctx: &Context,
|
||||||
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
let mut categories: Vec<TripCategory> = vec![];
|
let mut categories: Vec<TripCategory> = vec![];
|
||||||
// we can ignore the return type as we collect into `categories`
|
// we can ignore the return type as we collect into `categories`
|
||||||
// in the `map_ok()` closure
|
// in the `map_ok()` closure
|
||||||
let id = self.id.to_string();
|
let id = self.id.to_string();
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT
|
SELECT
|
||||||
@@ -802,17 +875,21 @@ impl Trip {
|
|||||||
trip.pick as item_is_picked,
|
trip.pick as item_is_picked,
|
||||||
trip.pack as item_is_packed,
|
trip.pack as item_is_packed,
|
||||||
trip.ready as item_is_ready,
|
trip.ready as item_is_ready,
|
||||||
trip.new as item_is_new
|
trip.new as item_is_new,
|
||||||
|
trip.user_id as user_id
|
||||||
FROM trips_items as trip
|
FROM trips_items as trip
|
||||||
INNER JOIN inventory_items as item
|
INNER JOIN inventory_items as item
|
||||||
ON item.id = trip.item_id
|
ON item.id = trip.item_id
|
||||||
INNER JOIN inventory_items_categories as category
|
INNER JOIN inventory_items_categories as category
|
||||||
ON category.id = item.category_id
|
ON category.id = item.category_id
|
||||||
WHERE trip.trip_id = ?
|
WHERE trip.trip_id = ? AND trip.user_id = ?
|
||||||
) AS inner
|
) AS inner
|
||||||
ON inner.category_id = category.id
|
ON inner.category_id = category.id
|
||||||
|
WHERE category.user_id = ?
|
||||||
",
|
",
|
||||||
id
|
id,
|
||||||
|
user_id,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.fetch(pool)
|
.fetch(pool)
|
||||||
.map_ok(|row| -> Result<(), Error> {
|
.map_ok(|row| -> Result<(), Error> {
|
||||||
@@ -883,13 +960,16 @@ pub struct TripType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TripsType {
|
impl TripsType {
|
||||||
pub async fn all(pool: &sqlx::Pool<sqlx::Sqlite>) -> Result<Vec<Self>, Error> {
|
pub async fn all(ctx: &Context, pool: &sqlx::Pool<sqlx::Sqlite>) -> Result<Vec<Self>, Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
DbTripsTypesRow,
|
DbTripsTypesRow,
|
||||||
"SELECT
|
"SELECT
|
||||||
id,
|
id,
|
||||||
name
|
name
|
||||||
FROM trips_types",
|
FROM trips_types
|
||||||
|
WHERE user_id = ?",
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.fetch(pool)
|
.fetch(pool)
|
||||||
.map_ok(|row| row.try_into())
|
.map_ok(|row| row.try_into())
|
||||||
@@ -899,16 +979,22 @@ impl TripsType {
|
|||||||
.collect::<Result<Vec<Self>, Error>>()
|
.collect::<Result<Vec<Self>, Error>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn save(pool: &sqlx::Pool<sqlx::Sqlite>, name: &str) -> Result<Uuid, Error> {
|
pub async fn save(
|
||||||
|
ctx: &Context,
|
||||||
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
|
name: &str,
|
||||||
|
) -> Result<Uuid, Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let id = Uuid::new_v4();
|
let id = Uuid::new_v4();
|
||||||
let id_param = id.to_string();
|
let id_param = id.to_string();
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO trips_types
|
"INSERT INTO trips_types
|
||||||
(id, name)
|
(id, name, user_id)
|
||||||
VALUES
|
VALUES
|
||||||
(?, ?)",
|
(?, ?, ?)",
|
||||||
id_param,
|
id_param,
|
||||||
name,
|
name,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -917,18 +1003,21 @@ impl TripsType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_name(
|
pub async fn set_name(
|
||||||
|
ctx: &Context,
|
||||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
new_name: &str,
|
new_name: &str,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
|
let user_id = ctx.user.id.to_string();
|
||||||
let id_param = id.to_string();
|
let id_param = id.to_string();
|
||||||
|
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"UPDATE trips_types
|
"UPDATE trips_types
|
||||||
SET name = ?
|
SET name = ?
|
||||||
WHERE id = ?",
|
WHERE id = ? and user_id = ?",
|
||||||
new_name,
|
new_name,
|
||||||
id_param,
|
id_param,
|
||||||
|
user_id,
|
||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -308,9 +308,11 @@ pub async fn inventory_item_cancel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_create(
|
pub async fn trip_create(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Form(new_trip): Form<NewTrip>,
|
Form(new_trip): Form<NewTrip>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
if new_trip.name.is_empty() {
|
if new_trip.name.is_empty() {
|
||||||
return Err(Error::Request(RequestError::EmptyFormElement {
|
return Err(Error::Request(RequestError::EmptyFormElement {
|
||||||
name: "name".to_string(),
|
name: "name".to_string(),
|
||||||
@@ -318,6 +320,7 @@ pub async fn trip_create(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let new_id = models::trips::Trip::save(
|
let new_id = models::trips::Trip::save(
|
||||||
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
&new_trip.name,
|
&new_trip.name,
|
||||||
new_trip.date_start,
|
new_trip.date_start,
|
||||||
@@ -332,10 +335,11 @@ pub async fn trips(
|
|||||||
Extension(current_user): Extension<models::user::User>,
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let trips = models::trips::Trip::all(&state.database_pool).await?;
|
let ctx = Context::build(current_user);
|
||||||
|
let trips = models::trips::Trip::all(&ctx, &state.database_pool).await?;
|
||||||
|
|
||||||
Ok(view::Root::build(
|
Ok(view::Root::build(
|
||||||
&Context::build(current_user),
|
&ctx,
|
||||||
&view::trip::TripManager::build(trips),
|
&view::trip::TripManager::build(trips),
|
||||||
Some(&TopLevelPage::Trips),
|
Some(&TopLevelPage::Trips),
|
||||||
))
|
))
|
||||||
@@ -347,21 +351,22 @@ pub async fn trip(
|
|||||||
Path(id): Path<Uuid>,
|
Path(id): Path<Uuid>,
|
||||||
Query(trip_query): Query<TripQuery>,
|
Query(trip_query): Query<TripQuery>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
state.client_state.trip_edit_attribute = trip_query.edit;
|
state.client_state.trip_edit_attribute = trip_query.edit;
|
||||||
state.client_state.active_category_id = trip_query.category;
|
state.client_state.active_category_id = trip_query.category;
|
||||||
|
|
||||||
let mut trip: models::trips::Trip = models::trips::Trip::find(&state.database_pool, id)
|
let mut trip: models::trips::Trip = models::trips::Trip::find(&ctx, &state.database_pool, id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(Error::Request(RequestError::NotFound {
|
.ok_or(Error::Request(RequestError::NotFound {
|
||||||
message: format!("trip with id {id} not found"),
|
message: format!("trip with id {id} not found"),
|
||||||
}))?;
|
}))?;
|
||||||
|
|
||||||
trip.load_trips_types(&state.database_pool).await?;
|
trip.load_trips_types(&ctx, &state.database_pool).await?;
|
||||||
|
|
||||||
trip.sync_trip_items_with_inventory(&state.database_pool)
|
trip.sync_trip_items_with_inventory(&ctx, &state.database_pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
trip.load_categories(&state.database_pool).await?;
|
trip.load_categories(&ctx, &state.database_pool).await?;
|
||||||
|
|
||||||
let active_category: Option<&models::trips::TripCategory> = state
|
let active_category: Option<&models::trips::TripCategory> = state
|
||||||
.client_state
|
.client_state
|
||||||
@@ -377,7 +382,7 @@ pub async fn trip(
|
|||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
Ok(view::Root::build(
|
Ok(view::Root::build(
|
||||||
&Context::build(current_user),
|
&ctx,
|
||||||
&view::trip::Trip::build(
|
&view::trip::Trip::build(
|
||||||
&trip,
|
&trip,
|
||||||
state.client_state.trip_edit_attribute,
|
state.client_state.trip_edit_attribute,
|
||||||
@@ -388,11 +393,13 @@ pub async fn trip(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_type_remove(
|
pub async fn trip_type_remove(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, type_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, type_id)): Path<(Uuid, Uuid)>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
let found =
|
let found =
|
||||||
models::trips::Trip::trip_type_remove(&state.database_pool, trip_id, type_id).await?;
|
models::trips::Trip::trip_type_remove(&ctx, &state.database_pool, trip_id, type_id).await?;
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
Err(Error::Request(RequestError::NotFound {
|
Err(Error::Request(RequestError::NotFound {
|
||||||
@@ -404,20 +411,25 @@ pub async fn trip_type_remove(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_type_add(
|
pub async fn trip_type_add(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, type_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, type_id)): Path<(Uuid, Uuid)>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
models::trips::Trip::trip_type_add(&state.database_pool, trip_id, type_id).await?;
|
let ctx = Context::build(current_user);
|
||||||
|
models::trips::Trip::trip_type_add(&ctx, &state.database_pool, trip_id, type_id).await?;
|
||||||
|
|
||||||
Ok(Redirect::to(&format!("/trips/{trip_id}/")))
|
Ok(Redirect::to(&format!("/trips/{trip_id}/")))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_comment_set(
|
pub async fn trip_comment_set(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path(trip_id): Path<Uuid>,
|
Path(trip_id): Path<Uuid>,
|
||||||
Form(comment_update): Form<CommentUpdate>,
|
Form(comment_update): Form<CommentUpdate>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
let found = models::trips::Trip::set_comment(
|
let found = models::trips::Trip::set_comment(
|
||||||
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
trip_id,
|
trip_id,
|
||||||
&comment_update.new_comment,
|
&comment_update.new_comment,
|
||||||
@@ -434,10 +446,12 @@ pub async fn trip_comment_set(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_edit_attribute(
|
pub async fn trip_edit_attribute(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, attribute)): Path<(Uuid, models::trips::TripAttribute)>,
|
Path((trip_id, attribute)): Path<(Uuid, models::trips::TripAttribute)>,
|
||||||
Form(trip_update): Form<TripUpdate>,
|
Form(trip_update): Form<TripUpdate>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
if attribute == models::trips::TripAttribute::Name {
|
if attribute == models::trips::TripAttribute::Name {
|
||||||
if trip_update.new_value.is_empty() {
|
if trip_update.new_value.is_empty() {
|
||||||
return Err(Error::Request(RequestError::EmptyFormElement {
|
return Err(Error::Request(RequestError::EmptyFormElement {
|
||||||
@@ -446,6 +460,7 @@ pub async fn trip_edit_attribute(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
models::trips::Trip::set_attribute(
|
models::trips::Trip::set_attribute(
|
||||||
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
trip_id,
|
trip_id,
|
||||||
attribute,
|
attribute,
|
||||||
@@ -457,13 +472,15 @@ pub async fn trip_edit_attribute(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_set_state(
|
pub async fn trip_item_set_state(
|
||||||
|
ctx: &Context,
|
||||||
state: &AppState,
|
state: &AppState,
|
||||||
trip_id: Uuid,
|
trip_id: Uuid,
|
||||||
item_id: Uuid,
|
item_id: Uuid,
|
||||||
key: models::trips::TripItemStateKey,
|
key: models::trips::TripItemStateKey,
|
||||||
value: bool,
|
value: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
models::trips::TripItem::set_state(&state.database_pool, trip_id, item_id, key, value).await?;
|
models::trips::TripItem::set_state(&ctx, &state.database_pool, trip_id, item_id, key, value)
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,7 +490,7 @@ pub async fn trip_row(
|
|||||||
trip_id: Uuid,
|
trip_id: Uuid,
|
||||||
item_id: Uuid,
|
item_id: Uuid,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let item = models::trips::TripItem::find(&state.database_pool, trip_id, item_id)
|
let item = models::trips::TripItem::find(ctx, &state.database_pool, trip_id, item_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::Request(RequestError::NotFound {
|
Error::Request(RequestError::NotFound {
|
||||||
@@ -492,8 +509,12 @@ pub async fn trip_row(
|
|||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
|
|
||||||
let category =
|
let category = models::trips::TripCategory::find(
|
||||||
models::trips::TripCategory::find(&state.database_pool, trip_id, item.item.category_id)
|
ctx,
|
||||||
|
&state.database_pool,
|
||||||
|
trip_id,
|
||||||
|
item.item.category_id,
|
||||||
|
)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::Request(RequestError::NotFound {
|
Error::Request(RequestError::NotFound {
|
||||||
@@ -508,12 +529,15 @@ pub async fn trip_row(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_set_pick(
|
pub async fn trip_item_set_pick(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
Ok::<_, Error>(
|
Ok::<_, Error>(
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -532,6 +556,7 @@ pub async fn trip_item_set_pick_htmx(
|
|||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -548,12 +573,15 @@ pub async fn trip_item_set_pick_htmx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_set_unpick(
|
pub async fn trip_item_set_unpick(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
Ok::<_, Error>(
|
Ok::<_, Error>(
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -572,6 +600,7 @@ pub async fn trip_item_set_unpick_htmx(
|
|||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -588,12 +617,15 @@ pub async fn trip_item_set_unpick_htmx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_set_pack(
|
pub async fn trip_item_set_pack(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
Ok::<_, Error>(
|
Ok::<_, Error>(
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -612,6 +644,7 @@ pub async fn trip_item_set_pack_htmx(
|
|||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -628,12 +661,15 @@ pub async fn trip_item_set_pack_htmx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_set_unpack(
|
pub async fn trip_item_set_unpack(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
Ok::<_, Error>(
|
Ok::<_, Error>(
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -652,6 +688,7 @@ pub async fn trip_item_set_unpack_htmx(
|
|||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -668,12 +705,15 @@ pub async fn trip_item_set_unpack_htmx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_set_ready(
|
pub async fn trip_item_set_ready(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
Ok::<_, Error>(
|
Ok::<_, Error>(
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -692,6 +732,7 @@ pub async fn trip_item_set_ready_htmx(
|
|||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -708,12 +749,15 @@ pub async fn trip_item_set_ready_htmx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_set_unready(
|
pub async fn trip_item_set_unready(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
Ok::<_, Error>(
|
Ok::<_, Error>(
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -732,6 +776,7 @@ pub async fn trip_item_set_unready_htmx(
|
|||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -748,11 +793,13 @@ pub async fn trip_item_set_unready_htmx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_total_weight_htmx(
|
pub async fn trip_total_weight_htmx(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path(trip_id): Path<Uuid>,
|
Path(trip_id): Path<Uuid>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
let total_weight =
|
let total_weight =
|
||||||
models::trips::Trip::find_total_picked_weight(&state.database_pool, trip_id).await?;
|
models::trips::Trip::find_total_picked_weight(&ctx, &state.database_pool, trip_id).await?;
|
||||||
Ok(view::trip::TripInfoTotalWeightRow::build(
|
Ok(view::trip::TripInfoTotalWeightRow::build(
|
||||||
trip_id,
|
trip_id,
|
||||||
total_weight,
|
total_weight,
|
||||||
@@ -778,11 +825,14 @@ pub async fn inventory_category_create(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_state_set(
|
pub async fn trip_state_set(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
Path((trip_id, new_state)): Path<(Uuid, models::trips::TripState)>,
|
Path((trip_id, new_state)): Path<(Uuid, models::trips::TripState)>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let exists = models::trips::Trip::set_state(&state.database_pool, trip_id, &new_state).await?;
|
let ctx = Context::build(current_user);
|
||||||
|
let exists =
|
||||||
|
models::trips::Trip::set_state(&ctx, &state.database_pool, trip_id, &new_state).await?;
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return Err(Error::Request(RequestError::NotFound {
|
return Err(Error::Request(RequestError::NotFound {
|
||||||
@@ -801,36 +851,42 @@ pub async fn trips_types(
|
|||||||
State(mut state): State<AppState>,
|
State(mut state): State<AppState>,
|
||||||
Query(trip_type_query): Query<TripTypeQuery>,
|
Query(trip_type_query): Query<TripTypeQuery>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
state.client_state.trip_type_edit = trip_type_query.edit;
|
state.client_state.trip_type_edit = trip_type_query.edit;
|
||||||
|
|
||||||
let trip_types: Vec<models::trips::TripsType> =
|
let trip_types: Vec<models::trips::TripsType> =
|
||||||
models::trips::TripsType::all(&state.database_pool).await?;
|
models::trips::TripsType::all(&ctx, &state.database_pool).await?;
|
||||||
|
|
||||||
Ok(view::Root::build(
|
Ok(view::Root::build(
|
||||||
&Context::build(current_user),
|
&ctx,
|
||||||
&view::trip::types::TypeList::build(&state.client_state, trip_types),
|
&view::trip::types::TypeList::build(&state.client_state, trip_types),
|
||||||
Some(&TopLevelPage::Trips),
|
Some(&TopLevelPage::Trips),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
pub async fn trip_type_create(
|
pub async fn trip_type_create(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Form(new_trip_type): Form<NewTripType>,
|
Form(new_trip_type): Form<NewTripType>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
if new_trip_type.name.is_empty() {
|
if new_trip_type.name.is_empty() {
|
||||||
return Err(Error::Request(RequestError::EmptyFormElement {
|
return Err(Error::Request(RequestError::EmptyFormElement {
|
||||||
name: "name".to_string(),
|
name: "name".to_string(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let _new_id = models::trips::TripsType::save(&state.database_pool, &new_trip_type.name).await?;
|
let _new_id =
|
||||||
|
models::trips::TripsType::save(&ctx, &state.database_pool, &new_trip_type.name).await?;
|
||||||
|
|
||||||
Ok(Redirect::to("/trips/types/"))
|
Ok(Redirect::to("/trips/types/"))
|
||||||
}
|
}
|
||||||
pub async fn trips_types_edit_name(
|
pub async fn trips_types_edit_name(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path(trip_type_id): Path<Uuid>,
|
Path(trip_type_id): Path<Uuid>,
|
||||||
Form(trip_update): Form<TripTypeUpdate>,
|
Form(trip_update): Form<TripTypeUpdate>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
if trip_update.new_value.is_empty() {
|
if trip_update.new_value.is_empty() {
|
||||||
return Err(Error::Request(RequestError::EmptyFormElement {
|
return Err(Error::Request(RequestError::EmptyFormElement {
|
||||||
name: "name".to_string(),
|
name: "name".to_string(),
|
||||||
@@ -838,6 +894,7 @@ pub async fn trips_types_edit_name(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let exists = models::trips::TripsType::set_name(
|
let exists = models::trips::TripsType::set_name(
|
||||||
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
trip_type_id,
|
trip_type_id,
|
||||||
&trip_update.new_value,
|
&trip_update.new_value,
|
||||||
@@ -873,16 +930,18 @@ pub async fn inventory_item(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_category_select(
|
pub async fn trip_category_select(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, category_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, category_id)): Path<(Uuid, Uuid)>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let mut trip = models::trips::Trip::find(&state.database_pool, trip_id)
|
let ctx = Context::build(current_user);
|
||||||
|
let mut trip = models::trips::Trip::find(&ctx, &state.database_pool, trip_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(Error::Request(RequestError::NotFound {
|
.ok_or(Error::Request(RequestError::NotFound {
|
||||||
message: format!("trip with id {trip_id} not found"),
|
message: format!("trip with id {trip_id} not found"),
|
||||||
}))?;
|
}))?;
|
||||||
|
|
||||||
trip.load_categories(&state.database_pool).await?;
|
trip.load_categories(&ctx, &state.database_pool).await?;
|
||||||
|
|
||||||
let active_category = trip
|
let active_category = trip
|
||||||
.categories()
|
.categories()
|
||||||
@@ -945,26 +1004,30 @@ pub async fn trip_packagelist(
|
|||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path(trip_id): Path<Uuid>,
|
Path(trip_id): Path<Uuid>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let mut trip = models::trips::Trip::find(&state.database_pool, trip_id)
|
let ctx = Context::build(current_user);
|
||||||
|
let mut trip = models::trips::Trip::find(&ctx, &state.database_pool, trip_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(Error::Request(RequestError::NotFound {
|
.ok_or(Error::Request(RequestError::NotFound {
|
||||||
message: format!("trip with id {trip_id} not found"),
|
message: format!("trip with id {trip_id} not found"),
|
||||||
}))?;
|
}))?;
|
||||||
|
|
||||||
trip.load_categories(&state.database_pool).await?;
|
trip.load_categories(&ctx, &state.database_pool).await?;
|
||||||
|
|
||||||
Ok(view::Root::build(
|
Ok(view::Root::build(
|
||||||
&Context::build(current_user),
|
&ctx,
|
||||||
&view::trip::packagelist::TripPackageList::build(&trip),
|
&view::trip::packagelist::TripPackageList::build(&trip),
|
||||||
Some(&TopLevelPage::Trips),
|
Some(&TopLevelPage::Trips),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_packagelist_set_pack_htmx(
|
pub async fn trip_item_packagelist_set_pack_htmx(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -973,7 +1036,7 @@ pub async fn trip_item_packagelist_set_pack_htmx(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let item = models::trips::TripItem::find(&state.database_pool, trip_id, item_id)
|
let item = models::trips::TripItem::find(&ctx, &state.database_pool, trip_id, item_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(Error::Request(RequestError::NotFound {
|
.ok_or(Error::Request(RequestError::NotFound {
|
||||||
message: format!("an item with id {item_id} does not exist"),
|
message: format!("an item with id {item_id} does not exist"),
|
||||||
@@ -985,10 +1048,13 @@ pub async fn trip_item_packagelist_set_pack_htmx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_packagelist_set_unpack_htmx(
|
pub async fn trip_item_packagelist_set_unpack_htmx(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -999,7 +1065,7 @@ pub async fn trip_item_packagelist_set_unpack_htmx(
|
|||||||
|
|
||||||
// note that this cannot fail due to a missing item, as trip_item_set_state would already
|
// note that this cannot fail due to a missing item, as trip_item_set_state would already
|
||||||
// return 404. but error handling cannot hurt ;)
|
// return 404. but error handling cannot hurt ;)
|
||||||
let item = models::trips::TripItem::find(&state.database_pool, trip_id, item_id)
|
let item = models::trips::TripItem::find(&ctx, &state.database_pool, trip_id, item_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(Error::Request(RequestError::NotFound {
|
.ok_or(Error::Request(RequestError::NotFound {
|
||||||
message: format!("an item with id {item_id} does not exist"),
|
message: format!("an item with id {item_id} does not exist"),
|
||||||
@@ -1011,10 +1077,13 @@ pub async fn trip_item_packagelist_set_unpack_htmx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_packagelist_set_ready_htmx(
|
pub async fn trip_item_packagelist_set_ready_htmx(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -1023,7 +1092,7 @@ pub async fn trip_item_packagelist_set_ready_htmx(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let item = models::trips::TripItem::find(&state.database_pool, trip_id, item_id)
|
let item = models::trips::TripItem::find(&ctx, &state.database_pool, trip_id, item_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(Error::Request(RequestError::NotFound {
|
.ok_or(Error::Request(RequestError::NotFound {
|
||||||
message: format!("an item with id {item_id} does not exist"),
|
message: format!("an item with id {item_id} does not exist"),
|
||||||
@@ -1035,10 +1104,13 @@ pub async fn trip_item_packagelist_set_ready_htmx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn trip_item_packagelist_set_unready_htmx(
|
pub async fn trip_item_packagelist_set_unready_htmx(
|
||||||
|
Extension(current_user): Extension<models::user::User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, item_id)): Path<(Uuid, Uuid)>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
|
let ctx = Context::build(current_user);
|
||||||
trip_item_set_state(
|
trip_item_set_state(
|
||||||
|
&ctx,
|
||||||
&state,
|
&state,
|
||||||
trip_id,
|
trip_id,
|
||||||
item_id,
|
item_id,
|
||||||
@@ -1049,7 +1121,7 @@ pub async fn trip_item_packagelist_set_unready_htmx(
|
|||||||
|
|
||||||
// note that this cannot fail due to a missing item, as trip_item_set_state would already
|
// note that this cannot fail due to a missing item, as trip_item_set_state would already
|
||||||
// return 404. but error handling cannot hurt ;)
|
// return 404. but error handling cannot hurt ;)
|
||||||
let item = models::trips::TripItem::find(&state.database_pool, trip_id, item_id)
|
let item = models::trips::TripItem::find(&ctx, &state.database_pool, trip_id, item_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(Error::Request(RequestError::NotFound {
|
.ok_or(Error::Request(RequestError::NotFound {
|
||||||
message: format!("an item with id {item_id} does not exist"),
|
message: format!("an item with id {item_id} does not exist"),
|
||||||
|
|||||||
Reference in New Issue
Block a user