aboutsummaryrefslogtreecommitdiff
path: root/examples/tutorial02/polls
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tutorial02/polls')
-rw-r--r--examples/tutorial02/polls/mod.rs11
-rw-r--r--examples/tutorial02/polls/models.rs21
-rw-r--r--examples/tutorial02/polls/urls.rs9
-rw-r--r--examples/tutorial02/polls/views.rs5
4 files changed, 46 insertions, 0 deletions
diff --git a/examples/tutorial02/polls/mod.rs b/examples/tutorial02/polls/mod.rs
new file mode 100644
index 0000000..f4fde54
--- /dev/null
+++ b/examples/tutorial02/polls/mod.rs
@@ -0,0 +1,11 @@
+use tosin::apps::AppConfig;
+
+pub mod models;
+pub mod urls;
+pub mod views;
+
+pub use urls::urls;
+
+pub const APP: AppConfig = AppConfig {
+
+};
diff --git a/examples/tutorial02/polls/models.rs b/examples/tutorial02/polls/models.rs
new file mode 100644
index 0000000..5ed52c5
--- /dev/null
+++ b/examples/tutorial02/polls/models.rs
@@ -0,0 +1,21 @@
+use tosin::db::models::{Model, Id};
+
+#[derive(Model)]
+pub struct Question {
+ id: Option<Id>,
+ #[model(max_length=200)]
+ question_text: String,
+ /// date published
+ pub_date: time::PrimitiveDateTime,
+}
+
+#[derive(Model)]
+pub struct Choice {
+ id: Option<Id>,
+ #[model(Question, on_delete=Cascade)]
+ question: Id,
+ #[model(max_length=200)]
+ choice_text: String,
+ #[model(default = 0)]
+ votes: usize,
+}
diff --git a/examples/tutorial02/polls/urls.rs b/examples/tutorial02/polls/urls.rs
new file mode 100644
index 0000000..04d93cc
--- /dev/null
+++ b/examples/tutorial02/polls/urls.rs
@@ -0,0 +1,9 @@
+use tosin::urls::{UrlMap, url_map};
+
+use super::views;
+
+pub fn urls() -> UrlMap {
+ url_map! {
+ => views::index, // TODO name: "index"
+ }
+}
diff --git a/examples/tutorial02/polls/views.rs b/examples/tutorial02/polls/views.rs
new file mode 100644
index 0000000..4859cec
--- /dev/null
+++ b/examples/tutorial02/polls/views.rs
@@ -0,0 +1,5 @@
+use tosin::http::{Reply, Response};
+
+pub fn index() -> Response {
+ "Hello, world. You're at the polls index.".into_response()
+}