Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/d-alejandro/laravel-code-examples

Clean Architecture, SOLID, PHP 8.2, Laravel 9, RESTful API, Nginx, PostgreSQL 16, MySQL 8, CRUD, DTO, Enum, Docker Compose, Unit tests, Feature tests, SQL, Repository Criteria Pattern, Mocking Objects, Design Patterns, PHPUnit
https://github.com/d-alejandro/laravel-code-examples

clean-architecture clean-code crud decorator dependency-injection design-patterns docker-compose dto enum feature-tests laravel mocking-objects nginx php phpunit postgresql solid sql unit-tests xdebug

Last synced: 5 days ago
JSON representation

Clean Architecture, SOLID, PHP 8.2, Laravel 9, RESTful API, Nginx, PostgreSQL 16, MySQL 8, CRUD, DTO, Enum, Docker Compose, Unit tests, Feature tests, SQL, Repository Criteria Pattern, Mocking Objects, Design Patterns, PHPUnit

Awesome Lists containing this project

README

        

# Laravel Code Examples

## Topics

- Back-end
- Clean Architecture
- Code coverage
- CRUD
- Dependency Injection
- Design Patterns
- Docker Compose
- DTO
- Enums
- Feature tests
- Interfaces
- Laravel 9
- Linux
- Makefile
- Mocking Objects
- MySQL 8
- Nginx
- PHP 8.2
- PHPUnit
- PostgreSQL 16
- Presenters
- Repository Pattern (with criteria queries)
- RESTful API
- SOLID
- SQL
- Unit tests
- Use Cases
- Xdebug

## Installation

1. Clone this repository:
```
git clone [email protected]:d-alejandro/laravel-code-examples.git
```
2. Go to 'laravel-code-examples' directory:
```
cd laravel-code-examples
```
3. Create a new .env file:
```
cp .env.example .env
```
4. Run following commands:

- `docker-compose build --no-cache`
- `docker-compose up -d`
- `docker-compose exec php-fpm composer install`
- `docker-compose exec php-fpm php artisan key:generate`
- `docker-compose exec php-fpm php artisan migrate`
- `docker-compose exec php-fpm php artisan db:seed`

## Testing

To run the unit tests:
```
docker-compose exec php-fpm php artisan test --testsuite=Unit
```

To run the feature tests:
```
docker-compose exec php-fpm php artisan test --testsuite=Feature
```

To run the test coverage:
```
docker-compose exec php-fpm php artisan test --coverage
```
```
docker-compose exec php-fpm ./vendor/bin/phpunit --coverage-html ./storage/reports/coverage
```

## API Endpoints

### All Orders with pagination
- Request URL: `http://localhost:8081/api/orders?start=0&end=2&sort_column=id&sort_type=asc`
- Method: `GET`
- Path: `/orders`
- Headers: `Accept:application/json, Content-Type:application/json`
- Parameters: `start, end, sort_column, sort_type`
- Status Code: `200`
- Response:
```json
{
"data": [
{
"id": 10000001,
"agency_name": "МКК ТверьВектор",
"status": "prepayment",
"is_confirmed": true,
"is_checked": true,
"rental_date": "21-12-2023",
"user_name": "Марат Романович Яковлев",
"transport_count": 3,
"guest_count": 3,
"admin_note": "Ну, душа, вот это так!"
},
{
"id": 10000002,
"agency_name": "ЗАО КазТехРечЛизинг",
"status": "waiting",
"is_confirmed": true,
"is_checked": true,
"rental_date": "27-12-2023",
"user_name": "Сергеева Эльвира Андреевна",
"transport_count": 3,
"guest_count": 3,
"admin_note": null
}
]
}
```

### Create Order
- Request URL: `http://localhost:8081/api/orders`
- Method: `POST`
- Path: `/orders`
- Headers: `Accept:application/json, Content-Type:application/json`
- Parameters: `agency_name, rental_date, guest_count, transport_count, user_name, email, phone`
- Status Code: `201`
- Response:
```json
{
"data": {
"id": 10000011,
"agency_name": "Test Agency Name",
"status": "waiting",
"is_confirmed": false,
"is_checked": false,
"rental_date": "22-12-2023",
"user_name": "Test User Name",
"transport_count": 1,
"guest_count": 1,
"admin_note": null,
"note": null,
"email": "[email protected]",
"phone": "71437854547",
"confirmed_at": null,
"created_at": "21-12-2023 12:22:33",
"updated_at": "21-12-2023 12:22:33"
}
}
```

### Order Details
- Request URL: `http://localhost:8081/api/orders/10000011`
- Method: `GET`
- Path: `/orders/{id}`
- Headers: `Accept:application/json, Content-Type:application/json`
- Status Code: `200`
- Response:
```json
{
"data": {
"id": 10000011,
"agency_name": "Test Agency Name",
"status": "waiting",
"is_confirmed": false,
"is_checked": false,
"rental_date": "22-12-2023",
"user_name": "Test User Name",
"transport_count": 1,
"guest_count": 1,
"admin_note": null,
"note": null,
"email": "[email protected]",
"phone": "71437854547",
"confirmed_at": null,
"created_at": "21-12-2023 12:22:33",
"updated_at": "21-12-2023 12:22:33"
}
}
```

### Update Order
- Request URL: `http://localhost:8081/api/orders/10000011`
- Method: `PUT`
- Path: `/orders/{id}`
- Headers: `Accept:application/json, Content-Type:application/json`
- Parameters: `guest_count, transport_count, user_name, email, phone`
- Status Code: `200`
- Response:
```json
{
"data": {
"id": 10000011,
"agency_name": "Test Agency Name",
"status": "waiting",
"is_confirmed": false,
"is_checked": false,
"rental_date": "22-12-2023",
"user_name": "Test User Name",
"transport_count": 1,
"guest_count": 1,
"admin_note": null,
"note": null,
"email": "[email protected]",
"phone": "70000000001",
"confirmed_at": null,
"created_at": "21-12-2023 12:22:33",
"updated_at": "21-12-2023 15:03:33"
}
}
```

### Delete Order
- Request URL: `http://localhost:8081/api/orders/10000011`
- Method: `DELETE`
- Path: `/orders/{id}`
- Headers: `Accept:application/json, Content-Type:application/json`
- Status Code: `200`
- Response:
```json
{
"data": {
"id": 10000011,
"agency_name": "Test Agency Name",
"status": "waiting",
"is_confirmed": false,
"is_checked": false,
"rental_date": "22-12-2023",
"user_name": "Test User Name",
"transport_count": 1,
"guest_count": 1,
"admin_note": null,
"note": null,
"email": "[email protected]",
"phone": "70000000001",
"confirmed_at": null,
"created_at": "21-12-2023 12:22:33",
"updated_at": "21-12-2023 15:13:30"
}
}
```