loans

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: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	StatusReserved  = "reserved"
	StatusBorrowed  = "borrowed"
	StatusReturned  = "returned"
	StatusCancelled = "cancelled"
)

Variables

View Source
var (
	ErrBookNotFound     = errors.New("book not found")
	ErrUserNotFound     = errors.New("user not found")
	ErrNoStockAvailable = errors.New("no copies available for this book")
	ErrLoanNotFound     = errors.New("loan not found")
)

Functions

This section is empty.

Types

type Handler

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

func NewHandler

func NewHandler(service *Service, rabbitChannel *amqp.Channel, jwtSecret string) *Handler

func (*Handler) CancelReservation

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

CancelReservation

func (*Handler) ConfirmBorrow

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

ConfirmBorrow

func (*Handler) GetUserLoans

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

GetUserLoans

func (*Handler) RegisterRoutes

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

RegisterRoutes

func (*Handler) ReserveBook

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

ReserveBook

func (*Handler) ReturnBook

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

ReturnBook

type Loan

type Loan struct {
	ID          uint       `gorm:"primaryKey" json:"id"`
	UserID      uint       `gorm:"not null;index" json:"user_id"`
	BookID      uint       `gorm:"not null;index" json:"book_id"`
	Status      string     `gorm:"type:enum('reserved','borrowed','returned','cancelled');not null;default:'reserved'" json:"status"`
	IsActive    bool       `gorm:"not null;default:true" json:"is_active"`
	ReservedAt  time.Time  `gorm:"not null;autoCreateTime" json:"reserved_at"`
	BorrowedAt  *time.Time `json:"borrowed_at,omitempty"`
	DueDate     *time.Time `json:"due_date,omitempty"`
	ReturnedAt  *time.Time `json:"returned_at,omitempty"`
	CancelledAt *time.Time `json:"cancelled_at,omitempty"`
	Notes       string     `gorm:"type:varchar(255)" json:"notes,omitempty"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (Loan) TableName

func (Loan) TableName() string

type Repository

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

func NewRepository

func NewRepository(db *gorm.DB) *Repository

func (*Repository) CreateLoan

func (r *Repository) CreateLoan(ctx context.Context, loan *Loan) error

func (*Repository) GetActiveLoansByBook

func (r *Repository) GetActiveLoansByBook(ctx context.Context, bookID uint) ([]Loan, error)

func (*Repository) GetLoanByID

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

func (*Repository) GetLoansByUser

func (r *Repository) GetLoansByUser(ctx context.Context, userID uint) ([]Loan, error)

func (*Repository) UpdateLoan

func (r *Repository) UpdateLoan(ctx context.Context, loan *Loan) error

type Service

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

func NewService

func NewService(db *gorm.DB, loanRepo *Repository, bookRepo *books.Repository) *Service

func (*Service) CancelReservation

func (s *Service) CancelReservation(ctx context.Context, loanID uint) error

CancelReservation

func (*Service) ConfirmBorrow

func (s *Service) ConfirmBorrow(ctx context.Context, loanID uint) error

ConfirmBorrow

func (*Service) ReserveBook

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

ReserveBook

func (*Service) ReturnBook

func (s *Service) ReturnBook(ctx context.Context, loanID uint) error

ReturnBook stock ++

Jump to

Keyboard shortcuts

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