Coder Social home page Coder Social logo

tlshifat / calc Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 22.19 MB

This Project is created for BASIC Calculator operation with PHP standard pattern.

PHP 94.56% JavaScript 1.56% Vue 0.52% SCSS 0.45% Blade 1.56% Dockerfile 0.55% Shell 0.79%
php docker design-patterns

calc's Introduction

RestAPI - Based on Laravel with Docker

Laravel 6.0 Restful API with:

  • api;
  • json responses;
  • phpunit tests;

Requirements

As it is build on the Laravel framework, it has a few system requirements.
Of course, all of these are satisfied by the Docker, so it's highly recommended that you use Docker as your local Laravel development environment.

However, if you are not using Docker, you will need to make sure your server meets the following requirements:

  • PHP >= 7.1.3
  • Composer
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • BCMath PHP Extension

You can check all the laravel related dependecies here.

Install application.

  1. Clone repository and setup.
    git clone https://github.com/shifatbuet/calc.git
    cd calc
  2. Start docker.
    docker-compose up -d
  3. Install needed packages.
    docker exec php-fpm composer install
  4. Storage log permission (sometimes an issue).
    sudo chmod -R 777 bootstrap storage
  5. Generate key.
    docker exec php-fpm php artisan key:generate
    This way is to setup app with docker, but if you want use it without docker just skip second step and replace from commands docker exec php-fpm part. For example 3 step without Docker should look like:
    composer install

API Endpoints and Routes

docker exec php-fpm php artisan route:list
+--------+----------+---------------+------+-----------------------------------------------------+------------+
| Domain | Method   | URI           | Name | Action                                              | Middleware |
+--------+----------+---------------+------+-----------------------------------------------------+------------+
|        | GET|HEAD | /             |      | Closure                                             | web        |
|        | POST     | api/calculate |      | App\Http\Controllers\CalculatorController@calculate | api        |
+--------+----------+---------------+------+-----------------------------------------------------+------------+

Example calculate request

  • For Linux :
curl -d "input_1=1&input_2=2&operation=add" -X POST http://localhost:88/api/calculate

Example calculate response

{
"success":true,
"data":3 
}

Tests

Used a library for printing the result in pretty format codedungeon/phpunit-result-printer.

  • All the success, failure test cases checked in phpunit:
./vendor/phpunit/phpunit/phpunit tests/Feature/CalculatorTest.php
  • Output will be something like followings:
PHPUnit 8.5.21 by Sebastian Bergmann and contributors.

 ==> CalculatorTest             ✔  ✔  ✔  ✔  ✔  ✔  ✔  ✔  ✔  ✔  ✔  ✔  ✔  

Time: 632 ms, Memory: 20.00 MB

OK (13 tests, 26 assertions)

Logs

  • For checking logs:
tail -f storage/logs/laravel-"`date +'%Y-%m-%d'`".log
  • Log output at a glimpse without errors
[2021-09-30 05:38:10] testing.ERROR: Exception occurred in operation . {"input_1":1,"input_2":0,"operator":null} 
[2021-09-30 05:38:35] testing.INFO: Calculating the inputs based on operation . {"input_1":1,"input_2":2,"operator":"add"} 
[2021-09-30 05:38:35] testing.INFO: Executing addition . {"input_1":1,"input_2":2} 
[2021-09-30 05:38:35] testing.INFO: Calculating the inputs based on operation . {"input_1":1,"input_2":1,"operator":"add"} 
[2021-09-30 05:38:35] testing.INFO: Executing addition . {"input_1":1,"input_2":1} 
[2021-09-30 05:38:35] testing.INFO: Calculating the inputs based on operation . {"input_1":10,"input_2":1,"operator":"subtract"} 
[2021-09-30 05:38:35] testing.INFO: Executing subtraction . {"input_1":10,"input_2":1} 
[2021-09-30 05:38:35] testing.INFO: Calculating the inputs based on operation . {"input_1":1,"input_2":1,"operator":"subtract"} 
[2021-09-30 05:38:35] testing.INFO: Executing subtraction . {"input_1":1,"input_2":1} 
[2021-09-30 05:38:35] testing.INFO: Calculating the inputs based on operation . {"input_1":10,"input_2":1,"operator":"multiply"} 
[2021-09-30 05:38:35] testing.INFO: Executing multiplication . {"input_1":10,"input_2":1} 
[2021-09-30 05:38:35] testing.INFO: Calculating the inputs based on operation . {"input_1":1,"input_2":1,"operator":"multiply"} 
[2021-09-30 05:38:35] testing.INFO: Executing multiplication . {"input_1":1,"input_2":1} 
[2021-09-30 05:38:35] testing.INFO: Calculating the inputs based on operation . {"input_1":10,"input_2":1,"operator":"divide"} 
[2021-09-30 05:38:35] testing.INFO: Executing division . {"input_1":10,"input_2":1} 
[2021-09-30 05:38:35] testing.INFO: Calculating the inputs based on operation . {"input_1":1,"input_2":1,"operator":"divide"} 
[2021-09-30 05:38:35] testing.INFO: Executing division . {"input_1":1,"input_2":1} 
[2021-09-30 05:38:35] testing.ERROR: Exception occurred in operation . {"input_1":"wrong_data","input_2":2,"operator":null} 
[2021-09-30 05:38:35] testing.ERROR: Exception occurred in operation . {"input_1":1,"input_2":"wrong_data","operator":null} 
[2021-09-30 05:38:35] testing.ERROR: Exception occurred in operation . {"input_1":10,"input_2":1,"operator":null} 
[2021-09-30 05:38:35] testing.ERROR: Exception occurred in operation . {"input_1":1,"input_2":1,"operator":null} 

Format code

  • Find out the files that needs to be fixed : docker exec php-fpm composer sniff

  • Fix all the code format : docker exec php-fpm composer lint

calc's People

Contributors

tlshifat avatar shifatbjit avatar

Watchers

James Cloos avatar  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.