Skip to content

evryn/laravel-code-challenge-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 

Repository files navigation

Laravel Code Challenge I

About

This document tests an examinee's knowledge of PHP design principles and its implementations on the Laravel framework.

System

This project is about an image uploading system. The user will sign in and upload images.

Development

The developer will do the project in 3 versions. The first two are required to complete the project, and the other is optional. You'll have one day to work on the project and decide how you're going to balance the things we care about (see below). Some people choose to do the required versions but keep the code as clean and high quality as possible, and some care about the task completion.

We care about:

  • Code Quality & Standardization
  • Optimization
  • Security
  • Tasks Progress
  • Deadline

Note that:

  • Everything is API-based. No need to write a single HTML/CSS/JS code.
  • The instructions below are not necessarily complete nor explicit; You can use your ideas too.

Output

You'll need to have your final code pushed into your own GitHub repository.


Version 1

We need a Laravel application to let users sign up and sign in to allow them to upload images.

Intention

  • Knowing your familiarity with Laravel core features.
  • Getting familiar with how you use git.

Goals

  • Implement sign up and sign in features using Laravel Sanctum
  • Implement an endpoint to upload a new image and get the response

Prerequisites

Use the following tables for your migrations:

mysql> show columns from `users`;
+-------------------+-----------------+------+-----+---------+----------------+
| Field             | Type            | Null | Key | Default | Extra          |
+-------------------+-----------------+------+-----+---------+----------------+
| id                | bigint unsigned | NO   | PRI | NULL    | auto_increment |
| firstname         | varchar(255)    | NO   |     | NULL    |                |
| lastname          | varchar(255)    | NO   |     | NULL    |                |
| email             | varchar(255)    | NO   | UNI | NULL    |                |
| password          | varchar(255)    | NO   |     | NULL    |                |
| created_at        | timestamp       | NO   |     | NULL    |                |
| updated_at        | timestamp       | YES  |     | NULL    |                |
+-------------------+-----------------+------+-----+---------+----------------+
mysql> show columns from `images`;
+-------------------+-----------------+------+-----+---------+----------------+
| Field             | Type            | Null | Key | Default | Extra          |
+-------------------+-----------------+------+-----+---------+----------------+
| id                | bigint unsigned | NO   | PRI | NULL    | auto_increment |
| user_id           | bigint unsigned | NO   | FRI | NULL    |                |
| path              | varchar(255)    | NO   | UNI | NULL    |                |
| title             | varchar(255)    | NO   | UNI | NULL    |                |
| created_at        | timestamp       | NO   |     | NULL    |                |
| updated_at        | timestamp       | YES  |     | NULL    |                |
+-------------------+-----------------+------+-----+---------+----------------+

Instructions

  1. Create a Laravel project
  2. Use Laravel Sanctum to implement SPA sign up and sign in features.
  3. Add an endpoint (POST /api/images) where the user can upload an image with its title and response its URL and title. Store the file in the local filesystem and save its path and title into the database.
  4. Protect the endpoint from unauthorized access.

Version 2

Now, we've decided to add another storage platform - S3. We need to configure the app and use either the local filesystem or the S3 instance.

Intention

  • Getting familiar with your coding quality and standardization ideas.

Goals

  • Implement a Strategy Pattern for uploading images to the local filesystem and S3 platform

Instructions

  1. Create two drivers called FilesystemStorage and S3Storage
  2. Create a service called ImageStorage
  3. Decide to use a driver by looking up a IMAGE_STORAGE_DRIVER environment variable as config.

Note: It's OK to use mocked S3 uploads. We don't want its real functionality for this testing project.

Hint: Write a new migration for images table and keep the strategy method used there.


Version 3 (Optional)

Due to the high usage of our AA (Awesome Application!), we're getting substantial image uploads! We need to clean up old images periodically and optimize how we perform table scans during its process.

Intention

  • Getting familiar with your research process

Goals

  • Schedule a task to clean up old images.
  • Consider optimizing the database for finding old records efficiently.

Instructions

  1. Create a command called images:cleanup and remove images older than 3 days
  2. Use the Laravel Scheduling mechanism to schedule the command every 20 seconds.
  3. Research how to efficiently optimize the images table to perform table scans during your SELECT query of the cleanup task. Consider that the table will have nearly 1,000,000,000 records!

Note: Command may take a long time. We don't need two instances of the scheduled command running simultaneously.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published