Skip to content

Latest commit

 

History

History
180 lines (127 loc) · 4.31 KB

README.md

File metadata and controls

180 lines (127 loc) · 4.31 KB

Flashcard Interactive Command

This repository contains a Laravel 11 application with a feature for managing flashcards through an interactive console command.

Branches

This repo has the following branches:

  • main: Contains the base Laravel 11 code.
  • clean-up: Derived from main, this branch removes unnecessary files/containers.
  • interactive-command: Derived from clean-up, Contains the code related to the flashcards interactive command.

Branch Hierarchy:

  • main -> clean-up -> interactive-command

Pull Request

A Pull Request has been created from interactive-command to clean-up for easy code review.

PR

Solution Details

The primary feature of this repository is a Laravel console command that manages flashcards. Below are the key files related to this feature:

Console Command

  • app/Console/Commands/FlashcardInteractive.php

Services

  • app/Services/FlashcardService.php
  • app/Services/FlashcardPracticeService.php
  • app/Services/MenuService.php

Models

  • app/Models/Flashcard.php
  • app/Models/FlashcardPractice.php

Enums

  • app/Enums/MenuItem.php
  • app/Enums/FlashcardPracticeStatus.php

Tests

  • tests/Feature/FlashcardCommandTest.php
  • tests/Unit/FlashcardPracticeTest.php
  • tests/Unit/FlashcardTest.php
  • tests/Unit/MenuTest.php

Migrations

  • Database migration files are located in database/migrations.

Schema

Two tables are created for the flashcard functionality:

  1. flashcards [id, question, answer]
  2. flashcard_practices [id, flashcard_id, user_id, answer, status]

Note: Although we currently don't have a user entity in the system, the user_id is included in the flashcard_practices table to allow future user integration. For now, the user_id is passed as a command argument.

Setup Guidelines

Prerequisites

  • Docker
  • WSL2 (for Windows users)

Setup Steps

  1. Clone the repository:

    git clone [email protected]:tayyabhussainit/flashcard.git
    cd flashcard
  2. Checkout the interactive-command branch:

    git checkout interactive-command
  3. Copy the environment file:

    cp .env.example .env
  4. Install dependencies:

    docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/var/www/html" -w /var/www/html laravelsail/php83-composer:latest composer install --ignore-platform-reqs

    Reference: https://laravel.com/docs/11.x/sail#installing-composer-dependencies-for-existing-projects

  5. Start the project using WSL (required for setup on windows):

    wsl -d ubuntu
  6. Go to the project directory (inside WSL, required for setup on windows).

  7. Start the Docker containers:

    ./vendor/bin/sail up -d
  8. Generate the application key:

    ./vendor/bin/sail artisan key:generate
  9. Run migrations:

    ./vendor/bin/sail artisan migrate

Running the Flashcards Command

To run the flashcards interactive command, use the following:

./vendor/bin/sail artisan flashcard:interactive {user_id}

example:

./vendor/bin/sail artisan flashcard:interactive 1

Running Test Cases

To run the test cases, "testing" database must be created:

./vendor/bin/sail mysql
mysql> CREATE DATABASE testing;
mysql> exit
./vendor/bin/sail artisan test

Code Quality: PHP Code Sniffer

To ensure code quality, PHP Code Sniffer was used to check the code for any violations of coding standards.

Running PHP Code Sniffer

  1. Access the Docker container:

    ./vendor/bin/sail bash
  2. Run PHP Code Sniffer on specific files or directories:

    • To check the FlashcardInteractive command file:

      ./vendor/bin/phpcs -v app/Console/Commands/FlashcardInteractive.php
    • To check the Services directory:

      ./vendor/bin/phpcs -v app/Services/
    • To check the Models directory:

      ./vendor/bin/phpcs -v app/Models/
    • To check the Enums directory:

      ./vendor/bin/phpcs -v app/Enums/

Screenshots

Screenshots of the commands, tests and schema exists in screenshots folder at root