├── .gitignore ├── Appendix A ├── authenticating_requests │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── docker-compose.yml │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ └── src │ │ ├── auth │ │ ├── jwt.rs │ │ ├── mod.rs │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ │ ├── our_jwt.rs │ │ ├── schema.rs │ │ └── to_do │ │ ├── mod.rs │ │ └── structs │ │ ├── base.rs │ │ ├── done.rs │ │ ├── mod.rs │ │ ├── pending.rs │ │ └── traits │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ └── mod.rs ├── connecting_to_database │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── docker-compose.yml │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ └── src │ │ ├── database.rs │ │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ │ ├── schema.rs │ │ └── to_do │ │ ├── mod.rs │ │ └── structs │ │ ├── base.rs │ │ ├── done.rs │ │ ├── mod.rs │ │ ├── pending.rs │ │ └── traits │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ └── mod.rs ├── passing_parameters │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── docker-compose.yml │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ └── src │ │ ├── auth │ │ ├── jwt.rs │ │ ├── mod.rs │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ │ ├── our_jwt.rs │ │ ├── schema.rs │ │ └── to_do │ │ ├── mod.rs │ │ └── structs │ │ ├── base.rs │ │ ├── done.rs │ │ ├── mod.rs │ │ ├── pending.rs │ │ └── traits │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ └── mod.rs └── warp_server │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ └── main.rs ├── Chapter01 ├── error_handling.rs ├── hash_maps.rs ├── integers_and_floats.rs ├── lifetimes.rs ├── macros.rs ├── scopes.rs ├── strings.rs ├── structs.rs ├── traits.rs └── vectors_and_arrays.rs ├── Chapter02 ├── building_structs │ ├── Cargo.toml │ └── src │ │ ├── main.rs │ │ └── to_do │ │ ├── mod.rs │ │ └── structs │ │ ├── base.rs │ │ ├── done.rs │ │ ├── mod.rs │ │ └── pending.rs ├── defining_traits │ ├── Cargo.toml │ └── src │ │ ├── main.rs │ │ └── to_do │ │ ├── mod.rs │ │ └── structs │ │ ├── base.rs │ │ ├── done.rs │ │ ├── mod.rs │ │ ├── pending.rs │ │ └── traits │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ └── mod.rs ├── json_files │ ├── Cargo.toml │ ├── src │ │ ├── main.rs │ │ ├── state.rs │ │ └── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── state.json ├── managing_structs │ ├── Cargo.toml │ └── src │ │ ├── main.rs │ │ └── to_do │ │ ├── mod.rs │ │ └── structs │ │ ├── base.rs │ │ ├── done.rs │ │ ├── mod.rs │ │ └── pending.rs ├── processing_structs_and_traits │ ├── Cargo.toml │ ├── src │ │ ├── main.rs │ │ ├── processes.rs │ │ ├── state.rs │ │ └── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── state.json ├── revisiting_traits │ ├── Cargo.lock │ ├── Cargo.toml │ ├── src │ │ ├── main.rs │ │ ├── state.rs │ │ └── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── state.json └── web_app │ ├── Cargo.toml │ └── src │ └── main.rs ├── Chapter03 ├── async_functions │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── basic_async │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── basic_setup │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── managing_views │ ├── Cargo.toml │ └── src │ │ ├── main.rs │ │ └── views │ │ ├── auth │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ └── path.rs ├── multiple_servers │ ├── Cargo.toml │ └── src │ │ └── main.rs └── one_page_app │ ├── Cargo.toml │ └── src │ └── main.rs ├── Chapter04 ├── basic_setup │ ├── Cargo.toml │ ├── src │ │ ├── main.rs │ │ ├── processes.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ └── path.rs │ └── state.json ├── extracting_data │ ├── Cargo.lock │ ├── Cargo.toml │ ├── src │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── processes.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── token.rs │ └── state.json ├── json_serialization │ ├── Cargo.toml │ ├── src │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── processes.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ └── to_do │ │ │ ├── create.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ └── state.json └── passing_parameters │ ├── Cargo.toml │ ├── src │ ├── main.rs │ ├── processes.rs │ ├── state.rs │ ├── to_do │ │ ├── mod.rs │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── views │ │ ├── auth │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── path.rs │ │ └── to_do │ │ ├── create.rs │ │ └── mod.rs │ └── state.json ├── Chapter05 ├── displaying_html │ ├── Cargo.toml │ ├── src │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── processes.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── token.rs │ ├── state.json │ └── templates │ │ └── main.html ├── injecting_css │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── javascript │ │ └── main.js │ ├── src │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── processes.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── token.rs │ ├── state.json │ └── templates │ │ └── main.html ├── injecting_header │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── javascript │ │ └── main.js │ ├── src │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── processes.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── token.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ └── main.html └── injecting_javascript │ ├── Cargo.lock │ ├── Cargo.toml │ ├── javascript │ └── main.js │ ├── src │ ├── json_serialization │ │ ├── mod.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ ├── main.rs │ ├── processes.rs │ ├── state.rs │ ├── to_do │ │ ├── mod.rs │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── views │ │ ├── app │ │ ├── content_loader.rs │ │ ├── items.rs │ │ └── mod.rs │ │ ├── auth │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── path.rs │ │ ├── to_do │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ ├── mod.rs │ │ └── utils.rs │ │ └── token.rs │ ├── state.json │ └── templates │ └── main.html ├── Chapter06 ├── connecting_to_db │ ├── .env │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── processes.rs │ │ ├── schema.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── token.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ └── main.html ├── data_models │ ├── .env │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ └── mod.rs │ │ ├── processes.rs │ │ ├── schema.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── token.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ └── main.html └── defining_db │ ├── Cargo.toml │ ├── css │ ├── base.css │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ └── main.js │ ├── migrations │ ├── .gitkeep │ ├── 00000000000000_diesel_initial_setup │ │ ├── down.sql │ │ └── up.sql │ └── 2020-09-28-003845_create_items │ │ ├── down.sql │ │ └── up.sql │ ├── src │ ├── database.rs │ ├── json_serialization │ │ ├── mod.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ ├── main.rs │ ├── processes.rs │ ├── schema.rs │ ├── state.rs │ ├── to_do │ │ ├── mod.rs │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── views │ │ ├── app │ │ ├── content_loader.rs │ │ ├── items.rs │ │ └── mod.rs │ │ ├── auth │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── path.rs │ │ ├── to_do │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ ├── mod.rs │ │ └── utils.rs │ │ └── token.rs │ ├── state.json │ └── templates │ ├── components │ ├── header.css │ └── header.html │ └── main.html ├── Chapter07 ├── Authenticating_users │ ├── .env │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── auth │ │ │ ├── jwt.rs │ │ │ ├── mod.rs │ │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── processes.rs │ │ ├── schema.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ └── main.html ├── creating_user_models │ ├── .env │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── processes.rs │ │ ├── schema.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ ├── token.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ └── main.html ├── intercepting_calls │ ├── .env │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── mod.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ └── mod.rs │ │ ├── processes.rs │ │ ├── schema.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── token.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ └── main.html └── managing_user_sessions │ ├── .env │ ├── Cargo.toml │ ├── css │ ├── base.css │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ ├── login.js │ └── main.js │ ├── migrations │ ├── .gitkeep │ ├── 00000000000000_diesel_initial_setup │ │ ├── down.sql │ │ └── up.sql │ ├── 2020-10-04-211444_create_to_do_items │ │ ├── down.sql │ │ └── up.sql │ └── 2020-10-21-003346_create_users │ │ ├── down.sql │ │ └── up.sql │ ├── src │ ├── auth │ │ ├── jwt.rs │ │ ├── mod.rs │ │ └── processes.rs │ ├── database.rs │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ ├── main.rs │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ ├── processes.rs │ ├── schema.rs │ ├── state.rs │ ├── to_do │ │ ├── mod.rs │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── views │ │ ├── app │ │ ├── content_loader.rs │ │ ├── items.rs │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── auth │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── path.rs │ │ ├── to_do │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ ├── mod.rs │ │ └── utils.rs │ │ └── users │ │ ├── create.rs │ │ └── mod.rs │ ├── state.json │ └── templates │ ├── components │ ├── header.css │ └── header.html │ ├── login.html │ └── main.html ├── Chapter08 ├── caching │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ ├── login.js │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── auth │ │ │ ├── jwt.rs │ │ │ ├── mod.rs │ │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── login.rs │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── processes.rs │ │ ├── schema.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ ├── login.html │ │ └── main.html ├── logging │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ ├── login.js │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── auth │ │ │ ├── jwt.rs │ │ │ ├── mod.rs │ │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── login.rs │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── processes.rs │ │ ├── schema.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ ├── login.html │ │ └── main.html ├── mapping_our_layers │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ ├── login.js │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── auth │ │ │ ├── jwt.rs │ │ │ ├── mod.rs │ │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── login.rs │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── processes.rs │ │ ├── schema.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ ├── login.html │ │ └── main.html ├── stateless_sessions │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ ├── login.js │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── auth │ │ │ ├── jwt.rs │ │ │ ├── mod.rs │ │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── login.rs │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── processes.rs │ │ ├── schema.rs │ │ ├── state.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ ├── state.json │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ ├── login.html │ │ └── main.html └── uniform_interface │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── css │ ├── base.css │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ ├── login.js │ └── main.js │ ├── migrations │ ├── .gitkeep │ ├── 00000000000000_diesel_initial_setup │ │ ├── down.sql │ │ └── up.sql │ ├── 2020-10-04-211444_create_to_do_items │ │ ├── down.sql │ │ └── up.sql │ └── 2020-10-21-003346_create_users │ │ ├── down.sql │ │ └── up.sql │ ├── src │ ├── auth │ │ ├── jwt.rs │ │ ├── mod.rs │ │ └── processes.rs │ ├── database.rs │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ ├── main.rs │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ ├── processes.rs │ ├── schema.rs │ ├── state.rs │ ├── to_do │ │ ├── mod.rs │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── views │ │ ├── app │ │ ├── content_loader.rs │ │ ├── items.rs │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── auth │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── path.rs │ │ ├── to_do │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ ├── mod.rs │ │ └── utils.rs │ │ └── users │ │ ├── create.rs │ │ └── mod.rs │ ├── state.json │ └── templates │ ├── components │ ├── header.css │ └── header.html │ ├── login.html │ └── main.html ├── Chapter09 ├── postman_testing │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ ├── login.js │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── auth │ │ │ ├── jwt.rs │ │ │ ├── mod.rs │ │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── login.rs │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── schema.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ ├── state.json │ ├── templates │ │ ├── components │ │ │ ├── header.css │ │ │ └── header.html │ │ ├── login.html │ │ └── main.html │ └── to_do_items.postman_collection.json └── unit_testing │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── css │ ├── base.css │ └── main.css │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ ├── login.js │ └── main.js │ ├── migrations │ ├── .gitkeep │ ├── 00000000000000_diesel_initial_setup │ │ ├── down.sql │ │ └── up.sql │ ├── 2020-10-04-211444_create_to_do_items │ │ ├── down.sql │ │ └── up.sql │ ├── 2020-10-21-003346_create_users │ │ ├── down.sql │ │ └── up.sql │ └── 2020-10-31-154850_user_title_constraint │ │ ├── down.sql │ │ └── up.sql │ ├── src │ ├── auth │ │ ├── jwt.rs │ │ ├── mod.rs │ │ └── processes.rs │ ├── database.rs │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ ├── main.rs │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ ├── schema.rs │ ├── to_do │ │ ├── mod.rs │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── views │ │ ├── app │ │ ├── content_loader.rs │ │ ├── items.rs │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── auth │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── path.rs │ │ ├── to_do │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ ├── mod.rs │ │ └── utils.rs │ │ └── users │ │ ├── create.rs │ │ └── mod.rs │ ├── state.json │ └── templates │ ├── components │ ├── header.css │ └── header.html │ ├── login.html │ └── main.html ├── Chapter10 ├── deploy_to_docker_hub │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Dockerfile │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── deploy │ │ ├── docker-compose.yml │ │ ├── nginx │ │ │ └── nginx.conf │ │ └── push_to_dockerhub.sh │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ ├── login.js │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── auth │ │ │ ├── jwt.rs │ │ │ ├── mod.rs │ │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── login.rs │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── schema.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ ├── login.html │ │ └── main.html ├── deploy_to_server │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Dockerfile │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── deploy │ │ ├── docker-compose.yml │ │ ├── nginx │ │ │ └── nginx.conf │ │ ├── push_to_dockerhub.sh │ │ └── push_to_server.sh │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ ├── login.js │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── auth │ │ │ ├── jwt.rs │ │ │ ├── mod.rs │ │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── login.rs │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── schema.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ ├── login.html │ │ └── main.html ├── persist_on_server │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Dockerfile │ ├── css │ │ ├── base.css │ │ └── main.css │ ├── deploy │ │ ├── docker-compose.yml │ │ ├── nginx │ │ │ └── nginx.conf │ │ ├── push_to_dockerhub.sh │ │ └── push_to_server.sh │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ │ ├── login.js │ │ └── main.js │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── src │ │ ├── auth │ │ │ ├── jwt.rs │ │ │ ├── mod.rs │ │ │ └── processes.rs │ │ ├── database.rs │ │ ├── json_serialization │ │ │ ├── login.rs │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ ├── to_do_item.rs │ │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ │ ├── item │ │ │ │ ├── item.rs │ │ │ │ ├── mod.rs │ │ │ │ └── new_item.rs │ │ │ ├── mod.rs │ │ │ └── user │ │ │ │ ├── mod.rs │ │ │ │ ├── new_user.rs │ │ │ │ └── user.rs │ │ ├── schema.rs │ │ ├── to_do │ │ │ ├── mod.rs │ │ │ └── structs │ │ │ │ ├── base.rs │ │ │ │ ├── done.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pending.rs │ │ │ │ └── traits │ │ │ │ ├── create.rs │ │ │ │ ├── delete.rs │ │ │ │ ├── edit.rs │ │ │ │ ├── get.rs │ │ │ │ └── mod.rs │ │ └── views │ │ │ ├── app │ │ │ ├── content_loader.rs │ │ │ ├── items.rs │ │ │ ├── login.rs │ │ │ ├── logout.rs │ │ │ └── mod.rs │ │ │ ├── auth │ │ │ ├── login.rs │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── path.rs │ │ │ ├── to_do │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ ├── mod.rs │ │ │ └── utils.rs │ │ │ └── users │ │ │ ├── create.rs │ │ │ └── mod.rs │ └── templates │ │ ├── components │ │ ├── header.css │ │ └── header.html │ │ ├── login.html │ │ └── main.html └── run_locally │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Dockerfile │ ├── css │ ├── base.css │ └── main.css │ ├── deploy │ ├── docker-compose.yml │ └── nginx │ │ └── nginx.conf │ ├── diesel.toml │ ├── docker-compose.yml │ ├── javascript │ ├── login.js │ └── main.js │ ├── migrations │ ├── .gitkeep │ ├── 00000000000000_diesel_initial_setup │ │ ├── down.sql │ │ └── up.sql │ ├── 2020-10-04-211444_create_to_do_items │ │ ├── down.sql │ │ └── up.sql │ ├── 2020-10-21-003346_create_users │ │ ├── down.sql │ │ └── up.sql │ └── 2020-10-31-154850_user_title_constraint │ │ ├── down.sql │ │ └── up.sql │ ├── src │ ├── auth │ │ ├── jwt.rs │ │ ├── mod.rs │ │ └── processes.rs │ ├── database.rs │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ ├── main.rs │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ ├── schema.rs │ ├── to_do │ │ ├── mod.rs │ │ └── structs │ │ │ ├── base.rs │ │ │ ├── done.rs │ │ │ ├── mod.rs │ │ │ ├── pending.rs │ │ │ └── traits │ │ │ ├── create.rs │ │ │ ├── delete.rs │ │ │ ├── edit.rs │ │ │ ├── get.rs │ │ │ └── mod.rs │ └── views │ │ ├── app │ │ ├── content_loader.rs │ │ ├── items.rs │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── auth │ │ ├── login.rs │ │ ├── logout.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── path.rs │ │ ├── to_do │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ ├── mod.rs │ │ └── utils.rs │ │ └── users │ │ ├── create.rs │ │ └── mod.rs │ └── templates │ ├── components │ ├── header.css │ └── header.html │ ├── login.html │ └── main.html ├── Chapter11 ├── authentication │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Rocket.toml │ ├── diesel.toml │ ├── docker-compose.yml │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ └── src │ │ ├── database.rs │ │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ │ ├── jwt.rs │ │ ├── main.rs │ │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ │ ├── schema.rs │ │ └── to_do │ │ ├── mod.rs │ │ └── structs │ │ ├── base.rs │ │ ├── done.rs │ │ ├── mod.rs │ │ ├── pending.rs │ │ └── traits │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ └── mod.rs ├── basic_setup │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── connecting_to_database │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Rocket.toml │ ├── diesel.toml │ ├── docker-compose.yml │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ └── src │ │ ├── database.rs │ │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ │ ├── main.rs │ │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ │ ├── schema.rs │ │ └── to_do │ │ ├── mod.rs │ │ └── structs │ │ ├── base.rs │ │ ├── done.rs │ │ ├── mod.rs │ │ ├── pending.rs │ │ └── traits │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ └── mod.rs ├── middleware │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Rocket.toml │ ├── diesel.toml │ ├── docker-compose.yml │ ├── migrations │ │ ├── .gitkeep │ │ ├── 00000000000000_diesel_initial_setup │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-04-211444_create_to_do_items │ │ │ ├── down.sql │ │ │ └── up.sql │ │ ├── 2020-10-21-003346_create_users │ │ │ ├── down.sql │ │ │ └── up.sql │ │ └── 2020-10-31-154850_user_title_constraint │ │ │ ├── down.sql │ │ │ └── up.sql │ └── src │ │ ├── database.rs │ │ ├── json_serialization │ │ ├── login.rs │ │ ├── mod.rs │ │ ├── new_user.rs │ │ ├── to_do_item.rs │ │ └── to_do_items.rs │ │ ├── jwt.rs │ │ ├── main.rs │ │ ├── models │ │ ├── item │ │ │ ├── item.rs │ │ │ ├── mod.rs │ │ │ └── new_item.rs │ │ ├── mod.rs │ │ └── user │ │ │ ├── mod.rs │ │ │ ├── new_user.rs │ │ │ └── user.rs │ │ ├── not_found.rs │ │ ├── schema.rs │ │ └── to_do │ │ ├── mod.rs │ │ └── structs │ │ ├── base.rs │ │ ├── done.rs │ │ ├── mod.rs │ │ ├── pending.rs │ │ └── traits │ │ ├── create.rs │ │ ├── delete.rs │ │ ├── edit.rs │ │ ├── get.rs │ │ └── mod.rs └── passing_data │ ├── .env │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Rocket.toml │ ├── diesel.toml │ ├── docker-compose.yml │ ├── migrations │ ├── .gitkeep │ ├── 00000000000000_diesel_initial_setup │ │ ├── down.sql │ │ └── up.sql │ ├── 2020-10-04-211444_create_to_do_items │ │ ├── down.sql │ │ └── up.sql │ ├── 2020-10-21-003346_create_users │ │ ├── down.sql │ │ └── up.sql │ └── 2020-10-31-154850_user_title_constraint │ │ ├── down.sql │ │ └── up.sql │ └── src │ ├── database.rs │ ├── json_serialization │ ├── login.rs │ ├── mod.rs │ ├── new_user.rs │ ├── to_do_item.rs │ └── to_do_items.rs │ ├── jwt.rs │ ├── main.rs │ ├── models │ ├── item │ │ ├── item.rs │ │ ├── mod.rs │ │ └── new_item.rs │ ├── mod.rs │ └── user │ │ ├── mod.rs │ │ ├── new_user.rs │ │ └── user.rs │ ├── not_found.rs │ ├── schema.rs │ └── to_do │ ├── mod.rs │ └── structs │ ├── base.rs │ ├── done.rs │ ├── mod.rs │ ├── pending.rs │ └── traits │ ├── create.rs │ ├── delete.rs │ ├── edit.rs │ ├── get.rs │ └── mod.rs ├── Dummy.txt ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # intelliJ 3 | .idea 4 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Appendix A/authenticating_requests/migrations/.gitkeep -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Appendix A/authenticating_requests/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Appendix A/connecting_to_database/migrations/.gitkeep -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Appendix A/connecting_to_database/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Appendix A/passing_parameters/migrations/.gitkeep -------------------------------------------------------------------------------- /Appendix A/passing_parameters/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Appendix A/passing_parameters/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Appendix A/passing_parameters/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Appendix A/warp_server/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "warp_server" 3 | version = "0.1.0" 4 | authors = ["maxwellflitton"] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | tokio = { version = "0.2", features = ["full"] } 11 | warp = "0.2" 12 | log = "0.4" 13 | pretty_env_logger = "0.3" 14 | -------------------------------------------------------------------------------- /Chapter02/building_structs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "todo_app" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | serde_json = { version = "1.0", default-features = false, features = ["alloc"] } 11 | -------------------------------------------------------------------------------- /Chapter02/building_structs/src/to_do/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod structs; 2 | -------------------------------------------------------------------------------- /Chapter02/building_structs/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | mod base; 2 | pub mod done; 3 | pub mod pending; 4 | -------------------------------------------------------------------------------- /Chapter02/defining_traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "todo_app" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | serde_json = { version = "1.0", default-features = false, features = ["alloc"] } 11 | -------------------------------------------------------------------------------- /Chapter02/defining_traits/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter02/defining_traits/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter02/json_files/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "todo_app" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | serde_json = { version = "1.0", default-features = false, features = ["alloc"] } 11 | -------------------------------------------------------------------------------- /Chapter02/json_files/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter02/json_files/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter02/json_files/state.json: -------------------------------------------------------------------------------- 1 | {"shopping":"pending","test":"test","washing":"done"} -------------------------------------------------------------------------------- /Chapter02/managing_structs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "todo_app" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | serde_json = { version = "1.0", default-features = false, features = ["alloc"] } 11 | -------------------------------------------------------------------------------- /Chapter02/managing_structs/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | mod base; 2 | pub mod done; 3 | pub mod pending; 4 | -------------------------------------------------------------------------------- /Chapter02/processing_structs_and_traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "todo_app" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | serde_json = { version = "1.0", default-features = false, features = ["alloc"] } 11 | -------------------------------------------------------------------------------- /Chapter02/processing_structs_and_traits/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter02/processing_structs_and_traits/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter02/processing_structs_and_traits/state.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /Chapter02/revisiting_traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "todo_app" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | serde_json = { version = "1.0", default-features = false, features = ["alloc"] } 11 | -------------------------------------------------------------------------------- /Chapter02/revisiting_traits/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter02/revisiting_traits/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter02/revisiting_traits/state.json: -------------------------------------------------------------------------------- 1 | {"running":"create","shopping":"pending","test":"pending","washing":"pending"} -------------------------------------------------------------------------------- /Chapter02/web_app/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "web_app" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | rand = "0.7.3" 11 | -------------------------------------------------------------------------------- /Chapter03/async_functions/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "async_functions" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | futures = "0.3.5" 11 | async-std = "1.6.3" 12 | -------------------------------------------------------------------------------- /Chapter03/basic_async/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "basic_async" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /Chapter03/basic_setup/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "basic_setup" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | actix-web = "2" 11 | actix-rt = "1.0" 12 | -------------------------------------------------------------------------------- /Chapter03/managing_views/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "managing_views" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | actix-web = "2" 11 | actix-rt = "1.0" 12 | -------------------------------------------------------------------------------- /Chapter03/managing_views/src/main.rs: -------------------------------------------------------------------------------- 1 | use actix_web::{App, HttpServer}; 2 | mod views; 3 | 4 | 5 | #[actix_rt::main] 6 | async fn main() -> std::io::Result<()> { 7 | HttpServer::new(|| { 8 | let app = App::new().configure(views::views_factory); 9 | return app 10 | }) 11 | .bind("127.0.0.1:8000")? 12 | .run() 13 | .await 14 | } 15 | -------------------------------------------------------------------------------- /Chapter03/managing_views/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter03/managing_views/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter03/multiple_servers/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "multiple_servers" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | actix-web = "2" 11 | actix-rt = "1.0" 12 | futures = "0.3" 13 | -------------------------------------------------------------------------------- /Chapter03/one_page_app/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "one_page_app" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | actix-web = "2" 11 | actix-rt = "1.0" 12 | -------------------------------------------------------------------------------- /Chapter04/basic_setup/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter04/basic_setup/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter04/basic_setup/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter04/basic_setup/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter04/basic_setup/state.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /Chapter04/extracting_data/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | -------------------------------------------------------------------------------- /Chapter04/extracting_data/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter04/extracting_data/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter04/extracting_data/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter04/extracting_data/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter04/extracting_data/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter04/extracting_data/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"pending","washing":"done"} -------------------------------------------------------------------------------- /Chapter04/json_serialization/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; -------------------------------------------------------------------------------- /Chapter04/json_serialization/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter04/json_serialization/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter04/json_serialization/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter04/json_serialization/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter04/json_serialization/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"pending","washing":"pending"} -------------------------------------------------------------------------------- /Chapter04/passing_parameters/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter04/passing_parameters/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter04/passing_parameters/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter04/passing_parameters/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter04/passing_parameters/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"pending","washing":"pending"} -------------------------------------------------------------------------------- /Chapter05/displaying_html/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | -------------------------------------------------------------------------------- /Chapter05/displaying_html/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter05/displaying_html/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter05/displaying_html/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter05/displaying_html/src/views/app/content_loader.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | 4 | pub fn read_file(file_path: String) -> String { 5 | let data: String = fs::read_to_string( 6 | file_path).expect("Unable to read file"); 7 | return data 8 | } 9 | -------------------------------------------------------------------------------- /Chapter05/displaying_html/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter05/displaying_html/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter05/displaying_html/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"pending","washing":"done"} -------------------------------------------------------------------------------- /Chapter05/injecting_css/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | -------------------------------------------------------------------------------- /Chapter05/injecting_css/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter05/injecting_css/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter05/injecting_css/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter05/injecting_css/src/views/app/content_loader.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | 4 | pub fn read_file(file_path: String) -> String { 5 | let data: String = fs::read_to_string( 6 | file_path).expect("Unable to read file"); 7 | return data 8 | } 9 | -------------------------------------------------------------------------------- /Chapter05/injecting_css/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter05/injecting_css/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter05/injecting_css/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending"} -------------------------------------------------------------------------------- /Chapter05/injecting_header/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | -------------------------------------------------------------------------------- /Chapter05/injecting_header/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter05/injecting_header/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter05/injecting_header/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter05/injecting_header/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter05/injecting_header/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter05/injecting_header/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending"} -------------------------------------------------------------------------------- /Chapter05/injecting_header/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter05/injecting_header/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter05/injecting_javascript/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | -------------------------------------------------------------------------------- /Chapter05/injecting_javascript/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter05/injecting_javascript/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter05/injecting_javascript/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter05/injecting_javascript/src/views/app/content_loader.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | 4 | pub fn read_file(file_path: String) -> String { 5 | let data: String = fs::read_to_string( 6 | file_path).expect("Unable to read file"); 7 | return data 8 | } 9 | -------------------------------------------------------------------------------- /Chapter05/injecting_javascript/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter05/injecting_javascript/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter05/injecting_javascript/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"pending","eat cereal for breakfast":"pending","eat ramen for breakfast":"done"} -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter06/connecting_to_db/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/src/schema.rs: -------------------------------------------------------------------------------- 1 | table! { 2 | to_do (id) { 3 | id -> Int4, 4 | title -> Varchar, 5 | status -> Varchar, 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending"} -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter06/connecting_to_db/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter06/data_models/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter06/data_models/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter06/data_models/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter06/data_models/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter06/data_models/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter06/data_models/migrations/00000000000000_diesel_initial_setup/down.sql: -------------------------------------------------------------------------------- 1 | -- This file was automatically created by Diesel to setup helper functions 2 | -- and other internal bookkeeping. This file is safe to edit, any future 3 | -- changes will be added to existing projects as new migrations. 4 | 5 | DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); 6 | DROP FUNCTION IF EXISTS diesel_set_updated_at(); 7 | -------------------------------------------------------------------------------- /Chapter06/data_models/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter06/data_models/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | 3 | 4 | #[derive(Queryable, Identifiable)] 5 | #[table_name="to_do"] 6 | pub struct Item { 7 | pub id: i32, 8 | pub title: String, 9 | pub status: String, 10 | } 11 | 12 | impl Item { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/models/item/new_item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | 3 | 4 | #[derive(Insertable)] 5 | #[table_name="to_do"] 6 | pub struct NewItem { 7 | pub title: String, 8 | pub status: String, 9 | } 10 | 11 | impl NewItem { 12 | pub fn new(title: String) -> NewItem { 13 | return NewItem{title, status: String::from("pending")} 14 | } 15 | } -------------------------------------------------------------------------------- /Chapter06/data_models/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/schema.rs: -------------------------------------------------------------------------------- 1 | table! { 2 | to_do (id) { 3 | id -> Int4, 4 | title -> Varchar, 5 | status -> Varchar, 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter06/data_models/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter06/data_models/src/views/to_do/get.rs: -------------------------------------------------------------------------------- 1 | use actix_web::Responder; 2 | 3 | use super::utils::return_state; 4 | 5 | 6 | /// This view gets all of the saved to do items that are stored in the state.json file. 7 | /// 8 | /// # Arguments 9 | /// None 10 | /// 11 | /// # Returns 12 | /// * (web::Json): all of the stored to do items 13 | pub async fn get() -> impl Responder { 14 | return return_state() 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/data_models/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter06/data_models/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter06/data_models/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter06/defining_db/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter06/defining_db/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter06/defining_db/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter06/defining_db/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter06/defining_db/migrations/00000000000000_diesel_initial_setup/down.sql: -------------------------------------------------------------------------------- 1 | -- This file was automatically created by Diesel to setup helper functions 2 | -- and other internal bookkeeping. This file is safe to edit, any future 3 | -- changes will be added to existing projects as new migrations. 4 | 5 | DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); 6 | DROP FUNCTION IF EXISTS diesel_set_updated_at(); 7 | -------------------------------------------------------------------------------- /Chapter06/defining_db/migrations/2020-09-28-003845_create_items/down.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE to_do_items 2 | -------------------------------------------------------------------------------- /Chapter06/defining_db/migrations/2020-09-28-003845_create_items/up.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE to_do_items ( 2 | id SERIAL PRIMARY KEY, 3 | title VARCHAR NOT NULL, 4 | status VARCHAR NOT NULL 5 | ) 6 | -------------------------------------------------------------------------------- /Chapter06/defining_db/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | -------------------------------------------------------------------------------- /Chapter06/defining_db/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter06/defining_db/src/schema.rs: -------------------------------------------------------------------------------- 1 | table! { 2 | to_do_items (id) { 3 | id -> Int4, 4 | title -> Varchar, 5 | status -> Varchar, 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Chapter06/defining_db/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter06/defining_db/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter06/defining_db/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter06/defining_db/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter06/defining_db/src/views/to_do/get.rs: -------------------------------------------------------------------------------- 1 | use actix_web::Responder; 2 | 3 | use super::utils::return_state; 4 | 5 | 6 | /// This view gets all of the saved to do items that are stored in the state.json file. 7 | /// 8 | /// # Arguments 9 | /// None 10 | /// 11 | /// # Returns 12 | /// * (web::Json): all of the stored to do items 13 | pub async fn get() -> impl Responder { 14 | return return_state() 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/defining_db/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending"} -------------------------------------------------------------------------------- /Chapter06/defining_db/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter06/defining_db/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter07/Authenticating_users/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter07/Authenticating_users/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter07/creating_user_models/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter07/creating_user_models/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter07/creating_user_models/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter07/creating_user_models/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter07/creating_user_models/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter07/intercepting_calls/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | 3 | 4 | #[derive(Queryable, Identifiable)] 5 | #[table_name="to_do"] 6 | pub struct Item { 7 | pub id: i32, 8 | pub title: String, 9 | pub status: String, 10 | } 11 | 12 | impl Item { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/models/item/new_item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | 3 | 4 | #[derive(Insertable)] 5 | #[table_name="to_do"] 6 | pub struct NewItem { 7 | pub title: String, 8 | pub status: String, 9 | } 10 | 11 | impl NewItem { 12 | pub fn new(title: String) -> NewItem { 13 | return NewItem{title, status: String::from("pending")} 14 | } 15 | } -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/schema.rs: -------------------------------------------------------------------------------- 1 | table! { 2 | to_do (id) { 3 | id -> Int4, 4 | title -> Varchar, 5 | status -> Varchar, 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/views/auth/login.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a login view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the login view 8 | pub async fn login() -> String { 9 | format!("Login view") 10 | } -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter07/intercepting_calls/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter07/managing_user_sessions/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter07/managing_user_sessions/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter08/caching/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter08/caching/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter08/caching/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter08/caching/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter08/caching/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter08/caching/migrations/00000000000000_diesel_initial_setup/down.sql: -------------------------------------------------------------------------------- 1 | -- This file was automatically created by Diesel to setup helper functions 2 | -- and other internal bookkeeping. This file is safe to edit, any future 3 | -- changes will be added to existing projects as new migrations. 4 | 5 | DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); 6 | DROP FUNCTION IF EXISTS diesel_set_updated_at(); 7 | -------------------------------------------------------------------------------- /Chapter08/caching/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter08/caching/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter08/caching/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter08/caching/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter08/caching/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter08/caching/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter08/caching/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter08/caching/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/caching/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter08/caching/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter08/caching/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter08/caching/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/caching/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/caching/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter08/caching/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter08/caching/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/caching/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter08/caching/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/caching/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter08/logging/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter08/logging/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter08/logging/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter08/logging/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter08/logging/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter08/logging/migrations/00000000000000_diesel_initial_setup/down.sql: -------------------------------------------------------------------------------- 1 | -- This file was automatically created by Diesel to setup helper functions 2 | -- and other internal bookkeeping. This file is safe to edit, any future 3 | -- changes will be added to existing projects as new migrations. 4 | 5 | DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); 6 | DROP FUNCTION IF EXISTS diesel_set_updated_at(); 7 | -------------------------------------------------------------------------------- /Chapter08/logging/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter08/logging/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter08/logging/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter08/logging/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter08/logging/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter08/logging/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter08/logging/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter08/logging/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/logging/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter08/logging/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter08/logging/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter08/logging/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/logging/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/logging/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter08/logging/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter08/logging/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/logging/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter08/logging/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/logging/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter08/mapping_our_layers/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/mapping_our_layers/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter08/stateless_sessions/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/stateless_sessions/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter08/uniform_interface/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter08/uniform_interface/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter08/uniform_interface/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/uniform_interface/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter09/postman_testing/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter09/postman_testing/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter09/postman_testing/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter09/postman_testing/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter09/postman_testing/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter09/unit_testing/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter09/unit_testing/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter09/unit_testing/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/state.json: -------------------------------------------------------------------------------- 1 | {"code in rust":"done","eat cereal for breakfast":"done","eat ramen for breakfast":"pending","test":"pending"} -------------------------------------------------------------------------------- /Chapter09/unit_testing/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter09/unit_testing/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@postgres/to_do 2 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/deploy/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes auto; 2 | error_log /var/log/nginx/error.log warn; 3 | 4 | 5 | events { 6 | worker_connections 512; 7 | } 8 | 9 | 10 | http { 11 | server { 12 | listen 80; 13 | 14 | location / { 15 | proxy_pass http://rust_app:8000; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/deploy/push_to_dockerhub.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" 4 | cd $SCRIPTPATH 5 | cd .. 6 | 7 | docker build -t rust_app . 8 | 9 | docker tag rust_app:latest maxwellflitton/actix_web_application:latest 10 | 11 | docker login 12 | docker push maxwellflitton/actix_web_application:latest 13 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter10/deploy_to_docker_hub/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_docker_hub/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@postgres/to_do 2 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/deploy/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes auto; 2 | error_log /var/log/nginx/error.log warn; 3 | 4 | 5 | events { 6 | worker_connections 512; 7 | } 8 | 9 | 10 | http { 11 | server { 12 | listen 80; 13 | 14 | location / { 15 | proxy_pass http://rust_app:8000; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/deploy/push_to_dockerhub.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" 4 | cd $SCRIPTPATH 5 | cd .. 6 | 7 | docker build -t rust_app . 8 | 9 | docker tag rust_app:latest maxwellflitton/actix_web_application:latest 10 | 11 | docker login 12 | docker push maxwellflitton/actix_web_application:latest 13 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter10/deploy_to_server/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter10/deploy_to_server/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@postgres/to_do 2 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/deploy/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes auto; 2 | error_log /var/log/nginx/error.log warn; 3 | 4 | 5 | events { 6 | worker_connections 512; 7 | } 8 | 9 | 10 | http { 11 | server { 12 | listen 80; 13 | 14 | location / { 15 | proxy_pass http://rust_app:8000; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/deploy/push_to_dockerhub.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" 4 | cd $SCRIPTPATH 5 | cd .. 6 | 7 | docker build -t rust_app . 8 | 9 | docker tag rust_app:latest maxwellflitton/actix_web_application:latest 10 | 11 | docker login 12 | docker push maxwellflitton/actix_web_application:latest 13 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter10/persist_on_server/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter10/persist_on_server/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter10/persist_on_server/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter10/persist_on_server/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter10/run_locally/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@postgres/to_do 2 | -------------------------------------------------------------------------------- /Chapter10/run_locally/deploy/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes auto; 2 | error_log /var/log/nginx/error.log warn; 3 | 4 | 5 | events { 6 | worker_connections 512; 7 | } 8 | 9 | 10 | http { 11 | server { 12 | listen 80; 13 | 14 | location / { 15 | proxy_pass http://rust_app:8000; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter10/run_locally/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter10/run_locally/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter10/run_locally/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter10/run_locally/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter10/run_locally/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter10/run_locally/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter10/run_locally/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter10/run_locally/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter10/run_locally/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter10/run_locally/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter10/run_locally/src/views/auth/logout.rs: -------------------------------------------------------------------------------- 1 | /// This function defines a logout view. 2 | /// 3 | /// # Arguments 4 | /// None 5 | /// 6 | /// # Returns 7 | /// (String) message stating that it's the logout view 8 | pub async fn logout() -> String { 9 | format!("Logout view") 10 | } 11 | -------------------------------------------------------------------------------- /Chapter10/run_locally/templates/components/header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | background: #034f84; 3 | margin-bottom: 0.3rem; 4 | } 5 | .header p { 6 | color: white; 7 | display: inline-block; 8 | margin: 0.5rem; 9 | margin-right: 0.4rem; 10 | margin-left: 0.4rem; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter10/run_locally/templates/components/header.html: -------------------------------------------------------------------------------- 1 |
2 |

