unit module Zef::API::Validated;
multi sub trait_mod:<is>(Sub $s, :$validated!) is export {
&$s.wrap(&validate-params);
}
sub validate-params($req, $res) {
'stash'.say;
dd $req.params<stash>; #is dying here
'/stash'.say;
callsame;
}
unit module Zef::Controller::Search;
use Zef::API::Validated;
use Zef::API::Middleware;
use Zef::API::DB;
sub search($req, $res)
# is json-check
is validated
is export
{
my %query = (
%(
module => ( '-like' => "\%{$req.params<module>}%" ),
),
%(
qw<author>.map({
$req.params<body>{$_}.defined
?? ($_ => ( '-like' => "\%{$req.params<body>{$_}}%" ) )
!! ();
})
)
);
my $search = db.search('version', %query);
my @results;
while $search.next -> $module {
@results.push(%(
qw<version version author author commit_id commit module module>.map(-> $db, $key {
$key => $module.get($db)
});
));
}
$res.close(to-json({ status => 0, results => @results }));
};