Skip to content

Commit

Permalink
claim test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiritin committed Jul 22, 2024
1 parent 752f0db commit 2df1e8f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/Models/Fursuit/Fursuit.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,27 @@ public function imageUrl(): Attribute
);
}

private function getClaimCacheKey(int $userId): string
private function getClaimCacheKey(): string
{
return 'user:'.$userId.':fursuit:'.$this->id.':claim';
return 'fursuit:'.$this->id.':claim';
}

public function claim(User $user): bool
{
$cacheKey = $this->getClaimCacheKey($user->id);
$cacheKey = $this->getClaimCacheKey();

if (cache()->has($cacheKey)) {
return false;
}

cache()->put($cacheKey, $this->id, now()->addMinutes(5));
cache()->put($cacheKey, auth()->user()->id, now()->addMinutes(5));

return true;
}

public function unclaim(): bool
{
$cacheKey = $this->getClaimCacheKey(auth()->id());
$cacheKey = $this->getClaimCacheKey();

if (!cache()->has($cacheKey)) {
return false;
Expand All @@ -100,16 +100,16 @@ public function getActivitylogOptions(): LogOptions

public function isNotClaimed(): bool
{
return !cache()->has($this->getClaimCacheKey(auth()->id()));
return !cache()->has($this->getClaimCacheKey());
}

public function isClaimed()
{
return cache()->has($this->getClaimCacheKey(auth()->id()));
return cache()->has($this->getClaimCacheKey());
}

public function isClaimedBySelf(User $user)
{
return cache()->has($this->getClaimCacheKey($user->id));
return (int) cache()->get($this->getClaimCacheKey()) == $user->id;
}
}

0 comments on commit 2df1e8f

Please sign in to comment.