complete tasks:

3 |

pending tasks:

4 |
5 | -------------------------------------------------------------------------------- /Chapter11/authentication/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter11/authentication/Rocket.toml: -------------------------------------------------------------------------------- 1 | 2 | [development.databases] 3 | postgres = { url = "postgres://username:password@localhost/to_do" } -------------------------------------------------------------------------------- /Chapter11/authentication/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter11/authentication/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter11/authentication/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter11/authentication/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter11/authentication/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter11/authentication/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter11/authentication/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter11/authentication/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter11/authentication/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/database.rs: -------------------------------------------------------------------------------- 1 | use rocket_contrib::databases::{database, diesel::PgConnection}; 2 | 3 | 4 | #[database("postgres")] 5 | pub struct DbConn(PgConnection); 6 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter11/authentication/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter11/authentication/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter11/basic_setup/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rocket_server" 3 | version = "0.1.0" 4 | authors = ["Maxwell Flitton "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | rocket = "0.4.6" 11 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/Rocket.toml: -------------------------------------------------------------------------------- 1 | 2 | [development.databases] 3 | postgres = { url = "postgres://username:password@localhost/to_do" } -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter11/connecting_to_database/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/database.rs: -------------------------------------------------------------------------------- 1 | use rocket_contrib::databases::{database, diesel::PgConnection}; 2 | 3 | 4 | #[database("postgres")] 5 | pub struct DbConn(PgConnection); 6 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter11/connecting_to_database/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter11/middleware/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter11/middleware/Rocket.toml: -------------------------------------------------------------------------------- 1 | 2 | [development.databases] 3 | postgres = { url = "postgres://username:password@localhost/to_do" } -------------------------------------------------------------------------------- /Chapter11/middleware/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter11/middleware/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter11/middleware/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter11/middleware/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter11/middleware/migrations/00000000000000_diesel_initial_setup/down.sql: -------------------------------------------------------------------------------- 1 | -- This file was automatically created by Diesel to setup helper functions 2 | -- and other internal bookkeeping. This file is safe to edit, any future 3 | -- changes will be added to existing projects as new migrations. 4 | 5 | DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); 6 | DROP FUNCTION IF EXISTS diesel_set_updated_at(); 7 | -------------------------------------------------------------------------------- /Chapter11/middleware/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter11/middleware/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter11/middleware/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter11/middleware/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter11/middleware/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/database.rs: -------------------------------------------------------------------------------- 1 | use rocket_contrib::databases::{database, diesel::PgConnection}; 2 | 3 | 4 | #[database("postgres")] 5 | pub struct DbConn(PgConnection); 6 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter11/middleware/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct ToDoItem { 6 | pub title: String, 7 | pub status: String 8 | } 9 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter11/middleware/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Chapter11/passing_data/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres://username:password@localhost/to_do 2 | -------------------------------------------------------------------------------- /Chapter11/passing_data/Rocket.toml: -------------------------------------------------------------------------------- 1 | 2 | [development.databases] 3 | postgres = { url = "postgres://username:password@localhost/to_do" } -------------------------------------------------------------------------------- /Chapter11/passing_data/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /Chapter11/passing_data/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | postgres: 6 | container_name: 'to-do-postgres' 7 | image: 'postgres:11.2' 8 | restart: always 9 | ports: 10 | - '5432:5432' 11 | environment: 12 | - 'POSTGRES_USER=username' 13 | - 'POSTGRES_DB=to_do' 14 | - 'POSTGRES_PASSWORD=password' 15 | -------------------------------------------------------------------------------- /Chapter11/passing_data/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Chapter11/passing_data/migrations/.gitkeep -------------------------------------------------------------------------------- /Chapter11/passing_data/migrations/2020-10-04-211444_create_to_do_items/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE to_do 3 | -------------------------------------------------------------------------------- /Chapter11/passing_data/migrations/2020-10-04-211444_create_to_do_items/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE to_do ( 3 | id SERIAL PRIMARY KEY, 4 | title VARCHAR NOT NULL, 5 | status VARCHAR NOT NULL 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter11/passing_data/migrations/2020-10-21-003346_create_users/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP COLUMN user_id; 3 | 4 | -- drop the users table 5 | DROP TABLE users 6 | -------------------------------------------------------------------------------- /Chapter11/passing_data/migrations/2020-10-31-154850_user_title_constraint/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | ALTER TABLE to_do DROP CONSTRAINT uc_item; -------------------------------------------------------------------------------- /Chapter11/passing_data/migrations/2020-10-31-154850_user_title_constraint/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | ALTER TABLE to_do ADD CONSTRAINT uc_item UNIQUE (title, user_id); 3 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/database.rs: -------------------------------------------------------------------------------- 1 | use rocket_contrib::databases::{database, diesel::PgConnection}; 2 | 3 | 4 | #[database("postgres")] 5 | pub struct DbConn(PgConnection); 6 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/json_serialization/login.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct Login { 6 | pub username: String, 7 | pub password: String 8 | } -------------------------------------------------------------------------------- /Chapter11/passing_data/src/json_serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod to_do_items; 2 | pub mod to_do_item; 3 | pub mod new_user; 4 | pub mod login; 5 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/json_serialization/new_user.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | 4 | #[derive(Deserialize)] 5 | pub struct NewUserSchema { 6 | pub name: String, 7 | pub email: String, 8 | pub password: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/json_serialization/to_do_item.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | use serde::Serialize; 3 | 4 | 5 | #[derive(Deserialize, Serialize)] 6 | pub struct ToDoItem { 7 | pub title: String, 8 | pub status: String 9 | } 10 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/models/item/item.rs: -------------------------------------------------------------------------------- 1 | use crate::schema::to_do; 2 | use super::super::user::user::User; 3 | 4 | 5 | #[derive(Queryable, Identifiable, Associations)] 6 | #[belongs_to(User)] 7 | #[table_name="to_do"] 8 | pub struct Item { 9 | pub id: i32, 10 | pub title: String, 11 | pub status: String, 12 | pub user_id: i32, 13 | } 14 | 15 | impl Item { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/models/item/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_item; 2 | pub mod item; 3 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod item; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/models/user/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod new_user; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/to_do/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod traits; 2 | pub mod base; 3 | pub mod done; 4 | pub mod pending; 5 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/to_do/structs/traits/create.rs: -------------------------------------------------------------------------------- 1 | 2 | /// Trait for creating to do items. 3 | pub trait Create {} 4 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/to_do/structs/traits/delete.rs: -------------------------------------------------------------------------------- 1 | /// Trait for deleting to do items. 2 | pub trait Delete {} 3 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/to_do/structs/traits/edit.rs: -------------------------------------------------------------------------------- 1 | /// The trait for editing steps. 2 | pub trait Edit {} 3 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/to_do/structs/traits/get.rs: -------------------------------------------------------------------------------- 1 | /// Trait for getting to do items. 2 | pub trait Get {} 3 | -------------------------------------------------------------------------------- /Chapter11/passing_data/src/to_do/structs/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod create; 2 | pub mod delete; 3 | pub mod edit; 4 | pub mod get; 5 | -------------------------------------------------------------------------------- /Dummy.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rust-Web-Programming/fdbfc650695020b52fbf44ef5b292e5b26f2abfe/Dummy.txt --------------------------------------------------------------------------------