This commit is contained in:
2023-08-29 21:34:00 +02:00
parent 99b58d0721
commit 6e41d9b4fa
3 changed files with 21 additions and 198 deletions

View File

@@ -1,138 +0,0 @@
pub struct InventoryItem {
pub id: Uuid,
pub name: String,
pub description: Option<String>,
pub weight: i64,
pub category: Category,
pub product: Option<Product>,
}
struct DbInventoryItemRow {
pub id: String,
pub name: String,
pub description: Option<String>,
pub weight: i64,
pub category_id: String,
pub category_name: String,
pub category_description: Option<String>,
pub product_id: Option<String>,
pub product_name: Option<String>,
pub product_description: Option<String>,
pub product_comment: Option<String>,
}
impl TryFrom<DbInventoryItemRow> for InventoryItem {
type Error = Error;
fn try_from(row: DbInventoryItemRow) -> Result<Self, Self::Error> {
Ok(InventoryItem {
id: Uuid::try_parse(&row.id)?,
name: row.name,
description: row.description,
weight: row.weight,
category: Category {
id: Uuid::try_parse(&row.category_id)?,
name: row.category_name,
description: row.category_description,
items: None,
},
product: row
.product_id
.map(|id| -> Result<Product, Error> {
Ok(Product {
id: Uuid::try_parse(&id)?,
name: row.product_name.unwrap(),
description: row.product_description,
comment: row.product_comment,
})
})
.transpose()?,
})
}
}
impl InventoryItem {
pub async fn find(pool: &sqlx::Pool<sqlx::Sqlite>, id: Uuid) -> Result<Option<Self>, Error> {
let id_param = id.to_string();
sqlx::query_as!(
DbInventoryItemRow,
"SELECT
item.id AS id,
item.name AS name,
item.description AS description,
weight,
category.id AS category_id,
category.name AS category_name,
category.description AS category_description,
product.id AS product_id,
product.name AS product_name,
product.description AS product_description,
product.comment AS product_comment
FROM inventory_items AS item
INNER JOIN inventory_items_categories as category
ON item.category_id = category.id
LEFT JOIN inventory_products AS product
ON item.product_id = product.id
WHERE item.id = ?",
id_param,
)
.fetch_optional(pool)
.await?
.map(|row| row.try_into())
.transpose()
}
pub async fn name_exists(pool: &sqlx::Pool<sqlx::Sqlite>, name: &str) -> Result<bool, Error> {
Ok(sqlx::query!(
"SELECT id
FROM inventory_items
WHERE name = ?",
name,
)
.fetch_optional(pool)
.await?
.map(|_row| ())
.is_some())
}
pub async fn delete(pool: &sqlx::Pool<sqlx::Sqlite>, id: Uuid) -> Result<bool, Error> {
let id_param = id.to_string();
let results = sqlx::query!(
"DELETE FROM inventory_items
WHERE id = ?",
id_param
)
.execute(pool)
.await?;
Ok(results.rows_affected() != 0)
}
pub async fn save(
pool: &sqlx::Pool<sqlx::Sqlite>,
name: &str,
category_id: Uuid,
weight: u32,
) -> Result<Uuid, Error> {
let id = Uuid::new_v4();
let id_param = id.to_string();
let category_id_param = category_id.to_string();
sqlx::query!(
"INSERT INTO inventory_items
(id, name, description, weight, category_id)
VALUES
(?, ?, ?, ?, ?)",
id_param,
name,
"",
weight,
category_id_param
)
.execute(pool)
.await?;
Ok(id)
}
}

View File

@@ -1,60 +0,0 @@
// // Find element from element.
// let elem_text = elem_form.find(By::Id("searchInput")).await?;
// // Type in the search terms.
// elem_text.send_keys("selenium").await?;
// // Click the search button.
// let elem_button = elem_form.find(By::Css("button[type='submit']")).await?;
// elem_button.click().await?;
// // Look for header to implicitly wait for the page to load.
// driver.find(By::ClassName("firstHeading")).await?;
// assert_eq!(driver.title().await?, "Selenium - Wikipedia");
// Always explicitly close the browser.
// # browser.open('/')
// # browser.should(have.title('Packager'))
// # browser.should(have.url(url("/")))
// # browser.element(by.id('header')).should(have.text("Packager"))
// # browser.element(by.id('header')).element(by.id("header-link-inventory")).click()
// # browser.should(have.url(url("/inventory/")))
// # browser.element(by.id('header')).element(by.id("header-link-trips")).click()
// # browser.should(have.url(url("/trips/")))
// # browser.element(by.id('header')).element(by.id("home")).click()
// # browser.should(have.url(url("/")))
// browser.open('/inventory/')
// head = browser.element('#category-list').element("thead")
// head.all("th").first.should(have.text("Name"))
// head.all("th").second.should(have.text("Weight"))
// body = browser.element('#category-list').element("tbody")
// body.all("tr").should(have.size(1))
// row = body.all("tr")[-1]
// row.all("td").first.should(have.text("Sum"))
// row.all("td").second.should(have.text("0"))
// value = randname()
// new_category = browser.element('#new-category')
// new_category.element('#new-category-name').type(value)
// new_category.submit()
// body = browser.element('#category-list').element("tbody")
// body.all("tr").should(have.size(2))
// row = body.all("tr").first
// row.all("td").first.should(have.text(value))
// row.all("td").second.should(have.text("0"))
// row = body.all("tr")[-1].all("td").second.should(have.text("0"))
// browser.quit()
// print("Success")
// Ok(())

21
rust/update-k8s.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -o nounset
set -o pipefail
set -o errexit
id=$(pwgen -s 25 1)
url=registry.hkoerber.de/packager:$id
echo "NEW URL: " $url
./build-container.sh
docker tag packager:latest $url
docker push $url
pushd ~/projects/mycloud/
./kubectl.sh set image \
deployment/$(./kubectl.sh get deployment --output=jsonpath={.items..metadata.name} -l app=packager) \
packager=$url