package DTA::Controller::News;
use Moose;
use namespace::autoclean;

BEGIN {extends 'Catalyst::Controller'; }

=head1 NAME

DTA::Controller::News - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut

sub auto :Private {
    my ( $self, $c ) = @_;
    return 1;
}

=head2 index

=cut

sub index :Path :Args(0) {
#sub index :Local {
    my ( $self, $c, $arg ) = @_;

    if ( $arg ) {
        $c->detach( 'entry', [ $arg ] );
    }

    $c->stash(
        template => 'news/list.tt',
        news     => [ $c->model('DTADB::News')->search(
            {
                'me.archive' => 1,
            },
            {
                order_by => 'me.created DESC',
            },
        )->all ],
    );
}

=head2 entry

=cut

#sub entry :LocalRegex('^(\d+)$') {
sub entry :Private {
    my ( $self, $c, undef, $id ) = @_;
#    my $id = $c->req->captures->[0];

    my $entry = $c->model('DTADB::News')->search({
        id      => $id,
        archive => 1,
    })->first;
    $c->detach('/default') unless $entry;

    $c->stash(
        template => 'news/show.tt',
        entry    => $entry,
    );
}

__PACKAGE__->meta->make_immutable;

1;
__END__

=head1 AUTHOR

Frank Wiegand

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut
