Add shelves list to interior_ref_lists
So that shops can have multiple shelves that save their page, filter, sort, etc. state to the server. Buttons for the shelves are reconstructed in the plugin during the load shop procedure.
This commit is contained in:
parent
0adbf7c5c0
commit
81840b3d34
@ -137,10 +137,9 @@ PORT=3030
|
|||||||
4. Install
|
4. Install
|
||||||
[`sqlx_cli`](https://github.com/launchbadge/sqlx/tree/master/sqlx-cli) with
|
[`sqlx_cli`](https://github.com/launchbadge/sqlx/tree/master/sqlx-cli) with
|
||||||
`cargo install --version=0.1.0-beta.1 sqlx-cli --no-default-features --features postgres`
|
`cargo install --version=0.1.0-beta.1 sqlx-cli --no-default-features --features postgres`
|
||||||
5. `cd db` to enter the `db` sub-directory of this repo.
|
5. Run `sqlx migrate --source db/migrations run` which will run all the database
|
||||||
6. Run `sqlx migrate run` which will run all the database migrations.
|
migrations.
|
||||||
7. `cd ..` to return to the top-level directory of this repo.
|
6. Run `./devserver.sh` to run the dev server (by default it listens at
|
||||||
8. Run `./devserver.sh` to run the dev server (by default it listens at
|
|
||||||
`127.0.0.1:3030`). Note that this runs the server in debug mode and shouldn't
|
`127.0.0.1:3030`). Note that this runs the server in debug mode and shouldn't
|
||||||
be used to serve requests from the mod. You can build the release version of
|
be used to serve requests from the mod. You can build the release version of
|
||||||
the server with `cargo build --release`.
|
the server with `cargo build --release`.
|
||||||
|
@ -22,6 +22,7 @@ CREATE TABLE "interior_ref_lists" (
|
|||||||
"shop_id" INTEGER REFERENCES "shops"(id) NOT NULL UNIQUE,
|
"shop_id" INTEGER REFERENCES "shops"(id) NOT NULL UNIQUE,
|
||||||
"owner_id" INTEGER REFERENCES "owners"(id) NOT NULL,
|
"owner_id" INTEGER REFERENCES "owners"(id) NOT NULL,
|
||||||
"ref_list" jsonb NOT NULL,
|
"ref_list" jsonb NOT NULL,
|
||||||
|
"shelves" jsonb NOT NULL,
|
||||||
"created_at" timestamp(3) NOT NULL,
|
"created_at" timestamp(3) NOT NULL,
|
||||||
"updated_at" timestamp(3) NOT NULL
|
"updated_at" timestamp(3) NOT NULL
|
||||||
);
|
);
|
||||||
|
@ -3,4 +3,4 @@ DROP TABLE shops CASCADE;
|
|||||||
DROP TABLE interior_ref_lists CASCADE;
|
DROP TABLE interior_ref_lists CASCADE;
|
||||||
DROP TABLE merchandise_lists CASCADE;
|
DROP TABLE merchandise_lists CASCADE;
|
||||||
DROP TABLE transactions CASCADE;
|
DROP TABLE transactions CASCADE;
|
||||||
DROP TABLE refinery_schema_history CASCADE;
|
DROP TABLE _sqlx_migrations CASCADE;
|
||||||
|
@ -95,6 +95,7 @@ pub async fn create(
|
|||||||
shop_id: saved_shop.id,
|
shop_id: saved_shop.id,
|
||||||
owner_id: Some(owner_id),
|
owner_id: Some(owner_id),
|
||||||
ref_list: sqlx::types::Json::default(),
|
ref_list: sqlx::types::Json::default(),
|
||||||
|
shelves: sqlx::types::Json::default(),
|
||||||
};
|
};
|
||||||
InteriorRefList::create(interior_ref_list, &mut tx)
|
InteriorRefList::create(interior_ref_list, &mut tx)
|
||||||
.await
|
.await
|
||||||
|
@ -24,12 +24,31 @@ pub struct InteriorRef {
|
|||||||
pub scale: u16,
|
pub scale: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(sqlx::FromRow, Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct Shelf {
|
||||||
|
pub shelf_type: u32,
|
||||||
|
pub position_x: f32,
|
||||||
|
pub position_y: f32,
|
||||||
|
pub position_z: f32,
|
||||||
|
pub angle_x: f32,
|
||||||
|
pub angle_y: f32,
|
||||||
|
pub angle_z: f32,
|
||||||
|
pub scale: u16,
|
||||||
|
pub page: u32,
|
||||||
|
pub filter_form_type: Option<u32>,
|
||||||
|
pub filter_is_food: bool,
|
||||||
|
pub search: Option<String>,
|
||||||
|
pub sort_on: Option<String>,
|
||||||
|
pub sort_asc: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(sqlx::FromRow, Debug, Serialize, Deserialize, Clone)]
|
#[derive(sqlx::FromRow, Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct InteriorRefList {
|
pub struct InteriorRefList {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub shop_id: i32,
|
pub shop_id: i32,
|
||||||
pub owner_id: i32,
|
pub owner_id: i32,
|
||||||
pub ref_list: Json<Vec<InteriorRef>>,
|
pub ref_list: Json<Vec<InteriorRef>>,
|
||||||
|
pub shelves: Json<Vec<Shelf>>,
|
||||||
pub created_at: NaiveDateTime,
|
pub created_at: NaiveDateTime,
|
||||||
pub updated_at: NaiveDateTime,
|
pub updated_at: NaiveDateTime,
|
||||||
}
|
}
|
||||||
@ -39,6 +58,7 @@ pub struct PostedInteriorRefList {
|
|||||||
pub shop_id: i32,
|
pub shop_id: i32,
|
||||||
pub owner_id: Option<i32>,
|
pub owner_id: Option<i32>,
|
||||||
pub ref_list: Json<Vec<InteriorRef>>,
|
pub ref_list: Json<Vec<InteriorRef>>,
|
||||||
|
pub shelves: Json<Vec<Shelf>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteriorRefList {
|
impl InteriorRefList {
|
||||||
@ -60,7 +80,8 @@ impl InteriorRefList {
|
|||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Self,
|
Self,
|
||||||
r#"SELECT id, shop_id, owner_id, created_at, updated_at,
|
r#"SELECT id, shop_id, owner_id, created_at, updated_at,
|
||||||
ref_list as "ref_list: Json<Vec<InteriorRef>>"
|
ref_list as "ref_list: Json<Vec<InteriorRef>>",
|
||||||
|
shelves as "shelves: Json<Vec<Shelf>>"
|
||||||
FROM interior_ref_lists WHERE id = $1"#,
|
FROM interior_ref_lists WHERE id = $1"#,
|
||||||
id
|
id
|
||||||
)
|
)
|
||||||
@ -77,13 +98,15 @@ impl InteriorRefList {
|
|||||||
Ok(sqlx::query_as!(
|
Ok(sqlx::query_as!(
|
||||||
Self,
|
Self,
|
||||||
r#"INSERT INTO interior_ref_lists
|
r#"INSERT INTO interior_ref_lists
|
||||||
(shop_id, owner_id, ref_list, created_at, updated_at)
|
(shop_id, owner_id, ref_list, shelves, created_at, updated_at)
|
||||||
VALUES ($1, $2, $3, now(), now())
|
VALUES ($1, $2, $3, $4, now(), now())
|
||||||
RETURNING id, shop_id, owner_id, created_at, updated_at,
|
RETURNING id, shop_id, owner_id, created_at, updated_at,
|
||||||
ref_list as "ref_list: Json<Vec<InteriorRef>>""#,
|
ref_list as "ref_list: Json<Vec<InteriorRef>>",
|
||||||
|
shelves as "shelves: Json<Vec<Shelf>>""#,
|
||||||
interior_ref_list.shop_id,
|
interior_ref_list.shop_id,
|
||||||
interior_ref_list.owner_id,
|
interior_ref_list.owner_id,
|
||||||
serde_json::json!(interior_ref_list.ref_list),
|
serde_json::json!(interior_ref_list.ref_list),
|
||||||
|
serde_json::json!(interior_ref_list.shelves),
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await?)
|
.await?)
|
||||||
@ -120,7 +143,8 @@ impl InteriorRefList {
|
|||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Self,
|
Self,
|
||||||
r#"SELECT id, shop_id, owner_id, created_at, updated_at,
|
r#"SELECT id, shop_id, owner_id, created_at, updated_at,
|
||||||
ref_list as "ref_list: Json<Vec<InteriorRef>>" FROM interior_ref_lists
|
ref_list as "ref_list: Json<Vec<InteriorRef>>",
|
||||||
|
shelves as "shelves: Json<Vec<Shelf>>" FROM interior_ref_lists
|
||||||
ORDER BY $1
|
ORDER BY $1
|
||||||
LIMIT $2
|
LIMIT $2
|
||||||
OFFSET $3"#,
|
OFFSET $3"#,
|
||||||
@ -134,7 +158,8 @@ impl InteriorRefList {
|
|||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Self,
|
Self,
|
||||||
r#"SELECT id, shop_id, owner_id, created_at, updated_at,
|
r#"SELECT id, shop_id, owner_id, created_at, updated_at,
|
||||||
ref_list as "ref_list: Json<Vec<InteriorRef>>" FROM interior_ref_lists
|
ref_list as "ref_list: Json<Vec<InteriorRef>>",
|
||||||
|
shelves as "shelves: Json<Vec<Shelf>>" FROM interior_ref_lists
|
||||||
LIMIT $1
|
LIMIT $1
|
||||||
OFFSET $2"#,
|
OFFSET $2"#,
|
||||||
list_params.limit.unwrap_or(10),
|
list_params.limit.unwrap_or(10),
|
||||||
@ -162,12 +187,15 @@ impl InteriorRefList {
|
|||||||
Self,
|
Self,
|
||||||
r#"UPDATE interior_ref_lists SET
|
r#"UPDATE interior_ref_lists SET
|
||||||
ref_list = $2,
|
ref_list = $2,
|
||||||
|
shelves = $3,
|
||||||
updated_at = now()
|
updated_at = now()
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
RETURNING id, shop_id, owner_id, created_at, updated_at,
|
RETURNING id, shop_id, owner_id, created_at, updated_at,
|
||||||
ref_list as "ref_list: Json<Vec<InteriorRef>>""#,
|
ref_list as "ref_list: Json<Vec<InteriorRef>>",
|
||||||
|
shelves as "shelves: Json<Vec<Shelf>>""#,
|
||||||
id,
|
id,
|
||||||
serde_json::json!(interior_ref_list.ref_list),
|
serde_json::json!(interior_ref_list.ref_list),
|
||||||
|
serde_json::json!(interior_ref_list.shelves),
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await?)
|
.await?)
|
||||||
@ -184,7 +212,8 @@ impl InteriorRefList {
|
|||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Self,
|
Self,
|
||||||
r#"SELECT id, shop_id, owner_id, created_at, updated_at,
|
r#"SELECT id, shop_id, owner_id, created_at, updated_at,
|
||||||
ref_list as "ref_list: Json<Vec<InteriorRef>>" FROM interior_ref_lists
|
ref_list as "ref_list: Json<Vec<InteriorRef>>",
|
||||||
|
shelves as "shelves: Json<Vec<Shelf>>" FROM interior_ref_lists
|
||||||
WHERE shop_id = $1"#,
|
WHERE shop_id = $1"#,
|
||||||
shop_id,
|
shop_id,
|
||||||
)
|
)
|
||||||
@ -211,12 +240,15 @@ impl InteriorRefList {
|
|||||||
Self,
|
Self,
|
||||||
r#"UPDATE interior_ref_lists SET
|
r#"UPDATE interior_ref_lists SET
|
||||||
ref_list = $2,
|
ref_list = $2,
|
||||||
|
shelves = $3,
|
||||||
updated_at = now()
|
updated_at = now()
|
||||||
WHERE shop_id = $1
|
WHERE shop_id = $1
|
||||||
RETURNING id, shop_id, owner_id, created_at, updated_at,
|
RETURNING id, shop_id, owner_id, created_at, updated_at,
|
||||||
ref_list as "ref_list: Json<Vec<InteriorRef>>""#,
|
ref_list as "ref_list: Json<Vec<InteriorRef>>",
|
||||||
|
shelves as "shelves: Json<Vec<Shelf>>""#,
|
||||||
shop_id,
|
shop_id,
|
||||||
serde_json::json!(interior_ref_list.ref_list),
|
serde_json::json!(interior_ref_list.ref_list),
|
||||||
|
serde_json::json!(interior_ref_list.shelves),
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await?)
|
.await?)
|
||||||
|
@ -2602,5 +2602,23 @@
|
|||||||
"angle_z": 1.006,
|
"angle_z": 1.006,
|
||||||
"scale": 1
|
"scale": 1
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"shelves": [
|
||||||
|
{
|
||||||
|
"shelf_type": 1,
|
||||||
|
"position_x": 1.001,
|
||||||
|
"position_y": 1.002,
|
||||||
|
"position_z": 1.003,
|
||||||
|
"angle_x": 1.004,
|
||||||
|
"angle_y": 1.005,
|
||||||
|
"angle_z": 1.006,
|
||||||
|
"scale": 1,
|
||||||
|
"page": 1,
|
||||||
|
"filter_form_type": null,
|
||||||
|
"filter_is_food": false,
|
||||||
|
"search": null,
|
||||||
|
"sort_on": null,
|
||||||
|
"sort_asc": true
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user