diff --git a/Literature/lib/Literature.pm b/Literature/lib/Literature.pm index a2bea24..83a8135 100644 --- a/Literature/lib/Literature.pm +++ b/Literature/lib/Literature.pm @@ -8,16 +8,31 @@ my $cfg = dancer_app->config; $cfg->{plugins}{DBIC}{default}{user} = $ENV{LIT_USER}; $cfg->{plugins}{DBIC}{default}{pass} = $ENV{LIT_PASS}; +my %resources = qw[ + actors Actor + authors Author + productions Production + works Work + fictional_characters FictionalCharacter +]; + +my $route_re = '/(' . join('|', keys %resources) . ')/'; +my $id_re = $route_re . '(\d+)'; + get '/' => sub { template 'index'; }; -get '/authors/' => sub { - template 'authors', { authors => resultset('Author') }; +get qr{^$route_re$} => sub { + my ($resource) = splat; + template $resource, + { $resource => resultset($resources{$resource}) }; }; -get '/authors/:id' => sub { - template 'author', { author => resultset('Author')->find(param('id')) }; +get qr{$id_re} => sub { + my ($resource, $id) = splat; + template substr($resource, 0, -1), + { lc $resources{$resource} => resultset($resources{$resource})->find($id) }; }; true; diff --git a/Literature/lib/Literature/Schema/Result/Character.pm b/Literature/lib/Literature/Schema/Result/Character.pm deleted file mode 100644 index 66bc26b..0000000 --- a/Literature/lib/Literature/Schema/Result/Character.pm +++ /dev/null @@ -1,76 +0,0 @@ -use utf8; -package Literature::Schema::Result::Character; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Literature::Schema::Result::Character - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 COMPONENTS LOADED - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->load_components("InflateColumn::DateTime"); - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("character"); - -=head1 ACCESSORS - -=head2 id - - data_type: 'integer' - is_nullable: 0 - -=head2 name - - data_type: 'varchar' - is_nullable: 0 - size: 255 - -=cut - -__PACKAGE__->add_columns( - "id", - { data_type => "integer", is_nullable => 0 }, - "name", - { data_type => "varchar", is_nullable => 0, size => 255 }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("id"); - - -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-10-01 12:22:59 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Uik0XqoMCthAw/Cb+JzSpg - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/Literature/views/actor.tt b/Literature/views/actor.tt new file mode 100644 index 0000000..e95d5a2 --- /dev/null +++ b/Literature/views/actor.tt @@ -0,0 +1,19 @@ +[% META title = 'Actor' %] + +

[% actor.name %]

+[% IF actor.born OR actor.died %] +

[% IF actor.born %]Born: [% actor.born.strftime('%m %B %Y'); END -%] +[% IF actor.born AND actor.died %], [% END %] +[% IF actor.died %]Died: [% actor.died.strftime('%m %B %Y'); END %]

+[% END %] +

[% actor.name %] on IMDB

+[% IF actor.actor_roles.size %] + +[% ELSE %] +

No roles found.

+[% END %] diff --git a/Literature/views/actors.tt b/Literature/views/actors.tt new file mode 100644 index 0000000..bd1c40f --- /dev/null +++ b/Literature/views/actors.tt @@ -0,0 +1,8 @@ +[% # Provide a title -%] +[% META title = 'List of Actors' -%] + + diff --git a/Literature/views/authors.tt b/Literature/views/authors.tt index fe05d29..37ce22c 100644 --- a/Literature/views/authors.tt +++ b/Literature/views/authors.tt @@ -1,5 +1,5 @@ diff --git a/Literature/views/fictional_character.tt b/Literature/views/fictional_character.tt new file mode 100644 index 0000000..e1473dd --- /dev/null +++ b/Literature/views/fictional_character.tt @@ -0,0 +1,31 @@ +[% META title = 'Character' %] + +

[% fictionalcharacter.name %]

+[% IF fictionalcharacter.imdb %]

[% fictionalcharacter.name %] on IMDB

[% END %] +

Appearances

+[% IF fictionalcharacter.fictional_character_appearances.size %] + +[% ELSE %] +

No appearances found.

+[% END %] + +

Played By

+[% IF fictionalcharacter.actor_roles.size %] +