entities

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToResponseSlice

func ToResponseSlice[R Entity[E], E any](entities []*R) ([]*E, error)

Types

type BaseEntity

type BaseEntity[E any] struct {
	RespInstance *E `gorm:"-"`
}

func (*BaseEntity[E]) CopyToResponse

func (b *BaseEntity[E]) CopyToResponse(source any) (*E, error)

type Entity

type Entity[E any] interface {
	ToResponse() (*E, error)
}

type Image

type Image struct {
	BaseEntity[response.ImageResponse]
	Id        uint      `gorm:"primaryKey"`
	S3Key     string    `gorm:"size:255;not null"`
	Url       string    `gorm:"size:512;not null"`
	UserID    *uint     `gorm:"index"` // Указатель для nullable
	Size      int       `gorm:""`
	MimeType  string    `gorm:"size:50"`
	ExpiresAt time.Time `gorm:""`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}

func (Image) ToResponse

func (a Image) ToResponse() (*response.ImageResponse, error)

type Role

type Role struct {
	BaseEntity[response.RoleResponse]

	Id          uint               `gorm:"primaryKey" query:"unique"`
	Name        role_enum.RoleName `gorm:"unique;not null" query:"unique"`
	Description string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

func (Role) Is

func (r Role) Is(roleName role_enum.RoleName) bool

Is проверяет, соответствует ли роль указанному enum значению

func (Role) ToResponse

func (r Role) ToResponse() (*response.RoleResponse, error)

type User

type User struct {
	BaseEntity[response.UserResponse]
	Id           uint   `gorm:"primaryKey"`
	Username     string `gorm:"unique;not null"`
	Email        string `gorm:"unique;not null" query:"ops:ilike|like|eq|neq"`
	PasswordHash string `gorm:"not null" query:"ignore"`
	FirstName    string
	LastName     string
	RoleId       uint
	Role         Role `gorm:"foreignKey:RoleId"`
	IsActive     bool `gorm:"default:true"`
	LastLogin    *time.Time
	CreatedAt    time.Time `gorm:"default:CURRENT_TIMESTAMP"`
	UpdatedAt    time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}

func (User) ToResponse

func (u User) ToResponse() (*response.UserResponse, error)

Jump to

Keyboard shortcuts

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