333 lines
7.2 KiB
Perl
333 lines
7.2 KiB
Perl
package Peace::Model::Developer;
|
|
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::Application;
|
|
|
|
{
|
|
my $validator = validation_for(
|
|
params => {
|
|
uuid => { type => Str, optional => 1 },
|
|
date_creation => { type => InstanceOf ['DateTime'], optional => 1 },
|
|
secret_bcrypt => { type => Str },
|
|
name => { type => Str },
|
|
surname => { type => Str },
|
|
email => { type => Str },
|
|
stripe_id => { type => Str, optional => 1 },
|
|
country => { type => Str },
|
|
verified => { type => Bool },
|
|
dbh => { type => HasMethods ['selectall_arrayref'], optional => 1 },
|
|
}
|
|
);
|
|
|
|
sub new {
|
|
my $class = shift;
|
|
my %params = $validator->(@_);
|
|
my $self = bless {%params}, $class;
|
|
return $self;
|
|
}
|
|
}
|
|
|
|
sub to_json {
|
|
my $self = shift;
|
|
return {
|
|
uuid => $self->uuid,
|
|
date_creation => '' . $self->date_creation,
|
|
name => $self->name,
|
|
surname => $self->surname,
|
|
email => $self->email,
|
|
country => $self->country,
|
|
verified => $self->verified,
|
|
};
|
|
}
|
|
|
|
sub applications {
|
|
my $self = shift;
|
|
if ( !defined $self->{applications} ) {
|
|
my $dbh = $self->_dbh;
|
|
if ( !defined $dbh ) {
|
|
die
|
|
"There is no database handle, so no chance to recover applications from the developer.";
|
|
}
|
|
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
|
|
$self->{applications} =
|
|
$application_dao->recover_by_developer( developer => $self );
|
|
}
|
|
|
|
return $self->{applications};
|
|
}
|
|
|
|
{
|
|
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 => Str, optional => 1 } ] );
|
|
|
|
sub secret_bcrypt {
|
|
my $self = shift;
|
|
if (@_) {
|
|
my ($new_secret_bcrypt) = $validator->(@_);
|
|
$self->{secret_bcrypt} = $new_secret_bcrypt;
|
|
}
|
|
return $self->{secret_bcrypt};
|
|
}
|
|
}
|
|
|
|
{
|
|
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};
|
|
}
|
|
}
|
|
|
|
{
|
|
my $validator =
|
|
validation_for( params => [ { type => Str, optional => 1 } ] );
|
|
|
|
sub surname {
|
|
my $self = shift;
|
|
if (@_) {
|
|
my ($new_surname) = $validator->(@_);
|
|
$self->{surname} = $new_surname;
|
|
}
|
|
return $self->{surname};
|
|
}
|
|
}
|
|
|
|
{
|
|
my $validator =
|
|
validation_for( params => [ { type => Str, optional => 1 } ] );
|
|
|
|
sub email {
|
|
my $self = shift;
|
|
if (@_) {
|
|
my ($new_email) = $validator->(@_);
|
|
$self->{email} = $new_email;
|
|
}
|
|
return $self->{email};
|
|
}
|
|
}
|
|
|
|
{
|
|
my $validator =
|
|
validation_for( params => [ { type => Str, optional => 1 } ] );
|
|
|
|
sub stripe_id {
|
|
my $self = shift;
|
|
if (@_) {
|
|
my ($new_stripe_id) = $validator->(@_);
|
|
$self->{stripe_id} = $new_stripe_id;
|
|
}
|
|
return $self->{stripe_id};
|
|
}
|
|
}
|
|
|
|
{
|
|
my $validator =
|
|
validation_for( params => [ { type => Str, optional => 1 } ] );
|
|
|
|
sub country {
|
|
my $self = shift;
|
|
if (@_) {
|
|
my ($new_country) = $validator->(@_);
|
|
$self->{country} = $new_country;
|
|
}
|
|
return $self->{country};
|
|
}
|
|
}
|
|
|
|
{
|
|
my $validator =
|
|
validation_for( params => [ { type => Bool, optional => 1 } ] );
|
|
|
|
sub verified {
|
|
my $self = shift;
|
|
if (@_) {
|
|
my ($new_verified) = $validator->(@_);
|
|
$self->{verified} = $new_verified;
|
|
}
|
|
return $self->{verified};
|
|
}
|
|
}
|
|
|
|
sub _dbh {
|
|
my $self = shift;
|
|
return $self->{dbh};
|
|
}
|
|
1;
|
|
|
|
=encoding utf8
|
|
|
|
=head1 NAME
|
|
|
|
Peace::Model::Developer - The developer object representation.
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
my $developer = Peace::Model::Developer->new(
|
|
secret_bcrypt => $secret_bcrypt,
|
|
name => $name,
|
|
surname => $surname,
|
|
email => $email,
|
|
country => $country,
|
|
verified => $verified,
|
|
);
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
Describes a developer capable of submit Applications to Peace
|
|
and get money.
|
|
|
|
=head1 INSTANCE METHODS
|
|
|
|
Peace::Model::Developer implements the following instance methods:
|
|
|
|
=head2 new
|
|
|
|
my $developer = Peace::Model::Developer->new(
|
|
uuid => $uuid, # optional
|
|
date_creation => $date_creation, # optional
|
|
secret_bcrypt => $secret_bcrypt,
|
|
name => $name,
|
|
surname => $surname,
|
|
email => $email,
|
|
stripe_id => $stripe_id, # optional
|
|
country => $country,
|
|
verified => $verified,
|
|
dbh => $dbh, # optional, allows to retrieve applications
|
|
);
|
|
|
|
=head1 METHODS
|
|
|
|
Peace::Model::Developer implements the following methods:
|
|
|
|
=head2 to_json
|
|
|
|
my $json = $developer->to_json;
|
|
|
|
Renders the developer in a json like structure.
|
|
|
|
=head2 applications
|
|
|
|
my $applications = $developer->applications;
|
|
|
|
Allows to retrieve the developer's applications which is a arrayref of
|
|
L<Peace::Model::Application>.
|
|
|
|
=head2 uuid
|
|
|
|
my $uuid = $developer->uuid;
|
|
|
|
$developer->uuid($uuid);
|
|
|
|
Allows to retrieve and set the developer uuid.
|
|
|
|
=head2 date_creation
|
|
|
|
my $date_creation = $developer->date_creation;
|
|
|
|
$developer->date_creation($date_creation);
|
|
|
|
Allows to retrieve and set the developer date_creation.
|
|
|
|
=head2 secret_bcrypt
|
|
|
|
my $secret_bcrypt = $developer->secret_bcrypt;
|
|
|
|
$developer->secret_bcrypt($secret_bcrypt);
|
|
|
|
Allows to retrieve and set the developer secret_bcrypt.
|
|
|
|
=head2 name
|
|
|
|
my $name = $developer->name;
|
|
|
|
$developer->name($name);
|
|
|
|
Allows to retrieve and set the developer name.
|
|
|
|
=head2 surname
|
|
|
|
my $surname = $developer->surname;
|
|
|
|
$developer->surname($surname);
|
|
|
|
=head2 email
|
|
|
|
my $email = $developer->email;
|
|
|
|
$developer->email($email);
|
|
|
|
Allows to retrieve and set the developer email.
|
|
|
|
=head2 stripe_id
|
|
|
|
my $stripe_id = $developer->stripe_id;
|
|
|
|
$developer->stripe_id($stripe_id);
|
|
|
|
Allows to retrieve and set the developer stripe_id.
|
|
|
|
=head2 country
|
|
|
|
my $country = $developer->country;
|
|
|
|
$developer->country($country);
|
|
|
|
Allows to retrieve and set the developer country.
|
|
|
|
=head2 verified
|
|
|
|
my $verified = $developer->verified
|
|
|
|
$developer->verified($verified);
|
|
|
|
Allows to retrieve and set the developer verified.
|
|
|
|
=head1 SEE ALSO
|
|
|
|
L<Peace::DAO::Developer>, L<Peace::Model::Application>
|
|
|
|
=cut
|