From 436edcef00dade896699daccfd346a7da21dd9b6 Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Thu, 24 Mar 2022 18:52:35 +0100 Subject: [PATCH] Adding Release Model and multiple doc improvements. --- doc/index.html | 3 + doc/lib/Peace/Model/Application.pm.html | 2 +- doc/lib/Peace/Model/Release.pm.html | 120 ++++++++++ lib/Peace/DB.pm | 2 +- lib/Peace/Model/Application.pm | 2 +- lib/Peace/Model/Release.pm | 212 ++++++++++++++++++ ...09-pod-coverage.t => 00000-pod-coverage.t} | 4 +- t/00009-release-model.t | 68 ++++++ 8 files changed, 409 insertions(+), 4 deletions(-) create mode 100644 doc/lib/Peace/Model/Release.pm.html create mode 100644 lib/Peace/Model/Release.pm rename t/{00009-pod-coverage.t => 00000-pod-coverage.t} (87%) create mode 100644 t/00009-release-model.t diff --git a/doc/index.html b/doc/index.html index 5811812..f3737f2 100644 --- a/doc/index.html +++ b/doc/index.html @@ -32,6 +32,9 @@
  • Peace::Model::Developer
  • +
  • + Peace::Model::Release +
  • diff --git a/doc/lib/Peace/Model/Application.pm.html b/doc/lib/Peace/Model/Application.pm.html index ae22365..1c588fc 100644 --- a/doc/lib/Peace/Model/Application.pm.html +++ b/doc/lib/Peace/Model/Application.pm.html @@ -56,7 +56,7 @@

    DESCRIPTION

    -

    Describes a application from Peace for sale.

    +

    Describes an application from Peace for sale.

    INSTANCE METHODS

    diff --git a/doc/lib/Peace/Model/Release.pm.html b/doc/lib/Peace/Model/Release.pm.html new file mode 100644 index 0000000..5388eb6 --- /dev/null +++ b/doc/lib/Peace/Model/Release.pm.html @@ -0,0 +1,120 @@ + + + + +Peace::Model::Release - The release object representation. + + + + + + + + + + +

    NAME

    + +

    Peace::Model::Release - The release object representation.

    + +

    SYNOPSIS

    + +
    my $release = Peace::Model::Release->new(
    +  application => $application,
    +  tag         => $tag,
    +  name        => $name,
    +);
    + +

    DESCRIPTION

    + +

    Describes a release from an application from Peace.

    + +

    INSTANCE METHODS

    + +

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

    + +

    new

    + +
    my $release = Peace::Model::Release->new(
    +  uuid             => $uuid,             # optional
    +  date_creation    => $date_creation,    # optional
    +  application      => $application,      # required or application_uuid should be passed.
    +  application_uuid => $application_uuid, # required or application should be passed
    +  dbh              => $dbh,              # needed if application_uuid is passed
    +  tag              => $tag,
    +  name             => $name,
    +);
    + +

    METHODS

    + +

    Peace::Model::Release implements the following methods:

    + +

    uuid

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

    Allows to retrieve and set the release uuid.

    + +

    date_creation

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

    Allows to retrieve and set the release date creation as a DateTime.

    + +

    application

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

    Allows to retrieve and set the release application as a Peace::Model::Application.

    + +

    tag

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

    Allows to retrieve and set the release tag.

    + +

    name

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

    Allows to retrieve and set the release name.

    + +

    SEE ALSO

    + +

    Peace::Model::Application, Peace::DAO::Release

    + + + + + + + diff --git a/lib/Peace/DB.pm b/lib/Peace/DB.pm index 96bb5d2..fda324c 100644 --- a/lib/Peace/DB.pm +++ b/lib/Peace/DB.pm @@ -52,8 +52,8 @@ my @migrations = ( );', 'CREATE TABLE releases ( uuid UUID NOT NULL DEFAULT gen_random_uuid(), - application UUID NOT NULL, date timestamp DEFAULT NOW(), + application UUID NOT NULL, tag TEXT NOT NULL, name TEXT NOT NULL, PRIMARY KEY (uuid), diff --git a/lib/Peace/Model/Application.pm b/lib/Peace/Model/Application.pm index 3050a46..28eee12 100644 --- a/lib/Peace/Model/Application.pm +++ b/lib/Peace/Model/Application.pm @@ -218,7 +218,7 @@ Peace::Model::Application - The application object representation. =head1 DESCRIPTION -Describes a application from Peace for sale. +Describes an application from Peace for sale. =head1 INSTANCE METHODS diff --git a/lib/Peace/Model/Release.pm b/lib/Peace/Model/Release.pm new file mode 100644 index 0000000..85e5710 --- /dev/null +++ b/lib/Peace/Model/Release.pm @@ -0,0 +1,212 @@ +package Peace::Model::Release; + +use v5.30.0; + +use strict; +use warnings; + +use Params::ValidationCompiler qw/validation_for/; +use Types::Standard qw/InstanceOf Str HasMethods/; + +{ + my $validator = validation_for( + params => { + uuid => { type => Str, optional => 1 }, + date_creation => { type => InstanceOf ['DateTime'], optional => 1 }, + application => { + type => InstanceOf ['Peace::Model::Application'], + optional => 1 + }, + application_uuid => { type => Str, optional => 1 }, + dbh => { type => HasMethods ['selectrow_hashref'], optional => 1 }, + tag => { type => Str }, + name => { type => Str }, + } + ); + + sub new { + my $class = shift; + my %params = $validator->(@_); + die +'application or application_uuid with dbh should be passed on construct' + unless exists $params{application} + || ( exists $params{application_uuid} && exists $params{dbh} ); + + return bless {%params}, $class; + } +} + +{ + 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::Application'], optional => 1 } + ] + ); + sub application { + my $self = shift; + if (@_) { + my ($new_application) = $validator->(@_); + $self->{application} = $new_application; + } + unless ( exists $self->{developer} ) { + my $application_uuid = $self->{application_uuid}; + my $application_dao = + Peace::DAO::Application->new( dbh => $self->_dbh ); + $self->{application} = + $application_dao->recover_by_uuid( uuid => $application_uuid ); + } + return $self->{application}; + + } +} + +{ + my $validator = validation_for( + params => [ + { + type => Str, optional => 1, + } + ] + ); + sub tag { + my $self = shift; + if (@_) { + my $new_tag = $validator->(@_); + $self->{tag} = $new_tag; + } + return $self->{tag}; + } +} + +{ + my $validator = validation_for( + params => [ + { type => Str, optional => 1 }, + ] + ); + + sub name { + my $self = shift; + if (@_) { + my ($new_name) = $validator->(@_); + $self->{name} = $new_name; + } + return $self->{name}; + } +} + +1; + +=encoding utf8 + +=head1 NAME + +Peace::Model::Release - The release object representation. + +=head1 SYNOPSIS + + my $release = Peace::Model::Release->new( + application => $application, + tag => $tag, + name => $name, + ); + +=head1 DESCRIPTION + +Describes a release from an application from Peace. + +=head1 INSTANCE METHODS + +Peace::Model::Release implements the following instance +methods: + +=head2 new + + my $release = Peace::Model::Release->new( + uuid => $uuid, # optional + date_creation => $date_creation, # optional + application => $application, # required or application_uuid should be passed. + application_uuid => $application_uuid, # required or application should be passed + dbh => $dbh, # needed if application_uuid is passed + tag => $tag, + name => $name, + ); + +=head1 METHODS + +Peace::Model::Release implements the following methods: + +=head2 uuid + + my $uuid = $release->uuid; + + $release->uuid($uuid); + +Allows to retrieve and set the release uuid. + +=head2 date_creation + + my $date_creation = $release->date_creation; + + $release->date_creation($date_creation); + +Allows to retrieve and set the release date creation as a L. + +=head2 application + + my $application = $release->application; + + $release->application($application); + +Allows to retrieve and set the release application as a L. + +=head2 tag + + my $tag = $release->tag; + + $release->tag($tag); + +Allows to retrieve and set the release tag. + +=head2 name + + my $name = $release->name + + $release->name($name); + +Allows to retrieve and set the release name. + +=head1 SEE ALSO + +L, L + +=cut diff --git a/t/00009-pod-coverage.t b/t/00000-pod-coverage.t similarity index 87% rename from t/00009-pod-coverage.t rename to t/00000-pod-coverage.t index 70452a0..cc782d2 100644 --- a/t/00009-pod-coverage.t +++ b/t/00000-pod-coverage.t @@ -5,7 +5,7 @@ use v5.30.0; use strict; use warnings; -use Test::Most tests => 9; +use Test::Most; use Test::Pod::Coverage; { @@ -14,3 +14,5 @@ use Test::Pod::Coverage; pod_coverage_ok($module); } } + +done_testing; diff --git a/t/00009-release-model.t b/t/00009-release-model.t new file mode 100644 index 0000000..549cf89 --- /dev/null +++ b/t/00009-release-model.t @@ -0,0 +1,68 @@ +use v5.30.0; + +use strict; +use warnings; + +use Test::Most tests => 4; + +use Peace::Model::Application; +use Peace::Model::Developer; + +BEGIN { + use_ok 'Peace::Model::Release'; +} + +{ + ## GIVEN + ### Developer data. + my $developer_secret_bcrypt = 'hola'; + my $developer_name = 'Larry'; + my $developer_surname = 'Wall'; + my $developer_email = 'larry@perl.org'; + my $developer_country = 'US'; + my $developer_verified = 0; + + ### Application data. + my $app_name = 'Desfronificator'; + my $app_description = 'Desfronifies the files.'; + my $app_url = 'https://desfronificator.example.com'; + my $app_price = '4.20'; + my $app_git_repo = + 'https://git.desfronificator.example.com/larry/desfronificator.git'; + my $app_flatpak_builder_file = + './resources/com.example.desfronificator.yml'; + my $app_verified = 0; + my $app_developer = Peace::Model::Developer->new( + secret_bcrypt => $developer_secret_bcrypt, + name => $developer_name, + surname => $developer_surname, + email => $developer_email, + country => $developer_country, + verified => $developer_verified, + ); + ### Release data. + my $release_application = Peace::Model::Application->new( + developer => $app_developer, + name => $app_name, + description => $app_description, + url => $app_url, + price => $app_price, + flatpak_builder_file => $app_flatpak_builder_file, + verified => $app_verified, + git_repo => $app_git_repo, + ); + my $release_name = '0.0.1'; + my $release_tag = 'v0.0.1'; + + ## WHEN + my $release = Peace::Model::Release->new( + name => $release_name, + application => $release_application, + tag => $release_tag + ); + ## THEN + ok $release->isa('Peace::Model::Release'), + 'Instanced release is made of Peace::Model::Release.'; + is $release->name, $release_name, 'Name is correctly setup'; + is $release->uuid, undef, 'Uuid is undef.'; +}