Skip to content

artemind/test-task-1

Test Task 1 (Simple Laravel API with Job Queue, Database, and Event Handling)

Set Up and Run

  1. Clone repository
  2. Run docker-compose up -d
  3. Copy .env.example, rename to .env and configure
  4. Run docker-compose exec php php artisan migrate
  5. Run docker-compose exec php php artisan test to running tests
  6. Go to terminal and send curl request
curl --location 'http://127.0.0.1:8000/api/submit' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "John Doe",
    "email": "john.doe@example.com",
    "message": "test message"
}'

Requirements

  1. API Endpoint: Develop a single API endpoint /api/submit that accepts a POST request with the following JSON payload structure:
{
  "name": "John Doe",
  "email": "john.doe@example.com",
  "message": "This is a test message"
}
  1. Validate the data (ensure name', email and message are present).
  2. Database setup: Use Laravel migrations to create a table named submissions with columns for id, name, email, message and timestamps (creayed_at and updated_at).
  3. Job Queue: Upon receiving the API request, the data should not be immediately saved to the database. Instead, dispatch a Laravel job to process the data. The job should perform the following tasks:
    1. Save the data to the submissions table in the database.
  4. Events: After the data is successfully saved to the database, trigger a Laravel event named SubmissionSaved. Attach a listener to this event that logs a message indicating a successful save, including name and email of the submission.
  5. Error handling: Implement error handling for the API to respond with appropriate messages and status codes for the following scenarios:
    1. Invalid data input (e.g., missing required fields).
    2. Any errors that occur during the job processing.
  6. Documentation: Briefly document the following in a README file:
    1. Instructions on setting up the project and running migrations.
    2. A simple explanation of how to test the API endpoint.
  7. Write a simple test.

About

Test task from employer.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages