keep id and entity in json object
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 12 Dec 2012 17:10:33 +0000 (18:10 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 12 Dec 2012 17:10:33 +0000 (18:10 +0100)
angular-server.pl

index 62c2651..e8d3729 100755 (executable)
@@ -123,8 +123,15 @@ any [ 'post' ] => '/data/:database/:entity' => sub {
        my $database = $self->param('database');
        my $entity   = $self->param('entity');
        my $json = $self->req->json;
-       my $id = $1 if $json->{'_id'} =~ m/^\Q$entity\E\.(.+)$/;
-       $id ||= new_uuid;
+       my $id;
+       if ( exists $json->{'id'} ) { # @id in resource
+               $id = $json->{'id'};
+               warn "EXISTING $id\n";
+       } else {
+               $id = $json->{'id'} = new_uuid;
+               $json->{entity} = $entity;
+               warn "NEW $id\n";
+       }
        warn "## $database $entity $id body ",dump($self->req->body, $json);
 
        my $new = _couchdb_put "/$database/$entity.$id" => $json;