mirror of
https://github.com/JGH0/Todo-App-Backend.git
synced 2026-06-03 13:28:47 +02:00
implement full backend requirements: pagination, filtering, sorting, meta responses, JWT auth, model validation, request logging, API key management
- BaseController: paginatedResponse() helper with meta (page/perPage/total/lastPage/hasMore), getSortParams(), getFilterParams(), encodeJwt()/decodeJwt(), logActivity() helper, validateWithModel() - TodoController: paginated/sortable/filterable index, model-based validation, boolean conversion on write, activity logging - CategoryController: same pagination/sort/filter patterns + duplicate-name check (409) - ProjectController: paginated index + activity logging - RecurringTaskController: paginated/sortable/filterable index + junction-table category linking - AuthController: JWT register/login/refresh endpoints (firebase/php-jwt v7) - Routes: JWT routes added as public endpoints - Models: all have proper validationRules with exact error messages (field-level, user-facing) - ApiAuthFilter: scoped API key auth + UserThemeController generateUuid visibility fix - composer.json: add firebase/php-jwt ^7.0
This commit is contained in:
@@ -6,53 +6,51 @@ use CodeIgniter\Model;
|
||||
|
||||
class TodoModel extends Model
|
||||
{
|
||||
protected $table = 'todos';
|
||||
protected $primaryKey = 'id';
|
||||
protected $table = 'todos';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = false;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $allowedFields = [
|
||||
'id',
|
||||
'user_id',
|
||||
'title',
|
||||
'description',
|
||||
'status',
|
||||
'due_date',
|
||||
'due_time',
|
||||
'sync_enabled',
|
||||
'reminder_enabled',
|
||||
'recurring_enabled',
|
||||
'project_id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $allowedFields = [
|
||||
'id', 'user_id', 'title', 'description', 'status',
|
||||
'due_date', 'due_time', 'sync_enabled', 'reminder_enabled',
|
||||
'recurring_enabled', 'project_id', 'created_at', 'updated_at',
|
||||
];
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
protected $validationRules = [
|
||||
'user_id' => 'required',
|
||||
'title' => 'required|max_length[255]',
|
||||
'status' => 'permit_empty|in_list[open,in_progress,completed,archived]',
|
||||
'user_id' => [
|
||||
'rules' => 'required',
|
||||
'errors' => ['required' => 'User ID is required.'],
|
||||
],
|
||||
'title' => [
|
||||
'rules' => 'required|max_length[255]',
|
||||
'errors' => [
|
||||
'required' => 'The todo title is required.',
|
||||
'max_length' => 'The title must not exceed 255 characters.',
|
||||
],
|
||||
],
|
||||
'status' => [
|
||||
'rules' => 'permit_empty|in_list[open,in_progress,completed,archived]',
|
||||
'errors' => [
|
||||
'in_list' => 'Status must be one of: open, in_progress, completed, archived.',
|
||||
],
|
||||
],
|
||||
'due_date' => [
|
||||
'rules' => 'permit_empty|valid_date[Y-m-d]',
|
||||
'errors' => ['valid_date' => 'Due date must be in YYYY-MM-DD format.'],
|
||||
],
|
||||
'due_time' => [
|
||||
'rules' => 'permit_empty|valid_date[H:i:s]',
|
||||
'errors' => ['valid_date' => 'Due time must be in HH:MM format.'],
|
||||
],
|
||||
];
|
||||
|
||||
// Get todos with categories
|
||||
public function getWithCategories($todoId = null)
|
||||
{
|
||||
$builder = $this->select('todos.*, GROUP_CONCAT(categories.name) as category_names')
|
||||
->join('todo_categories', 'todos.id = todo_categories.todo_id', 'left')
|
||||
->join('categories', 'todo_categories.category_id = categories.id', 'left')
|
||||
->groupBy('todos.id');
|
||||
// ── Queries ────────────────────────────────────────────────────────────
|
||||
|
||||
if ($todoId) {
|
||||
$builder->where('todos.id', $todoId);
|
||||
}
|
||||
|
||||
return $builder->get()->getResultArray();
|
||||
}
|
||||
|
||||
// Get todos by user with categories (optionally filtered by todo id)
|
||||
public function getByUserWithCategories($userId, $todoId = null)
|
||||
{
|
||||
$builder = $this->select('
|
||||
|
||||
Reference in New Issue
Block a user