Skip to content
This repository
Browse code

Added basic display pages for users and lists.

  • Loading branch information...
commit 9436dbcddba27de83e6202fb7f801ea6f60fc147 1 parent 34872cb
Dave Cross authored February 05, 2014
37  lib/Lystyng.pm
@@ -22,6 +22,43 @@ get '/' => sub {
22 22
   template 'index';
23 23
 };
24 24
 
  25
+get '/user' => sub {
  26
+  template 'users', {
  27
+    users => resultset('User')->all,
  28
+  };
  29
+};
  30
+
  31
+get '/user/:username' => sub {
  32
+  if (my $user = resultset('User')->find({
  33
+    username => params->{username},
  34
+  })) {
  35
+    template 'user', {
  36
+      user => $user,
  37
+    };
  38
+  } else {
  39
+    send_error 'User not found', 404;
  40
+  }
  41
+};
  42
+
  43
+get '/user/:username/list/:list' => sub {
  44
+  my $user;
  45
+  unless ($user = resultset('User')->find({
  46
+    username => params->{username},
  47
+  })) {
  48
+    send_error 'User not found', 404;
  49
+  };
  50
+
  51
+  if (my $list = $user->lists->find({
  52
+    slug => params->{list},
  53
+  })) {
  54
+    template 'list', {
  55
+      list => $list,
  56
+    };
  57
+  } else {
  58
+    send_error 'List not found', 404;
  59
+  };
  60
+};
  61
+
25 62
 get '/register' => sub {
26 63
   template 'register';
27 64
 };
12  views/list.tt
... ...
@@ -0,0 +1,12 @@
  1
+<h2>[% list.title %]</h2>
  2
+<p>By <a href="">[% list.user.username %]</a></p>
  3
+<p>[% list.description %]</p>
  4
+[% IF list.list_items.size -%]
  5
+<ul>
  6
+[%   FOREACH item IN list.list_items -%]
  7
+<li><h3>[% item.title %]</h3>
  8
+<p>[% item.description %]</p></li>
  9
+[%   END -%]
  10
+[% ELSE -%]
  11
+<p>List has no items</p>
  12
+[% END -%]
2  views/register.tt
@@ -9,7 +9,7 @@
9 9
     </ul>
10 10
   </div>
11 11
 [% END -%]
12  
-  <form role="form" class="form-horizontal">
  12
+  <form role="form" class="form-horizontal" method="post" action="/register">
13 13
     <div class="form-group">
14 14
       <label class="col-md-2 control-label" for="username">Username</label>
15 15
       <div class="col-md-6">
10  views/user.tt
... ...
@@ -0,0 +1,10 @@
  1
+<h2>[% user.username %]</h2>
  2
+[% IF user.lists.size -%]
  3
+<ul>
  4
+[%   FOREACH list IN user.lists -%]
  5
+<li><a href="/user/[% user.username %]/list/[% list.slug %]">[% list.title %]</a>
  6
+<br>[% list.description %]</li>
  7
+[%   END -%]
  8
+[% ELSE -%]
  9
+<p>User has no lists</p>
  10
+[% END -%]
9  views/users.tt
... ...
@@ -0,0 +1,9 @@
  1
+[% IF users.size -%]
  2
+<ul>
  3
+[%   FOREACH user IN users -%]
  4
+  <li><a href="/user/[% user.username %]">[% user.username %]</a></li>
  5
+[%   END -%]
  6
+</ul>
  7
+[% ELSE -%]
  8
+  <p>No users found</p>
  9
+[% END -%]

0 notes on commit 9436dbc

Please sign in to comment.
Something went wrong with that request. Please try again.