service

package
v0.0.0-...-b319b81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptions

func ApplyOptions(db *gorm.DB, options *types.ServiceOptions) (tx *gorm.DB)

ApplyOptions applies pagination, sorting, and filtering options to a GORM database query. It returns a modified gorm.DB instance with the applied options.

Types

type CRUD

type CRUD[T any] struct {
	CreateFn[T]
	ReadFn[T]
	ListFn[T]
	UpdateFn[T]
	DeleteFn[T]
}

CRUD is a generic struct that combines all CRUD operations. It embeds CreateFn, ReadFn, ListFn, UpdateFn, and DeleteFn to provide a complete set of handlers.

type CreateFn

type CreateFn[T any] struct{}

CreateFn is a generic struct that implements the types.ServiceCreator interface.

func (*CreateFn[T]) Create

func (r *CreateFn[T]) Create(resource types.Resource[T], _ *types.ServiceOptions, entity *T) (createdEntity *T, err error)

Create is a method of CreateFn that handles the creation of a resource. It interacts with a repository (e.g. a database) to persist the entity and returns the created entity and any error encountered.

type DeleteFn

type DeleteFn[T any] struct{}

DeleteFn is a generic struct that implements the types.ServiceDeleter interface.

func (*DeleteFn[T]) Delete

func (r *DeleteFn[T]) Delete(resource types.Resource[T], _ *types.ServiceOptions, id string) error

Delete is a method of DeleteFn that handles the deletion of a resource. It interacts with a repository (e.g. a database) to delete the entity by its ID and returns any error encountered.

type ListFn

type ListFn[T any] struct{}

ListFn is a generic struct that implements the types.ServiceLister interface.

func (*ListFn[T]) List

func (r *ListFn[T]) List(resource types.Resource[T], options *types.ServiceOptions) (entities *[]T, meta *types.ServiceMeta, err error)

List is a method of ListFn that handles the listing of resources. It interacts with a repository (e.g. a database) to retrieve entities based on the provided options and returns the entities, metadata, and any error encountered.

type ReadFn

type ReadFn[T any] struct{}

ReadFn is a generic struct that implements the types.ServiceReader interface.

func (*ReadFn[T]) Read

func (r *ReadFn[T]) Read(resource types.Resource[T], _ *types.ServiceOptions, id string) (entity *T, err error)

Read is a method of ReadFn that handles the retrieval of a resource. It interacts with a repository (e.g. a database) to fetch the entity by its ID and returns the entity and any error encountered.

type UpdateFn

type UpdateFn[T any] struct{}

UpdateFn is a generic struct that implements the types.ServiceUpdater interface.

func (*UpdateFn[T]) Update

func (r *UpdateFn[T]) Update(resource types.Resource[T], options *types.ServiceOptions, id string, entity *T) (updatedEntity *T, err error)

Update is a method of UpdateFn that handles the updating of a resource. It interacts with a repository (e.g. a database) to update the entity either partially or fully based on the provided flag and returns the updated entity and any error encountered.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL