burguillos.info/lib/BurguillosInfo/Schema/Result/ConquerUser.pm

89 lines
2.2 KiB
Perl
Raw Normal View History

2023-11-17 23:16:54 +01:00
package BurguillosInfo::Schema::Result::ConquerUser;
use v5.36.0;
use strict;
use warnings;
use parent 'DBIx::Class::Core';
2023-11-19 19:26:59 +01:00
use feature 'signatures';
2024-01-13 01:17:57 +01:00
use JSON;
2023-11-19 19:26:59 +01:00
__PACKAGE__->table('conquer_user');
2023-11-19 23:14:02 +01:00
__PACKAGE__->load_components("TimeStamp");
2023-11-17 23:16:54 +01:00
__PACKAGE__->add_columns(
uuid => {
2023-11-19 19:26:59 +01:00
data_type => 'uuid',
2023-11-17 23:16:54 +01:00
is_nullable => 0,
},
2024-01-13 01:17:57 +01:00
team => {
data_type => 'uuid',
is_nullable => 1,
},
2023-11-17 23:16:54 +01:00
username => {
2023-11-19 19:26:59 +01:00
data_type => 'text',
2023-11-17 23:16:54 +01:00
is_nullable => 0,
},
encrypted_password => {
2023-11-19 19:26:59 +01:00
data_type => 'text',
2023-11-17 23:16:54 +01:00
is_nullable => 0,
},
last_activity => {
2023-11-19 19:26:59 +01:00
data_type => 'timestamp',
is_nullable => 0,
default_value => \'NOW()',
},
registration_date => {
data_type => 'timestamp',
is_nullable => 0,
2023-11-17 23:16:54 +01:00
default_value => \'NOW()',
},
is_admin => {
2023-11-19 19:26:59 +01:00
data_type => 'boolean',
is_nullable => 0,
2023-11-17 23:16:54 +01:00
default_value => \'0',
2023-12-31 20:43:53 +01:00
},
last_coordinate_1 => {
data_type => 'real',
is_nullable => 0,
default_value => \'0',
},
last_coordinate_2 => {
data_type => 'real',
is_nullable => 0,
default_value => \'0',
},
2023-11-17 23:16:54 +01:00
);
2023-11-19 19:26:59 +01:00
2024-01-13 01:17:57 +01:00
sub coordinates ( $self, $coordinates = undef ) {
if ( defined $coordinates ) {
if ( ref $coordinates ne 'ARRAY' || scalar $coordinates->@* != 2 ) {
2023-12-31 20:43:53 +01:00
die 'The second parameter of this subroutine '
2024-01-13 01:17:57 +01:00
. 'must be an ARRAYREF of exactly two elements.';
2023-12-31 20:43:53 +01:00
}
2024-01-13 01:17:57 +01:00
$self->last_coordinate_1( $coordinates->[0] );
$self->last_coordinate_2( $coordinates->[1] );
2023-12-31 20:43:53 +01:00
}
2024-01-13 01:17:57 +01:00
return [ $self->last_coordinate_1, $self->last_coordinate_2 ];
2023-12-31 20:43:53 +01:00
}
2023-11-19 19:26:59 +01:00
sub serialize_to_owner ($self) {
$self = $self->get_from_storage();
2023-11-19 19:26:59 +01:00
return {
kind => 'ConquerUser',
uuid => $self->uuid,
2024-01-13 01:17:57 +01:00
team => $self->team,
2023-11-19 19:26:59 +01:00
username => $self->username,
2024-01-13 01:17:57 +01:00
is_admin => $self->is_admin ? $JSON::true : $JSON::false,
2023-11-19 19:26:59 +01:00
last_activity => $self->last_activity,
registration_date => $self->registration_date,
};
}
2023-11-17 23:16:54 +01:00
__PACKAGE__->set_primary_key('uuid');
2023-11-19 19:26:59 +01:00
__PACKAGE__->add_unique_constraint( "unique_constraint_username",
['username'] );
2023-11-17 23:16:54 +01:00
1;