OSDN Git Service

Controller::API::Story: fix post()
authorhylom <hylom@users.sourceforge.jp>
Thu, 31 Jan 2019 12:09:58 +0000 (21:09 +0900)
committerhylom <hylom@users.sourceforge.jp>
Thu, 31 Jan 2019 12:09:58 +0000 (21:09 +0900)
src/newslash_web/lib/Newslash/Model/Stories.pm
src/newslash_web/lib/Newslash/Web/Controller/API/Story.pm

index 500481e..2c4d8d5 100644 (file)
@@ -482,7 +482,7 @@ sub create {
             #warn "set_tag fault..." if !$ret
         }
     }
-    return $stoid;
+    return wantarray ? ($sid, $stoid) : $stoid;
 }
 
 sub create2 {
index 6bf0590..e78593b 100644 (file)
@@ -5,6 +5,7 @@ use Mojo::JSON qw(decode_json encode_json);
 
 use DateTime::Format::ISO8601;
 use DateTime::Format::MySQL;
+use Data::Dumper;
 
 sub get {
     my $c = shift;
@@ -108,9 +109,8 @@ sub post {
     # tags
     # tags_strings is like: "mainpage japan business transport"
     my @tags = split(/\s+/, $item->{tags_string} || "");
-
     # add topics
-    my $primary_topic = $topics->get_primary_topic_from_tags(@tags);
+    my $primary_topic = $topics->get_primary_topic_from_tags(\@tags);
     if ($primary_topic) {
         $params->{topics_chosen} = { $primary_topic->{tid} => 10 };
     }
@@ -147,16 +147,17 @@ sub post {
     }
 
     # post action
-    my $stoid;
+    my ($sid, $stoid);
     if ($item->{stoid}) {
         # update story
         $params->{stoid} = $item->{stoid};
         my $rs = $stories->update(user => $user, %$params);
         $stoid = $rs ? $item->{stoid} : 0;
+        $sid = $item->{sid} : 0;
     }
     else {
         # create story
-        $stoid = $stories->create(user => $user, %$params);
+        ($sid, $stoid) = $stories->create(user => $user, %$params);
         #$stoid = $stories->create2(user => $user,
         #                           config => $c->config->{Story},
         #                           params => $params);
@@ -176,7 +177,7 @@ sub post {
     }
 
     # post succeeded, return result
-    $c->render(json => {type => "story", id => $stoid});
+    $c->render(json => {type => "story", id => $stoid, sid => $sid});
     $c->event_que->emit("story", "post", $user->{uid}, $stoid);
     return;
 }