Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotFound is used when a specific Product is requested but does not exist. ErrNotFound = errors.New("not found") // ErrInvalidID occurs when an ID is not in a valid form. ErrInvalidID = errors.New("ID is not in its proper form") )
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct { ID string `db:"book_id" json:"book_id"` AuthorID string `db:"author_id" json:"author_id,omitempty"` AuthorName string `db:"author_name" json:"author_name"` Title string `db:"title" json:"title"` PublishedDate string `db:"published_date" json:"published_date"` ImageUrl string `db:"image_url" json:"image_url"` Description string `db:"description" json:"description"` }
Info is the book model.
type NewBook ¶
type NewBook struct { AuthorName string `json:"author_name" validate:"required,alpha_space"` Title string `json:"title" validate:"required"` PublishedDate string `json:"published_date" validate:"required,date"` ImageUrl string `json:"image_url" validate:"required,url,max=255"` Description string `json:"description" validate:"required,max=255"` }
NewBook is the required data for creating a new book.
type Repo ¶
type Repo interface { Query() (Infos, error) QueryByID(bookID string) (Info, error) QueryByTitle(bookTitle string) (Info, error) Create(book NewBook) (Info, error) Delete(bookID string) error }
Repo is the interface for the book repository.
type RepositoryDb ¶
BookRepositoryDb defines the repository for the book service.
func (*RepositoryDb) Create ¶
func (r *RepositoryDb) Create(book NewBook) (Info, error)
Create adds a new book to the database. It returns the created book with fields like ID and Author_ID populated.
func (*RepositoryDb) Delete ¶
func (r *RepositoryDb) Delete(bookID string) error
Delete removes a book by ID from the database.
func (*RepositoryDb) Query ¶
func (r *RepositoryDb) Query() (Infos, error)
Query retrieves all books from the database.
func (*RepositoryDb) QueryByID ¶
func (r *RepositoryDb) QueryByID(bookID string) (Info, error)
QuerybyID retrieves a book by ID from the database.
func (*RepositoryDb) QueryByTitle ¶
func (r *RepositoryDb) QueryByTitle(bookTitle string) (Infos, error)
QuerybyTitle retrieves a book by quering the title from the database.
Click to show internal directories.
Click to hide internal directories.