~bluet/+junk/lijibo-wallpaper

« back to all changes in this revision

Viewing changes to lib/Conifer/Board.pm

  • Committer: BlueT - Matthew Lien - 練喆明
  • Date: 2011-10-03 22:20:48 UTC
  • mfrom: (29.1.14 lijibo-mojox-redis)
  • Revision ID: bluet@bluet.org-20111003222048-ar7ur1iobz1c8wdi
switch to MojoX::Redis

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
use Conifer;
5
5
use Mojo::Base 'Mojolicious::Controller';
6
6
use Time::HiRes 'time', 'gettimeofday';
7
 
#~ use Data::Dumper;
 
7
use Data::Dumper::Simple;
8
8
#~ use Digest::SHA1 qw(sha1_hex sha1_base64);
9
9
#~ use Digest::MD5 qw(md5 md5_hex md5_base64);
10
10
use MIME::Base64;
56
56
        
57
57
        #~ my $post_id = &_key_lookup("article",$hash);
58
58
        
59
 
        my $title = Conifer->redis->get("board:$bid:title");
60
 
        my $desc = Conifer->redis->get("board:$bid:desc");
61
 
        
62
 
        
63
 
        my @post_ids = Conifer->redis->zrange("board:$bid:posts", 0, -1);
64
 
        say $c->app->dumper(\@post_ids);
 
59
        #~ my $title = Conifer->redis->get("board:$bid:title");
 
60
        #~ my $desc = Conifer->redis->get("board:$bid:desc");
 
61
        my $info = $c->get_board_info($bid, "title", "desc");
 
62
        
 
63
        
 
64
        #~ my @post_ids = Conifer->redis->zrange("board:$bid:posts", 0, -1);
 
65
        #~ my $post_ids = $c->get_board_posts($bid);
 
66
        my $post_ids = $c->get_list("board:$bid:posts", 0, -1);
 
67
        say "Board: list:\n\tboard_ids: ". $c->app->dumper($post_ids);
65
68
        
66
69
        my @all_posts;
67
 
        for (@post_ids) {
 
70
        for (@$post_ids) {
 
71
                my $post_id = $_->[0];
68
72
                my %post;
69
 
                my $hash = encode_base64($_);
 
73
                my $hash = encode_base64($post_id);
70
74
                chomp $hash;
71
75
                $hash =~ s/=//g;
72
76
                
84
88
        
85
89
        #~ my $motd = "A Fuck A Day, keeps the doctor away.";
86
90
        
87
 
        $c->render(title => "$title", desc => "$desc", all_posts => \@all_posts);
 
91
        $c->render(title => $info->{'title'}, desc => $info->{'desc'}, all_posts => \@all_posts);
88
92
}
89
93
 
90
94
sub list {
92
96
        my $c = shift;
93
97
        #~ my $hash = $self->param('hash');
94
98
        
95
 
        my @board_ids = Conifer->redis->zrange("board:list", 0, -1);
96
 
        say $c->app->dumper(\@board_ids);
 
99
        #~ my $board_ids = $c->get_board_list;
 
100
        my $board_ids = $c->get_list("board:list");
 
101
        say "Board: list:\n\tboard_ids: ". $c->app->dumper($board_ids);
97
102
        
98
103
        my @all_boards;
99
 
        for (@board_ids) {
100
 
                my %board;
101
 
                #~ my $hash = encode_base64($_);
102
 
                #~ chomp $hash;
103
 
                #~ $hash =~ s/=//g;
104
 
                
105
 
                $board{'id'} = $_;
106
 
                $board{'title'} = Conifer->redis->get("board:$_:title");
107
 
                $board{'desc'} = Conifer->redis->get("board:$_:desc");
108
 
                
 
104
        for (@$board_ids) {
 
105
                my $bid = $_->[0];
 
106
                say "Board: list:\n\tCurrent board id: ". $c->app->dumper($bid);
 
107
                
 
108
                my %board = %{ $c->get_board_info($bid, "title", "desc") };
 
109
                
 
110
                $board{'id'} = $bid;
 
111
                #~ $board{'title'} = Conifer->redis->get("board:$_:title");
 
112
                #~ $board{'desc'} = Conifer->redis->get("board:$_:desc");
 
113
                
 
114
                say "Board: list:\n\tCurrent board data: ". Dumper(\%board);
109
115
                push @all_boards, \%board;
110
116
        }
111
117