Compare commits
71 Commits
3f858d754e
...
done
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7c185b6987 | ||
![]() |
b607934c8d | ||
![]() |
62ac1011cc | ||
![]() |
c8582c8813 | ||
![]() |
b2ce4f829d | ||
![]() |
9ca46b9b3e | ||
![]() |
9a00e7eb16 | ||
![]() |
e465ed9e95 | ||
![]() |
09ab443622 | ||
![]() |
e8775385cf | ||
![]() |
c717e5c4e9 | ||
![]() |
67912410d9 | ||
![]() |
83019b999c | ||
![]() |
288dbd6d4c | ||
![]() |
92f539fa14 | ||
![]() |
c110825140 | ||
![]() |
1034dd30f9 | ||
![]() |
464a9c7dbc | ||
![]() |
082ab46590 | ||
70c3a61103 | |||
7c4ab54f45 | |||
e666991b60 | |||
b93e0c8e5a | |||
66a9311cae | |||
c754569143 | |||
71ab5b8dae | |||
0d811dd059 | |||
d28b3fac90 | |||
fbfeeb7679 | |||
![]() |
2860a01cf8 | ||
![]() |
a887921e5d | ||
![]() |
a2178733da | ||
![]() |
5fea5ad15f | ||
![]() |
fe5efbe8f1 | ||
![]() |
f25b2a72f7 | ||
af0d895227 | |||
da0445ccf6 | |||
c23b77ff0d | |||
03a42f3ba7 | |||
![]() |
7b5672d36b | ||
1d80d93b1d | |||
![]() |
21ebecac54 | ||
![]() |
acfae23029 | ||
![]() |
e1a0f112a2 | ||
![]() |
23cf1b54e4 | ||
![]() |
95a2c3e3fe | ||
151b1ab549 | |||
![]() |
148f95087d | ||
![]() |
81cdae85b0 | ||
e31b7b6319 | |||
84bf6b2d36 | |||
143874af78 | |||
b0ef6fc88d | |||
85f49f1c8c | |||
aa90447465 | |||
d4e275e28c | |||
6dffa09e88 | |||
a568d36eb2 | |||
d8154b9d0f | |||
![]() |
b8562a50e0 | ||
![]() |
072744998c | ||
![]() |
bcaf03610a | ||
306f489bd9 | |||
bc11dc127c | |||
3c497c3a5f | |||
![]() |
05e3cf9553 | ||
![]() |
d0baa7b10b | ||
![]() |
2c0f17fd30 | ||
![]() |
a37a681a33 | ||
0d0b8e8f32 | |||
![]() |
1038deded0 |
237
.editorconfig
Normal file
237
.editorconfig
Normal file
@@ -0,0 +1,237 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
ij_continuation_indent_size = 8
|
||||
ij_formatter_off_tag = @formatter:off
|
||||
ij_formatter_on_tag = @formatter:on
|
||||
ij_formatter_tags_enabled = false
|
||||
ij_smart_tabs = false
|
||||
ij_visual_guides = none
|
||||
ij_wrap_on_typing = false
|
||||
|
||||
[{*.ctp,*.hphp,*.inc,*.module,*.php,*.php4,*.php5,*.phtml}]
|
||||
ij_continuation_indent_size = 4
|
||||
ij_php_align_assignments = false
|
||||
ij_php_align_class_constants = false
|
||||
ij_php_align_enum_cases = false
|
||||
ij_php_align_group_field_declarations = false
|
||||
ij_php_align_inline_comments = false
|
||||
ij_php_align_key_value_pairs = false
|
||||
ij_php_align_match_arm_bodies = false
|
||||
ij_php_align_multiline_array_initializer_expression = false
|
||||
ij_php_align_multiline_binary_operation = false
|
||||
ij_php_align_multiline_chained_methods = false
|
||||
ij_php_align_multiline_extends_list = false
|
||||
ij_php_align_multiline_for = true
|
||||
ij_php_align_multiline_parameters = true
|
||||
ij_php_align_multiline_parameters_in_calls = false
|
||||
ij_php_align_multiline_ternary_operation = false
|
||||
ij_php_align_named_arguments = false
|
||||
ij_php_align_phpdoc_comments = false
|
||||
ij_php_align_phpdoc_param_names = false
|
||||
ij_php_anonymous_brace_style = end_of_line
|
||||
ij_php_api_weight = 28
|
||||
ij_php_array_initializer_new_line_after_left_brace = false
|
||||
ij_php_array_initializer_right_brace_on_new_line = false
|
||||
ij_php_array_initializer_wrap = off
|
||||
ij_php_assignment_wrap = off
|
||||
ij_php_attributes_wrap = off
|
||||
ij_php_author_weight = 28
|
||||
ij_php_binary_operation_sign_on_next_line = false
|
||||
ij_php_binary_operation_wrap = off
|
||||
ij_php_blank_lines_after_class_header = 0
|
||||
ij_php_blank_lines_after_function = 1
|
||||
ij_php_blank_lines_after_imports = 1
|
||||
ij_php_blank_lines_after_opening_tag = 0
|
||||
ij_php_blank_lines_after_package = 0
|
||||
ij_php_blank_lines_around_class = 1
|
||||
ij_php_blank_lines_around_constants = 0
|
||||
ij_php_blank_lines_around_enum_cases = 0
|
||||
ij_php_blank_lines_around_field = 0
|
||||
ij_php_blank_lines_around_method = 1
|
||||
ij_php_blank_lines_before_class_end = 0
|
||||
ij_php_blank_lines_before_imports = 1
|
||||
ij_php_blank_lines_before_method_body = 0
|
||||
ij_php_blank_lines_before_package = 1
|
||||
ij_php_blank_lines_before_return_statement = 0
|
||||
ij_php_blank_lines_between_imports = 0
|
||||
ij_php_block_brace_style = end_of_line
|
||||
ij_php_call_parameters_new_line_after_left_paren = false
|
||||
ij_php_call_parameters_right_paren_on_new_line = false
|
||||
ij_php_call_parameters_wrap = off
|
||||
ij_php_catch_on_new_line = false
|
||||
ij_php_category_weight = 28
|
||||
ij_php_class_brace_style = end_of_line
|
||||
ij_php_comma_after_last_argument = false
|
||||
ij_php_comma_after_last_array_element = false
|
||||
ij_php_comma_after_last_closure_use_var = false
|
||||
ij_php_comma_after_last_match_arm = false
|
||||
ij_php_comma_after_last_parameter = false
|
||||
ij_php_concat_spaces = true
|
||||
ij_php_copyright_weight = 28
|
||||
ij_php_deprecated_weight = 28
|
||||
ij_php_do_while_brace_force = never
|
||||
ij_php_else_if_style = as_is
|
||||
ij_php_else_on_new_line = false
|
||||
ij_php_example_weight = 28
|
||||
ij_php_extends_keyword_wrap = off
|
||||
ij_php_extends_list_wrap = off
|
||||
ij_php_fields_default_visibility = private
|
||||
ij_php_filesource_weight = 28
|
||||
ij_php_finally_on_new_line = false
|
||||
ij_php_for_brace_force = never
|
||||
ij_php_for_statement_new_line_after_left_paren = false
|
||||
ij_php_for_statement_right_paren_on_new_line = false
|
||||
ij_php_for_statement_wrap = off
|
||||
ij_php_force_empty_methods_in_one_line = false
|
||||
ij_php_force_short_declaration_array_style = false
|
||||
ij_php_getters_setters_naming_style = camel_case
|
||||
ij_php_getters_setters_order_style = getters_first
|
||||
ij_php_global_weight = 28
|
||||
ij_php_group_use_wrap = on_every_item
|
||||
ij_php_if_brace_force = never
|
||||
ij_php_if_lparen_on_next_line = false
|
||||
ij_php_if_rparen_on_next_line = false
|
||||
ij_php_ignore_weight = 28
|
||||
ij_php_import_sorting = alphabetic
|
||||
ij_php_indent_break_from_case = true
|
||||
ij_php_indent_case_from_switch = true
|
||||
ij_php_indent_code_in_php_tags = false
|
||||
ij_php_internal_weight = 28
|
||||
ij_php_keep_blank_lines_after_lbrace = 2
|
||||
ij_php_keep_blank_lines_before_right_brace = 2
|
||||
ij_php_keep_blank_lines_in_code = 2
|
||||
ij_php_keep_blank_lines_in_declarations = 2
|
||||
ij_php_keep_control_statement_in_one_line = true
|
||||
ij_php_keep_first_column_comment = true
|
||||
ij_php_keep_indents_on_empty_lines = false
|
||||
ij_php_keep_line_breaks = true
|
||||
ij_php_keep_rparen_and_lbrace_on_one_line = false
|
||||
ij_php_keep_simple_classes_in_one_line = false
|
||||
ij_php_keep_simple_methods_in_one_line = false
|
||||
ij_php_lambda_brace_style = end_of_line
|
||||
ij_php_license_weight = 28
|
||||
ij_php_line_comment_add_space = false
|
||||
ij_php_line_comment_at_first_column = true
|
||||
ij_php_link_weight = 28
|
||||
ij_php_lower_case_boolean_const = false
|
||||
ij_php_lower_case_keywords = true
|
||||
ij_php_lower_case_null_const = false
|
||||
ij_php_method_brace_style = end_of_line
|
||||
ij_php_method_call_chain_wrap = off
|
||||
ij_php_method_parameters_new_line_after_left_paren = false
|
||||
ij_php_method_parameters_right_paren_on_new_line = false
|
||||
ij_php_method_parameters_wrap = off
|
||||
ij_php_method_weight = 28
|
||||
ij_php_modifier_list_wrap = false
|
||||
ij_php_multiline_chained_calls_semicolon_on_new_line = false
|
||||
ij_php_namespace_brace_style = 1
|
||||
ij_php_new_line_after_php_opening_tag = false
|
||||
ij_php_null_type_position = in_the_end
|
||||
ij_php_package_weight = 28
|
||||
ij_php_param_weight = 0
|
||||
ij_php_parameters_attributes_wrap = off
|
||||
ij_php_parentheses_expression_new_line_after_left_paren = false
|
||||
ij_php_parentheses_expression_right_paren_on_new_line = false
|
||||
ij_php_phpdoc_blank_line_before_tags = false
|
||||
ij_php_phpdoc_blank_lines_around_parameters = false
|
||||
ij_php_phpdoc_keep_blank_lines = true
|
||||
ij_php_phpdoc_param_spaces_between_name_and_description = 1
|
||||
ij_php_phpdoc_param_spaces_between_tag_and_type = 1
|
||||
ij_php_phpdoc_param_spaces_between_type_and_name = 1
|
||||
ij_php_phpdoc_use_fqcn = false
|
||||
ij_php_phpdoc_wrap_long_lines = false
|
||||
ij_php_place_assignment_sign_on_next_line = false
|
||||
ij_php_place_parens_for_constructor = 0
|
||||
ij_php_property_read_weight = 28
|
||||
ij_php_property_weight = 28
|
||||
ij_php_property_write_weight = 28
|
||||
ij_php_return_type_on_new_line = false
|
||||
ij_php_return_weight = 1
|
||||
ij_php_see_weight = 28
|
||||
ij_php_since_weight = 28
|
||||
ij_php_sort_phpdoc_elements = true
|
||||
ij_php_space_after_colon = true
|
||||
ij_php_space_after_colon_in_enum_backed_type = true
|
||||
ij_php_space_after_colon_in_named_argument = true
|
||||
ij_php_space_after_colon_in_return_type = true
|
||||
ij_php_space_after_comma = true
|
||||
ij_php_space_after_for_semicolon = true
|
||||
ij_php_space_after_quest = true
|
||||
ij_php_space_after_type_cast = false
|
||||
ij_php_space_after_unary_not = false
|
||||
ij_php_space_before_array_initializer_left_brace = false
|
||||
ij_php_space_before_catch_keyword = true
|
||||
ij_php_space_before_catch_left_brace = true
|
||||
ij_php_space_before_catch_parentheses = true
|
||||
ij_php_space_before_class_left_brace = true
|
||||
ij_php_space_before_closure_left_parenthesis = true
|
||||
ij_php_space_before_colon = true
|
||||
ij_php_space_before_colon_in_enum_backed_type = false
|
||||
ij_php_space_before_colon_in_named_argument = false
|
||||
ij_php_space_before_colon_in_return_type = false
|
||||
ij_php_space_before_comma = false
|
||||
ij_php_space_before_do_left_brace = true
|
||||
ij_php_space_before_else_keyword = true
|
||||
ij_php_space_before_else_left_brace = true
|
||||
ij_php_space_before_finally_keyword = true
|
||||
ij_php_space_before_finally_left_brace = true
|
||||
ij_php_space_before_for_left_brace = true
|
||||
ij_php_space_before_for_parentheses = true
|
||||
ij_php_space_before_for_semicolon = false
|
||||
ij_php_space_before_if_left_brace = true
|
||||
ij_php_space_before_if_parentheses = true
|
||||
ij_php_space_before_method_call_parentheses = false
|
||||
ij_php_space_before_method_left_brace = true
|
||||
ij_php_space_before_method_parentheses = false
|
||||
ij_php_space_before_quest = true
|
||||
ij_php_space_before_short_closure_left_parenthesis = false
|
||||
ij_php_space_before_switch_left_brace = true
|
||||
ij_php_space_before_switch_parentheses = true
|
||||
ij_php_space_before_try_left_brace = true
|
||||
ij_php_space_before_unary_not = false
|
||||
ij_php_space_before_while_keyword = true
|
||||
ij_php_space_before_while_left_brace = true
|
||||
ij_php_space_before_while_parentheses = true
|
||||
ij_php_space_between_ternary_quest_and_colon = false
|
||||
ij_php_spaces_around_additive_operators = true
|
||||
ij_php_spaces_around_arrow = false
|
||||
ij_php_spaces_around_assignment_in_declare = false
|
||||
ij_php_spaces_around_assignment_operators = true
|
||||
ij_php_spaces_around_bitwise_operators = true
|
||||
ij_php_spaces_around_equality_operators = true
|
||||
ij_php_spaces_around_logical_operators = true
|
||||
ij_php_spaces_around_multiplicative_operators = true
|
||||
ij_php_spaces_around_null_coalesce_operator = true
|
||||
ij_php_spaces_around_pipe_in_union_type = false
|
||||
ij_php_spaces_around_relational_operators = true
|
||||
ij_php_spaces_around_shift_operators = true
|
||||
ij_php_spaces_around_unary_operator = false
|
||||
ij_php_spaces_around_var_within_brackets = false
|
||||
ij_php_spaces_within_array_initializer_braces = false
|
||||
ij_php_spaces_within_brackets = false
|
||||
ij_php_spaces_within_catch_parentheses = false
|
||||
ij_php_spaces_within_for_parentheses = false
|
||||
ij_php_spaces_within_if_parentheses = false
|
||||
ij_php_spaces_within_method_call_parentheses = false
|
||||
ij_php_spaces_within_method_parentheses = false
|
||||
ij_php_spaces_within_parentheses = false
|
||||
ij_php_spaces_within_short_echo_tags = true
|
||||
ij_php_spaces_within_switch_parentheses = false
|
||||
ij_php_spaces_within_while_parentheses = false
|
||||
ij_php_special_else_if_treatment = false
|
||||
ij_php_subpackage_weight = 28
|
||||
ij_php_ternary_operation_signs_on_next_line = false
|
||||
ij_php_ternary_operation_wrap = off
|
||||
ij_php_throws_weight = 2
|
||||
ij_php_todo_weight = 28
|
||||
ij_php_treat_multiline_arrays_and_lambdas_multiline = false
|
||||
ij_php_unknown_tag_weight = 28
|
||||
ij_php_upper_case_boolean_const = false
|
||||
ij_php_upper_case_null_const = false
|
||||
ij_php_uses_weight = 28
|
||||
ij_php_var_weight = 28
|
||||
ij_php_variable_naming_style = mixed
|
||||
ij_php_version_weight = 28
|
||||
ij_php_while_brace_force = never
|
||||
ij_php_while_on_new_line = false
|
@@ -1 +1,5 @@
|
||||
FallbackResource /DirektiveDesDons/index.php
|
||||
# Redirect everything to index.php
|
||||
RewriteEngine on
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^.*$ /DirektiveDesDons/index.php [L,QSA]
|
152
BancaDati.sql
152
BancaDati.sql
@@ -1,85 +1,101 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 4.5.1
|
||||
-- http://www.phpmyadmin.net
|
||||
--
|
||||
-- Host: 127.0.0.1
|
||||
-- Erstellungszeit: 24. Nov 2017 um 17:01
|
||||
-- Server-Version: 10.1.16-MariaDB
|
||||
-- PHP-Version: 7.0.9
|
||||
SET
|
||||
SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET
|
||||
time_zone = "+00:00";
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
--
|
||||
-- Datenbank: `blog`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
CREATE TABLE `ingredienti` ( /*Zutaten*/
|
||||
`id` varchar(36) NOT NULL,
|
||||
`cognome` varchar(200) NOT NULL, /*Name*/
|
||||
`caloriePerCento` int(5) NOT NULL, /*Kalorien pro Gramm*/
|
||||
`ilPeso` int(5) NULL, /*Gewicht*/
|
||||
`prezzo` decimal(4,2) NOT NULL, /*Preis*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
CREATE TABLE `folla`
|
||||
( /*Menge*/
|
||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||
`unita` varchar(200) UNIQUE NOT NULL, /*Einheit*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `folla` ( /*Menge*/
|
||||
`id` varchar(36) NOT NULL,
|
||||
`unita` varchar(200) NOT NULL, /*Einheit*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
CREATE TABLE `ingredienti`
|
||||
( /*Zutaten*/
|
||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||
`cognome` varchar(200) NOT NULL, /*Name*/
|
||||
`calorie` integer(5) NOT NULL, /*Kalorien*/
|
||||
`quantita` integer(5) NOT NULL, /*Anzahl*/
|
||||
`prezzo` decimal(8, 2) NOT NULL, /*Preis*/
|
||||
`follaID` int NOT NULL, /*MengeID*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `elenco` ( /*Liste*/
|
||||
`id` varchar(36) NOT NULL,
|
||||
`creatore` varchar(200) NOT NULL, /*Ersteller*/
|
||||
`coloreDiSfondo` integer(10) NOT NULL, /*Hintergrundfarbe*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
CREATE TABLE `elenco`
|
||||
( /*Liste*/
|
||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||
`utenteID` int NOT NULL, /*ErstellerID*/
|
||||
`cognome` varchar(200) NOT NULL, /*Name*/
|
||||
`coloreDiSfondo` varchar(200), /*Hintergrundfarbe*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `utente` ( /*Benutzer*/
|
||||
`id` varchar(36) NOT NULL,
|
||||
`email` varchar(200) NOT NULL, /*Email*/
|
||||
`parolaDordine` integer(10) NOT NULL, /*Passwort*/
|
||||
`nomeUtente` integer(10) NOT NULL, /*Benutzernamen*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
CREATE TABLE `utente`
|
||||
( /*Benutzer*/
|
||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||
`email` varchar(200) NOT NULL, /*Email*/
|
||||
`parolaDordine` varchar(255) NOT NULL, /*Passwort*/
|
||||
`nomeUtente` varchar(50) UNIQUE NOT NULL, /*Benutzernamen*/
|
||||
`gettone` varchar(255), /*Token für Session*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `elencoIngredienti` ( /*Liste_Zutaten*/
|
||||
`id` varchar(36) NOT NULL,
|
||||
`ingredientiID` varchar(36) NOT NULL, /*ZutatenID*/
|
||||
`elencoID` varchar(36) NOT NULL, /*ListeID*/
|
||||
`follaID` integer(10) NOT NULL, /*MengeID*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
CREATE TABLE `elencoIngredienti`
|
||||
( /*Liste_Zutaten*/
|
||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||
`ingredientiID` int NOT NULL, /*ZutatenID*/
|
||||
`elencoID` int NOT NULL, /*ListeID*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `utenteElenco` ( /*Benutzer_Liste*/
|
||||
`id` varchar(36) NOT NULL,
|
||||
`elencoID` varchar(36) NOT NULL, /*ListeID*/
|
||||
`utenteID` varchar(36) NOT NULL, /*BenutzerID*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
CREATE TABLE `utenteElenco`
|
||||
( /*Benutzer_Liste*/
|
||||
`id` int auto_increment NOT NULL PRIMARY KEY,
|
||||
`elencoID` int NOT NULL, /*ListeID*/
|
||||
`utenteID` int NOT NULL, /*BenutzerID*/
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
ALTER TABLE `ingredienti`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
ALTER TABLE `folla`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
ALTER TABLE `elenco`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
ALTER TABLE `utente`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
ALTER TABLE `elencoIngredienti`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ALTER TABLE `elencoIngredienti` /*Liste_Zutaten*/
|
||||
ADD CONSTRAINT `FK_ElencoIngredienti_Ingredienti` FOREIGN KEY (`ingredientiID`) REFERENCES `ingredienti`(`id`), /*Liste_Zutaten hat Foreignkey von Zutaten(id)*/
|
||||
ADD CONSTRAINT `FK_ElencoIngredienti_Elenco` FOREIGN KEY (`elencoID`) REFERENCES `elenco`(`id`); /*Liste_Zutaten hat Foreignkey von Liste(id)*/
|
||||
ADD CONSTRAINT `FK_ElencoIngredienti_Folla` FOREIGN KEY (`follaID`) REFERENCES `folla`(`id`); /*Liste_Zutaten hat Foreignkey von Menge(id)*/
|
||||
|
||||
ALTER TABLE `utenteElenco`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ALTER TABLE `utenteElenco` /*Benutzer_Liste*/
|
||||
ADD CONSTRAINT `FK_UtenteElenco_Utente` FOREIGN KEY (`utenteId`) REFERENCES `utente`(`id`), /*Benutzer_Liste hat Foreignkey von Benutzer(id)*/
|
||||
ADD CONSTRAINT `FK_UtenteElenco_Elenco` FOREIGN KEY (`elencoId`) REFERENCES `elenco`(`id`), /*Benutzer_Liste hat Foreignkey von Liste(id)*/
|
||||
ADD CONSTRAINT `FK_UtenteElenco_Elenco` FOREIGN KEY (`elencoId`) REFERENCES `elenco`(`id`); /*Benutzer_Liste hat Foreignkey von Liste(id)*/
|
||||
|
||||
ALTER TABLE `ingredienti`
|
||||
ADD CONSTRAINT `FK_Ingredienti_Folla` FOREIGN KEY (`follaID`) REFERENCES `folla`(`id`); /*Zutaten hat Foreignkey von Menge(id)*/
|
||||
|
||||
ALTER TABLE `elenco`
|
||||
ADD CONSTRAINT `FK_Elenco_Utente` FOREIGN KEY (`utenteId`) REFERENCES `utente`(`id`); /*Liste hat Foreignkey von Benutzer(id)*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*Test Data*/
|
||||
INSERT INTO `utente` (email, parolaDordine, nomeUtente) VALUES ('test@test.com', 'password', "testuser");
|
||||
INSERT INTO `utente` (email, parolaDordine, nomeUtente) VALUES ('test1@test.com', 'hunter2', "testuser1");
|
||||
|
||||
|
||||
INSERT INTO `folla` (unita) VALUES ('st');
|
||||
INSERT INTO `folla` (unita) VALUES ('g');
|
||||
INSERT INTO `folla` (unita) VALUES ('kg');
|
||||
INSERT INTO `folla` (unita) VALUES ('mg');
|
||||
INSERT INTO `folla` (unita) VALUES ('l');
|
||||
INSERT INTO `folla` (unita) VALUES ('ml');
|
||||
INSERT INTO `folla` (unita) VALUES ('TL');
|
||||
INSERT INTO `folla` (unita) VALUES ('EL');
|
||||
|
||||
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Raffinierter Zucker', 3870, 1000, 5, 2);
|
||||
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Die Chips von der Tanke', 843, 375, 4.30, 2);
|
||||
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Reines Copium', 420, 1337, 6.9, 4);
|
||||
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Maggi', 420, 1337, 6.9, 4);
|
||||
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Eine große Pommes Frites mit Pommes Frites', 4200, 1, 6.9, 3);
|
||||
|
||||
INSERT INTO `elenco` (utenteID, cognome) VALUES (1, 'Liste für den Einkauf bei Netto');
|
||||
|
||||
INSERT INTO `elencoIngredienti` (ingredientiID, elencoID) VALUES (1, 1);
|
||||
INSERT INTO `elencoIngredienti` (ingredientiID, elencoID) VALUES (2, 1);
|
||||
|
138
BancaDati/BancaDati.php
Normal file
138
BancaDati/BancaDati.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace BancaDati;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
class BancaDati {
|
||||
private $dbName = "BancaDati";
|
||||
private $linkName = "localhost";
|
||||
private $user = "root";
|
||||
private $pw = "root";
|
||||
|
||||
public $pdo;
|
||||
public function __construct() {
|
||||
$this->linkDB();
|
||||
}
|
||||
private function linkDB() {
|
||||
try {
|
||||
$this->pdo = new PDO("mysql:dbname=$this->dbName;host=$this->linkName"
|
||||
, $this->user
|
||||
, $this->pw
|
||||
, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
|
||||
} catch (PDOException $e) {
|
||||
var_dump($e);
|
||||
die;
|
||||
}
|
||||
}
|
||||
public function createUUID()
|
||||
{
|
||||
$data = openssl_random_pseudo_bytes(16);
|
||||
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
|
||||
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
|
||||
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
|
||||
}
|
||||
|
||||
/**
|
||||
* Einheitliche Insert Funktion
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return void
|
||||
* author Simon Bock
|
||||
*/
|
||||
public function insert(string $table, array $values){
|
||||
$value = "";
|
||||
$column = "";
|
||||
foreach ($values as $col => $v){
|
||||
$value .= "'" . $v . "',";
|
||||
$column .= $col . ",";
|
||||
}
|
||||
$value = trim($value, ",");
|
||||
$column = trim($column, ",");
|
||||
|
||||
$sql = "INSERT INTO $table($column) VALUES ($value);";
|
||||
try {
|
||||
$sth = $this->pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
return $this->pdo->lastInsertId();
|
||||
}catch (PDOException $e){
|
||||
return false;
|
||||
//die;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Einheitliche Update Funktion
|
||||
* @param string $table
|
||||
* @param string $id
|
||||
* @param array $values
|
||||
* @return void
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public function update(string $table, string $id, array $values){
|
||||
$value = "";
|
||||
foreach ($values as $col => $v){
|
||||
$value .= $col . "='" . $v . "',";
|
||||
}
|
||||
$value = trim($value, ",");
|
||||
|
||||
$sql = "UPDATE " . $table . " SET " . $value . " WHERE `id` = " . $id . ";";
|
||||
try {
|
||||
$sth = $this->pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
}catch (PDOException $e){
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Einheitliche Delete Funktion
|
||||
* @param string $table
|
||||
* @param string $id
|
||||
* @return void
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public function delete(string $table, string $id){
|
||||
$sql = "DELETE FROM " . $table . " WHERE `id` = '" . $id . "';";
|
||||
try {
|
||||
$sth = $this->pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
}catch (PDOException $e){
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* einheitliche Select Funktion
|
||||
* kann sortiert werden durch ["by"]=>"col" und ["order"]=>"ASC|DESC"
|
||||
* @param string $table
|
||||
* @param array $where ["column"]=>"value" es wird mit LIKE verglichen und mit AND verbunden
|
||||
* @return void
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public function select(string $table, array $where = []){
|
||||
$whereString = "";
|
||||
$orderString = "";
|
||||
if(isset($where["by"])){
|
||||
$orderString = " ORDER BY " . $where["by"];
|
||||
unset($where["by"]);
|
||||
if(isset($where["order"])){
|
||||
$orderString .= " " . $where["order"];
|
||||
unset($where["order"]);
|
||||
}
|
||||
}
|
||||
foreach ($where as $col => $v) {
|
||||
if($whereString != ""){
|
||||
$whereString .= " AND ";
|
||||
}
|
||||
$whereString .= "`" . $col . "` LIKE '" . $v . "'";
|
||||
}
|
||||
$sql = "SELECT * FROM " . $table . ((count($where) > 0) ? " WHERE ".$whereString.$orderString : "") .";";
|
||||
try {
|
||||
return $this->pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
||||
}catch (PDOException $e){
|
||||
die;
|
||||
}
|
||||
}
|
||||
}
|
156
Documentation/Dokumentation.md
Normal file
156
Documentation/Dokumentation.md
Normal file
@@ -0,0 +1,156 @@
|
||||
# Dokumentation
|
||||
|
||||
Eine auflistung von allen Funktionen und API-Endpunkten mit Erklärung.
|
||||
|
||||
- User
|
||||
- Einkaufsliste
|
||||
- Zutaten
|
||||
- Einheiten
|
||||
|
||||
---
|
||||
|
||||
## User
|
||||
|
||||
### User erstellen
|
||||
```shell
|
||||
POST 127.0.0.1/DirektiveDesDons/signup
|
||||
|
||||
BODY
|
||||
{
|
||||
"username": "Benutzername",
|
||||
"email": "email",
|
||||
"password": "Passwort"
|
||||
}
|
||||
```
|
||||
|
||||
### Aktueller User ausgeben
|
||||
```shell
|
||||
GET 127.0.0.1/DirektiveDesDons/user
|
||||
```
|
||||
|
||||
### Login
|
||||
```shell
|
||||
POST 127.0.0.1/DirektiveDesDons/login
|
||||
|
||||
BODY
|
||||
{
|
||||
"username": "Benutzername",
|
||||
"password": "Passwort"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Einkaufsliste
|
||||
|
||||
### Einkaufsliste erstellen
|
||||
```shell
|
||||
POST 127.0.0.1/DirektiveDesDons/list
|
||||
|
||||
BODY
|
||||
{
|
||||
"name": "Einkaufsliste 1",
|
||||
"backgoundColor": "#123"
|
||||
}
|
||||
```
|
||||
|
||||
### Einkauslisten ausgeben
|
||||
```shell
|
||||
GET 127.0.0.1/DirektiveDesDons/list
|
||||
```
|
||||
|
||||
### Einkaufsliste ausgeben
|
||||
```shell
|
||||
GET 127.0.0.1/DirektiveDesDons/list/1
|
||||
```
|
||||
|
||||
### Einkaufsliste löschen
|
||||
```shell
|
||||
DELETE 127.0.0.1/DirektiveDesDons/list/1
|
||||
```
|
||||
|
||||
### Zutat zu Einkaufsliste hinzufügen
|
||||
```shell
|
||||
POST 127.0.0.1/DirektiveDesDons/list/1
|
||||
|
||||
BODY
|
||||
{
|
||||
"ingredientId": 1
|
||||
}
|
||||
```
|
||||
|
||||
### Zutat von Liste löschen
|
||||
```shell
|
||||
DELETE 127.0.0.1/DirektiveDesDons/list/1/4
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Zutaten
|
||||
|
||||
### Zutaten erstellen
|
||||
```shell
|
||||
POST 127.0.0.1/DirektiveDesDons/ingredient
|
||||
|
||||
BODY
|
||||
{
|
||||
"name": "Nüsse",
|
||||
"calories": "123",
|
||||
"quantity": "5",
|
||||
"unit": "st",
|
||||
"price": "12.5"
|
||||
}
|
||||
```
|
||||
|
||||
### Zutaten ausgeben
|
||||
```shell
|
||||
GET 127.0.0.1/DirektiveDesDons/ingredient
|
||||
```
|
||||
|
||||
### Zutat ausgeben
|
||||
```shell
|
||||
GET 127.0.0.1/DirektiveDesDons/ingredient/1
|
||||
```
|
||||
|
||||
### Zutat löschen
|
||||
```shell
|
||||
DELETE 127.0.0.1/DirektiveDesDons/ingredient/1
|
||||
```
|
||||
|
||||
### Zutat ändern
|
||||
```shell
|
||||
POST 127.0.0.1/DirektiveDesDons/ingredient/3
|
||||
|
||||
BODY
|
||||
{
|
||||
"name": "Nüsse",
|
||||
"calories": "123",
|
||||
"quantity": "5",
|
||||
"unit": "st",
|
||||
"price": "13.5"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## MengenEinheiten
|
||||
|
||||
### Einheiten auflisten
|
||||
```shell
|
||||
GET 127.0.0.1/DirektiveDesDons/unit
|
||||
```
|
||||
|
||||
### Einheit Erstellen
|
||||
```shell
|
||||
POST 127.0.0.1/DirektiveDesDons/unit
|
||||
|
||||
BODY
|
||||
{
|
||||
"name": "lbs"
|
||||
}
|
||||
```
|
||||
|
||||
### Einheit löschen
|
||||
```shell
|
||||
DELETE 127.0.0.1/DirektiveDesDons/unit/4
|
||||
```
|
BIN
ERD/2022-11-30_Einkaufsliste.vpp
Normal file
BIN
ERD/2022-11-30_Einkaufsliste.vpp
Normal file
Binary file not shown.
BIN
ERD/Einkaufsliste.jpg
Normal file
BIN
ERD/Einkaufsliste.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
@@ -31,6 +31,7 @@ class Response
|
||||
http_response_code($status);
|
||||
}
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
$data["status"] = http_response_code();
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
|
@@ -20,8 +20,9 @@ class Router
|
||||
*/
|
||||
public function __construct(string $pathname)
|
||||
{
|
||||
$this->uri = is_countable($_SERVER['REQUEST_URI']) && count($_SERVER['REQUEST_URI']) > 1 ? rtrim($_SERVER['REQUEST_URI'], "/") : $_SERVER['REQUEST_URI'];
|
||||
$this->uri = str_replace($pathname, "", $this->uri);
|
||||
$this->uri = str_replace($pathname, "", $_SERVER['REQUEST_URI']);
|
||||
$this->uri = strlen($this->uri) > 1 ? rtrim($this->uri, "/") : $this->uri;
|
||||
|
||||
$this->requestType = $_SERVER['REQUEST_METHOD'];
|
||||
$this->routes = [];
|
||||
$this->middleware = [];
|
||||
@@ -30,9 +31,9 @@ class Router
|
||||
$this->request = $_SERVER;
|
||||
}
|
||||
if (isset($_POST)) {
|
||||
$this->request["body"] = $_POST;
|
||||
$this->request["body"] = json_decode(file_get_contents('php://input'), true);
|
||||
}
|
||||
if (isset($_POST)) {
|
||||
if (isset($_GET)) {
|
||||
$this->request["params"] = $_GET;
|
||||
}
|
||||
|
||||
@@ -235,7 +236,7 @@ class Router
|
||||
if ($controller) {
|
||||
$controller($this->request, $this->response);
|
||||
} else {
|
||||
echo "404";
|
||||
$this->response->json(["status" => "404", "message" => "Not found"], 404);
|
||||
}
|
||||
}
|
||||
}
|
53
User.php
Normal file
53
User.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
require_once("BancaDati/BancaDati.php");
|
||||
use BancaDati\BancaDati;
|
||||
class User {
|
||||
public string $id;
|
||||
public string $username;
|
||||
public string $email;
|
||||
public string $token;
|
||||
private string $password;
|
||||
private BancaDati $db;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = new BancaDati();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function exists() {
|
||||
return true;
|
||||
}
|
||||
public function loginWithUsername(string $username, string $password) : string {
|
||||
$userObject = $this->db->select("utente", ["nomeUtente" => $username])[0];
|
||||
|
||||
if(!$userObject){
|
||||
return false;
|
||||
}
|
||||
$this->id = $userObject["id"];
|
||||
$this->username = $userObject["nomeUtente"];
|
||||
$this->email = $userObject["email"];
|
||||
$this->password = $userObject["parolaDordine"];
|
||||
$this->token = $this->db->createUUID();
|
||||
|
||||
if($this->password != $password){
|
||||
return false; // ungültiges password
|
||||
}
|
||||
|
||||
$this->db->update("utente", $this->id, ["gettone" => $this->token]);
|
||||
|
||||
return $this->token;
|
||||
}
|
||||
public function loginWithToken(string $token){
|
||||
$userObject = $this->db->select("utente", ["gettone" => $token])[0];
|
||||
if(!$userObject){
|
||||
return false;
|
||||
}
|
||||
$this->id = $userObject["id"];
|
||||
$this->username = $userObject["nomeUtente"];
|
||||
$this->email = $userObject["email"];
|
||||
$this->password = $userObject["parolaDordine"];
|
||||
$this->token = $token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
291
index.php
291
index.php
@@ -2,19 +2,304 @@
|
||||
|
||||
require_once("Router/Router.php");
|
||||
require_once("Router/Response.php");
|
||||
require_once("Router/Route.php");
|
||||
require_once("BancaDati/BancaDati.php");
|
||||
require_once("User.php");
|
||||
|
||||
use Router\Response;
|
||||
use Router\Router;
|
||||
use Router\Route;
|
||||
use BancaDati\BancaDati;
|
||||
|
||||
abstract class HTTP_STATUS_CODE {
|
||||
const OK = 200;
|
||||
const CREATED = 201;
|
||||
const BAD_REQUEST = 400;
|
||||
const FORBIDDEN = 403;
|
||||
const NOT_FOUNT = 404;
|
||||
}
|
||||
|
||||
|
||||
$app = new Router("/DirektiveDesDons");
|
||||
$db = new BancaDati();
|
||||
|
||||
|
||||
$app->get("/", function (array $req, Response $res) {
|
||||
$res->send("Hello World");
|
||||
/*
|
||||
* Middleware
|
||||
*/
|
||||
$app->use("/", function (array &$req, Response $res) {
|
||||
if (isset($_COOKIE["TOKEN"])) {
|
||||
$user = new User();
|
||||
if ($user->loginWithToken($_COOKIE["TOKEN"])) {
|
||||
$req["user"] = $user;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Home
|
||||
*/
|
||||
$app->get("/", function (array $req, Response $res) use ($db) {
|
||||
$res->json(["message" => "Die Einkaufsliste des Don",
|
||||
"name" => "Shopping List",
|
||||
"authors" => "Simon Bock, Johannes Kantz & Malte Schulze Hobeling"]);
|
||||
});
|
||||
|
||||
/*
|
||||
* User
|
||||
*/
|
||||
$app->get("/user", function (array $req, Response $res) {
|
||||
$res->send("user");
|
||||
if (isset($req["user"])) {
|
||||
$res->json(["id" => $req["user"]->id, "username" => $req["user"]->username, "email" => $req["user"]->email]);
|
||||
} else {
|
||||
$res->json(["status" => HTTP_STATUS_CODE::FORBIDDEN, "message" => "You are not logged in. Goto '/login' to login"]);
|
||||
}
|
||||
});
|
||||
$app->post("/signup", function (array $req, Response $res) use ($db) {
|
||||
$newUsername = $req["body"]["username"];
|
||||
$newPassword = $req["body"]["password"];
|
||||
$newEmail = $req["body"]["email"];
|
||||
$db->insert("utente", ["email" => "$newEmail", "parolaDordine" => "$newPassword", "nomeUtente" => "$newUsername"]);
|
||||
|
||||
$res->send("Account Created", HTTP_STATUS_CODE::CREATED);
|
||||
});
|
||||
|
||||
$app->post("/login", function (array $req, Response $res) use ($db) {
|
||||
$username = $req["body"]["username"];
|
||||
$password = $req["body"]["password"];
|
||||
|
||||
$user = new User();
|
||||
$usertoken = $user->loginWithUsername($username, $password);
|
||||
|
||||
if ($usertoken) {
|
||||
setcookie("TOKEN", $usertoken, time() + 3600); // 1h
|
||||
$res->json(["message" => "Login successful", "token" => $usertoken]);
|
||||
} else {
|
||||
$res->json(["message" => "Login failed"], HTTP_STATUS_CODE::FORBIDDEN);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Ingredients
|
||||
*/
|
||||
$app->route("/ingredient")
|
||||
->get(function (array $req, Response $res) use ($db) {
|
||||
$res->json(["data" => $db->select("ingredienti")]);
|
||||
})
|
||||
->post(function (array $req, Response $res) use ($db) {
|
||||
$name = $req["body"]["name"];
|
||||
$calories = $req["body"]["calories"];
|
||||
$quantity = $req["body"]["quantity"];
|
||||
$unit = $req["body"]["unit"];
|
||||
$price = $req["body"]["price"];
|
||||
|
||||
$unitInTable = $db->select("folla", ["unita" => $unit]);
|
||||
if (count($unitInTable) > 1) {
|
||||
$res->json(["message" => "Unit: " . $unit . " does not exist. Please create unit first"], HTTP_STATUS_CODE::BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
$unitId = $unitInTable[0]["id"];
|
||||
|
||||
$id = $db->insert("ingredienti", ["cognome" => "$name", "calorie" => "$calories", "quantita" => "$quantity", "follaID" => $unitId, "prezzo" => "$price"]);
|
||||
if (!$id) {
|
||||
$res->json(["message" => "Something went wrong when creating the Ingredient"], HTTP_STATUS_CODE::BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
|
||||
$res->json(["message" => "New ingredient has been listed",
|
||||
"ingredient" => $db->select("ingredienti", ["id" => $id])]);
|
||||
});
|
||||
$app->route("/ingredient/:id")
|
||||
->get(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$query = $db->select("ingredienti", ["id" => $id]);
|
||||
if(count($query) < 1){
|
||||
$res->json(["message" => "Item does not exists"]);
|
||||
return;
|
||||
}
|
||||
$ingredient = $query[0];
|
||||
$res->json(["data" => $ingredient]);
|
||||
})
|
||||
->put(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
|
||||
$name = $req["body"]["name"];
|
||||
$calories = $req["body"]["calories"];
|
||||
$quantity = $req["body"]["quantity"];
|
||||
$unit = $req["body"]["unit"];
|
||||
$price = $req["body"]["price"];
|
||||
|
||||
$unitInTable = $db->select("folla", ["unita" => $unit]);
|
||||
if (count($unitInTable) > 1) {
|
||||
$res->json(["message" => "Unit: " . $unit . " does not exist. Please create unit first"], HTTP_STATUS_CODE::BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
$unitId = $unitInTable[0]["id"];
|
||||
|
||||
$db->update("ingredienti", $id, ["cognome" => "$name", "calorie" => "$calories", "quantita" => "$quantity", "follaID" => $unitId, "prezzo" => "$price"]);
|
||||
|
||||
$res->json(["message" => "Ingredient has been updated", "data" => $db->select("ingredienti", ["id" => $id])[0]]);
|
||||
})
|
||||
->delete(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$db->delete("ingredienti", $id);
|
||||
$res->json(["message" => "Ingredient has been deleted"]);
|
||||
});
|
||||
|
||||
/*
|
||||
* Unit
|
||||
*/
|
||||
$app->route("/unit")
|
||||
->get(function (array $req, Response $res) use ($db) {
|
||||
$res->json(["data" => $db->select("folla")]);
|
||||
})
|
||||
->post(function (array $req, Response $res) use ($db) {
|
||||
$name = $req["body"]["name"];
|
||||
|
||||
if (!isset($name) || strlen($name) < 1 || strlen($name) > 200) {
|
||||
$res->json(["message" => "Invalid Request. Please follow the Documentation", HTTP_STATUS_CODE::BAD_REQUEST]);
|
||||
return;
|
||||
}
|
||||
|
||||
$selectWithSameName = $db->select("folla", ["unita" => $name]);
|
||||
if (count($selectWithSameName) >= 1) {
|
||||
$res->json(["message" => "Unit: " . $name . " already exists", "data" => $selectWithSameName[0]], HTTP_STATUS_CODE::BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
|
||||
$newUnitId = $db->insert("folla", ["unita" => $name]);
|
||||
$res->json(["message" => "Unit: '" . $name . "' created", "data" => $db->select("folla", ["id" => $newUnitId])[0]], HTTP_STATUS_CODE::CREATED);
|
||||
});
|
||||
$app->route("/unit/:id")
|
||||
->get(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$query = $db->select("folla", ["id" => $id]);
|
||||
if(count($query) < 1){
|
||||
$res->json(["message" => "Unit does not exists"]);
|
||||
return;
|
||||
}
|
||||
$unit = $query[0];
|
||||
$res->json(["data" => $unit]);
|
||||
})
|
||||
->put(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$name = $req["body"]["name"];
|
||||
|
||||
if (!isset($name) || strlen($name) < 1 || strlen($name) > 200) {
|
||||
$res->json(["message" => "Invalid Request. Please follow the Documentation", HTTP_STATUS_CODE::BAD_REQUEST]);
|
||||
return;
|
||||
}
|
||||
$db->update("folla", $id, ["unita" => $name]);
|
||||
$res->json(["message" => "Unit has been updated", "data" => $db->select("folla", ["id" => $id])]);
|
||||
})
|
||||
->delete(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$db->delete("folla", $id);
|
||||
$res->json(["message" => "Unit has been deleted"]);
|
||||
});
|
||||
|
||||
/*
|
||||
* List
|
||||
*/
|
||||
$app->use("/list", function (array $req, Response $res) {
|
||||
if (!isset($req["user"])) {
|
||||
$res->json(["message" => "You need to be signed in to use lists"], HTTP_STATUS_CODE::FORBIDDEN);
|
||||
die;
|
||||
}
|
||||
});
|
||||
|
||||
$app->route("/list")
|
||||
->get(function (array $req, Response $res) use ($db) {
|
||||
$lists = $db->select("elenco", ["utenteID" => $req["user"]->id]);
|
||||
// add items to list
|
||||
foreach ($lists as &$list) {
|
||||
$listId = $list["id"];
|
||||
$ingredients = $db->select("elencoIngredienti", ["elencoId" => $listId]);
|
||||
$ingredientData = [];
|
||||
foreach ($ingredients as &$ingredient) {
|
||||
$ingredientData[] = $db->select("Ingredienti", ["id" => $ingredient["ingredientiID"]]);
|
||||
}
|
||||
$list["inredients"] = $ingredientData;
|
||||
}
|
||||
$res->json(["data" => $lists]);
|
||||
})
|
||||
->post(function (array $req, Response $res) use ($db) {
|
||||
$name = $req["body"]["name"];
|
||||
$bgColor = $req["body"]["backgoundColor"] ?? "#fff";
|
||||
|
||||
if (!isset($name) || strlen($name) < 1) {
|
||||
$res->json(["message" => "Invalid Request. Please follow the Documentation"], HTTP_STATUS_CODE::BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
|
||||
$lastListId = $db->insert("elenco", ["cognome" => $name, "coloreDiSfondo" => $bgColor, "utenteID" => $req["user"]->id]);
|
||||
$res->json(["message" => "New List '" . $name . "' created", "data" => $db->select("elenco", ["id" => $lastListId])], HTTP_STATUS_CODE::CREATED);
|
||||
});
|
||||
$app->route("/list/:id")
|
||||
->get(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$query = $db->select("elenco", ["id" => $id, "utenteID" => $req["user"]->id]);
|
||||
|
||||
if (count($query) < 1) {
|
||||
$res->json(["message" => "List does not exists or you dont have permissions to view it"]);
|
||||
return;
|
||||
}
|
||||
$list = $query[0];
|
||||
|
||||
$listId = $list["id"];
|
||||
$ingredients = $db->select("elencoIngredienti", ["elencoId" => $listId]);
|
||||
$ingredientData = [];
|
||||
foreach ($ingredients as &$ingredient) {
|
||||
$ingredientData[] = $db->select("Ingredienti", ["id" => $ingredient["ingredientiID"]]);
|
||||
}
|
||||
$list["inredients"] = $ingredientData;
|
||||
|
||||
$res->json(["data" => $list]);
|
||||
})
|
||||
->post(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$ingredientId = $req["body"]["ingredientId"];
|
||||
|
||||
if (!isset($ingredientId)) {
|
||||
$res->json(["message" => "You need to set a valid 'ingredientId'", HTTP_STATUS_CODE::BAD_REQUEST]);
|
||||
return;
|
||||
}
|
||||
|
||||
$newId = $db->insert("elencoIngredienti", ["ingredientiID" => $ingredientId, "elencoID" => $id]);
|
||||
if(!$newId){
|
||||
$res->json(["message" => "Cannot insert item in list"], HTTP_STATUS_CODE::BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
$res->json(["message" => "Item has been added"]);
|
||||
})
|
||||
->delete(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
|
||||
$list = $db->select("elenco", ["id" => $id]);
|
||||
if (count($list) < 1) {
|
||||
$res->json(["message" => "List does not exist"]);
|
||||
return;
|
||||
}
|
||||
if ($list[0]["utenteID"] != $req["user"]->id) {
|
||||
$res->json(["message" => "You have no permissions the delete this list"], HTTP_STATUS_CODE::FORBIDDEN);
|
||||
return;
|
||||
}
|
||||
|
||||
$db->delete("elenco", $id);
|
||||
$res->json(["message" => "List has been deleted"]);
|
||||
});
|
||||
$app->delete("/list/:id/:item", function (array $req, Response $res) use ($db) {
|
||||
$listId = $req["params"]["id"];
|
||||
$itemId = $req["params"]["item"];
|
||||
|
||||
$list = $db->select("elenco", ["id" => $listId, "utenteID" => $req["user"]->id]);
|
||||
if(count($list) < 1){
|
||||
$res->json(["message" => "List does not exist or you dont have the permissions to edit the list"]);
|
||||
return;
|
||||
}
|
||||
|
||||
$db->delete("elencoIngredienti", $itemId);
|
||||
$res->json(["message" => "Item has been deleted"]);
|
||||
});
|
||||
|
||||
$app->start();
|
27
italienIntoGerman.txt
Normal file
27
italienIntoGerman.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
ingredienti = Zutaten
|
||||
cognome = Name
|
||||
caloriePerCento = Kalorien pro Gramm
|
||||
ilPeso = Gewicht
|
||||
prezzo = Preis
|
||||
|
||||
folla = Menge
|
||||
unita = Einheit
|
||||
|
||||
elenco = Liste
|
||||
creatore = Ersteller
|
||||
coloreDiSfondo = Hintergrundfarbe
|
||||
|
||||
utente = Benutzer
|
||||
email = Email
|
||||
parolaDordine = Passwort
|
||||
nomeUtente = Benutzernamen
|
||||
gettone = Token (für die Session)
|
||||
|
||||
elencoIngredienti = Liste_Zutaten
|
||||
ingredientiID = ZutatenID
|
||||
elencoID = ListeID
|
||||
follaID = MengeID
|
||||
|
||||
utenteElenco = Benutzer_Liste
|
||||
elencoID = ListeID
|
||||
utenteID = BenutzerID
|
Reference in New Issue
Block a user