Skip to content

Commit

Permalink
Merge pull request #304 from mycookbook/small-improvements
Browse files Browse the repository at this point in the history
convert tiktokuserdto to php8 readonly class
  • Loading branch information
fokosun authored Oct 22, 2023
2 parents 7ba7ccc + 06c1bb2 commit 03fffae
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 122 deletions.
179 changes: 60 additions & 119 deletions app/Dtos/TikTokUserDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,126 +2,67 @@

declare(strict_types=1);

namespace App\Dtos;
namespace App\Dtos {

class TikTokUserDto
{
protected $user_id;
protected $open_id;
protected $code;
protected $is_verified;
protected $profile_deep_link;
protected $bio_description;
protected $display_name;
protected $avatar_large_url;
protected $avatar_url_100;
protected $avatar_url;
protected $union_id;
protected $video_count;

public function __construct(
int $user_id,
string $open_id,
string $code,
bool $is_verified,
string $profile_deep_link,
string $bio_description,
string $display_name,
string $avatar_large_url,
string $avatar_url_100,
string $avatar_url,
string $union_id,
int $video_count
) {
$this->user_id = $user_id;
$this->open_id = $open_id;
$this->code = $code;
$this->is_verified = $is_verified;
$this->profile_deep_link = $profile_deep_link;
$this->bio_description = $bio_description;
$this->display_name = $display_name;
$this->avatar_large_url = $avatar_large_url;
$this->avatar_url_100 = $avatar_url_100;
$this->avatar_url = $avatar_url;
$this->union_id = $union_id;
$this->video_count = $video_count;
}

public function getCode(): string
{
return $this->code;
}

public function getUserId(): int
{
return $this->user_id;
}

public function getOpenId(): string
{
return $this->open_id;
}

public function getProfileDeepLink(): string
{
return $this->profile_deep_link;
}

public function getBioDescription(): string
{
return $this->bio_description;
}

public function getDisplayName(): string
{
return $this->display_name;
}

public function getAvatarLargeUrl(): string
{
return $this->avatar_large_url;
}

public function getAvatarUrl100(): string
{
return $this->avatar_url_100;
}

public function getAvatarUrl(): string
{
return $this->avatar_url;
}

public function getUnionId(): string
{
return $this->union_id;
}

public function getVideoCount(): int
{
return $this->video_count;
}

public function getIsVerified(): bool
{
return $this->is_verified;
}

public function toArray(): array
readonly class TikTokUserDto
{
return [
'user_id' => $this->getUserId(),
'open_id' => $this->getOpenId(),
'code' => $this->getCode(),
'is_verified' => $this->getIsVerified(),
'profile_deep_link' => $this->getProfileDeepLink(),
'bio_description' => $this->getBioDescription(),
'display_name' => $this->getDisplayName(),
'avatar_large_url' => $this->getAvatarLargeUrl(),
'avatar_url_100' => $this->getAvatarUrl100(),
'avatar_url' => $this->getAvatarUrl(),
'union_id' => $this->getUnionId(),
'video_count' => $this->getVideoCount()
];
public int $user_id;
public string $open_id;
public string $code;
public bool $is_verified;
public string $profile_deep_link;
public string $bio_description;
public string $display_name;
public string $avatar_large_url;
public string $avatar_url_100;
public string $avatar_url;
public string $union_id;
public int $video_count;

public function __construct(
int $user_id,
string $open_id,
string $code,
bool $is_verified,
string $profile_deep_link,
string $bio_description,
string $display_name,
string $avatar_large_url,
string $avatar_url_100,
string $avatar_url,
string $union_id,
int $video_count
) {
$this->user_id = $user_id;
$this->open_id = $open_id;
$this->code = $code;
$this->is_verified = $is_verified;
$this->profile_deep_link = $profile_deep_link;
$this->bio_description = $bio_description;
$this->display_name = $display_name;
$this->avatar_large_url = $avatar_large_url;
$this->avatar_url_100 = $avatar_url_100;
$this->avatar_url = $avatar_url;
$this->union_id = $union_id;
$this->video_count = $video_count;
}

public function toArray(): array
{
return [
'user_id' => $this->user_id,
'open_id' => $this->open_id,
'code' => $this->code,
'is_verified' => $this->is_verified,
'profile_deep_link' => $this->profile_deep_link,
'bio_description' => $this->bio_description,
'display_name' => $this->display_name,
'avatar_large_url' => $this->avatar_large_url,
'avatar_url_100' => $this->avatar_url_100,
'avatar_url' => $this->avatar_url,
'union_id' => $this->union_id,
'video_count' => $this->video_count
];
}
}
}
2 changes: 1 addition & 1 deletion app/Events/TikTokUserIsAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function __construct(

public function getUser()
{
return User::findOrFail($this->tikTokUserDto->getUserId());
return User::findOrFail($this->tikTokUserDto->user_id);
}
}
2 changes: 1 addition & 1 deletion app/Http/Clients/TikTokHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function listVideos(TikTokUserDto $userDto): array
return $this->makeHttpRequest(
AllowedHttpMethod::POST,
VideoListEnum::values(),
['access_token' => $userDto->getCode(), 'uri' => '/video/list/']
['access_token' => $userDto->code, 'uri' => '/video/list/']
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/UpdateOrCreateTikTokUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UpdateOrCreateTikTokUser
{
public function handle(TikTokUserIsAuthenticated $event): void
{
$user_id = $event->tikTokUserDto->getUserId();
$user_id = $event->tikTokUserDto->user_id;
$db = DB::table('tiktok_users');
$attributes = $event->tikTokUserDto->toArray();
$timestamps = [
Expand Down

0 comments on commit 03fffae

Please sign in to comment.