diff --git a/lib/PoorBooru/API/V0.pm b/lib/PoorBooru/API/V0.pm index a121a12..1c5d658 100644 --- a/lib/PoorBooru/API/V0.pm +++ b/lib/PoorBooru/API/V0.pm @@ -51,19 +51,22 @@ get "/tags" => sub { }; post "/tags" => sub { - my $tag_name = body_parameters->get("name"); - send_error("Invalid tag name", 404) if $tag_name !~ $TAG_NAME_RE; + my @tag_names = body_parameters->get_all("name"); + send_error("No tags provided", 400) if @tag_names == 0; + send_error("Too many tags provided", 400) if @tag_names > 100; + send_error("Invalid tag names", 400) if + grep { $_ !~ $TAG_NAME_RE } @tag_names; - my $tag; + my @tags; eval { - $tag = schema("default")->resultset("Tag") - ->create({ name => $tag_name }); + @tags = map +( { + id => $_->tag_id, + name => $_->name, + } ), schema("default")->resultset("Tag") + ->populate([map +({ name => $_ }), @tag_names]); } or send_error("Tag exists", 409); - return { - id => $tag->tag_id, - name => $tag->name, - }; + return \@tags; }; get "/tag/:tag_id_or_name" => sub {