Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Controller script for User.
  • Loading branch information
Talina06 committed Jul 1, 2014
1 parent 2643696 commit 6ffe1e3
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions lib/MetaCPAN/Server/Controller/User/Stargazer.pm
@@ -0,0 +1,64 @@
package MetaCPAN::Server::Controller::User::Stargazer;

use strict;
use warnings;

use Moose;

BEGIN { extends 'Catalyst::Controller::REST' }

sub auto : Private {
my ( $self, $c ) = @_;
unless ( $c->user->looks_human ) {
$self->status_forbidden( $c,
message => 'please complete the turing test' );
return 0;
}
else {

This comment has been minimized.

Copy link
@oalders

oalders Jul 3, 2014

Member

There's no need for the else clause here, since the code which follows the unless path would have returned by this point.

return 1;
}
}

sub index : Path : ActionClass('REST') {
}

sub index_POST {
my ( $self, $c ) = @_;
my $pause = $c->stash->{pause};
my $req = $c->req;
my $star = $c->model('CPAN::Stargazer')->put(
{
user => $c->user->id,
author => $req->data->{author},
release => $req->data->{release},
module => $req->data->{module},

This comment has been minimized.

Copy link
@oalders

oalders Jul 3, 2014

Member

Do you have your pre-commit hook enabled? If you do, it's not working.

author => $req->data->{author},
},
{ refresh => 1 }
);
$self->status_created(
$c,
location => $c->uri_for(
join(
'/', '/stargazer', $star->user, $star->module
)
),
entity => $star->meta->get_data($star)
);
}

sub index_DELETE {
my ( $self, $c, $module ) = @_;
my $star = $c->model('CPAN::Stargazer')
->get( { user => $c->user->id, module => $module } );
if ($star) {
$star->delete( { refresh => 1 } );
$self->status_ok( $c,
entity => $star->meta->get_data($star) );
}
else {
$self->status_not_found( $c, message => 'Entity could not be found' );
}
}

1;

0 comments on commit 6ffe1e3

Please sign in to comment.