Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

day 07

  • Loading branch information...
commit 21311c6ddb22c64c4354e76927e653ca8c79249b 1 parent dae9521
@typester authored
View
3  config.pl
@@ -1,6 +1,9 @@
my $home = Jobeet::Models->get('home');
return {
+ active_days => 30,
+ max_jobs_on_homepage => 10,
+
database => [
'dbi:SQLite:' . $home->file('database.db'), '', '',
{
View
19 lib/Jobeet/API.pm
@@ -1,19 +0,0 @@
-package Jobeet::API;
-use Mouse;
-
-has errstr => (
- is => 'rw',
- isa => 'Str',
-);
-
-no Mouse;
-
-sub error {
- my ($self, $error) = @_;
-
- $self->_error($error);
- return;
-}
-
-1;
-
View
3  lib/Jobeet/Controller/Job.pm
@@ -1,12 +1,13 @@
package Jobeet::Controller::Job;
use Ark 'Controller';
+use DateTime;
use Jobeet::Models;
sub index :Path {
my ($self, $c) = @_;
- $c->stash->{jobs} = models('Schema::Job');
+ $c->stash->{categories} = models('Schema::Category')->get_with_jobs;
}
sub show :Path :Args(1) {
View
14 lib/Jobeet/Schema/Result/Category.pm
@@ -31,5 +31,19 @@ __PACKAGE__->has_many(
__PACKAGE__->many_to_many( affiliates => category_affiliate => 'affiliate' );
+sub get_active_jobs {
+ my $self = shift;
+ my $attr = shift || {};
+
+ $attr->{rows} ||= 10;
+
+ $self->jobs(
+ { expires_at => { '>=', DateTime->now } },
+ { order_by => { -desc => 'created_at' },
+ rows => $attr->{rows},
+ }
+ );
+}
+
1;
View
9 lib/Jobeet/Schema/Result/Job.pm
@@ -3,6 +3,9 @@ use strict;
use warnings;
use base 'Jobeet::Schema::ResultBase';
+use DateTime;
+use Jobeet::Models;
+
__PACKAGE__->table('jobeet_job');
__PACKAGE__->add_columns(
@@ -101,5 +104,11 @@ __PACKAGE__->add_unique_constraint(['token']);
__PACKAGE__->belongs_to( category => 'Jobeet::Schema::Result::Category', 'category_id' );
+sub insert {
+ my $self = shift;
+
+ $self->expires_at( DateTime->now->add( days => models('conf')->{active_days} ) );
+ $self->next::method(@_);
+}
1;
View
19 lib/Jobeet/Schema/ResultSet/Category.pm
@@ -0,0 +1,19 @@
+package Jobeet::Schema::ResultSet::Category;
+use strict;
+use warnings;
+use base 'DBIx::Class::ResultSet';
+
+sub get_with_jobs {
+ my $self = shift;
+
+ $self->search(
+ { 'jobs.expires_at' => { '>=', DateTime->now } },
+ {
+ join => 'jobs', group_by => 'me.name',
+ },
+ );
+}
+
+1;
+
+
View
7 lib/Jobeet/Schema/ResultSet/Job.pm
@@ -0,0 +1,7 @@
+package Jobeet::Schema::ResultSet::Job;
+use strict;
+use warnings;
+use base 'DBIx::Class::ResultSet';
+
+1;
+
View
43 root/job/index.mt
@@ -7,21 +7,34 @@
? block content => sub {
<div id="jobs">
- <table class="jobs">
+? for my $category ($c->stash->{categories}->all) {
+ <div class="category_<?= lc $category->name ?>">
+ <div class="category">
+ <div class="feed">
+ <a href="">Feed</a>
+ </div>
+ <h1><?= $category->name ?></h1>
+ </div>
+
+ <table class="jobs">
? my $i = 0;
-? for my $job ($c->stash->{jobs}->all) {
-? $i++;
- <tr class="<?= $i % 2 == 0 ? 'even' : 'odd' ?>">
- <td class="location"><?= $job->location ?></td>
- <td class="position">
- <a href="<?= $c->uri_for('/job', $job->id) ?>">
- <?= $job->position ?>
- </a>
- </td>
- <td class="company"><?= $job->company ?></td>
- </tr>
-? } # endfor
-</table>
+? my $max_rows = Jobeet::Models->get('conf')->{max_jobs_on_homepage};
+? for my $job ($category->get_active_jobs({ rows => $max_rows })) {
+ <tr class="<?= $i++ % 2 ? 'even' : 'odd' ?>">
+ <td class="location">
+ <?= $job->location ?>
+ </td>
+ <td class="position">
+ <?= $job->position ?>
+ </td>
+ <td class="company">
+ <?= $job->company ?>
+ </td>
+ </tr>
+? } #endfor $job
+ </table>
+ </div>
+? } #endfor $category
</div>
-? } # endblock content
+? } #endblcok content
View
42 script/insert_default_data.pl
@@ -4,6 +4,7 @@
use warnings;
use FindBin::libs;
+use DateTime;
use Jobeet::Models;
# create default Categories
@@ -47,4 +48,45 @@
expires_at => '2010-10-10',
});
+{
+ my $cat_programming = models('Schema::Category')->find({ name => 'Programming' });
+ my $job = models('Schema::Job')->create({
+ category_id => $cat_programming->id,
+ company => 'Sensio Labs',
+ position => 'Web Developer',
+ location => 'Paris, France',
+ description => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.',
+ how_to_apply => 'Send your resume to lorem.ipsum [at] dolor.sit',
+ is_public => 1,
+ is_activated => 1,
+ token => 'job_expired',
+ email => 'job@example.com',
+ });
+ $job->update({
+ created_at => '2005-12-01',
+ expires_at => '2005-12-31',
+ });
+}
+
+{
+ my $job_rs = models('Schema::Job');
+ my $cat_rs = models('Schema::Category');
+
+ my $cat_programming = $cat_rs->find({ name => 'Programming' });
+
+ for my $i (100 .. 130) {
+ my $job = $job_rs->create({
+ category_id => $cat_programming->id,
+ company => "Company $i",
+ position => 'Web Developer',
+ location => 'Paris, France',
+ description => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.',
+ how_to_apply => "Send your resume to lorem.ipsum [at] company_${i}.sit",
+ is_public => 1,
+ is_activated => 1,
+ token => "job_$i",
+ email => 'job@example.com',
+ });
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.