From: Damyan Ivanov Date: Fri, 4 Mar 2022 20:24:36 +0000 (+0000) Subject: implement list deletion X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=a6f7402055fd85cfa33e6c4855c3ddc70397f20b;p=lsl.git implement list deletion --- diff --git a/lib/App/LazyShoppingList/API/v1.pm b/lib/App/LazyShoppingList/API/v1.pm index 6a34491..cd7be18 100644 --- a/lib/App/LazyShoppingList/API/v1.pm +++ b/lib/App/LazyShoppingList/API/v1.pm @@ -210,6 +210,26 @@ put '/list/:list_id/:item_id' => sub { $r{version} = $item->version; $r{list_version} = $list->version; + return \%r; +}; + +# delete shopping list +del '/list/:list_id' => sub { + my $list_id = route_parameters->get('list_id'); + length($list_id) and $list_id =~ /^\d{1,18}$/ + or return invalid_input('bad list ID'); + + my $dbh = get_database; + + my %r = ( + lists_version => get_lists_version($dbh), + ); + + my $list = $dbh->resultset('ShoppingList')->find($list_id); + if ($list) { + $list->delete; + $r{lists_version} = increment_lists_version($dbh) + } return \%r; };