The GDC Group Affilates application will read a .txt file called affilate.txt, containing a list of affiliates containing correctly formatted JSON with objects (1 per row) containing the following fields: affiliate_id, name, longitude and latitude. The application will then calculate the distance between the affiliate and the GDC Group office in Dublin (longitude: 53.3340285, latitude: -6.2535495) and return a list of affiliates within 100km ordered by affiliate_id (ascending).
The affilate.txt file is located in the storage/app folder.
IMPORTANT: The affiliate.txt file is NOT correctly formatted JSON, therefore the application will split the file based on newlines, and not commas.
Therefore, the solution is as follows:
- The
App\Utilities\Affiliates::toArray
method will loop through each line and parse/decode the JSON object, returning an array of objects with properties (affiliate_id
,name
,latitude
andlongitude
) - The
App\Utilities\Affiliates::withinDistance
method will then calculate the distance between the affiliate, using the affiliate's latitude and longitude and calling theApp\Utilities\Haversine::distance
method to get the Great Circle Distance Great Circle Distance using the GDC Group office in Dublin (longitude: 53.3340285, latitude: -6.2535495) as the origin - The application will present the list of affiliates within 100km ordered by affiliate_id (ascending) on the UI
The affilate.txt file contains a list of affiliates containing JSON objects (1 per row) containing the following fields:
- affiliate_id
- name
- longitude
- latitude
{latitude: "52.986375", user_id: 12, name: "Yosef Giles", longitude: "-6.043701"}
{latitude: "51.92893", user_id: 1, name: "Lance Keith", longitude: "-10.27699"}
...
The affilate.txt file is located in the storage/affiliates folder.
- PHP (8.1+)
- Composer (2.5+)
- SQLite (3.8.8+)
- NodeJS (16.15+) + NPM (9.6+)
- Yarn (1.22+)
- Laravel (10.10+)
- Laravel Breeze (1.26+)
- Laravel Socialite (5.10+)
- PHPUnit (10.1+)
- Vite (4.0+)
- AlpineJS (3.4+)
- TailwindCSS (3.1+)
- Axios (1.6+)
- Clone the repository
- CD into the repository from within your terminal
- Run
composer install
- Run
php artisan migrate
(This sets up the users tables to allow for login via Github) - Run
php artisan serve
- In a separate terminal session, run
yarn install
- Run
yarn dev
- Visit
http://localhost:8000
(from thephp artisan serve
terminal session, NOT theyarn dev
session) in your browser, or whichever port the application is running on
- Visit
http://localhost:8000
in your browser, or whichever port the application is running on - Login using Github
- Once logged in, click the
List Affiliates
button to view the list of affiliates within 100km ordered by affiliate_id (ascending)
- tests/Unit/HaversineTest: Unit tests for the
App\Utilities\Haversine
class - tests/Unit/AffiliatesTest: Unit tests for the
App\Utilities\Affiliates
class
- tests/Unit/mocks/affilites.txt: Mock affiliates.txt file used by
Storage::fake
to generate a consistant data set for theAffilitesTest