1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: arthur |
5
|
|
|
* Date: 04.10.18 |
6
|
|
|
* Time: 16:17. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Modules\Proxy\Services; |
10
|
|
|
|
11
|
|
|
use Carbon\Carbon; |
12
|
|
|
use Modules\Proxy\Contracts\ProxyRepositoryContract; |
13
|
|
|
use Modules\Proxy\Contracts\ProxyServiceContract; |
14
|
|
|
use Modules\Proxy\Entities\Proxy; |
15
|
|
|
use Modules\Proxy\Events\ProxyCreatedEvent; |
16
|
|
|
use Modules\Proxy\Events\ProxyUpdatedEvent; |
17
|
|
|
|
18
|
|
|
class ProxyService implements ProxyServiceContract |
19
|
|
|
{ |
20
|
|
|
protected $repository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* ProxyService constructor. |
24
|
|
|
* @param $repository |
25
|
|
|
*/ |
26
|
|
|
public function __construct(ProxyRepositoryContract $repository) |
27
|
|
|
{ |
28
|
|
|
$this->repository = $repository; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getByUserId($userId) |
32
|
|
|
{ |
33
|
|
|
return Proxy::where('user_id', $userId)->get(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function find($id): ?Proxy |
37
|
|
|
{ |
38
|
|
|
return $this->repository->resolve($id); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function update($id, $data): Proxy |
42
|
|
|
{ |
43
|
|
|
$proxy = $this->repository->update($data, $id); |
44
|
|
|
event(new ProxyUpdatedEvent($proxy)); |
45
|
|
|
|
46
|
|
|
return $proxy; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function create($data): Proxy |
50
|
|
|
{ |
51
|
|
|
$proxy = Proxy::create($data); |
52
|
|
|
event(new ProxyCreatedEvent($proxy)); |
53
|
|
|
|
54
|
|
|
return $proxy; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function delete($id): bool |
58
|
|
|
{ |
59
|
|
|
return $this->find($id)->delete(); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function healthCheck($id, $data): void |
63
|
|
|
{ |
64
|
|
|
//TODO DO THE ACTUAL HEALTCHECK |
65
|
|
|
$this->update($id, [ |
66
|
|
|
'last_alive_at' => Carbon::now(), |
67
|
|
|
'last_checked_at' => Carbon::now(), |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|