ItemUrlScrapController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Http\Controllers\Api\Scrap;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Api23GateTokenService;
  5. use App\Services\Scrap\ItemUrlScrapService;
  6. use Exception;
  7. use Illuminate\Http\Request;
  8. class ItemUrlScrapController extends Controller
  9. {
  10. private $api23GateTokenService;
  11. private $itemUrlScrapService;
  12. public function __construct(
  13. Api23GateTokenService $api23GateTokenService,
  14. ItemUrlScrapService $itemUrlScrapService
  15. )
  16. {
  17. $this->api23GateTokenService = $api23GateTokenService;
  18. $this->itemUrlScrapService = $itemUrlScrapService;
  19. }
  20. public function store(Request $request)
  21. {
  22. $result = $this->api23GateTokenService->getToken($request->header('Api23Key'));
  23. if ($result['error']) {
  24. return response()->json($result['message'], 401);
  25. }
  26. $request = json_decode($request->getContent(), true);
  27. try {
  28. $response = $this->itemUrlScrapService->execute($result['data'], $request);
  29. return response()->json($response);
  30. } catch (Exception $e) {
  31. return response()->json('Unauthorized', 401);
  32. }
  33. }
  34. }