go4rest

package module
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

controllers/generic/controller.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyFilters

func ApplyFilters(db *gorm.DB, filters []FilterOptions) *gorm.DB

func ApplySorting added in v0.1.10

func ApplySorting(db *gorm.DB, sorts []SortOptions) *gorm.DB

func RegisterCRUDRoutes added in v0.1.14

func RegisterCRUDRoutes(r *gin.Engine, path string, controller Crudable) *gin.RouterGroup

func ToSnakeCase added in v0.1.12

func ToSnakeCase(str string) string

Types

type Crudable added in v0.1.14

type Crudable interface {
	List(*gin.Context)
	Create(*gin.Context)
	GetByID(*gin.Context)
	Update(*gin.Context)
	Delete(*gin.Context)
	Schema(*gin.Context)
	Full(*gin.Context)
}

type FilterOptions

type FilterOptions struct {
	Field    string
	Value    interface{}
	Operator string // "eq", "ne", "gt", "lt", "gte", "lte", "like"
}

type Model

type Model interface {
	~struct{} // Любая структура
}

type PaginatedResponse

type PaginatedResponse struct {
	Results    interface{} `json:"results"`
	Page       int         `json:"page"`
	TotalPages int         `json:"total_pages"`
	Count      int         `json:"count"`
}

type Pagination

type Pagination struct {
	Page       int
	PerPage    int
	TotalPages int
	Count      int
}

func NewPaginator

func NewPaginator(ctx *gin.Context) Pagination

func (*Pagination) GetResponse

func (p *Pagination) GetResponse(data interface{}) PaginatedResponse

func (*Pagination) PaginatedQueryset

func (p *Pagination) PaginatedQueryset(query *gorm.DB) *gorm.DB

type QueryOptions added in v0.1.10

type QueryOptions struct {
	Filters []FilterOptions
	Sorts   []SortOptions
}

func ParseQueryParams

func ParseQueryParams(params url.Values) QueryOptions

ParseQueryParams преобразует query-параметры в фильтры

type SortOptions added in v0.1.10

type SortOptions struct {
	Field string
	Order string // "asc", "desc"
}

type ViewSet

type ViewSet[T any] struct {
	PreloadField []string
	// contains filtered or unexported fields
}

func NewViewSet

func NewViewSet[T any](db *gorm.DB) *ViewSet[T]

func (*ViewSet[T]) Create

func (c *ViewSet[T]) Create(ctx *gin.Context)

Create создает новую запись

func (*ViewSet[T]) Delete

func (c *ViewSet[T]) Delete(ctx *gin.Context)

Delete удаляет запись

func (*ViewSet[T]) Full added in v0.1.5

func (c *ViewSet[T]) Full(ctx *gin.Context)

Full возвращает список записей без учета пагинации

func (*ViewSet[T]) GetByID

func (c *ViewSet[T]) GetByID(ctx *gin.Context)

GetByID возвращает запись по ID

func (*ViewSet[T]) GetQueryset

func (c *ViewSet[T]) GetQueryset(query *gorm.DB) *gorm.DB

func (*ViewSet[T]) List

func (c *ViewSet[T]) List(ctx *gin.Context)

List возвращает список записей с пагинацией

func (*ViewSet[T]) Schema added in v0.1.4

func (c *ViewSet[T]) Schema(ctx *gin.Context)

Schema возвращает запись по ID

func (*ViewSet[T]) Update

func (c *ViewSet[T]) Update(ctx *gin.Context)

Update обновляет запись

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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