-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* +----------------------------------------------------------------------+ | ||
* | ThinkSNS Plus | | ||
* +----------------------------------------------------------------------+ | ||
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. | | ||
* +----------------------------------------------------------------------+ | ||
* | This source file is subject to version 2.0 of the Apache license, | | ||
* | that is bundled with this package in the file LICENSE, and is | | ||
* | available through the world-wide-web at the following url: | | ||
* | http://www.apache.org/licenses/LICENSE-2.0.html | | ||
* +----------------------------------------------------------------------+ | ||
* | Author: Slim Kit Group <master@zhiyicx.com> | | ||
* | Homepage: www.thinksns.com | | ||
* +----------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Zhiyi\Plus\API2\Controllers\User\Message; | ||
|
||
use Illuminate\Http\Response; | ||
use Zhiyi\Plus\API2\Controllers\Controller; | ||
use Zhiyi\Plus\Models\AtMessage as AtMessageModel; | ||
use Zhiyi\Plus\API2\Requests\User\Message\ListAtMessageLine; | ||
use Zhiyi\Plus\API2\Resources\User\Message\AtMessage as AtMessageResource; | ||
|
||
class At extends Controller | ||
{ | ||
/** | ||
* Create the at message controller instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth:api'); | ||
} | ||
|
||
public function __invoke(ListAtMessageLine $request, AtMessageModel $model) | ||
{ | ||
$direction = $request->query('direction', 'desc'); | ||
$collection = $model | ||
->query() | ||
->when($index = $request->query('index'), function ($query) use ($index, $direction) { | ||
return $query->where('id', $direction === 'asc' ? '>' : '<', $index); | ||
}) | ||
->where('user_id', $request->user()->id) | ||
->limit($request->query('limit', 15)) | ||
->orderBy('id', $direction) | ||
->get(); | ||
|
||
// 暂不提供支持,动态付费内容难以处理!代码请不要删除! | ||
// $relationships = array_filter(explode(',', $request->query('load'))); | ||
// if ($relationships) { | ||
// $collection->load($relationships); | ||
// } | ||
|
||
return AtMessageResource::collection($collection) | ||
->toResponse($request) | ||
->setStatusCode(Response::HTTP_OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* +----------------------------------------------------------------------+ | ||
* | ThinkSNS Plus | | ||
* +----------------------------------------------------------------------+ | ||
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. | | ||
* +----------------------------------------------------------------------+ | ||
* | This source file is subject to version 2.0 of the Apache license, | | ||
* | that is bundled with this package in the file LICENSE, and is | | ||
* | available through the world-wide-web at the following url: | | ||
* | http://www.apache.org/licenses/LICENSE-2.0.html | | ||
* +----------------------------------------------------------------------+ | ||
* | Author: Slim Kit Group <master@zhiyicx.com> | | ||
* | Homepage: www.thinksns.com | | ||
* +----------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Zhiyi\Plus\API2\Requests\User\Message; | ||
|
||
use Zhiyi\Plus\API2\Requests\Request; | ||
|
||
class ListAtMessageLine extends Request | ||
{ | ||
/** | ||
* Get the validate rules. | ||
* @return array | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'limit' => 'nullable|integer|min:1|max:100', | ||
'index' => 'nullable|integer|min:0', | ||
'direction' => 'nullable|in:asc,desc', | ||
'load' => 'nullable|string', | ||
]; | ||
} | ||
|
||
/** | ||
* Get the validate error messages. | ||
* @return array | ||
*/ | ||
public function messages(): array | ||
{ | ||
return [ | ||
'limit.integer' => 'limit 参数非法', | ||
'limit.min' => '最少获取一条数据', | ||
'limit.max' => '最多获取 100 条数据', | ||
'index.integer' => 'index 参数非法', | ||
'inde.min' => 'index 参数不得低于 0', | ||
'direction.in' => '方向只允许 `asc` 或者 `desc`', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zhiyi\Plus\API2\Resources\User\Message; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
use Zhiyi\Plus\Utils\DateTimeToIso8601ZuluString; | ||
|
||
class AtMessage extends JsonResource | ||
{ | ||
use DateTimeToIso8601ZuluString; | ||
|
||
/** | ||
* The resource to array. | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function toArray($request): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'user_id' => $this->user_id, | ||
'resourceable' => [ | ||
'type' => $this->resourceable_type, | ||
'id' => $this->resourceable_id, | ||
], | ||
$this->mergeWhen($request->query('load'), [ | ||
'resource' => ['暂不提供数据支持'] | ||
]), | ||
'created_at' => $this->dateTimeToIso8601ZuluString( | ||
$this->{Model::CREATED_AT} | ||
), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters