@@ -13,7 +13,7 @@ use Dancer2::Serializer::JSON;
13
13
14
14
=head1 NAME
15
15
16
- Programming Exercise - BookStore
16
+ BookStore - Dancer2 REST API.
17
17
18
18
=head1 VERSION
19
19
@@ -58,6 +58,8 @@ put '/api/authors/:id' => sub {
58
58
my $country = body_parameters-> get(' country' );
59
59
60
60
my ($author ) = $schema -> search_object(' Author' , { id => $id });
61
+ return unless defined $author ;
62
+
61
63
$author -> first_name($first_name );
62
64
$author -> last_name($last_name );
63
65
$author -> country($country );
@@ -73,6 +75,8 @@ patch '/api/authors/:id' => sub {
73
75
my $country = body_parameters-> get(' country' );
74
76
75
77
my ($author ) = $schema -> search_object(' Author' , { id => $id });
78
+ return unless defined $author ;
79
+
76
80
$author -> first_name($first_name ) if defined $first_name ;
77
81
$author -> last_name($last_name ) if defined $last_name ;
78
82
$author -> country($country ) if defined $country ;
@@ -98,6 +102,10 @@ post '/api/authors' => sub {
98
102
del ' /api/authors/:id' => sub {
99
103
my $id = route_parameters-> get(' id' );
100
104
105
+ # check if it is valid author
106
+ return unless defined _author($id );
107
+
108
+ # get rid of author books first
101
109
my $books = _author_books($id );
102
110
foreach my $book (@$books ) {
103
111
$schema -> delete_object(' Book' , $book -> {id });
0 commit comments