|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Transformers\CalculatorTransformer; |
|
6
|
|
|
use App\SimulatorHistory; |
|
7
|
|
|
use App\User; |
|
8
|
|
|
use Chrisbjr\ApiGuard\Http\Controllers\ApiGuardController; |
|
9
|
|
|
use Illuminate\Http\Request; |
|
10
|
|
|
use App\Http\Requests; |
|
11
|
|
|
use Illuminate\Support\Facades\Auth; |
|
12
|
|
|
use Illuminate\Support\Facades\Input; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class CalculatorApiController |
|
16
|
|
|
* @package App\Http\Controllers |
|
17
|
|
|
*/ |
|
18
|
|
|
class CalculatorApiController extends ApiGuardController |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var CalculatorTransformer |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $calcul_transformer; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $apiMethods = [ |
|
29
|
|
|
'store' =>[ |
|
30
|
|
|
'keyAuthentication' => false |
|
31
|
|
|
] |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* CalculatorController constructor. |
|
36
|
|
|
* @param CalculatorTransformer $calcul_transformer |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(CalculatorTransformer $calcul_transformer) |
|
39
|
|
|
{ |
|
40
|
|
|
parent::__construct(); |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$this->calcul_transformer = $calcul_transformer; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
*Store calculator data in DB |
|
48
|
|
|
* @param Request $request |
|
49
|
|
|
* @return mixed |
|
50
|
|
|
*/ |
|
51
|
|
|
public function store(Request $request) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$user = Auth::user(); |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$calcul = new SimulatorHistory(); |
|
57
|
|
|
$calcul->user_id = Input::get('user_id'); |
|
|
|
|
|
|
58
|
|
|
$calcul->name = Input::get('name'); |
|
|
|
|
|
|
59
|
|
|
$calcul->quantity_to_buy = Input::get('quantity_to_buy'); |
|
|
|
|
|
|
60
|
|
|
$calcul->quote_to_buy = Input::get('quote_to_buy'); |
|
|
|
|
|
|
61
|
|
|
$calcul->price_to_buy = Input::get('price_to_buy'); |
|
|
|
|
|
|
62
|
|
|
$calcul->quantity_to_sell = Input::get('quantity_to_sell'); |
|
|
|
|
|
|
63
|
|
|
$calcul->quote_to_sell = Input::get('quote_to_sell'); |
|
|
|
|
|
|
64
|
|
|
$calcul->tax_percent_to_discount = Input::get('tax_percent_to_discount'); |
|
|
|
|
|
|
65
|
|
|
$calcul->price_to_sell = Input::get('price_to_sell'); |
|
|
|
|
|
|
66
|
|
|
$calcul->gains_or_losses = Input::get('gains_or_losses'); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
$user->getCalculations()->save($calcul); |
|
70
|
|
|
return $this->response->withItem($calcul,$this->calcul_transformer); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.