Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename the MetaCPAN::Role script, use MetaCPAN::Types and code tidy.
  • Loading branch information
Talina06 committed Jul 27, 2014
1 parent 1597f44 commit 9aef1f4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
11 changes: 6 additions & 5 deletions lib/MetaCPAN/Document/Stargazer.pm
Expand Up @@ -3,20 +3,21 @@ package MetaCPAN::Document::Stargazer;
use strict;
use warnings;

use Moose;
use ElasticSearchX::Model::Document;

use DateTime;
use ElasticSearchX::Model::Document;
use MetaCPAN::Types qw(:all);
use Moose;

has id => (
is => 'ro',
id => [qw(user module)],
is => 'ro',
id => [qw(user module)],
isa => 'NonEmptySimpleStr',
);

has [qw(author release user module)] => (
is => 'ro',
required => 1,
isa => 'NonEmptySimpleStr',
);

has date => (
Expand Down
3 changes: 1 addition & 2 deletions lib/MetaCPAN/Server/Controller/Stargazer.pm
Expand Up @@ -13,7 +13,6 @@ with 'MetaCPAN::Server::Role::JSONP';
sub find : Path('') : Args(2) {
my ( $self, $c, $user, $module ) = @_;
try {

my $stargazer = $self->model($c)->raw->get(
{
user => $user,
Expand All @@ -23,7 +22,7 @@ sub find : Path('') : Args(2) {
$c->stash( $stargazer->{_source} || $stargazer->{fields} );
}
catch {
$c->detach( '/not_found', [$@] );
$c->detach( '/not_found', [$_] );
};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Server/Controller/User/Stargazer.pm
Expand Up @@ -7,7 +7,7 @@ use Moose;

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

with 'MetaCPAN::Server::Role::MapStarring';
with 'MetaCPAN::Server::Role::Mapping';

sub auto : Private {
my ( $self, $c ) = @_;
Expand Down
@@ -1,4 +1,4 @@
package MetaCPAN::Server::Role::MapStarring;
package MetaCPAN::Server::Role::Mapping;

This comment has been minimized.

Copy link
@Talina06

Talina06 Jul 27, 2014

Author Contributor

@oalders Does this seem like a good enough name? I am not so good with the naming.. :)

This comment has been minimized.

Copy link
@oalders

oalders Jul 27, 2014

Member

Well, the problem is see with this is that "mapping" has a special meaning in terms of Elasticsearch, so this could get confusing. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping.html

This comment has been minimized.

Copy link
@Talina06

Talina06 Jul 27, 2014

Author Contributor

Ah, yes. Ok 👍

This comment has been minimized.

Copy link
@oalders

oalders Jul 27, 2014

Member

If this role is really just for starring, you could call it MetaCPAN::Server::Role::Starring. I only see this role being consumed in one place, though. Are you planning to use it elsewhere?

This comment has been minimized.

Copy link
@Talina06

Talina06 Jul 27, 2014

Author Contributor

No, only for Starring.

This comment has been minimized.

Copy link
@oalders

oalders Jul 27, 2014

Member

Ah, ok. So why does it need to be in a role?

This comment has been minimized.

Copy link
@Talina06

Talina06 Jul 27, 2014

Author Contributor

@oalders : because we thought that implementing it using a role would make it non repetitive and the working will be more abstract.

This comment has been minimized.

Copy link
@oalders

oalders Jul 27, 2014

Member

Right, but if we're only going to use the role in one specific module, we haven't removed any repetition. If we need to use this elsewhere, then the role makes sense.

This comment has been minimized.

Copy link
@Talina06

Talina06 Jul 27, 2014

Author Contributor

Hmm, this role can be implemented for the existing favorites data as well as the web of trust data.
I will see if I can make it more general. That way it will be helpful.


use strict;
use warnings;
Expand All @@ -12,9 +12,8 @@ sub index_POST {
{
user => $c->user->id,
author => $req->data->{author},
release => $req->data->{release},
module => $req->data->{module},
author => $req->data->{author},
release => $req->data->{release},
},
{ refresh => 1 }
);
Expand All @@ -33,11 +32,10 @@ sub index_DELETE {
->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' );
return $self->status_ok( $c, entity => $star->meta->get_data($star) );
}
return $self->status_not_found( $c,
message => 'Entity could not be found' );
}

1;

0 comments on commit 9aef1f4

Please sign in to comment.