https://github.com/fey/digital-spectr-academy
https://github.com/fey/digital-spectr-academy
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/fey/digital-spectr-academy
- Owner: fey
- Created: 2023-02-03T23:58:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-28T09:20:26.000Z (almost 3 years ago)
- Last Synced: 2025-02-01T01:51:41.098Z (over 1 year ago)
- Language: PHP
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#
[](https://github.com/fey/digital-spectr-academy/actions/workflows/main.yml)
## Commands
```bash
make install # install deps
make test # run tests
make lint # run linter
make start # start server for Shapes api
```
## Shapes api
Install and start server (see commands above)
Endpoint `POST localhost:8000/shapes/calculate`
params:
* shape - `triangle`, `circle`, `square`
* method: - `perimeter`, `area`
* params (depends on shape type):
* Square: `side`
* Triangle: `sideA`, `sideB`, `sideC`
* Circle: `radius`
Examples:
Calculate Triangle perimeter:
```bash
curl -X POST \
'localhost:8000/shapes/calculate' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"shape": "triangle",
"method": "perimeter",
"params": {
"sideA": 3,
"sideB": 5,
"sideC": 7
}
}'
```
Response:
```json
{
"data": {
"method": "perimeter",
"shape": "triangle",
"result": 15
}
}
```
Square area:
```bash
curl -X POST \
'localhost:8000/shapes/calculate' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"shape": "square",
"method": "area",
"params": {
"side": 5
}
}'
```
Response:
```json
{
"data": {
"method": "area",
"shape": "square",
"result": 25
}
}
```
Circle area:
```bash
curl -X POST \
'localhost:8000/shapes/calculate' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"shape": "circle",
"method": "area",
"params": {
"radius": 5
}
}'
```
Response:
```json
{
"data": {
"method": "area",
"shape": "circle",
"result": 78.53981633974483
}
}
```
### Validation
Works with float values
```bash
curl -X POST \
'localhost:8000/shapes/calculate' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"shape": "square",
"method": "area",
"params": {
"side": 5.0
}
}'
```
Response:
```json
{
"data": {
"method": "area",
"shape": "square",
"result": 25
}
}
```
Validation errors:
```json
{
"message": "side should be integer or float"
}
```
```json
{
"message": "side is required"
}
```
```json
{
"message": "round is invalid method, valid methods: perimeter, area"
}
```
```json
{
"message": "round is invalid shape type, valid types: triangle, circle, square"
}
```