diff --git a/doc/index.html b/doc/index.html index acb96b7..f675881 100644 --- a/doc/index.html +++ b/doc/index.html @@ -29,6 +29,9 @@
  • Peace::Model::Application
  • +
  • + Peace::Model::Build +
  • Peace::Model::Customer
  • diff --git a/doc/lib/Peace/Model/Build.pm.html b/doc/lib/Peace/Model/Build.pm.html new file mode 100644 index 0000000..26b7ada --- /dev/null +++ b/doc/lib/Peace/Model/Build.pm.html @@ -0,0 +1,111 @@ + + + + +Peace::Model::Build - An object representing a release build for an architecture. + + + + + + + + + + +

    NAME

    + +

    Peace::Model::Build - An object representing a release build for an architecture.

    + +

    SYNOPSIS

    + +
    my $build = Peace::Model::Build->new(
    +  release => $release,
    +  arch    => $arch,
    +);
    + +

    DESCRIPTION

    + +

    Peace::Model::Build represents a successful build for an architecture of Peace::Model::Release.

    + +

    INSTANCE METHODS

    + +

    Peace::Model::Build implements the following instance methods:

    + +

    new

    + +
    my $build = Peace::Model::Build->new(
    +  uuid          => $uuid,          # optional
    +  date_creation => $date_creation, # optional
    +  release       => $release,       # required or release_uuid should be passed.
    +  release_uuid  => $release_uuid,  # required or release should be passed,
    +  dbh           => $dbh,           # needed if release_uuid is passed.
    +  arch          => $arch,
    +);
    + +

    Instances a Peace::Model::Build.

    + +

    METHODS

    + +

    Peace::Model::Build implements the following methods:

    + +

    uuid

    + +
    my $uuid = $build->uuid;
    +
    +$build->uuid($uuid);
    + +

    Allows to set and retrieve the uuid attribute.

    + +

    date_creation

    + +
    my $date_creation = $build->date_creation;
    +
    +$build->date_creation($date_creation);
    + +

    Allows to set and retrieve the date_creation attribute as a DateTime.

    + +

    release

    + +
    my $release = $build->release;
    +
    +$build->release($release);
    + +

    Allows to set and retrieve the release attribute as a Peace::Model::Release.

    + +

    arch

    + +
    my $arch = $build->arch;
    +
    +$build->arch($arch);
    + +

    Allows to set and retrieve the architecture attribute.

    + +

    SEE ALSO

    + +

    Peace::Model::Release, Peace::DAO::Build

    + + + + + + + diff --git a/lib/Peace/DB.pm b/lib/Peace/DB.pm index f095cfa..7fea43e 100644 --- a/lib/Peace/DB.pm +++ b/lib/Peace/DB.pm @@ -63,7 +63,7 @@ my @migrations = ( 'CREATE TABLE builds ( uuid UUID NOT NULL DEFAULT gen_random_uuid(), release UUID NOT NULL, - date timestamp DEFAULT NOW(), + date_creation timestamp DEFAULT NOW(), arch TEXT NOT NULL, PRIMARY KEY (uuid), FOREIGN KEY (release) REFERENCES releases (uuid) @@ -71,7 +71,7 @@ my @migrations = ( 'CREATE TABLE purchases ( customer UUID NOT NULL, application UUID NOT NULL, - date timestamp DEFAULT NOW(), + date_purchase timestamp DEFAULT NOW(), PRIMARY KEY (customer, application), FOREIGN KEY (application) REFERENCES applications (uuid), FOREIGN KEY (customer) REFERENCES customers (uuid) diff --git a/lib/Peace/Model/Build.pm b/lib/Peace/Model/Build.pm new file mode 100644 index 0000000..3744bbe --- /dev/null +++ b/lib/Peace/Model/Build.pm @@ -0,0 +1,182 @@ +package Peace::Model::Build; + +use v5.30.0; + +use strict; +use warnings; + +use Params::ValidationCompiler qw/validation_for/; +use Types::Standard qw/Str InstanceOf Bool HasMethods/; + +use DateTime; + +use Peace::DAO::Release; + +{ + my $validator = validation_for( + params => { + uuid => { type => Str, optional => 1 }, + date_creation => { type => InstanceOf ['DateTime'], optional => 1 }, + release => + { type => InstanceOf ['Peace::Model::Release'], optional => 1 }, + release_uuid => { type => Str, optional => 1, }, + dbh => { type => HasMethods ['selectall_arrayref'], optional => 1 }, + arch => { type => Str, }, + } + ); + + sub new { + my $class = shift; + my %params = $validator->(@_); + die 'release or release_uuid should be passed on construct' + unless exists $params{release} + || ( exists $params{release_uuid} && exists $params{dbh} ); + my $self = bless {%params}, $class; + return $self; + } +} + +{ + my $validator = + validation_for( params => [ { type => Str, optional => 1 }, ] ); + + sub uuid { + my $self = shift; + if (@_) { + my ($new_uuid) = $validator->(@_); + $self->{uuid} = $new_uuid; + } + return $self->{uuid}; + } +} + +{ + my $validator = validation_for( + params => [ { type => InstanceOf ['DateTime'], optional => 1 } ] ); + + sub date_creation { + my $self = shift; + if (@_) { + my ($new_date_creation) = $validator->(@_); + $self->{date_creation} = $new_date_creation; + } + return $self->{date_creation}; + } +} + +{ + my $validator = validation_for( params => + { { type => InstanceOf ['Peace::Model::Release'], optional => 1 } } ); + + sub release { + my $self = shift; + if (@_) { + my ($new_release) = $validator->(@_); + $self->{release} = $new_release; + } + if ( !defined $self->{release} ) { + my $release_dao = Peace::DAO::Release->new( dbh => $self->_dbh ); + $self->{release} = + $release_dao->recover_by_uuid( uuid => $self->{release_uuid} ); + } + return $self->{release}; + } +} + +{ + my $validator = + validation_for( params => [ { type => Str, optional => 1, } ] ); + + sub arch { + my $self = shift; + if (@_) { + my ($new_arch) = $validator->(@_); + $self->{arch} = $new_arch; + } + return $self->{arch}; + } +} + +sub _dbh { + my $self = shift; + return $self->{dbh}; +} +1; + +=encoding utf8 + +=head1 NAME + +Peace::Model::Build - An object representing a release build for an +architecture. + +=head1 SYNOPSIS + + my $build = Peace::Model::Build->new( + release => $release, + arch => $arch, + ); + +=head1 DESCRIPTION + +Peace::Model::Build represents a successful build for an +architecture of L. + +=head1 INSTANCE METHODS + +Peace::Model::Build implements the following instance methods: + +=head2 new + + my $build = Peace::Model::Build->new( + uuid => $uuid, # optional + date_creation => $date_creation, # optional + release => $release, # required or release_uuid should be passed. + release_uuid => $release_uuid, # required or release should be passed, + dbh => $dbh, # needed if release_uuid is passed. + arch => $arch, + ); + +Instances a Peace::Model::Build. + +=head1 METHODS + +Peace::Model::Build implements the following methods: + +=head2 uuid + + my $uuid = $build->uuid; + + $build->uuid($uuid); + +Allows to set and retrieve the uuid attribute. + +=head2 date_creation + + my $date_creation = $build->date_creation; + + $build->date_creation($date_creation); + +Allows to set and retrieve the date_creation attribute as a L. + +=head2 release + + my $release = $build->release; + + $build->release($release); + +Allows to set and retrieve the release attribute as a L. + +=head2 arch + + my $arch = $build->arch; + + $build->arch($arch); + +Allows to set and retrieve the architecture attribute. + +=head1 SEE ALSO + +L, L + +=cut diff --git a/t/00011-build-model.t b/t/00011-build-model.t new file mode 100644 index 0000000..1a63d14 --- /dev/null +++ b/t/00011-build-model.t @@ -0,0 +1,11 @@ +#!/usr/bin/env perl +use v5.30.0; + +use strict; +use warnings; + +use Test::Most tests => 1; + +BEGIN { + use_ok('Peace::Model::Build'); +}