-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oscar Cabrera
committed
Jun 11, 2024
1 parent
0e6b108
commit 7ef4469
Showing
11 changed files
with
272 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters