go4rest

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: MIT Imports: 7 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

Types

type FilterOptions

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

func ParseQueryParams

func ParseQueryParams(params url.Values) []FilterOptions

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

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 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]) 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]) Update

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

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

Jump to

Keyboard shortcuts

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