Facebook
From Bistre Motmot, 1 Year ago, written in Perl.
Embed
Download Paste or View Raw
Hits: 111
  1. package Jizzy;
  2. use Mojo::Base 'Mojolicious';
  3. use Jizzy::Schema;
  4. use Mojolicious::Static;
  5.  
  6. # Connects once for entire application. For real apps, consider using a helper
  7. # that can reconnect on each request if necessary.
  8. #has schema => sub {
  9. #  return Jizzy::Schema->connect('dbi:SQLite:' . ($ENV{TEST_DB} || 'db.sqlite3'));
  10. #};
  11.  
  12. # This method will run once at server start
  13. sub startup {
  14.   my $self = shift;
  15.  
  16.   # DSN syntax
  17.   # dbi:DriverName:database=database_name;host=hostname;port=port
  18.   # For SQLite:
  19.   my $schema = Jizzy::Schema->connect('dbi:SQLite:db.sqlite3', '', '', { sqlite_unicode => 1});
  20.   #my $schema = Jizzy::Schema->connect('dbi:SQLite:/home/MushiX/domains/mojo.mushix.usermd.net/public_html/db.sqlite3', '', '', { sqlite_unicode => 1});
  21.  
  22.   #$self->helper(db => sub { $self->app->schema });
  23.  
  24.   $self->helper(db => sub { return $schema; });
  25.  
  26.   # Load configuration from hash returned by "my_app.conf"
  27.   #my $config = $self->plugin('Config');
  28.  
  29.   # Documentation browser under "/perldoc"
  30.   #$self->plugin('PODRenderer') if $config->{perldoc};
  31.  
  32.   # Router
  33.   my $r = $self->routes;
  34.  
  35.   # Normal route to controller
  36.  
  37.   #Public
  38.   $r->get('/')->to('public#index');
  39.  
  40.   #Users
  41.   $r->get('/users')->to('users#index');
  42.   #$r->get('/users/:id')->to('users#create');
  43.   #$authorized->get('/create')->name('create_post')->to(template => 'user/create_user');
  44.   #$authorized->post('/create')->name('creating_post')->to('users#create');
  45.   $r->get('/users/new')->name('new_user')->to(template => 'users/new');
  46.   $r->post('/users/create')->name('create_user')->to('users#create');
  47.  
  48.   #Cities
  49. =begin
  50.   my $r_cities = $r->get('/cities')->to(controller => 'cities');
  51.   $r_cities->get('/')->to(action => 'index');
  52.   $r_cities->get('/new')->name('new_city')->to(template => 'cities/new');
  53.   $r_cities->post('/create')->name('create_city')->to('cities#create');
  54.   $r_cities->get('/show/:id')->name('show_city')->to(action => 'show');
  55.   $r_cities->get('/edit/:id')->name('edit_city')->to(action => 'edit');
  56.   $r_cities->post('/update')->name('update_city')->to('cities#update');
  57.   $r_cities->post('/delete/:id', [id => qr/\d+/])->name('delete_city')->to('cities#delete');
  58. =cut
  59.   $r->get('/cities')->to('cities#index');
  60.   $r->get('/cities/new')->name('new_city')->to(template => 'cities/new');
  61.   $r->post('/cities/create')->name('create_city')->to('cities#create');
  62.   $r->get('/cities/show/:id')->name('show_city')->to('cities#show');
  63.   $r->get('/cities/edit/:id')->name('edit_city')->to('cities#edit');
  64.   $r->post('/cities/update/:id')->name('update_city')->to('cities#update');
  65.   $r->post('/cities/delete/:id', [id => qr/\d+/])->name('delete_city')->to('cities#delete');
  66.  
  67.   #Categories
  68.   $r->get('/categories')->to('categories#index');
  69.   $r->get('/categories/new')->name('new_category')->to(template => 'categories/new');
  70.   $r->post('/categories/create')->name('create_category')->to('categories#create');
  71.   $r->get('/categories/show/:id')->name('show_category')->to('categories#show');
  72.   $r->get('/categories/edit/:id')->name('edit_category')->to('categories#edit');
  73.   $r->post('/categories/update/:id')->name('update_category')->to('categories#update');
  74.   $r->post('/categories/delete/:id', [id => qr/\d+/])->name('delete_category')->to('categories#delete');
  75. }
  76.  
  77. 1;