summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/docs/1148
-rw-r--r--lib/Multi/API.pm28
2 files changed, 72 insertions, 4 deletions
diff --git a/data/docs/11 b/data/docs/11
index 86b8188e..d1f40ea4 100644
--- a/data/docs/11
+++ b/data/docs/11
@@ -1176,6 +1176,53 @@ however still required.<br />
</table>
+:SUBSUB:get user
+<p>Returned members:</p>
+<table style="margin: 5px 2%; width: 95%">
+ <thead><tr>
+ <td style="width: 80px">Member</td>
+ <td style="width: 50px">Flag</td>
+ <td style="width: 90px">Type</td>
+ <td style="width: 40px">null</td>
+ <td>Description</td>
+ </tr></thead>
+ <tr class="odd">
+ <td>id</td>
+ <td>basic</td>
+ <td>integer</td>
+ <td>no</td>
+ <td>User ID</td>
+ </tr>
+ <tr>
+ <td>username</td>
+ <td>basic</td>
+ <td>string</td>
+ <td>no</td>
+ <td></td>
+ </tr>
+</table>
+<p>The returned list is always sorted on the 'id' field.</p><br />
+
+<p>The following filters are recognised:</p>
+<table style="margin: 5px 2%; width: 95%">
+ <thead><tr>
+ <td style="width: 80px">Field</td>
+ <td style="width: 90px">Value</td>
+ <td style="width: 90px">Operators</td>
+ <td>&nbsp;</td>
+ </tr></thead>
+ <tr class="odd">
+ <td>id</td>
+ <td>integer<br />array of integers</td>
+ <td>=</td>
+ <td>This filter must be present. The special value '0' is recognized as the currently logged in user.</td>
+ </tr>
+</table>
+<p>
+ Note: Internally, the user with id '0' is reserved for the "deleted" user.
+</p>
+
+
:SUBSUB:get votelist
<p>Returned members:</p>
<table style="margin: 5px 2%; width: 95%">
@@ -1515,6 +1562,7 @@ however still required.<br />
<li>Added "screens" flag and member to "get vn"</li>
<li>Added "vns" flag and member to "get character"</li>
<li>Allow sorting "get vn" on popularity, rating and votecount</li>
+ <li>Added basic "get user" command</li>
</ul>
<b>2.23</b>
<ul>
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,