Skip to content

Commit

Permalink
Merge pull request #5 from maurobonfietti/0.7.0
Browse files Browse the repository at this point in the history
Version 0.7.0
  • Loading branch information
maurobonfietti committed Mar 3, 2020
2 parents 7874b2c + 5d0e339 commit 74ed098
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 45 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ Furthermore, the script make a file with PHPUnit tests, for each new endpoint ge

```bash
$ ./console api:generate:endpoints [table-name]
Starting!
Generate Endpoints For New Entity: [table-name]
Finish ;-)
OK - Generated endpoints for entity: [table-name]
```

**This package is for exclusive use of this [Slim 4 - Api Skeleton](https://github.com/maurobonfietti/slim4-api-skeleton).**
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CrudGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class CrudGeneratorCommand extends Command
{
const COMMAND_VERSION = '0.6.0';
const COMMAND_VERSION = '0.7.0';

public function __construct($app)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Command/CrudGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function getRepositoryFunctions()
$fields3 = substr_replace($this->list3, '', -2);
$fields4 = substr_replace($this->list4, '', -2);
$fields5 = substr_replace($this->list5, '', -9);
$this->postParams = substr_replace($this->list6, '', -3);
$this->postParams = substr_replace($this->list6, '', -14);
$this->getBaseInsertQueryFunction($fields1, $fields2, $fields3);
$this->getBaseUpdateQueryFunction($fields3, $fields4, $fields5);
}
Expand All @@ -76,11 +76,11 @@ private function getFieldsList($field)
$this->list5.= sprintf(" %s", '');
if ($field['Null'] == "NO" && strpos($field['Type'], 'varchar') !== false) {
$this->list6.= sprintf("'%s' => '%s',%s", $field['Field'], 'aaa', PHP_EOL);
$this->list6.= sprintf("%'\t2s", '');
$this->list6.= sprintf(" %s", '');
}
if ($field['Null'] == "NO" && strpos($field['Type'], 'int') !== false) {
$this->list6.= sprintf("'%s' => %s,%s", $field['Field'], 1, PHP_EOL);
$this->list6.= sprintf("%'\t2s", '');
$this->list6.= sprintf(" %s", '');
}
}
}
Expand All @@ -93,7 +93,7 @@ private function getBaseInsertQueryFunction($fields1, $fields2, $fields3)
'.$fields3.'
$statement->execute();
return $this->checkAndGet'.$this->entityUpper.'((int) $this->getDb()->lastInsertId());';
return $this->checkAndGet((int) $this->getDb()->lastInsertId());';
// End Mock Code...
}

