Skip to content

Commit

Permalink
Merge pull request #18 from AmrAhmedFekry/master
Browse files Browse the repository at this point in the history
Add auto generated postman and markdown files
  • Loading branch information
hassanzohdy committed Sep 20, 2019
2 parents 92ec383 + 57e03a1 commit 71fbc07
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 6 deletions.
67 changes: 67 additions & 0 deletions module/docs/module-docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# moduleName API DOCS

# Base URL
BaseUrl

# Headers

Authorization: key your token

Accept : application/json

# API

| Route | Request Method | Parameters | Response |
| ----------- | ----------- |----------- |---------- |
| /api/admin/routeName | POST | [Create Parmaters](#Create)|[Response](#Response)|
| /api/admin/routeName | GET |-| [Response](#Response) |
|/api/admin/routeName/{id} | GET | - | [Response](#Response) |
|/api/admin/routeName/{id} |PUT | [Update Parmaters](#Update)|[Response](#Response) |
|/api/admin/routeName/{id} |DELETE | -|[Response](#Response)|
|/api/routeName |GET |-| [Response](#Response)|
|/api/routeName/{id} |GET |-|[Response](#Response)|


# <a name="Create"> </a> Create new moduleName

```json
data
```

# <a name="Update"> </a> Update moduleName

```json
data
```
# <a name="Response"> </a> Responses

## Unauthorized error

__*Response code : 401*__
```json
{
"message" : "Unauthenticated"
}
```

## Validation error
__*Response code : 422*__

```json
{
"errors" {
"Key" : "Error message"
}
}
```
## Success
__*Response code : 200*__
```json
{
"records" [
{

},
]
}
```
227 changes: 227 additions & 0 deletions module/docs/module.postman.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
{
"info": {
"_postman_id": "0402fe17-e481-4c12-a34e-569e61795aba",
"name": "{moduleName} Postman",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Create {moduleName} ",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
},
{
"key": "Authorization",
"value": "Bearer Token",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": "{formData}"
},
"url": {
"raw": "{baseUrl}/api/admin/{routeUri}",
"protocol":"{protocol}",
"host":"{host}",
"path": [
"api",
"admin"
]
}
},
"response": []
},
{
"name": "Update {moduleName}",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
},
{
"key": "Authorization",
"type": "text",
"value": "Bearer Token"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": "{formData}"
},
"url": {
"raw": "{baseUrl}/api/admin/{routeUri}/{id}",
"protocol":"{protocol}",
"host":"{host}",
"path": [
"api",
"admin",
"{id}"
]
}
},
"response": []
},
{
"name": "Listing of {moduleName}",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
},
{
"key": "Authorization",
"value": "Bearer Token",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": []
},
"url": {
"raw": "{baseUrl}/api/admin/{moduleName}",
"protocol":"{protocol}",
"host":"{host}",
"path": [
"api",
"admin"
]
}
},
"response": []
},
{
"name": "Get single of {moduleName} ",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer Token",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"url": {
"raw": "{baseUrl}/api/admin/{routeUri}/{id}",
"protocol":"{protocol}",
"host":"{host}",
"path": [
"api",
"admin",
"{id}"
]
}
},
"response": []
},
{
"name": "Delete {moduleName} record",
"request": {
"method": "DELETE",
"header": [
{
"key": "Authorization",
"value": "Bearer Token",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"url": {
"raw": "{baseUrl}/api/admin/{routeUri}/{id}",
"protocol":"{protocol}",
"host":"{host}",
"path": [
"api",
"admin",
"{id}"
]
}
},
"response": []
},
{
"name": "Show single record of {moduleName} in front",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
},
{
"key": "Authorization",
"value": "Bearer Token",
"type": "text"
}
],
"url": {
"raw": "{baseUrl}/api/{routeUri}/{id}",
"protocol":"{protocol}",
"host":"{host}",
"path": [
"api",
"{id}"
]
}
},
"response": []
},
{
"name": "Show list {moduleName} in front",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
},
{
"key": "Authorization",
"value": "Bearer Token",
"type": "text"
}
],
"url": {
"raw": "{baseUrl}/api/{routeUri}",
"protocol":"{protocol}",
"host":"{host}",
"path": [
"api"
]
}
},
"response": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public function validateArguments()
*/
public function init()
{
// $this->root = Mongez::packagePath();

$this->info['controllerName'] = Str::studly($this->argument('controller'));
$this->info['moduleName'] = Str::studly($this->option('module'));
$this->info['type'] = $this->argument('type');
Expand Down
36 changes: 34 additions & 2 deletions src/HZ/Illuminate/Organizer/Console/Commands/EngezModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class EngezModel extends Command implements EngezInterface
*
* @var string
*/
protected $signature = 'engez:model {model} {--module=}';
protected $signature = 'engez:model {model} {--module=} {--data=}';

/**
* The console command description.
Expand Down Expand Up @@ -49,6 +49,11 @@ public function handle()
$this->init();
$this->validateArguments();
$this->create();

if ($this->databaseName == 'mongodb' && $this->option('data')) {
$this->createSchema();
}

$this->info('Model created successfully');
}

Expand Down Expand Up @@ -126,6 +131,33 @@ public function create()
$this->info['modelPath'] = $modelPath . '\\' . $modelName;
// create the file
$this->createFile("$modelDirectory/{$modelName}.php", $content, 'Model');
}

/**
* Create schema of table in mongo
*
* @param string $dataFileName
* @return void
*/
protected function createSchema()
{
$defaultContent = [
'_id' => "objectId",
'id'=>'int',
];

$databaseFileName = strtolower(str::plural($this->info['moduleName']));

$path = $this->modulePath("database/migrations");

$customData = explode(',', $this->option('data')) ?? [];

unset($customData['id'], $customData['_id']);

$customData = array_fill_keys($customData, 'string');

$content = array_merge($defaultContent, $customData);

}
$this->createFile("$path/{$databaseFileName}.json", json_encode($content, JSON_PRETTY_PRINT), 'Schema');
}
}
Loading

0 comments on commit 71fbc07

Please sign in to comment.