Git Product home page Git Product logo

backend-laravel-test's Introduction

Test Laravel Project

Scrutinizer Code Quality Build Status

This is a Laravel test project providing APIs for property analytics inquiry.

Design considerations

The properties table is many-to-many mapped to analytic_types table with intermediate table property_analytics and additional field value.

Adding/update property analytic is simply about creating/updating relations between those 2 tables.

The nesting of API endpoints properties/{uuid}/analytics/{analyticid} makes the "belonging" relationship obvious. CRUD operations of analytics against a property should be performed on this endpont. Deleting a property means deleting the analytics with it.

Properties might have sensitive info, with {uuid} here, it stops user iterating all properties with this API. But it might not be neccesary for protected API.

The reporting API endpoint resides in report/properties/analytics. Reporting on large scale is an intensive job. Imaging millions of properties with hundreds of types of analytics are processed in 1 API call, it has to be fast.

The PropertyAnalyticsReport Controller uses optimised DB query to generate the result, avoiding extensive traversing with PHP code. DB aggr function such as percentile_cont() and casting is used to make sure result is produced fast and accurate, this is also the reason for dropped support of SQLite/Mysql.

Ideally, the report results should be cached in various layers for performance benifits and resource consideration.

Requirements

Make sure you have server requirements checked for Laravel.

Postgres 9.5 and above must be installed(for percentile_cont func). I have CI tests running on pgsql 9.5 and local machine running Unit tests on Postgres 12.5.

Since report summary using percentile function, SQLite and lower version of pgsql is not supported.

Installation

Configuration

  • Copy file .env.example to .env

  • Edit .env for Postgres DB connection

  • Install project dependencies

composer install

DB setup

Create Database with name defined in .env. For example,

createdb laravel

Run below command to create DB schema and seed DB with sample data.

CSV files in database/csvs are imported to seed DB.

php artisan migrate:fresh --seed

Testing

Start web server

php artisan serve

Create a new property

curl --location --request POST 'http://127.0.0.1:8000/api/v1/properties' \
--header 'Content-Type: application/json' \
--header 'X-Requested-With: XMLHttpRequest' \
--data-raw '{"state": "NSW", "country": "Australia", "suburb": "Parramatta"}'

Add/update an analytic value for a property

Replace {uuid} with a Property's guid. {analyticid} is a integer. E.g 1.

curl --location --request PUT 'http://127.0.0.1:8000/api/v1/properties/{uuid}/analytics/{analyticid}?value={value}' \
--header 'X-Requested-With: XMLHttpRequest' \
--header 'Content-Type: application/json'

Getting all analytics for a property

curl --location --request GET 'http://127.0.0.1:8000/api/v1/properties/{uuid}/analytics' \
--header 'Content-Type: application/json' \
--header 'X-Requested-With: XMLHttpRequest'

Report analytics summary

curl --location --request GET 'http://127.0.0.1:8000/api/v1/report/properties/analytics?filter=country&value=Australia' \
--header 'X-Requested-With: XMLHttpRequest' \
--header 'Content-Type: application/json'

Run unit tests

php artisan test

backend-laravel-test's People

Contributors

xwan510 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.