Skip to content

Commit

Permalink
v2.0.1 restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Cabrera committed Jun 11, 2024
1 parent 0e6b108 commit 7ef4469
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 3 deletions.
14 changes: 14 additions & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ export default {
{ text: "Usage", link: "/custom-exception/usage" },
],
},
{
text: 'Interfaces',
items: [
{ text: 'Introduction', link: '/repository-interfaces/Introduction' },
{ text: 'IRepositoryResource', link: '/repository-interfaces/IRepositoryResource' },
{ text: 'ICreateModel', link: '/repository-interfaces/ICreateModel' },
{ text: 'IReadModel', link: '/repository-interfaces/IReadModel' },
{ text: 'IUpdateModel', link: '/repository-interfaces/IUpdateModel' },
{ text: 'IDeleteModel', link: '/repository-interfaces/IDeleteModel' },
{ text: 'IListModel', link: '/repository-interfaces/IListModel' },
{ text: 'IEntitySearch', link: '/repository-interfaces/IEntitySearch' },
{ text: 'IEntityCount', link: '/repository-interfaces/IEntityCount' },
]
},
{
text: "Code Quality",
items: [
Expand Down
29 changes: 29 additions & 0 deletions docs/repository-interfaces/ICreateModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ICreateModel

The `ICreateModel` interface defines the methods necessary for model creation.

## Code
```php
<?php

namespace Oscabrera\ModelRepository\Contracts\Resources;

use Illuminate\Database\Eloquent\Model;

/**
* Interface IEntityCreate
*
* This interface defines the contract for creating a new record in the database.
*/
interface ICreateModel
{
/**
* Create a new record in the database.
*
* @param array<string, mixed> $entity The object to be created.
*
* @return Model The created object.
*/
public function create(array $entity): Model;
}
```
29 changes: 29 additions & 0 deletions docs/repository-interfaces/IDeleteModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# IDeleteModel

The `IDeleteModel` interface defines the methods necessary for deleting models.

## Code
```php
<?php

namespace Oscabrera\ModelRepository\Contracts\Resources;

use Illuminate\Database\Eloquent\Model;

/**
* Interface IEntityDelete
*
* Defines the methods that a service class must implement to perform delete operations on entities.
*/
interface IDeleteModel
{
/**
* Deletes a record from the database based on the given ID.
*
* @param Model $entity
*
* @return bool True if the record is successfully deleted, false otherwise.
*/
public function delete(Model $entity): bool;
}
```
29 changes: 29 additions & 0 deletions docs/repository-interfaces/IEntityCount.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# IEntityCount

This interface defines the contract for counting the number of records in the database that match certain conditions.

## Code

```php
<?php

use Oscabrera\QueryFilters\Utilities\QueryFilters;

/**
* Interface IEntityCount
*
* This interface defines the contract for counting the number of records in the database that match certain conditions.
*/
interface IEntityCount
{
/**
* Counts the number of records in the database that match the given conditions.
*
* @param QueryFilters $options
* An associative array of conditions to match the records against.
*
* @return int The number of records that match the conditions.
*/
public function count(QueryFilters $options): int;
}
```
30 changes: 30 additions & 0 deletions docs/repository-interfaces/IEntitySearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# IEntitySearch

This interface defines the contract for searching entities in a database, use QueryFilters to filter records.

## Code

```php
<?php

use Illuminate\Database\Eloquent\Model;
use Oscabrera\QueryFilters\Utilities\QueryFilters;

/**
* Interface IEntitySearch
*
* Defines a contract for searching entities in a database.
*/
interface IEntitySearch
{
/**
* Finds a single record from the database that matches the given conditions.
*
* @param QueryFilters $options
* An associative array of conditions to match the record against.
*
* @return Model The fetched record if found.
*/
public function search(QueryFilters $options): Model;
}
```
30 changes: 30 additions & 0 deletions docs/repository-interfaces/IListModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# IListModel

The `IListModel` interface defines the methods needed to list models.

## Code
```php
<?php

namespace Oscabrera\ModelRepository\Contracts\Resources;

use Illuminate\Pagination\LengthAwarePaginator;
use Oscabrera\QueryFilters\Utilities\QueryFilters;

/**
* Interface IEntityList
*
* Defines the contract for classes that implement list functionality for entities.
*/
interface IListModel
{
/**
* Lists records from the database based on the given conditions.
*
* @param QueryFilters $options
*
* @return LengthAwarePaginator An array of records that match the conditions.
*/
public function list(QueryFilters $options): LengthAwarePaginator;
}
```
29 changes: 29 additions & 0 deletions docs/repository-interfaces/IReadModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ICreateModel

The `ICreateModel` interface defines the methods necessary for model creation.

## Code
```php
<?php

namespace Oscabrera\ModelRepository\Contracts\Resources;

use Illuminate\Database\Eloquent\Model;

/**
* Interface IEntityRead
*
* This interface defines a method for reading a record from the database based on the given ID.
*/
interface IReadModel
{
/**
* Reads a record from the database based on the given ID.
*
* @param string $id The ID of the record to be fetched.
*
* @return Model The fetched record.
*/
public function read(string $id): Model;
}
```
35 changes: 35 additions & 0 deletions docs/repository-interfaces/IRepositoryResource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# IRepositoryResource

The `IRepositoryResource` interface provides an abstraction for basic CRUD operations and model enumeration. Several
interfaces are exposed to help manage the repositories:

- [ICreateModel](./ICreateModel.md): For creating models.
- [IReadModel](./IReadModel.md): For reading models.
- [IUpdateModel](./IUpdateModel.md): For updating models.
- [IDeleteModel](./IDeleteModel.md): For deleting models.
- [IListModel](./IListModel.md): To list models.

## Code

```php
<?php

namespace Oscabrera\ModelRepository\Contracts\Resources;

/**
* Interface IEntityResource
*
* Defines the contract for an entity resource.
* the methods for a resource are: create, read, update, delete and list.
*
* This class does not contain additional methods to extended interfaces.
*/
interface IRepositoryResource extends
ICreateModel,
IReadModel,
IUpdateModel,
IDeleteModel,
IListModel
{
}
```
30 changes: 30 additions & 0 deletions docs/repository-interfaces/IUpdateModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# IUpdateModel

The `IUpdateModel` interface defines the methods necessary for updating models.

## Code
```php
<?php

namespace Oscabrera\ModelRepository\Contracts\Resources;

use Illuminate\Database\Eloquent\Model;

/**
* Interface IEntityUpdate
*
* Defines the contract for updating a record in the database.
*/
interface IUpdateModel
{
/**
* Updates the given record in the database.
*
* @param Model $entity The record to be updated.
* @param array<string, mixed> $dataEntity
*
* @return bool True if the record was successfully updated, false otherwise.
*/
public function update(Model $entity, array $dataEntity): bool;
}
```
15 changes: 15 additions & 0 deletions docs/repository-interfaces/Introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Interfaces for Repository

This documentation covers the main interfaces used in the project, providing details on their methods and how to use
them.

## Content

- [IRepositoryResource](./IRepositoryResource.md)
- [ICreateModel](./ICreateModel.md)
- [IReadModel](./IReadModel.md)
- [IUpdateModel](./IUpdateModel.md)
- [IDeleteModel](./IDeleteModel.md)
- [IListModel](./IListModel.md)
- [IEntitySearch](./IEntitySearch.md)
- [IEntityCount](./IEntityCount.md)
5 changes: 2 additions & 3 deletions docs/usage/Install.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ DummyModel: Denotes the name of your model for which the API will be created.
- **`--migration, -m`**: Creates a migration file to define the database schema for your model.
- **`--factory, -f`**: Generates a factory class to generate dummy data for your model.
- **`--service, -s`**: Generates a service class to encapsulate business logic related to your model operations.
- **`--controller, -c`**: Creates a controller class that handles incoming API requests and interacts with the service layer.
- **`--controller, -c`**: Creates a controller class that handles incoming API requests and interacts with the service
layer.
- **`--request, -r`**: Generates request classes for validation and data formatting during API interactions.
- **`--collection, -col`**: Generates a collection class that assists in transforming model collections into a standardized
format for API responses.
- **`--all`**: Creates all structure for working with the Repository.
- **`--force`**: Overwrites existing files if they already exist.

Expand Down

0 comments on commit 7ef4469

Please sign in to comment.