Expand All @@ -107,7 +107,7 @@ private function getBaseUpdateQueryFunction($fields3, $fields4, $fields5)
'.$fields3.'
$statement->execute();
return $this->checkAndGet'.$this->entityUpper.'((int) $'.$this->entity.'->id);';
return $this->checkAndGet((int) $'.$this->entity.'->id);';
// End Mock Code...
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/TemplateBase/Objectbase/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Create extends Base
public function __invoke($request, $response)
{
$input = $request->getParsedBody();
$objectbase = $this->getObjectbaseService()->createObjectbase($input);
$objectbase = $this->getObjectbaseService()->create($input);

$payload = json_encode($objectbase);
$response->getBody()->write($payload);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/TemplateBase/Objectbase/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Delete extends Base
{
public function __invoke($request, $response, array $args)
{
$this->getObjectbaseService()->deleteObjectbase((int) $args['id']);
$this->getObjectbaseService()->delete((int) $args['id']);

return $response->withHeader('Content-Type', 'application/json')->withStatus(204);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/TemplateBase/Objectbase/GetAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GetAll extends Base
{
public function __invoke($request, $response)
{
$objectbases = $this->getObjectbaseService()->getAllObjectbase();
$objectbases = $this->getObjectbaseService()->getAll();

$payload = json_encode($objectbases);
$response->getBody()->write($payload);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/TemplateBase/Objectbase/GetOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GetOne extends Base
{
public function __invoke($request, $response, array $args)
{
$objectbase = $this->getObjectbaseService()->getObjectbase((int) $args['id']);
$objectbase = $this->getObjectbaseService()->getOne((int) $args['id']);

$payload = json_encode($objectbase);
$response->getBody()->write($payload);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/TemplateBase/Objectbase/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Update extends Base
public function __invoke($request, $response, array $args)
{
$input = $request->getParsedBody();
$objectbase = $this->getObjectbaseService()->updateObjectbase($input, (int) $args['id']);
$objectbase = $this->getObjectbaseService()->update($input, (int) $args['id']);

$payload = json_encode($objectbase);
$response->getBody()->write($payload);
Expand Down
10 changes: 5 additions & 5 deletions src/Command/TemplateBase/ObjectbaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(\PDO $database)
$this->database = $database;
}

public function checkAndGetObjectbase(int $objectbaseId)
public function checkAndGet(int $objectbaseId)
{
$query = 'SELECT * FROM `objectbase` WHERE `id` = :id';
$statement = $this->getDb()->prepare($query);
Expand All @@ -27,7 +27,7 @@ public function checkAndGetObjectbase(int $objectbaseId)
return $objectbase;
}

public function getAllObjectbase(): array
public function getAll(): array
{
$query = 'SELECT * FROM `objectbase` ORDER BY `id`';
$statement = $this->getDb()->prepare($query);
Expand All @@ -36,17 +36,17 @@ public function getAllObjectbase(): array
return $statement->fetchAll();
}

public function createObjectbase($objectbase)
public function create($objectbase)
{
#createFunction
}

public function updateObjectbase($objectbase, $data)
public function update($objectbase, $data)
{
#updateFunction
}

public function deleteObjectbase(int $objectbaseId)
public function delete(int $objectbaseId)
{
$query = 'DELETE FROM `objectbase` WHERE `id` = :id';
$statement = $this->getDb()->prepare($query);
Expand Down
28 changes: 14 additions & 14 deletions src/Command/TemplateBase/ObjectbaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@ public function __construct(ObjectbaseRepository $objectbaseRepository)
$this->objectbaseRepository = $objectbaseRepository;
}

protected function checkAndGetObjectbase(int $objectbaseId)
protected function checkAndGet(int $objectbaseId)
{
return $this->objectbaseRepository->checkAndGetObjectbase($objectbaseId);
return $this->objectbaseRepository->checkAndGet($objectbaseId);
}

public function getAllObjectbase(): array
public function getAll(): array
{
return $this->objectbaseRepository->getAllObjectbase();
return $this->objectbaseRepository->getAll();
}

public function getObjectbase(int $objectbaseId)
public function getOne(int $objectbaseId)
{
return $this->checkAndGetObjectbase($objectbaseId);
return $this->checkAndGet($objectbaseId);
}

public function createObjectbase($input)
public function create($input)
{
$objectbase = json_decode(json_encode($input), false);

return $this->objectbaseRepository->createObjectbase($objectbase);
return $this->objectbaseRepository->create($objectbase);
}

public function updateObjectbase(array $input, int $objectbaseId)
public function update(array $input, int $objectbaseId)
{
$objectbase = $this->checkAndGetObjectbase($objectbaseId);
$objectbase = $this->checkAndGet($objectbaseId);
$data = json_decode(json_encode($input), false);

return $this->objectbaseRepository->updateObjectbase($objectbase, $data);
return $this->objectbaseRepository->update($objectbase, $data);
}

public function deleteObjectbase(int $objectbaseId)
public function delete(int $objectbaseId)
{
$this->checkAndGetObjectbase($objectbaseId);
$this->objectbaseRepository->deleteObjectbase($objectbaseId);
$this->checkAndGet($objectbaseId);
$this->objectbaseRepository->delete($objectbaseId);
}
}
24 changes: 12 additions & 12 deletions src/Command/TemplateBase/ObjectbaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class ObjectbaseTest extends TestCase
{
private static $id;

public function testCreateObjectbase()
public function testCreate()
{
$params = [
'' => '',
#postParams
'' => '',
#postParams
];
$app = $this->getAppInstance();
$request = $this->createRequest('POST', '/objectbase');
$request = $request->withParsedBody($params);
$req = $this->createRequest('POST', '/objectbase');
$request = $req->withParsedBody($params);
$response = $app->handle($request);

$result = (string) $response->getBody();
Expand All @@ -28,7 +28,7 @@ public function testCreateObjectbase()
$this->assertStringNotContainsString('error', $result);
}

public function testGetObjectbases()
public function testGetAll()
{
$app = $this->getAppInstance();
$request = $this->createRequest('GET', '/objectbase');
Expand All @@ -41,7 +41,7 @@ public function testGetObjectbases()
$this->assertStringNotContainsString('error', $result);
}

public function testGetObjectbase()
public function testGetOne()
{
$app = $this->getAppInstance();
$request = $this->createRequest('GET', '/objectbase/' . self::$id);
Expand All @@ -54,7 +54,7 @@ public function testGetObjectbase()
$this->assertStringNotContainsString('error', $result);
}

public function testGetObjectbaseNotFound()
public function testGetOneNotFound()
{
$app = $this->getAppInstance();
$request = $this->createRequest('GET', '/objectbase/123456789');
Expand All @@ -66,11 +66,11 @@ public function testGetObjectbaseNotFound()
$this->assertStringContainsString('error', $result);
}

public function testUpdateObjectbase()
public function testUpdate()
{
$app = $this->getAppInstance();
$request = $this->createRequest('PUT', '/objectbase/' . self::$id);
$request = $request->withParsedBody(['' => '']);
$req = $this->createRequest('PUT', '/objectbase/' . self::$id);
$request = $req->withParsedBody(['' => '']);
$response = $app->handle($request);

$result = (string) $response->getBody();
Expand All @@ -80,7 +80,7 @@ public function testUpdateObjectbase()
$this->assertStringNotContainsString('error', $result);
}

public function testDeleteObjectbase()
public function testDelete()
{
$app = $this->getAppInstance();
$request = $this->createRequest('DELETE', '/objectbase/' . self::$id);
Expand Down

0 comments on commit 74ed098

Please sign in to comment.