books

package
v0.0.0-...-4a77db7 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	ID                uint   `gorm:"primaryKey" json:"id"`
	Title             string `gorm:"type:varchar(200);not null" json:"title"`
	Author            string `gorm:"type:varchar(150);not null" json:"author"`
	ISBN              string `gorm:"type:varchar(20);uniqueIndex" json:"isbn"`
	Publisher         string `gorm:"type:varchar(150)" json:"publisher"`
	YearOfPublication int    `gorm:"type:int" json:"year_of_publication"`
	Edition           string `gorm:"type:varchar(50)" json:"edition"`
	Genre             string `gorm:"type:varchar(100)" json:"genre"`
	Language          string `gorm:"type:varchar(50);default:'fa'" json:"language"`
	Description       string `gorm:"type:text" json:"description"`

	Stock int `gorm:"not null;default:1" json:"stock"`

	ReservationStatus string `gorm:"type:enum('available','reserved');default:'available'" json:"reservation_status"`
	SellingStatus     string `gorm:"type:enum('available','sold_out');default:'available'" json:"selling_status"`

	CoverImage string  `gorm:"type:varchar(255)" json:"cover_image"`
	Tags       string  `gorm:"type:varchar(255)" json:"tags"`
	Price      float64 `gorm:"default:0" json:"price"`

	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `gorm:"index" json:"deleted_at"`
}

func (Book) TableName

func (Book) TableName() string

type Favorite

type Favorite struct {
	ID        uint      `gorm:"primarykey" json:"id"`
	UserID    uint      `json:"user_id"`
	BookID    uint      `json:"book_id"`
	CreatedAt time.Time `json:"created_at"`
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(service *Service) *Handler

func (*Handler) AddToFavorites

func (h *Handler) AddToFavorites(c echo.Context) error

func (*Handler) CreateBook

func (h *Handler) CreateBook(c echo.Context) error

func (*Handler) DeleteBook

func (h *Handler) DeleteBook(c echo.Context) error

func (*Handler) GetBookByID

func (h *Handler) GetBookByID(c echo.Context) error

func (*Handler) GetFavoritesByUser

func (h *Handler) GetFavoritesByUser(c echo.Context) error

func (*Handler) ListBooks

func (h *Handler) ListBooks(c echo.Context) error

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(e *echo.Echo)

func (*Handler) SearchBooks

func (h *Handler) SearchBooks(c echo.Context) error

func (*Handler) UpdateBook

func (h *Handler) UpdateBook(c echo.Context) error

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(db *gorm.DB) *Repository

func (*Repository) AddToFavorites

func (r *Repository) AddToFavorites(ctx context.Context, userID, bookID uint) error

func (*Repository) CreateBook

func (r *Repository) CreateBook(ctx context.Context, book *Book) error

func (*Repository) DeleteBook

func (r *Repository) DeleteBook(ctx context.Context, id uint) error

func (*Repository) Exists

func (r *Repository) Exists(ctx context.Context, id uint) (bool, error)

func (*Repository) FindBookByID

func (r *Repository) FindBookByID(ctx context.Context, id uint) (*Book, error)

func (*Repository) GetBookByID

func (r *Repository) GetBookByID(ctx context.Context, id uint) (*Book, error)

func (*Repository) GetFavoritesByUser

func (r *Repository) GetFavoritesByUser(ctx context.Context, userID int) ([]Book, error)

func (*Repository) ListBooks

func (r *Repository) ListBooks(ctx context.Context) ([]Book, error)

func (*Repository) SaveBook

func (r *Repository) SaveBook(ctx context.Context, book *Book) error

func (*Repository) SearchBooks

func (r *Repository) SearchBooks(ctx context.Context, q string) ([]Book, error)

func (*Repository) UpdateBook

func (r *Repository) UpdateBook(ctx context.Context, book *Book) error

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(repo *Repository, cache *redis.Client) *Service

func (*Service) AddToFavorites

func (s *Service) AddToFavorites(ctx context.Context, userID, bookID uint) error

func (*Service) CreateBook

func (s *Service) CreateBook(ctx context.Context, book *Book) error

CreateBook — هم دیتا ذخیره میشه، هم کش پاک میشه

func (*Service) DeleteBook

func (s *Service) DeleteBook(ctx context.Context, id uint) error

func (*Service) GetBookByID

func (s *Service) GetBookByID(ctx context.Context, id uint) (*Book, error)

func (*Service) GetFavoritesByUser

func (s *Service) GetFavoritesByUser(ctx context.Context, userID int) ([]Book, error)

func (*Service) ListBooks

func (s *Service) ListBooks(ctx context.Context) ([]Book, error)

func (*Service) SearchBooks

func (s *Service) SearchBooks(ctx context.Context, q string) ([]Book, error)

func (*Service) UpdateBook

func (s *Service) UpdateBook(ctx context.Context, book *Book) error

Jump to

Keyboard shortcuts

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