Skip to content

Accenture Test Level 2 <> Hiren @Atyantik #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5699dad
Create models
hiren-atyantik Aug 25, 2022
128477b
WIP: RestAPIs
hiren-atyantik Aug 25, 2022
8df0e86
Create REST APIs
hiren-atyantik Aug 25, 2022
c227970
Merge pull request #1 from hiren-atyantik/feature/rest-api
hiren-atyantik Aug 25, 2022
e0f0434
Implement features
hiren-atyantik Aug 25, 2022
b320fd0
Implement Pagination
hiren-atyantik Aug 25, 2022
fcf8a57
Implement Pagination
hiren-atyantik Aug 25, 2022
9991e59
Add Postman Collections
hiren-atyantik Aug 25, 2022
f7b4fa6
Merge pull request #2 from hiren-atyantik/feature/core-functions
hiren-atyantik Aug 25, 2022
08139d8
Merge pull request #3 from hiren-atyantik/feature/core-functions
hiren-atyantik Aug 25, 2022
c1430ae
Added Bonus Feature Cache & Docker Image
hiren-atyantik Aug 25, 2022
3acdd17
Merge pull request #4 from hiren-atyantik/feature/bonus
hiren-atyantik Aug 25, 2022
fb243d0
Write Test
hiren-atyantik Aug 26, 2022
031b0bb
Merge pull request #5 from hiren-atyantik/feature/core-functions
hiren-atyantik Aug 26, 2022
d89f529
Basic Open API features
hiren-atyantik Aug 26, 2022
0e89cbb
Merge pull request #6 from hiren-atyantik/feature/bonus
hiren-atyantik Aug 26, 2022
ceb191b
Added User List API with sanctum authorizaion feature for OpenAPI 3.0
hiren-atyantik Aug 26, 2022
8bbaa32
uncommented middleware for get users
hiren-atyantik Aug 26, 2022
1af2903
Merge pull request #7 from hiren-atyantik/feature/bonus
hiren-atyantik Aug 26, 2022
b3f8ec5
WIP:User Create API Open API 3.0
hiren-atyantik Aug 26, 2022
9efc01d
Merge pull request #8 from hiren-atyantik/feature/bonus
hiren-atyantik Aug 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
49 changes: 49 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:k/nD/nGycrB8CR2Xuu1svePLBI4YT8mBR7TbmZznigI=
APP_DEBUG=false
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

DB_DATABASE=":memory:"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ npm-debug.log
yarn-error.log
/.idea
/.vscode
/storage/debugbar
81 changes: 81 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
FROM php:8.0-fpm

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
libmemcached-dev \
wget \
libonig-dev \
libzip-dev \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
unzip \
git \
curl \
lua-zlib-dev \
libmemcached-dev \
nginx \
redis-server

# Install php extensions
RUN docker-php-ext-install mbstring pdo_mysql zip exif pcntl gd

