Skip to content

Commit ae65add

Browse files
committed
- Small improvements.
1 parent 58d552a commit ae65add

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/BookStore.pm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Dancer2::Serializer::JSON;
1313

1414
=head1 NAME
1515
16-
Programming Exercise - BookStore
16+
BookStore - Dancer2 REST API.
1717
1818
=head1 VERSION
1919
@@ -58,6 +58,8 @@ put '/api/authors/:id' => sub {
5858
my $country = body_parameters->get('country');
5959

6060
my ($author) = $schema->search_object('Author', { id => $id });
61+
return unless defined $author;
62+
6163
$author->first_name($first_name);
6264
$author->last_name($last_name);
6365
$author->country($country);
@@ -73,6 +75,8 @@ patch '/api/authors/:id' => sub {
7375
my $country = body_parameters->get('country');
7476

7577
my ($author) = $schema->search_object('Author', { id => $id });
78+
return unless defined $author;
79+
7680
$author->first_name($first_name) if defined $first_name;
7781
$author->last_name($last_name) if defined $last_name;
7882
$author->country($country) if defined $country;
@@ -98,6 +102,10 @@ post '/api/authors' => sub {
98102
del '/api/authors/:id' => sub {
99103
my $id = route_parameters->get('id');
100104

105+
# check if it is valid author
106+
return unless defined _author($id);
107+
108+
# get rid of author books first
101109
my $books = _author_books($id);
102110
foreach my $book (@$books) {
103111
$schema->delete_object('Book', $book->{id});

0 commit comments

Comments
 (0)