app.services.base_service module

class app.services.base_service.BaseService(repository)[source]

Bases: object

Async base service class providing common CRUD operations on top of an async repository.

async get_list(schema)[source]

Return a filtered, paginated list of entities.

Parameters:

schema – Search schema with filters and ordering/pagination.

Returns:

dict[str, Any] – Items plus search metadata, as returned by the repository.

Return type:

dict[str, Any]

async get_by_id(id)[source]

Fetch a single entity by primary key.

Parameters:

id (UUID) – Primary key of the entity.

Returns:

Any – The matching entity.

Return type:

Any

async add(schema)[source]

Create a new entity from schema.

Parameters:

schema – Pydantic schema describing the entity to create.

Returns:

Any – The persisted entity.

Return type:

Any

async patch(id, schema)[source]

Partially update an entity, ignoring null fields.

Parameters:
  • id (UUID) – Primary key of the entity to update.

  • schema – Schema whose non-null fields are applied.

Returns:

Any – The updated entity.

Return type:

Any

async patch_attr(id, attr, value)[source]

Update a single attribute of an entity.

Parameters:
  • id (UUID) – Primary key of the entity.

  • attr (str) – Name of the attribute to set.

  • value – New value for the attribute.

Returns:

Any – The updated entity.

Return type:

Any

async put_update(id, schema)[source]

Fully replace an entity’s fields from schema.

Parameters:
  • id (UUID) – Primary key of the entity to replace.

  • schema – Schema dumped in full into the update.

Returns:

Any – The updated entity.

Return type:

Any

async remove_by_id(id)[source]

Delete an entity by primary key.

Parameters:

id (UUID) – Primary key of the entity to delete.

Return type:

None