From a6f7402055fd85cfa33e6c4855c3ddc70397f20b Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 4 Mar 2022 20:24:36 +0000 Subject: [PATCH] implement list deletion --- lib/App/LazyShoppingList/API/v1.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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; }; -- 2.39.5