api: add /random/tag
This commit is contained in:
parent
7ccbc3af12
commit
6ecf98f917
@ -24,6 +24,8 @@ sub startup ($self)
|
||||
|
||||
$r->get("/tags")->to("tags#list");
|
||||
$r->get("/tag/:tag_id_or_name")->to("tags#show");
|
||||
|
||||
$r->get("/random/tag")->to("random#tag");
|
||||
}
|
||||
|
||||
1;
|
||||
|
21
lib/PoorBooru/API/V0/Controller/Random.pm
Normal file
21
lib/PoorBooru/API/V0/Controller/Random.pm
Normal file
@ -0,0 +1,21 @@
|
||||
package PoorBooru::API::V0::Controller::Random;
|
||||
use v5.36;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Mojo::Base "Mojolicious::Controller";
|
||||
|
||||
sub tag ($self)
|
||||
{
|
||||
my $tag = $self->schema->resultset("Tag")
|
||||
->search({}, { order_by => \"random()", limit => 1 })->single;
|
||||
|
||||
return $self->render(
|
||||
json => {error => "Tag not found"},
|
||||
status => 404,
|
||||
) if !defined($tag);
|
||||
|
||||
return $self->redirect_to("/tag/" . $tag->name);
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue
Block a user