dependency injection

agranig/2.004-ramoptimized
Lars Dieckow 12 years ago
parent a0be037d0c
commit f8f770f8d7

@ -7,7 +7,7 @@ use Regexp::IPv6 qw($IPv6_re);
our $VERSION = '1.000';
has('config', is => 'ro', lazy => 1, default => sub { NGCP::Schema::Config->new->config });
has('config', is => 'rw', lazy => 1, default => sub { NGCP::Schema::Config->new->config });
method validate($data, $mandatory_params, $optional_params?) {
Exception->throw({

@ -17,6 +17,11 @@ use NGCP::Schema qw();
use NGCP::Schema::provisioning qw();
use aliased 'NGCP::Schema::Exception';
has('validator', is => 'rw', isa => 'NGCP::Schema', lazy => 1, default => sub { return NGCP::Schema->new; });
has('provisioning', is => 'rw', isa => 'NGCP::Schema::provisioning', lazy => 1, default => sub {
return NGCP::Schema::provisioning->connect;
});
method get_domain($reseller_id, $domain) {
my %return;
$return{domain} = $domain;
@ -86,7 +91,7 @@ method create_domain($data, $reseller_id?) {
Exception->throw({
description => 'Client.Syntax.MalformedDomain',
message => "malformed domain '$data->{domain}' in request",
}) unless NGCP::Schema->new->check_domain({domain => $data->{domain}});
}) unless $self->validator->check_domain({domain => $data->{domain}});
# /FIXME
$self->txn_do(λ{
# just to verify the domain does not exist for the reseller
@ -124,7 +129,7 @@ method create_domain($data, $reseller_id?) {
}) if defined $reseller_id;
}
# domain may already exist in provisioning DB if another reseller uses it
my $provisioning = NGCP::Schema::provisioning->connect;
my $provisioning = $self->provisioning;
if ($provisioning->get_domain({domain => $data->{domain}})) {
$provisioning->update_domain($data);
} else {
@ -142,7 +147,7 @@ method delete_domain($data, $reseller_id) {
Exception->throw({
description => 'Client.Syntax.MalformedDomain',
message => "malformed domain '$data->{domain}' in request",
}) unless NGCP::Schema->new->check_domain({domain => $data->{domain}});
}) unless $self->validator->check_domain({domain => $data->{domain}});
$self->txn_do(λ{
my $remaining_resellers = $self->delete_domain($reseller_id, $data->{domain});
unless ($remaining_resellers) {

@ -16,6 +16,8 @@ __PACKAGE__->load_namespaces;
use NGCP::Schema qw();
use aliased 'NGCP::Schema::Exception';
has('validator', is => 'rw', isa => 'NGCP::Schema', lazy => 1, default => sub { return NGCP::Schema->new; });
method _get_domain_id($domain) {
my $domainid = $self->resultset('voip_domains')->search({domain => $domain})->first->id;
Exception->throw({
@ -35,7 +37,7 @@ method create_domain($data) {
Exception->throw({
description => 'Client.Syntax.MalformedDomain',
message => "malformed domain '$data->{domain}' in request",
}) unless NGCP::Schema->new->check_domain({domain => $data->{domain}});
}) unless $self->validator->check_domain({domain => $data->{domain}});
# /FIXME
$self->txn_do(λ{
@ -62,7 +64,7 @@ method get_domain($data) {
Exception->throw({
description => 'Client.Syntax.MalformedDomain',
message => "malformed domain '$data->{domain}' in request",
}) unless NGCP::Schema->new->check_domain({domain => $data->{domain}});
}) unless $self->validator->check_domain({domain => $data->{domain}});
return $self->resultset('voip_domains')->search({id => $self->_get_domain_id($data->{domain})});
}
@ -74,7 +76,7 @@ method update_domain($data) {
Exception->throw({
description => 'Client.Syntax.MalformedDomain',
message => "malformed domain '$data->{domain}' in request",
}) unless NGCP::Schema->new->check_domain({domain => $data->{domain}});
}) unless $self->validator->check_domain({domain => $data->{domain}});
$self->txn_do(λ{
my $domainid = $self->_get_domain_id($data->{domain});
});
@ -90,7 +92,7 @@ method delete_domain($data) {
Exception->throw({
description => 'Client.Syntax.MalformedDomain',
message => "malformed domain '$data->{domain}' in request",
}) unless NGCP::Schema->new->check_domain({domain => $data->{domain}});
}) unless $self->validator->check_domain({domain => $data->{domain}});
$self->txn_do(λ{
my $domainid = $self->_get_domain_id($data->{domain});
$self->resultset('voip_domains')->search(

Loading…
Cancel
Save