diff --git a/.env.testing b/.env.testing index 8c253d1..2e9b1b9 100644 --- a/.env.testing +++ b/.env.testing @@ -4,6 +4,6 @@ APP_DEBUG=true DB_CONNECTION=sqlite DB_HOST=sqlite -DB_DATABASE=:memory: +DB_DATABASE=/var/tmp/laraland.db DB_USERNAME= DB_PASSWORD= diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5cf4da..3172c2e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,13 +1,13 @@ # This file is a template, and might need editing before it works on your project. # Official framework image. Look for the different tagged releases at: # https://hub.docker.com/r/library/php -image: registry.waf.or.id/ywa/sarpras:latest +image: registry.waf.or.id/gregorio/laraland:latest # Pick zero or more services to be used on all builds. # Only needed when using a docker container to run your tests in. # Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service services: - # - mysql:latest + - registry.waf.or.id/gregorio/laraland/mariadb:latest variables: # MYSQL_DATABASE: laraland @@ -23,14 +23,18 @@ cache: # This is a basic example for a gem or script which doesn't use # services such as redis or postgres before_script: - # Update packages - # - apt-get update -yqq + # Add mariadb hostname to hosts file + - printf "172.17.0.2 mariadb\n" >> /etc/hosts + + # Update packages + - apt-get update -yqq # Upgrade to Node 7 # - curl -sL https://deb.nodesource.com/setup_7.x | bash - # Install dependencies - # - apt-get install git nodejs libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq + - apt-get install git libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev mysql-client -yqq + # nodejs # Install php extensions # - docker-php-ext-install mbstring pdo_mysql curl json intl gd xml zip bz2 opcache @@ -40,8 +44,9 @@ before_script: # - docker-php-ext-enable xdebug # Install Composer and project dependencies. - - curl -sS https://getcomposer.org/installer | php - - php composer.phar install + # - curl -sS https://getcomposer.org/installer | php + # - php composer.phar install + - composer install # Install Node dependencies. # comment this out if you don't have a node dependency @@ -55,6 +60,9 @@ before_script: # DB_PASSWORD=secret - cp .env.testing .env + # Generate database file + - touch /var/tmp/laraland.db + # Run npm build # comment this out if you don't have a frontend build # you can change this to to your frontend building script like @@ -67,17 +75,21 @@ before_script: # Run database migrations. - php artisan migrate + - php artisan module:migrate # Run database seed - - php artisan db:seed + # - php artisan db:seed + # - php artisan module:seed + + # Generate passport password client + - php artisan passport:client --password --name=laraland test: script: # run laravel tests # - php vendor/bin/phpunit --coverage-text --colors=never - - php vendor/bin/codeception run acceptance - - php vendor/bin/codeception run functional - - php vendor/bin/codeception run functional -c Modules/Karyawaf + - php vendor/bin/codecept run functional + - php vendor/bin/codecept run functional -c Modules/Karyawaf # run frontend tests # if you have any task for testing frontend diff --git a/.gitlab-ci.yml.orig b/.gitlab-ci.yml.orig new file mode 100644 index 0000000..42a8796 --- /dev/null +++ b/.gitlab-ci.yml.orig @@ -0,0 +1,84 @@ +# This file is a template, and might need editing before it works on your project. +# Official framework image. Look for the different tagged releases at: +# https://hub.docker.com/r/library/php +image: php:latest + +# Pick zero or more services to be used on all builds. +# Only needed when using a docker container to run your tests in. +# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service +services: + - mysql:latest + +variables: + MYSQL_DATABASE: laraland + MYSQL_ROOT_PASSWORD: root + +# This folder is cached between builds +# http://docs.gitlab.com/ce/ci/yaml/README.html#cache +cache: + paths: + - vendor/ + # - node_modules/ + +# This is a basic example for a gem or script which doesn't use +# services such as redis or postgres +before_script: + # Update packages + - apt-get update -yqq + + # Upgrade to Node 7 + # - curl -sL https://deb.nodesource.com/setup_7.x | bash - + + # Install dependencies + - apt-get install git libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq + # nodejs + + # Install php extensions + - docker-php-ext-install mbstring pdo_mysql curl json intl gd xml zip bz2 opcache + + # Install & enable Xdebug for code coverage reports + - pecl install xdebug + - docker-php-ext-enable xdebug + + # Install Composer and project dependencies. + - curl -sS https://getcomposer.org/installer | php + - php composer.phar install + + # Install Node dependencies. + # comment this out if you don't have a node dependency + # - npm install + + # Copy over testing configuration. + # Don't forget to set the database config in .env.testing correctly + # DB_HOST=mysql + # DB_DATABASE=project_name + # DB_USERNAME=root + # DB_PASSWORD=secret + - cp .env.testing .env + + # Run npm build + # comment this out if you don't have a frontend build + # you can change this to to your frontend building script like + # npm run build + # - npm run dev + + # Generate an application key. Re-cache. + - php artisan key:generate + - php artisan config:cache + + # Run database migrations. + # - php artisan migrate + + # Run database seed + # - php artisan db:seed + +test: + script: + # run laravel tests + - php vendor/bin/phpunit --coverage-text --colors=never + + # run frontend tests + # if you have any task for testing frontend + # set it in your package.json script + # comment this out if you don't have a frontend test + # - npm test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..48f939b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM debian:stretch +MAINTAINER Gregorio Chiko + +RUN apt-get update && \ + apt-get install -y \ + apt-transport-https \ + lsb-release \ + ca-certificates \ + curl \ + git \ + zip \ + unzip \ + sudo \ + wget \ + gnupg1 + +ADD https://packages.sury.org/php/apt.gpg /etc/apt/trusted.gpg.d/php.gpg +RUN sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' +RUN chmod 664 /etc/apt/trusted.gpg.d/php.gpg + +RUN apt-get update && \ + apt-get install -y \ + php7.2-fpm \ + php7.2-cli \ + php7.2-mysql \ + php7.2-mbstring \ + php7.2-json \ + php7.2-sqlite3 \ + php7.2-xml \ + php7.2-curl \ + php7.2-zip \ + php7.2-intl \ + php7.2-gd \ + php7.2-bz2 \ + php7.2-opcache + +COPY --from=composer:1.5 /usr/bin/composer /usr/bin/composer + +RUN php -v && \ + git --version && \ + composer --version \ No newline at end of file diff --git a/Modules/Karyawaf/Http/Controllers/KaryawanController.php b/Modules/Karyawaf/Http/Controllers/KaryawanController.php index 40cd942..b2ea727 100644 --- a/Modules/Karyawaf/Http/Controllers/KaryawanController.php +++ b/Modules/Karyawaf/Http/Controllers/KaryawanController.php @@ -18,11 +18,15 @@ class KaryawanController extends Controller */ public function index() { - $response = Karyawan::all(); + // $response = Karyawan::all(); - return response()->json([ - 'data' => $response - ]); + // return response()->json([ + // 'data' => $response + // ]); + return responder() + ->success(Karyawan::all()) + ->meta(['count' => Karyawan::count()]) + ->respond(); } /** @@ -45,9 +49,12 @@ class KaryawanController extends Controller $response = Auth::user()->karyawans()->create($validated); // Auth::user()->karyawan->create() - return response()->json([ - 'data' => $response - ]); + // return response()->json([ + // 'data' => $response + // ]); + return responder() + ->success($response) + ->respond(); } /** @@ -59,9 +66,18 @@ class KaryawanController extends Controller { $response = Karyawan::find($id); - return response()->json([ - 'data' => $response - ]); + // return response()->json([ + // 'data' => $response + // ]); + if (!$response) { + return responder() + ->error('karyawan_error', 'Cannot find `karyawan` with id ' . $id) + ->respond(); + } + + return responder() + ->success($response) + ->respond(); } /** @@ -86,9 +102,13 @@ class KaryawanController extends Controller $karyawan->update($validated); - return response()->json([ - 'data' => $karyawan - ]); + // return response()->json([ + // 'data' => $karyawan + // ]); + + return responder() + ->success($karyawan) + ->respond(); } /** @@ -102,8 +122,12 @@ class KaryawanController extends Controller $karyawan->delete(); - return response()->json([ - 'message' => 'The data has been deleted' - ]); + // return response()->json([ + // 'message' => 'The data has been deleted' + // ]); + + return responder() + ->success(['message' => 'The data has been deleted']) + ->respond(); } } diff --git a/Modules/Karyawaf/Tests/_output/ApiKaryawansCest.deleteData.fail.html b/Modules/Karyawaf/Tests/_output/ApiKaryawansCest.deleteData.fail.html index b6d68a6..9d239a1 100644 --- a/Modules/Karyawaf/Tests/_output/ApiKaryawansCest.deleteData.fail.html +++ b/Modules/Karyawaf/Tests/_output/ApiKaryawansCest.deleteData.fail.html @@ -1,112 +1 @@ - - - - - - - - - - - Laravel - - - - - -
- - -
-
-
-
-
Login
- -
-
- - -
- - -
- - -
-
- -
- - -
- - -
-
- -
-
-
- -
-
-
- -
-
- - - - Forgot Your Password? - -
-
-
-
-
-
-
-
-
- - - - - +{"status":200,"success":true,"data":{"message":"The data has been removed"}} \ No newline at end of file diff --git a/config/app.php b/config/app.php index 53e0706..8df2d6b 100644 --- a/config/app.php +++ b/config/app.php @@ -169,6 +169,7 @@ return [ */ Spatie\Permission\PermissionServiceProvider::class, Nwidart\Modules\LaravelModulesServiceProvider::class, + Flugg\Responder\ResponderServiceProvider::class, /* * Application Service Providers... @@ -227,6 +228,8 @@ return [ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, + 'Responder' => Flugg\Responder\Facades\Responder::class, + 'Transformation' => Flugg\Responder\Facades\Transformation::class, ], diff --git a/config/laravel b/config/laravel new file mode 100644 index 0000000..9e33ba3 --- /dev/null +++ b/config/laravel @@ -0,0 +1,32 @@ +server { + + listen 80; + listen [::]:80; + + server_name laraland.test; + root /var/www/laraland/public; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri /index.php =404; + fastcgi_pass php-upstream; + fastcgi_index index.php; + fastcgi_buffers 16 16k; + fastcgi_buffer_size 32k; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + location ~ /\.ht { + deny all; + } + + location /.well-known/acme-challenge/ { + root /var/www/letsencrypt/; + log_not_found off; + } +} diff --git a/config/nginx-start.sh b/config/nginx-start.sh new file mode 100644 index 0000000..9177a6c --- /dev/null +++ b/config/nginx-start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +cp /opt/etc/nginx.conf /etc/nginx/nginx.conf +sed -i "s/%fpm-ip%/$FPM_PORT_9000_TCP_ADDR/" /etc/nginx/nginx.conf +exec /usr/sbin/nginx diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 0000000..e747e98 --- /dev/null +++ b/config/nginx.conf @@ -0,0 +1,34 @@ +user www-data; +worker_processes 4; +pid /run/nginx.pid; +daemon off; + +events { + worker_connections 2048; + multi_accept on; + use epoll; +} + +http { + server_tokens off; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 15; + types_hash_max_size 2048; + client_max_body_size 20M; + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log /dev/stdout; + error_log /dev/stderr; + gzip on; + gzip_disable "msie6"; + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-available/*.conf; + open_file_cache off; # Disabled for issue 619 + charset UTF-8; +} diff --git a/config/responder.php b/config/responder.php new file mode 100644 index 0000000..73cfd88 --- /dev/null +++ b/config/responder.php @@ -0,0 +1,102 @@ + [ + 'success' => Flugg\Responder\Serializers\SuccessSerializer::class, + 'error' => \Flugg\Responder\Serializers\ErrorSerializer::class, + ], + + /* + |-------------------------------------------------------------------------- + | Response Decorators + |-------------------------------------------------------------------------- + | + | Response decorators are used to decorate both your success- and error + | responses. A decorator can be disabled by removing it from the list + | below. You may additionally add your own decorators to the list. + | + */ + + 'decorators' => [ + \Flugg\Responder\Http\Responses\Decorators\StatusCodeDecorator::class, + \Flugg\Responder\Http\Responses\Decorators\SuccessFlagDecorator::class, + ], + + /* + |-------------------------------------------------------------------------- + | Fallback Transformer + |-------------------------------------------------------------------------- + | + | When transforming data without specifying a transformer we'll instead + | use a fallback transformer specified below. The [ArrayTransformer] + | transformer will simply convert the data to an array untouched. + | + */ + + 'fallback_transformer' => \Flugg\Responder\Transformers\ArrayTransformer::class, + + /* + |-------------------------------------------------------------------------- + | Load Relationships With Query String Parameter + |-------------------------------------------------------------------------- + | + | The package can automatically load relationships from the query string + | and will look for a query string parameter with the name configured + | below. You can set the value to null to disable the autoloading. + | + */ + + 'load_relations_parameter' => 'with', + + /* + |-------------------------------------------------------------------------- + | Filter Fields With Query String Parameter + |-------------------------------------------------------------------------- + | + | The package can automatically filter the fields of transformed data + | from a query string parameter configured below. The technique is + | also known as sparse fieldsets. Set it to null to disable it. + | + */ + + 'filter_fields_parameter' => 'only', + + /* + |-------------------------------------------------------------------------- + | Recursion Limit + |-------------------------------------------------------------------------- + | + | When transforming data, you may be including relations recursively. + | By setting the value below, you can limit the amount of times it + | should include relationships recursively. Five might be good. + | + */ + + 'recursion_limit' => 5, + + /* + |-------------------------------------------------------------------------- + | Error Message Translation Files + |-------------------------------------------------------------------------- + | + | You can declare error messages in a language file, which allows for + | returning messages in different languages. The array below lists + | the language files that will be searched in to find messages. + | + */ + + 'error_message_files' => ['errors'], + +]; \ No newline at end of file diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php new file mode 100644 index 0000000..ed405cd --- /dev/null +++ b/resources/lang/en/errors.php @@ -0,0 +1,22 @@ + 'You are not authenticated for this request.', + 'unauthorized' => 'You are not authorized for this request.', + 'page_not_found' => 'The requested page does not exist.', + 'relation_not_found' => 'The requested relation does not exist.', + 'validation_failed' => 'The given data failed to pass validation.', + +]; \ No newline at end of file