<?php

namespace App\Http\Controllers;

use App\Models\Log as LogModel;
use App\Utils\UploadUtils;
use Illuminate\Http\Request;

class UploadController extends Controller
{
    public function __construct(Request $request)
    {
        $this->log = new LogModel([
            'module' => 'file',
            'action' => $request->getMethod(),
            'target_type' => 'upload',
        ]);
    }

    public function store(Request $request)
    {
        if (!$request->hasFile('uploadFile')) {
            $this->res = [
                'httpCode' => 404,
                'errorCode' => 404404,
                'errorMessage' => 'not found file',
            ];
        }
        $this->addLog(0, 'add');
        $this->res['resource'] = UploadUtils::putForUploadedFile('image', $request->uploadFile);

        return response($this->res, $this->res['httpCode']);
    }
}
