search route

This commit is contained in:
Difrex(Denis Zheleztsov) 2014-08-12 10:42:27 +04:00
parent 8be1c614f1
commit 52503dfebf
2 changed files with 32 additions and 14 deletions

View File

@ -20,6 +20,7 @@ sub new {
return $self; return $self;
} }
# Check message hash
sub check_hash { sub check_hash {
my ( $self, $hash, $echo ) = @_; my ( $self, $hash, $echo ) = @_;
my $dbh = $self->{_dbh}; my $dbh = $self->{_dbh};
@ -39,6 +40,7 @@ sub check_hash {
} }
} }
# Begin transaction
sub begin { sub begin {
my ($self) = @_; my ($self) = @_;
my $dbh = $self->{_dbh}; my $dbh = $self->{_dbh};

View File

@ -19,6 +19,7 @@ use warnings;
use Plack::Builder; use Plack::Builder;
use Plack::Request; use Plack::Request;
use Plack::Response; use Plack::Response;
# Static files # Static files
use Plack::App::File; use Plack::App::File;
@ -176,16 +177,31 @@ my $user = sub {
return [ 200, [ 'Content-type' => 'text/html' ], [$mes_from], ]; return [ 200, [ 'Content-type' => 'text/html' ], [$mes_from], ];
}; };
# Search
########
my $search = sub {
my $env = shift;
my $req = Plack::Request->new($env);
my $query = $req->param('q');
my $db = II::DB->new();
my $result = $db->do_search($q);
return [ 200, [ 'Content-type' => 'text/html' ], [$result], ];
};
# Mountpoints # Mountpoints
builder { builder {
mount "/static" => Plack::App::File->new( root => './s/' )->to_app; mount "/static" => Plack::App::File->new( root => './s/' )->to_app;
mount "/search" => $search;
mount '/' => $root; mount '/' => $root;
mount '/e' => $echo; mount '/e' => $echo;
mount '/s' => $thread; mount '/s' => $thread;
mount '/u' => $user; mount '/u' => $user;
mount '/me' => $me; mount '/me' => $me;
mount '/tree' => $tree; mount '/tree' => $tree;
mount '/get/' => $get; mount '/get' => $get;
mount '/send' => $send; mount '/send' => $send;
mount '/enc' => $enc; mount '/enc' => $enc;
mount '/out' => $out; mount '/out' => $out;