From abf3d5c2319fd9f8b8398ed05df31afd7f442d19 Mon Sep 17 00:00:00 2001 From: Iain C Docherty Date: Mon, 2 May 2016 07:33:42 -0400 Subject: [PATCH] Completed survey --- lib/Lacuna/DB/Result/Empire.pm | 2 ++ lib/Lacuna/DB/Result/Survey.pm | 23 +++++++++++++++++ lib/Lacuna/RPC/Empire.pm | 46 ++++++++++++++++++++++++++++++++++ var/upgrades/3.0923.sql | 8 ++++++ 4 files changed, 79 insertions(+) create mode 100644 lib/Lacuna/DB/Result/Survey.pm create mode 100644 var/upgrades/3.0923.sql diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 96f97c35..4aab581f 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -124,6 +124,8 @@ __PACKAGE__->has_many('medals', 'Lacuna::DB::Result::Medals', __PACKAGE__->has_many('all_probes', 'Lacuna::DB::Result::Probes', 'empire_id'); __PACKAGE__->has_many('bodies', 'Lacuna::DB::Result::Map::Body', 'empire_id'); +__PACKAGE__->might_have(survey => 'Lacuna::DB::Result::Survey', 'empire_id'); + has has_new_messages => ( is => 'ro', isa => 'Int', diff --git a/lib/Lacuna/DB/Result/Survey.pm b/lib/Lacuna/DB/Result/Survey.pm new file mode 100644 index 00000000..5104db4a --- /dev/null +++ b/lib/Lacuna/DB/Result/Survey.pm @@ -0,0 +1,23 @@ +package Lacuna::DB::Result::Survey; + +use Moose; +use utf8; +use DateTime; + +# no "id" column. +extends 'Lacuna::DB::ResultBase'; + +__PACKAGE__->load_components('TimeStamp', 'InflateColumn::DateTime', 'InflateColumn::Serializer', 'Core'); + +__PACKAGE__->table('survey'); +__PACKAGE__->add_columns( + empire_id => { data_type => 'int', is_nullable => 0 }, + choice => { data_type => 'int', is_nullable => 1 }, + comment => { data_type => 'text', is_nullable => 1 }, +); +__PACKAGE__->set_primary_key('empire_id'); + +__PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id', { on_delete => 'cascade' }); + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index 3a6e0b55..edc898f9 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -714,6 +714,51 @@ sub set_status_message { return $self->format_status($session); } +sub set_survey { + my ($self, $session_id, $choice, $comment) = @_; + + my $session = $self->get_session({session_id => $session_id}); + my $empire = $session->current_empire; + + my $survey = $empire->survey; + if (defined $survey) { + $survey->choice($choice); + $survey->comment($comment); + $survey->update; + } + else { + $empire->create_related('survey', { + choice => $choice, + comment => $comment, + }); + } + + return $self->format_status($session); +} + +sub get_survey { + my ($self, $session_id) = @_; + + my $session = $self->get_session({session_id => $session_id}); + my $empire = $session->current_empire; + + my $survey = $empire->survey; + my $out = { + choice => 0, + comment => "No Comment", + }; + + if (defined $survey) { + $out = { + choice => $survey->choice, + comment => $survey->comment, + }; + } + return { survey => $out, status => $self->format_status($session) }; +} + + + sub view_public_profile { my ($self, $session_id, $empire_id) = @_; my $session = $self->get_session({session_id => $session_id}); @@ -1370,6 +1415,7 @@ __PACKAGE__->register_rpc_method_names( boost_building boost_storage boost_water boost_energy boost_ore boost_food boost_happiness boost_spy_training view_boosts view_authorized_sitters authorize_sitters deauthorize_sitters + get_survey set_survey ), ); diff --git a/var/upgrades/3.0923.sql b/var/upgrades/3.0923.sql new file mode 100644 index 00000000..96ebd8dd --- /dev/null +++ b/var/upgrades/3.0923.sql @@ -0,0 +1,8 @@ +create table survey ( + empire_id int(11) not null, + choice int(11) not null default 0, + comment text not null default '', + primary key (empire_id), + constraint survey_fk_empire_id foreign key (empire_id) references empire (id) +); + -- 2.51.2