# Install Memcached
RUN mkdir -p /usr/src/php/ext/memcached
WORKDIR /usr/src/php/ext/memcached
RUN wget https://github.com/php-memcached-dev/php-memcached/archive/v3.2.0.zip; unzip /usr/src/php/ext/memcached/v3.2.0.zip
RUN mv /usr/src/php/ext/memcached/php-memcached-3.2.0/* /usr/src/php/ext/memcached/
RUN docker-php-ext-configure memcached && docker-php-ext-install memcached
# reset working dir
WORKDIR /var/www


RUN mkdir -p /usr/src/php/ext/redis
WORKDIR /usr/src/php/ext/redis
RUN curl -fsSL https://pecl.php.net/get/redis --ipv4 | tar xvz -C "/usr/src/php/ext/redis" --strip 1;
RUN docker-php-ext-configure redis && docker-php-ext-install redis
# reset working dir
WORKDIR /var/www


# Install supervisor
RUN apt-get install -y supervisor

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy code to /var/www
COPY --chown=www:www-data . /var/www

# add root to www group
RUN chmod -R ug+w /var/www/storage

# Copy nginx/php/supervisor configs
RUN cp docker/supervisor.conf /etc/supervisord.conf
RUN cp docker/php.ini /usr/local/etc/php/conf.d/app.ini
RUN cp docker/nginx.conf /etc/nginx/sites-enabled/default

# PHP Error Log Files
RUN mkdir /var/log/php
RUN touch /var/log/php/errors.log && chmod 777 /var/log/php/errors.log

# Deployment steps
RUN composer install --optimize-autoloader --no-dev
RUN chmod +x /var/www/docker/run.sh

EXPOSE 80
ENTRYPOINT ["/var/www/docker/run.sh"]
83 changes: 83 additions & 0 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
FROM php:8.0-fpm

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
libmemcached-dev \
wget \
libonig-dev \
libzip-dev \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
unzip \
git \
curl \
lua-zlib-dev \
libmemcached-dev \
nginx \
redis-server

# Install php extensions
RUN docker-php-ext-install mbstring pdo_mysql zip exif pcntl gd

# Install Memcached
RUN mkdir -p /usr/src/php/ext/memcached
WORKDIR /usr/src/php/ext/memcached
RUN wget https://github.com/php-memcached-dev/php-memcached/archive/v3.2.0.zip; unzip /usr/src/php/ext/memcached/v3.2.0.zip
RUN mv /usr/src/php/ext/memcached/php-memcached-3.2.0/* /usr/src/php/ext/memcached/
RUN docker-php-ext-configure memcached && docker-php-ext-install memcached
# reset working dir
WORKDIR /var/www


RUN mkdir -p /usr/src/php/ext/redis
WORKDIR /usr/src/php/ext/redis
RUN curl -fsSL https://pecl.php.net/get/redis --ipv4 | tar xvz -C "/usr/src/php/ext/redis" --strip 1;
RUN docker-php-ext-configure redis && docker-php-ext-install redis
# reset working dir
WORKDIR /var/www


# Install supervisor
RUN apt-get install -y supervisor

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy code to /var/www
COPY --chown=www:www-data . /var/www

# add root to www group
RUN chmod -R ug+w /var/www/storage

VOLUME . /var/www

# Copy nginx/php/supervisor configs
RUN cp docker/supervisor.conf /etc/supervisord.conf
RUN cp docker/php.ini /usr/local/etc/php/conf.d/app.ini
RUN cp docker/nginx.conf /etc/nginx/sites-enabled/default

# PHP Error Log Files
RUN mkdir /var/log/php
RUN touch /var/log/php/errors.log && chmod 777 /var/log/php/errors.log

# Deployment steps
RUN composer install --optimize-autoloader --no-dev
RUN chmod +x /var/www/docker/run.sh

EXPOSE 80
ENTRYPOINT ["/var/www/docker/run.sh"]
69 changes: 59 additions & 10 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<?php


namespace App\Exceptions;

use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<Throwable>>
* @var array
*/
protected $dontReport = [
//
Expand All @@ -19,23 +26,65 @@ class Handler extends ExceptionHandler
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array<int, string>
* @var array
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Register the exception handling callbacks for the application.
* Report or log an exception.
*
* @param Exception $exception
* @return void
*/
public function register()
public function report(Throwable $exception)
{
if (app()->bound('sentry') && $this->shouldReport($exception)) {
app('sentry')->captureException($exception);
}
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param Request $request
* @param Exception $exception
* @return Response
*/
public function render($request, Throwable $exception)
{
if ($exception instanceof UnauthorizedException) {
return response()->json(["message" => $exception->getMessage()], 403);
} elseif ($exception instanceof ModelNotFoundException) {
return response()->json(['message' => 'Respected model not found'], 422);
} elseif ($exception instanceof NotFoundHttpException) {
return response()->json(['message' => $exception->getMessage()], 404);
} elseif ($request->expectsJson() && $exception instanceof HttpException && $exception->getStatusCode()===503) {
return response()->json(['message' => $exception->getMessage()], 503);
}

return parent::render($request, $exception);
}

/**
* Convert a validation exception into a JSON response.
*
* @param Request $request
* @param ValidationException $exception
* @return JsonResponse
*/
protected function invalidJson($request, ValidationException $exception)
{
return response()->json($exception->errors(), $exception->status);
}
protected function convertValidationExceptionToResponse(ValidationException $e, $request)
{
$this->reportable(function (Throwable $e) {
//
});
if ($e->response) {
return $e->response;
}
return $this->invalidJson($request, $e);
}
}
}
Loading