about summary refs log tree commit diff
path: root/lib/jitterbug/Project.pm
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-10-03 11:39:27 +0200
committerfranck cuny <franck@lumberjaph.net>2010-10-03 11:39:27 +0200
commitbc6e18fbdbe7b716cb7c13e308c2a66a69193fcd (patch)
treeee5c9b3ea7bab636e7a75c05743cd0373fde8f3c /lib/jitterbug/Project.pm
parentadd schema (diff)
downloadjitterbug-bc6e18fbdbe7b716cb7c13e308c2a66a69193fcd.tar.gz
use dbic
Diffstat (limited to 'lib/jitterbug/Project.pm')
-rw-r--r--lib/jitterbug/Project.pm34
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/jitterbug/Project.pm b/lib/jitterbug/Project.pm
index 44c6844..30821ef 100644
--- a/lib/jitterbug/Project.pm
+++ b/lib/jitterbug/Project.pm
@@ -1,20 +1,18 @@
 package jitterbug::Project;
 
 use Dancer ':syntax';
-use jitterbug::Plugin::Redis;
+use Dancer::Plugin::DBIC;
 use jitterbug::Plugin::Template;
 
 use DateTime;
 use XML::Feed;
 
 get '/:project' => sub {
-    my $project = params->{project};
+    my $project =
+      schema->resultset('Project')->find( { name => params->{project} } );
 
-    my $res = redis->get( key_project($project) );
-
-    send_error( "Project $project not found", 404 ) if !$res;
-
-    my $desc = from_json($res);
+    send_error( "Project " . params->{project} . " not found", 404 )
+      unless $project;
 
     my $builds = _sorted_builds($project);
 
@@ -28,16 +26,20 @@ get '/:project' => sub {
     my @days = sort {$b cmp $a} keys %$commits;
 
     template 'project/index',
-      { project => $project, days => \@days, builds => $commits, %$desc };
+        {project => $project, days => \@days, commits => $commits};
 };
 
 get '/:project/feed' => sub {
-    my $project = params->{project};
+    my $project =
+      schema->resultset('Project')->find( { name => params->{project} } );
+
+    send_error( "Project " . params->{project} . " not found", 404 )
+      unless $project;
 
     my $builds = _sorted_builds($project);
 
     my $feed = XML::Feed->new('Atom');
-    $feed->title('builds for '.$project);
+    $feed->title('builds for '.$project->name);
 
     foreach my $build (@$builds) {
         foreach my $version (keys %{$build->{version}}) {
@@ -61,14 +63,16 @@ get '/:project/feed' => sub {
 sub _sorted_builds {
     my $project = shift;
 
-    my @ids = redis->smembers( key_builds_project($project) );
+    my $commits =
+      schema->resultset('Commit')
+      ->search( { projectid => $project->projectid } );
 
     my @builds;
-    foreach my $id (@ids) {
-        my $res = redis->get($id);
-        push @builds, from_json($res) if $res;
+    while ( my $c = $commits->next ) {
+        push @builds, from_json( $c->content );
     }
-    @builds = sort {$b->{timestamp} cmp $a->{timestamp}} @builds;
+
+    @builds = sort { $b->{timestamp} cmp $a->{timestamp} } @builds;
     \@builds;
 }