-
-
Save aanoaa/1520730 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#----------------------------------------------- | |
# by @jeen | |
#----------------------------------------------- | |
sub get_activities { | |
my ($self, $args) = @_; | |
my ( $cond, $attr ) = $self->_get_activities_condition($args); | |
my $r = $self->resultset('Activity')->search($cond, $attr); | |
my $pager = $self->pageset($r->pager); | |
my @list; | |
while(my $row = $r->next) { | |
push @list, $row; | |
} | |
(\@list, $pager); | |
} | |
# 사용할때는, | |
my ($activities, $pager) = $self->system_api->get_activities($param); | |
$c->stash->{activities} = $activities; | |
$c->stash->{pager} = $pager; | |
#----------------------------------------------- | |
# by @aanoaa | |
#----------------------------------------------- | |
use Data::SearchEngine::Results; | |
use Data::SearchEngine::Item; | |
use Data::SearchEngine::Paginator; | |
sub search { | |
my ($self, $query) = @_; | |
my $cond = $query->query; | |
my $count = $self->get_subjects($cond)->count; | |
my $attr = { row => $query->count, page => $query->page }; | |
my $rs = $self->get_subjects($cond, $attr); | |
my $result = Data::SearchEngine::Results->new( | |
query => $query, | |
pager => Data::SearchEngine::Paginator->new( | |
current_page => $query->page, | |
entries_per_page => $query->count, | |
total_entries => $count, | |
) | |
); | |
while (my $subject = $rs->next) { | |
my %columns; | |
map { $columns{$_} = $subject->$_ } qw/foo bar baz/; | |
$columns{oops} = [$subject->oops]; | |
$result->add(Data::SearchEngine::Item->new( | |
id => $subject->id, | |
values => \%columns, | |
)); | |
} | |
return $result; | |
} | |
# 사용할때는, | |
my $query = Data::SearchEngine::Query->new( | |
count => $self->ROW_COUNT, | |
page => $c->req->param('page') || 1, | |
type => 'query_string', | |
query => $cond, | |
); | |
$c->stash->{oops} = $c->model('API')->find('Subject')->search($query); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
내부 API 통일?
..그딴거 없고 패기있게 구현하고 그지 같으면 혼나가면서 바꿉니다.