diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index 5134e95..c8d154b 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -172,7 +172,9 @@ sub startup { $admin_routes->get('/organisations')->to('admin-organisations#list'); $admin_routes->get('/organisations/valid/:id')->to('admin-organisations#valid_read'); + $admin_routes->get('/organisations/valid/:id/edit')->to('admin-organisations#valid_edit'); $admin_routes->get('/organisations/pending/:id')->to('admin-organisations#pending_read'); + $admin_routes->get('/organisations/pending/:id/edit')->to('admin-organisations#pending_edit'); $admin_routes->get('/organisations/pending/:id/approve')->to('admin-organisations#pending_approve'); $admin_routes->get('/feedback')->to('admin-feedback#index'); diff --git a/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm b/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm index 1dffdc9..84eef3f 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm @@ -2,6 +2,7 @@ package Pear::LocalLoop::Controller::Admin::Organisations; use Mojo::Base 'Mojolicious::Controller'; use Try::Tiny; +use Data::Dumper; sub list { my $c = shift; @@ -30,6 +31,43 @@ sub valid_read { ); } +sub valid_edit { + my $c = shift; + + my $validation = $c->validation; + $validation->required('name'); + $validation->required('street_name'); + $validation->required('town'); + $validation->required('postcode')->postcode; + + if ( $validation->has_error ) { + $c->flash( error => 'The validation has failed' ); + $c->app->log->warn(Dumper $validation); + return $c->redirect_to( '/admin/organisations/valid/' . $c->param('id') ); + } + + my $valid_org = $c->schema->resultset('Organisation')->find( $c->param('id') ); + + try { + $c->schema->storage->txn_do( sub { + $valid_org->update({ + name => $validation->param('name'), + street_name => $validation->param('street_name'), + town => $validation->param('town'), + postcode => $validation->param('postcode'), + }); + } ); + } finally { + if ( @_ ) { + $c->flash( error => 'Something went wrong Updating the Organisation' ); + $c->app->log->warn(Dumper @_); + } else { + $c->flash( success => 'Updated Organisation' ); + } + }; + $c->redirect_to( '/admin/organisations/valid/' . $valid_org->id ); +} + sub pending_read { my $c = shift; my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') ); @@ -45,6 +83,43 @@ sub pending_read { ); } +sub pending_edit { + my $c = shift; + + my $validation = $c->validation; + $validation->required('name'); + $validation->required('street_name'); + $validation->required('town'); + $validation->required('postcode')->postcode; + + if ( $validation->has_error ) { + $c->flash( error => 'The validation has failed' ); + $c->app->log->warn(Dumper $validation); + return $c->redirect_to( '/admin/organisations/pending/' . $c->param('id') ); + } + + my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') ); + + try { + $c->schema->storage->txn_do( sub { + $pending_org->update({ + name => $validation->param('name'), + street_name => $validation->param('street_name'), + town => $validation->param('town'), + postcode => $validation->param('postcode'), + }); + } ); + } finally { + if ( @_ ) { + $c->flash( error => 'Something went wrong Updating the Organisation' ); + $c->app->log->warn(Dumper @_); + } else { + $c->flash( success => 'Updated Organisation' ); + } + }; + $c->redirect_to( '/admin/organisations/valid/' . $pending_org->id ); +} + sub pending_approve { my $c = shift; my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') ); diff --git a/templates/admin/organisations/pending_read.html.ep b/templates/admin/organisations/pending_read.html.ep index 13995ff..aa0bec9 100644 --- a/templates/admin/organisations/pending_read.html.ep +++ b/templates/admin/organisations/pending_read.html.ep @@ -16,10 +16,12 @@ %= $pending_org->name