[api] reward + thanks

This commit is contained in:
xiaomlove
2022-03-30 15:37:11 +08:00
parent b613a46b8d
commit 3e4a5766c4
38 changed files with 983 additions and 64 deletions
+1
View File
@@ -19,6 +19,7 @@ class MessageResource extends JsonResource
'subject' => $this->subject,
'msg' => strip_all_tags($this->msg),
'added_human' => $this->added->diffForHumans(),
'added' => format_datetime($this->added),
'send_user' => new UserResource($this->whenLoaded('send_user')),
];
}
+4 -2
View File
@@ -14,11 +14,13 @@ class NewsResource extends JsonResource
*/
public function toArray($request)
{
$descriptionArr = format_description($this->body);
return [
'id' => $this->id,
'title' => $this->title,
'body' => $this->body,
'added' => $this->added,
'body' => $descriptionArr,
'images' => get_image_from_description($descriptionArr),
'added' => format_datetime($this->added, 'Y.m.d'),
'user' => new UserResource($this->whenLoaded('user'))
];
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class PollResource extends JsonResource
{
public $preserveKeys = true;
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$out = [
'id' => $this->id,
'added' => format_datetime($this->added),
'question' => $this->question,
'answers_count' => $this->answers_count,
'options' => $this->options,
];
return $out;
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class RewardResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'user_id' => $this->userid,
'torrent_id' => $this->torrentid,
'value' => $this->value,
'created_at' => format_datetime($this->created_at),
'updated_at' => format_datetime($this->updated_at),
'user' => new UserResource($this->whenLoaded('user'))
];
}
}
+2
View File
@@ -16,6 +16,8 @@ class ThankResource extends JsonResource
{
return [
'id' => $this->id,
'torrent_id' => $this->torrentid,
'user_id' => $this->userid,
'user' => new UserResource($this->whenLoaded('user')),
];
}
+3
View File
@@ -43,6 +43,8 @@ class TorrentResource extends JsonResource
'user' => new UserResource($this->whenLoaded('user')),
'basic_category' => new CategoryResource($this->whenLoaded('basic_category')),
'tags' => TagResource::collection($this->whenLoaded('tags')),
'thanks' => ThankResource::collection($this->whenLoaded('thanks')),
'reward_logs' => RewardResource::collection($this->whenLoaded('reward_logs')),
];
$descriptionArr = format_description($this->descr);
$out['cover'] = get_image_from_description($descriptionArr, true);
@@ -63,6 +65,7 @@ class TorrentResource extends JsonResource
$out['thank_users_count'] = $this->thank_users_count;
$out['peers_count'] = $this->peers_count;
$out['reward_logs_count'] = $this->reward_logs_count;
}
// $out['upload_peers_count'] = $this->upload_peers_count;
// $out['download_peers_count'] = $this->download_peers_count;