Skip to content

Commit

Permalink
use storage facade to write keywords to local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
fokosun committed Sep 21, 2023
1 parent 1fc5969 commit 19c4890
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 343 deletions.
1 change: 0 additions & 1 deletion app/Http/Controllers/Files/keywords.txt

This file was deleted.

13 changes: 3 additions & 10 deletions app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Services\SearchService;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

Expand Down Expand Up @@ -176,16 +177,8 @@ private function jsonResponse(Collection $collection)
public function writeToCsv(Request $request)
{
$data = $request->only(['city', 'country', 'ip', 'keyword', 'loc', 'timezone']);
$filePath = __DIR__ . '/Files/keywords.txt';
$contents = file_get_contents($filePath);

if ($contents == "") {
$data = json_encode($data);
} else {
$originalContents = json_decode($contents, true);
$data = json_encode([$data, $originalContents]);
}
//TODO: if any data is null, fill up, default keyword to ""

file_put_contents($filePath, $data);
Storage::disk('local')->append('keywords.txt', json_encode($data), "," . PHP_EOL);
}
}
48 changes: 27 additions & 21 deletions app/Http/Controllers/StaticContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,40 @@

namespace App\Http\Controllers;

use App\Models\Category;
use App\Models\StaticContent;
use Illuminate\Http\Request;

class StaticContentController extends Controller
{
/**
* @return \Illuminate\Http\JsonResponse
*/
public function get()
public function get(Request $request)
{
/** @var \Illuminate\Database\Eloquent\Builder $cookie_policy */
$cookie_policy = StaticContent::where('title', 'cookie-policy');

/** @var \Illuminate\Database\Eloquent\Builder $usage_policy */
$usage_policy = StaticContent::where('title', 'usage-policy');

/** @var \Illuminate\Database\Eloquent\Builder $dr_policy */
$dr_policy = StaticContent::where('title', 'data-retention-policy');

/** @var \Illuminate\Database\Eloquent\Builder $tnc */
$tnc = StaticContent::where('title', 'terms-and-conditions');

return response()->json([
'response' => [
'cookiePolicy' => $cookie_policy->first(),
'usagePolicy' => $usage_policy->first(),
'dataRetentionPolicy' => $dr_policy->first(),
'termsAndConditions' => $tnc->first(),
],
]);
if ($request->route() && $request->route()->getName() == 'getCategories') {
return $this->successResponse(['response' => Category::all()]);
} else {
/** @var \Illuminate\Database\Eloquent\Builder $cookie_policy */
$cookie_policy = StaticContent::where('title', 'cookie-policy');

/** @var \Illuminate\Database\Eloquent\Builder $usage_policy */
$usage_policy = StaticContent::where('title', 'usage-policy');

/** @var \Illuminate\Database\Eloquent\Builder $dr_policy */
$dr_policy = StaticContent::where('title', 'data-retention-policy');

/** @var \Illuminate\Database\Eloquent\Builder $tnc */
$tnc = StaticContent::where('title', 'terms-and-conditions');

return response()->json([
'response' => [
'cookiePolicy' => $cookie_policy->first(),
'usagePolicy' => $usage_policy->first(),
'dataRetentionPolicy' => $dr_policy->first(),
'termsAndConditions' => $tnc->first()
],
]);
}
}
}
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"database/seeders"
],
"files": [
"app/Http/helpers.php",
"app/Http/Controllers/Files/keywords.txt"
"app/Http/helpers.php"
]
},
"autoload-dev": {
Expand Down
Loading

0 comments on commit 19c4890

Please sign in to comment.