[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[4981] trunk/LedgerSMB/REST_Class/Contact.pm



Revision: 4981
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4981&view=rev
Author:   einhverfr
Date:     2012-07-14 07:49:01 +0000 (Sat, 14 Jul 2012)
Log Message:
-----------
Entity Contact Web Services Module is complete

Modified Paths:
--------------
    trunk/LedgerSMB/REST_Class/Contact.pm

Modified: trunk/LedgerSMB/REST_Class/Contact.pm
===================================================================
--- trunk/LedgerSMB/REST_Class/Contact.pm	2012-07-14 07:02:19 UTC (rev 4980)
+++ trunk/LedgerSMB/REST_Class/Contact.pm	2012-07-14 07:49:01 UTC (rev 4981)
@@ -107,10 +107,46 @@
 
 Determines of record exists and if not creates it.  If so, throws a 400 error
 
+=cut
+
+sub post {
+    my ($request, $id) = @_;
+    if ($id or $request->{payload}->{entity_id}){
+        $request->{payload}->{entity_id} = $id if $id;
+        if (LedgerSMB::DBObject::Entity->get($id)){
+            die '409 Conflict';
+        }
+    }
+    put($request, $id);
+}
+
 =item put
 
 Saves record, overwriting any record that was there before.
 
+=cut
+
+sub put {
+    my ($request, $id) = @_;
+    my $payload = $request->{payload};
+    $payload->{entity_id} = $id;
+    if (lc($payload->{entity_type}) eq 'person') {
+        LedgerSMB::DBObject::Entity::Company->new(%$payload)->save();
+    } elsif (lc($payload->{entity_type}) eq 'company'){
+        LedgerSMB::DBObject::Entity::Person->new(%$payload)->save();
+    } else {
+        die '400 Bad Request:  Must Specify entity_type';
+    }
+    for $act (@{$payload->{credit_accounts}}){
+        LedgerSMB::DBObject::Entity::Credit_Account->new(%$payload)->save();
+    }
+    if ($id){ 
+        die "303 Contact/$id.$request->{format}";
+    } else {
+        die "303 $id.$request->{format}";
+    }
+} 
+
 =item delete not implemented.
 
 =back

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.