<commit_before><?php

namespace App\Http\Controllers;

use App\Repositories\TodoRepository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class TodosController extends Controller
{
    // TODO Add Middleware to check todo exist
    private $todoRepo;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(TodoRepository $todoRepo)
    {
        // Construct
        $this->todoRepo = $todoRepo;

        $this->middleware('check_exist:\App\Models\Todo', [
            'only' => [
                'viewTodo', 'updateTodo', 'deleteTodo', 'moveTodo'
            ]
        ]);
    }

    public function index()
    {
        $response = [
            'message' => 'Hello from API Index',
        ];
        return new JsonResponse($response, 200);
    }

    public function indexTodos()
    {
        return $this->todoRepo->all();
    }

    public function viewTodo($id)
    {
        return $this->todoRepo->get($id);
    }

    public function createTodo(Request $request)
    {
        $this->validate($request, [
            'title' => 'required'
        ]);

        $data = [
            'title' => $request->input('title'),
            'due_date' => $request->input('due_date', null),
            'color' => $request->input('color', null),
            'todo_groups_id' => $request->input('todo_groups_id'),
            'marked' => $request->input('marked')
        ];
        return $this->todoRepo->create($data);
    }

    public function updateTodo($id, Request $request)
    {
        // TODO Check exist in middleware
        $this->validate($request, [
            'title' => 'required'
        ]);

        $data = [
            'title' => $request->input('title'),
            'due_date' => $request->input('due_date', null),
            'color' => $request->input('color', null),
            'marked' => $request->input('marked')
        ];

        $updated = $this->todoRepo->update($data, $id);
        if ($updated) {
            return $updated;
        }
        return response(['error' => 'Couldn\'t update'], 422);
    }

    public function deleteTodo($id)
    {
        $deleted = $this->todoRepo->delete($id);
        if ($deleted) {
            return $deleted;
        }
        return response(['error' => 'Couldn\'t delete'], 422);
    }

    public function moveTodo($id, Request $request)
    {
        $moved = $this->todoRepo->move($id, $request->input('prior_sibling_id', ''));
        if ($moved) {
            return $moved;
        }
        return response(['error' => 'Couldn\'t move'], 422);
    }
}
<commit_msg>Update default value for marked field<commit_after><?php

namespace App\Http\Controllers;

use App\Repositories\TodoRepository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class TodosController extends Controller
{
    // TODO Add Middleware to check todo exist
    private $todoRepo;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(TodoRepository $todoRepo)
    {
        // Construct
        $this->todoRepo = $todoRepo;

        $this->middleware('check_exist:\App\Models\Todo', [
            'only' => [
                'viewTodo', 'updateTodo', 'deleteTodo', 'moveTodo'
            ]
        ]);
    }

    public function index()
    {
        $response = [
            'message' => 'Hello from API Index',
        ];
        return new JsonResponse($response, 200);
    }

    public function indexTodos()
    {
        return $this->todoRepo->all();
    }

    public function viewTodo($id)
    {
        return $this->todoRepo->get($id);
    }

    public function createTodo(Request $request)
    {
        $this->validate($request, [
            'title' => 'required'
        ]);

        $data = [
            'title' => $request->input('title'),
            'due_date' => $request->input('due_date', null),
            'color' => $request->input('color', null),
            'todo_groups_id' => $request->input('todo_groups_id'),
            'marked' => $request->input('marked', 0)
        ];
        return $this->todoRepo->create($data);
    }

    public function updateTodo($id, Request $request)
    {
        // TODO Check exist in middleware
        $this->validate($request, [
            'title' => 'required'
        ]);

        $data = [
            'title' => $request->input('title'),
            'due_date' => $request->input('due_date', null),
            'color' => $request->input('color', null),
            'marked' => $request->input('marked', 0)
        ];

        $updated = $this->todoRepo->update($data, $id);
        if ($updated) {
            return $updated;
        }
        return response(['error' => 'Couldn\'t update'], 422);
    }

    public function deleteTodo($id)
    {
        $deleted = $this->todoRepo->delete($id);
        if ($deleted) {
            return $deleted;
        }
        return response(['error' => 'Couldn\'t delete'], 422);
    }

    public function moveTodo($id, Request $request)
    {
        $moved = $this->todoRepo->move($id, $request->input('prior_sibling_id', ''));
        if ($moved) {
            return $moved;
        }
        return response(['error' => 'Couldn\'t move'], 422);
    }
}

{'fraction_non_alphanumeric': 0.15912518853695323, 'fraction_numerical': 0.004901960784313725, 'mean_word_length': 1.9870495495495495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6874723', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1589, 'n_words': 315}