Compare commits
5 Commits
6565be735d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 45f8072679 | |||
| 984438729e | |||
| 1e8bfc2ac0 | |||
| 1148a65355 | |||
| acb1f63bae |
@@ -11,7 +11,7 @@
|
|||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
- [x] create installation script
|
- [x] create installation script
|
||||||
- [ ] connect to redis
|
- [x] connect to redis + setter and getter operations
|
||||||
- [ ] create dummy API endpoints
|
- [ ] create dummy API endpoints
|
||||||
- [ ] decide how to handle short url generation
|
- [ ] decide how to handle short url generation
|
||||||
- [ ] avoid collisions in short urls
|
- [ ] avoid collisions in short urls
|
||||||
|
|||||||
1
cpanfile
1
cpanfile
@@ -1,2 +1,3 @@
|
|||||||
requires 'Mojolicious', '>= 9.0';
|
requires 'Mojolicious', '>= 9.0';
|
||||||
requires 'Moose';
|
requires 'Moose';
|
||||||
|
requires 'Mojo::Redis2';
|
||||||
|
|||||||
@@ -141,6 +141,20 @@ DISTRIBUTIONS
|
|||||||
perl 5.006
|
perl 5.006
|
||||||
strict 0
|
strict 0
|
||||||
warnings 0
|
warnings 0
|
||||||
|
Mojo-Redis2-0.32
|
||||||
|
pathname: D/DB/DBOOK/Mojo-Redis2-0.32.tar.gz
|
||||||
|
provides:
|
||||||
|
Mojo::Redis2 0.32
|
||||||
|
Mojo::Redis2::Backend undef
|
||||||
|
Mojo::Redis2::Bulk undef
|
||||||
|
Mojo::Redis2::Client undef
|
||||||
|
Mojo::Redis2::Cursor undef
|
||||||
|
Mojo::Redis2::Server undef
|
||||||
|
Mojo::Redis2::Transaction 0.01
|
||||||
|
requirements:
|
||||||
|
ExtUtils::MakeMaker 0
|
||||||
|
Mojolicious 7.50
|
||||||
|
Protocol::Redis 1.0
|
||||||
Mojolicious-9.42
|
Mojolicious-9.42
|
||||||
pathname: S/SR/SRI/Mojolicious-9.42.tar.gz
|
pathname: S/SR/SRI/Mojolicious-9.42.tar.gz
|
||||||
provides:
|
provides:
|
||||||
@@ -787,6 +801,16 @@ DISTRIBUTIONS
|
|||||||
Scalar::Util 1.18
|
Scalar::Util 1.18
|
||||||
XSLoader 0.22
|
XSLoader 0.22
|
||||||
parent 0
|
parent 0
|
||||||
|
Protocol-Redis-1.0021
|
||||||
|
pathname: U/UN/UNDEF/Protocol-Redis-1.0021.tar.gz
|
||||||
|
provides:
|
||||||
|
Protocol::Redis 1.0021
|
||||||
|
Protocol::Redis::Test undef
|
||||||
|
requirements:
|
||||||
|
Carp 0
|
||||||
|
ExtUtils::MakeMaker 0
|
||||||
|
Test::More 0.94
|
||||||
|
perl 5.008001
|
||||||
Sub-Exporter-0.991
|
Sub-Exporter-0.991
|
||||||
pathname: R/RJ/RJBS/Sub-Exporter-0.991.tar.gz
|
pathname: R/RJ/RJBS/Sub-Exporter-0.991.tar.gz
|
||||||
provides:
|
provides:
|
||||||
|
|||||||
@@ -1,19 +1,50 @@
|
|||||||
package Urupam::App;
|
package Urupam::App;
|
||||||
|
|
||||||
use Mojo::Base 'Mojolicious';
|
use Mojo::Base 'Mojolicious';
|
||||||
use Moose;
|
use Urupam::DB;
|
||||||
|
|
||||||
sub startup {
|
sub startup {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
$self->helper(
|
||||||
|
db => sub {
|
||||||
|
my $c = shift;
|
||||||
|
$c->stash->{db} ||= Urupam::DB->new;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
my $r = $self->routes;
|
my $r = $self->routes;
|
||||||
$r->get('/')->to(
|
$r->get('/')->to(
|
||||||
cb => sub {
|
cb => sub {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
$c->render( text => 'Hello from urupam!' );
|
my $tx = $c->render_later->tx;
|
||||||
|
my $db = $c->db;
|
||||||
|
|
||||||
|
$db->set( 'test_key' => '123soleil' )->then(
|
||||||
|
sub {
|
||||||
|
$c->app->log->info('Value set: test_key => 123soleil');
|
||||||
|
return $db->get('test_key');
|
||||||
|
}
|
||||||
|
)->then(
|
||||||
|
sub {
|
||||||
|
my $value = shift;
|
||||||
|
$c->app->log->info("Value retrieved: $value");
|
||||||
|
$c->render( json => { status => 'ok', value => $value } );
|
||||||
|
undef $tx;
|
||||||
|
}
|
||||||
|
)->catch(
|
||||||
|
sub {
|
||||||
|
my $err = shift;
|
||||||
|
$c->app->log->error("DB error: $err");
|
||||||
|
$c->render(
|
||||||
|
json => { status => 'error', message => "$err" },
|
||||||
|
status => 500
|
||||||
|
);
|
||||||
|
undef $tx;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user