Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
I
IPRSv2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Ngei
IPRSv2
Commits
3ef2ec07
Commit
3ef2ec07
authored
Mar 25, 2025
by
Michael Ngei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates search quota plugin
parent
49f4c19d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
86 deletions
+116
-86
PaymentsAPI.php
app/Http/Controllers/API/PaymentsAPI.php
+83
-80
TokensAPI.php
app/Http/Controllers/API/TokensAPI.php
+29
-4
TokensController.php
app/Http/Controllers/TokensController.php
+4
-2
No files found.
app/Http/Controllers/API/PaymentsAPI.php
View file @
3ef2ec07
...
...
@@ -104,15 +104,18 @@ class PaymentsAPI extends Controller
$consumer_name
=
str_replace
(
' '
,
'_'
,
strtoupper
(
$contract
->
client
->
name_sh
));
//$res=Redis::set('name', 'mikee');
//$checkKey = Redis::get('search_quota:countsse:user23');
try
{
if
(
Redis
::
exists
(
"search_quota:max:"
.
$consumer_name
))
{
$tokens
=
$validated
[
'tokens'
];
$maxToken
=
Redis
::
get
(
"search_quota:max:"
.
$consumer_name
);
//$currentToken = Redis::get("search_quota:count:".$consumer_name);
// added tokens
$newMax
=
$tokens
+
$maxToken
;
//set tokens
$tokenRes
=
Redis
::
set
(
"search_quota:max:"
.
$consumer_name
,
$newMax
);
// Attempt to insert the payment
if
(
$tokenRes
){
$payment
=
Payments
::
create
([
...
...
@@ -132,7 +135,7 @@ class PaymentsAPI extends Controller
}
}
else
{
//create new
$this
->
apiContract
(
$consumer_name
,
$validated
[
'tokens'
],
$validated
[
'contract_id'
]);
$res
=
$this
->
apiContract
(
$consumer_name
,
$validated
[
'tokens'
],
$validated
[
'contract_id'
]);
$payment
=
Payments
::
create
([
'PAYMENT_REF'
=>
$validated
[
'payment_ref'
],
'PAYMENT_MODE'
=>
$validated
[
'payment_mode'
],
...
...
@@ -224,8 +227,8 @@ class PaymentsAPI extends Controller
],
"search-quota-redis"
=>
[
"redis_host"
=>
'redis'
,
"redis_port"
=>
(
int
)
env
(
'REDIS_PORT'
)
,
"redis_password"
=>
env
(
'REDIS_PASSWORD'
)
,
"redis_port"
=>
6379
,
"redis_password"
=>
'password'
,
"default_max_queries"
=>
$tokens
]
]
...
...
app/Http/Controllers/API/TokensAPI.php
View file @
3ef2ec07
...
...
@@ -3,8 +3,10 @@
namespace
App\Http\Controllers\API
;
use
App\Http\Controllers\Controller
;
use
App\Models\Contract
;
use
App\Models\Tokens
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Redis
;
class
TokensAPI
extends
Controller
{
...
...
@@ -13,14 +15,37 @@ class TokensAPI extends Controller
* Get tokens give a contract ID
*
* */
public
function
show
(
$contract_id
)
public
function
show
(
$contract_id
)
{
// $token = Tokens::with('contract')->get();
$token
=
Tokens
::
where
(
'contract_id'
,
$contract_id
)
->
with
(
'contract'
)
->
get
();
//$token = Tokens::where('contract_id', $contract_id)->with('contract')->get();
$consumer
=
Contract
::
where
(
'rid'
,
$contract_id
)
->
with
([
'client:rid,name_sh,name_fl'
])
->
select
(
'rid'
,
'client_rid'
)
->
get
();
$consumerName
=
$consumer
[
0
][
'client'
][
'name_sh'
];
$searchQuota
=
[];
$cursor
=
'0'
;
$pattern
=
'search_quota:*:'
.
$consumerName
;
//dd($pattern);
//dump("Keys from KEYS:", Redis::keys($pattern));
do
{
$result
=
Redis
::
scan
(
$cursor
,
'MATCH'
,
$pattern
,
'COUNT'
,
10
);
$cursor
=
$result
[
0
];
// Update cursor for the next iteration
$keys
=
$result
[
1
];
if
(
!
empty
(
$keys
))
{
foreach
(
$keys
as
$key
)
{
$searchQuota
[
$key
]
=
Redis
::
get
(
$key
);
}
}
}
while
(
$cursor
!==
'0'
);
/*
* "search_quota:count:MIKELTD250" => "3"
"search_quota:max:MIKELTD250" => "6"
*/
// Return the data as a JSON response
return
response
()
->
json
([
'status'
=>
'success'
,
'data'
=>
$
token
,
'data'
=>
$
searchQuota
,
],
200
);
}
}
app/Http/Controllers/TokensController.php
View file @
3ef2ec07
...
...
@@ -15,7 +15,7 @@ class TokensController extends Controller
{
$searchQuotas
=
[];
$cursor
=
'0'
;
$pattern
=
'search_quota:
count:
*'
;
$pattern
=
'search_quota:*'
;
//dump("Keys from KEYS:", Redis::keys($pattern));
do
{
$result
=
Redis
::
scan
(
$cursor
,
'MATCH'
,
$pattern
,
'COUNT'
,
10
);
...
...
@@ -28,7 +28,9 @@ class TokensController extends Controller
}
}
}
while
(
$cursor
!==
'0'
);
dump
(
"Keys from SCAN:"
,
$searchQuotas
);
dd
(
$searchQuotas
);
$tokens
=
Tokens
::
with
(
'contract.client'
)
->
get
();
return
view
(
'tokens.tokens'
,
[
'tokens'
=>
$tokens
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment