Skip to content

Commit

Permalink
fix keywords endpoint, writes to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
fokosun committed Sep 19, 2023
1 parent b639084 commit 1fc5969
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/Http/Controllers/Files/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"city":"Toronto","country":"CA","ip":"99.225.78.10","keyword":"beans"}
16 changes: 16 additions & 0 deletions app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,20 @@ private function jsonResponse(Collection $collection)
'response' => $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]);
}

file_put_contents($filePath, $data);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"database/seeders"
],
"files": [
"app/Http/helpers.php"
"app/Http/helpers.php",
"app/Http/Controllers/Files/keywords.txt"
]
},
"autoload-dev": {
Expand Down

0 comments on commit 1fc5969

Please sign in to comment.