Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Controller script for User.
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Sorry, something went wrong. |
||
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.
Sorry, something went wrong. |
||
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; |
There's no need for the else clause here, since the code which follows the unless path would have returned by this point.