From: Dobrica Pavlinusic Date: Wed, 12 Dec 2012 17:10:33 +0000 (+0100) Subject: keep id and entity in json object X-Git-Tag: 0.4~98 X-Git-Url: http://git.rot13.org/?p=angular-drzb;a=commitdiff_plain;h=8c1baff0213671a1f9d8bd66be6e4e987366ce50 keep id and entity in json object --- diff --git a/angular-server.pl b/angular-server.pl index 62c2651..e8d3729 100755 --- a/angular-server.pl +++ b/angular-server.pl @@ -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;