blob: 5465abd35e9b6c066ca35f609a7620f6d478c549 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// rocie - An enterprise grocery management system
//
// Copyright (C) 2026 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of Rocie.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
use actix_web::web;
use log::info;
use percent_encoding::percent_decode_str;
pub(crate) mod inventory;
pub(crate) mod product;
pub(crate) mod product_parent;
pub(crate) mod recipe;
pub(crate) mod recipe_parent;
pub(crate) mod unit;
pub(crate) mod unit_property;
pub(crate) mod user;
pub(crate) fn register_paths(cfg: &mut web::ServiceConfig) {
cfg.service(inventory::amount_by_id)
.service(product::product_by_id)
.service(product::product_by_name)
.service(product::product_suggestion_by_name)
.service(product::products_by_product_parent_id_direct)
.service(product::products_by_product_parent_id_indirect)
.service(product::products_in_storage)
.service(product::products_registered)
.service(product::products_without_product_parent)
.service(product_parent::product_parents)
.service(product_parent::product_parents_toplevel)
.service(product_parent::product_parents_under)
.service(recipe::recipe_by_name)
.service(recipe::recipe_by_id)
.service(recipe::recipes)
.service(recipe::recipes_by_recipe_parent_id_direct)
.service(recipe::recipes_by_recipe_parent_id_indirect)
.service(recipe::recipes_without_recipe_parent)
.service(recipe_parent::recipe_parents)
.service(recipe_parent::recipe_parents_toplevel)
.service(recipe_parent::recipe_parents_under)
.service(unit::unit_by_id)
.service(unit::units)
.service(unit::units_by_property_id)
.service(unit_property::unit_properties)
.service(unit_property::unit_property_by_id)
.service(user::users)
.service(user::user_by_id);
}
/// A String, that is not url-decoded on parse.
struct UrlEncodedString(String);
impl UrlEncodedString {
/// Percent de-encode a given string
fn percent_decode(&self) -> Result<String, std::str::Utf8Error> {
percent_decode_str(self.0.replace('+', "%20").as_str())
.decode_utf8()
.map(|s| s.to_string())
.inspect(|s| info!("Decoded `{}` as `{s}`", self.0))
}
fn from_str(inner: &str) -> Self {
Self(inner.to_owned())
}
}
|