summaryrefslogtreecommitdiff
path: root/lib/Multi
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2016-08-31 10:59:02 +0200
committerYorhel <git@yorhel.nl>2016-08-31 10:59:02 +0200
commitbd0c0dedb28ef8f38069c6077acf47fdd117f25e (patch)
tree24ef04968603dab55d2460c81e6111d70e72432a /lib/Multi
parenta0bab3ea81af64ef5e9bea11cf390c56458c91cd (diff)
API: Add simple "get user" command
Diffstat (limited to 'lib/Multi')
-rw-r--r--lib/Multi/API.pm28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/Multi/API.pm b/lib/Multi/API.pm
index d09937e3..258189ff 100644
--- a/lib/Multi/API.pm
+++ b/lib/Multi/API.pm
@@ -835,10 +835,29 @@ my %GET_CHARACTER = (
);
-# the uid filter for votelist/vnlist/wishlist. Needs special care to handle the 'uid=0' case.
-my $UID_FILTER =
- [ 'int' => 'uid :op: :value:', {qw|= =|}, range => [0,1e6], process =>
- sub { my($uid, $c) = @_; !$uid && !$c->{uid} ? \'Not logged in.' : $uid || $c->{uid} } ];
+# All user ID filters consider uid=0 to be the logged in user. Needs a special processing function to handle that.
+sub subst_user_id { my($id, $c) = @_; !$id && !$c->{uid} ? \'Not logged in.' : $id || $c->{uid} }
+
+my %GET_USER = (
+ sql => "SELECT %s FROM users u WHERE (%s) %s",
+ select => "id, username",
+ proc => sub {
+ $_[0]{id}*=1;
+ },
+ sortdef => 'id',
+ sorts => { id => 'id %s' },
+ flags => { basic => {} },
+ filters => {
+ id => [
+ [ 'int' => 'u.id :op: :value:', {qw|= =|}, range => [0,1e6], process => \&subst_user_id ],
+ [ inta => 'u.id IN(:value:)', {'=',1}, range => [0,1e6], join => ',', process => \&subst_user_id ],
+ ],
+ },
+);
+
+
+# the uid filter for votelist/vnlist/wishlist
+my $UID_FILTER = [ 'int' => 'uid :op: :value:', {qw|= =|}, range => [0,1e6], process => \&subst_user_id ];
my %GET_VOTELIST = (
islist => 1,
@@ -895,6 +914,7 @@ my %GET = (
release => \%GET_RELEASE,
producer => \%GET_PRODUCER,
character => \%GET_CHARACTER,
+ user => \%GET_USER,
votelist => \%GET_VOTELIST,
vnlist => \%GET_VNLIST,
wishlist => \%GET_WISHLIST,