datastore

package
v0.0.0-...-bd22f50 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 5 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        string     `json:"id"`
	Title     string     `json:"title"`
	Author    string     `json:"author"`
	Publisher string     `json:"publisher"`
	ISBN      string     `json:"isbn"`
	Year      int        `json:"year"`
	Edition   int        `json:"edition,omitempty"` // omitempty for optional fields
	Rating    int        `json:"rating"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"` // omitempty for optional fields
}

Book represents a Book

type BookInterface

type BookInterface interface {
	List(ctx *gin.Context) ([]Book, error)
	Get(ctx *gin.Context, uuid string) (Book, error)
	Create(ctx *gin.Context, book Book) (Book, error)
	GetDatabaseObject() (*gorm.DB, error)
}

BookInterface represents a Book interface

func NewBookStore

func NewBookStore(db *gorm.DB) BookInterface

NewBookStore creates a new BookStore instance

type BookRepo

type BookRepo struct {
	DB *gorm.DB
}

BookRepo represents a Book

func (*BookRepo) Create

func (b *BookRepo) Create(ctx *gin.Context, book Book) (Book, error)

Create creates a new Book into the database and returns a new Book or an error

func (*BookRepo) Get

func (b *BookRepo) Get(ctx *gin.Context, uuid string) (Book, error)

Get returns a book from database or returns an error

func (*BookRepo) GetDatabaseObject

func (b *BookRepo) GetDatabaseObject() (*gorm.DB, error)

GetDatabaseObject return the databaseobject is set or return an error

func (*BookRepo) List

func (b *BookRepo) List(ctx *gin.Context) ([]Book, error)

List return books from database or return error

type Store

type Store struct {
	Book BookInterface
}

Store represents a datastore for interacting with the database

func NewStore

func NewStore(db *gorm.DB) *Store

NewStore creates a new Store instance

Jump to

Keyboard shortcuts

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