Skip to content

Commit

Permalink
feat(feed): Create a topic add review
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Aug 7, 2018
1 parent 04ee0e6 commit eefcbca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/API2/Controllers/Feed/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Zhiyi\Plus\API2\Requests\Feed\CreateTopic as CreateTopicRequest;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Zhiyi\Plus\API2\Resources\Feed\TopicCollection as TopicCollectionResource;
use function Zhiyi\Plus\setting;

class Topic extends Controller
{
Expand Down Expand Up @@ -182,6 +183,7 @@ public function create(CreateTopicRequest $request, ModelsTypes $types): JsonRes
// init default followers count.
$topic->creator_user_id = $user->id;
$topic->followers_count = 1;
$topic->status = setting('feed', 'topic:need-review', false) ? FeedTopicModel::REVIEW_WAITING : FeedTopicModel::REVIEW_PASSED;
$topic->save();

// Attach the creator user follow the topic.
Expand Down Expand Up @@ -210,7 +212,10 @@ public function create(CreateTopicRequest $request, ModelsTypes $types): JsonRes
// Body:
// { "id": $topid->id }
return new JsonResponse(
['id' => $topic->id],
[
'id' => $topic->id,
'need_review' => setting('feed', 'topic:need-review', false)
],
Response::HTTP_CREATED /* 201 */
);
}
Expand Down
4 changes: 4 additions & 0 deletions app/Models/FeedTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

class FeedTopic extends Model
{
public const REVIEW_PASSED = 'passed';
public const REVIEW_WAITING = 'waiting';
public const REVIEW_FAILED = 'failed';

/**
* The model table name.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Zhiyi\Plus\Models\FeedTopic as FeedTopicModel;

class CreateFeedTopicsTable extends Migration
{
Expand All @@ -40,10 +41,12 @@ public function up()
$table->integer('feeds_count')->unsigned()->nullable()->default(0)->comment('The topic link feeds count');
$table->integer('followers_count')->unsigned()->nullable()->default(0)->comment('The topic followers count');
$table->dateTime('hot_at')->nullable()->default(null)->comment('设置为热门的时间');
$table->string('status', 100)->nullable()->default(FeedTopicModel::REVIEW_WAITING)->comment('Review status');
$table->timestamps();

$table->unique('name');
$table->index('creator_user_id');
$table->index('status');
});
}

Expand Down

0 comments on commit eefcbca

Please sign in to comment.