book

package
v0.0.0-...-b56e1d8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

func New

func New(db *gorm.DB, v *validator.Validate) *API

func (*API) Create

func (a *API) Create(w http.ResponseWriter, r *http.Request)

Create godoc

@summary        Create book
@description    Create book
@tags           books
@accept         json
@produce        json
@param          body    body    Form    true    "Book form"
@success        201
@failure        400 {object}    err.Error
@failure        422 {object}    err.Errors
@failure        500 {object}    err.Error
@router         /books [post]

func (*API) Delete

func (a *API) Delete(w http.ResponseWriter, r *http.Request)

Delete godoc

@summary        Delete book
@description    Delete book
@tags           books
@accept         json
@produce        json
@param          id  path    string  true    "Book ID"
@success        200
@failure        400 {object}    err.Error
@failure        404
@failure        500 {object}    err.Error
@router         /books/{id} [delete]

func (*API) List

func (a *API) List(w http.ResponseWriter, r *http.Request)

List godoc

@summary        List books
@description    List books
@tags           books
@accept         json
@produce        json
@success        200 {array}     DTO
@failure        500 {object}    err.Error
@router         /books [get]

func (*API) Read

func (a *API) Read(w http.ResponseWriter, r *http.Request)

Read godoc

@summary        Read book
@description    Read book
@tags           books
@accept         json
@produce        json
@param          id	path        string  true    "Book ID"
@success        200 {object}    DTO
@failure        400 {object}    err.Error
@failure        404
@failure        500 {object}    err.Error
@router         /books/{id} [get]

func (*API) Update

func (a *API) Update(w http.ResponseWriter, r *http.Request)

Update godoc

@summary        Update book
@description    Update book
@tags           books
@accept         json
@produce        json
@param          id      path    string  true    "Book ID"
@param          body    body    Form    true    "Book form"
@success        200
@failure        400 {object}    err.Error
@failure        404
@failure        422 {object}    err.Errors
@failure        500 {object}    err.Error
@router         /books/{id} [put]

type Book

type Book struct {
	ID            uuid.UUID `gorm:"primarykey"`
	Title         string
	Author        string
	PublishedDate time.Time
	ImageURL      string
	Description   string
	CreatedAt     time.Time
	UpdatedAt     time.Time
	DeletedAt     gorm.DeletedAt
}

func (*Book) ToDto

func (b *Book) ToDto() *DTO

type Books

type Books []*Book

func (Books) ToDto

func (bs Books) ToDto() []*DTO

type DTO

type DTO struct {
	ID            string `json:"id"`
	Title         string `json:"title"`
	Author        string `json:"author"`
	PublishedDate string `json:"published_date"`
	ImageURL      string `json:"image_url"`
	Description   string `json:"description"`
}

type Form

type Form struct {
	Title         string `json:"title" validate:"required,max=255"`
	Author        string `json:"author" validate:"required,alphaspace,max=255"`
	PublishedDate string `json:"published_date" validate:"required,datetime=2006-01-02"`
	ImageURL      string `json:"image_url" validate:"url"`
	Description   string `json:"description"`
}

func (*Form) ToModel

func (f *Form) ToModel() *Book

type Repository

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

func NewRepository

func NewRepository(db *gorm.DB) *Repository

func (*Repository) Create

func (r *Repository) Create(book *Book) (*Book, error)

Create creates a new book.

func (*Repository) Delete

func (r *Repository) Delete(id uuid.UUID) (int64, error)

Delete deletes a book by the given id and returns the number of deleted rows and a potential error.

func (*Repository) List

func (r *Repository) List() (Books, error)

List returns all books.

func (*Repository) Read

func (r *Repository) Read(id uuid.UUID) (*Book, error)

Read returns a book by the given id.

func (*Repository) Update

func (r *Repository) Update(book *Book) (int64, error)

Jump to

Keyboard shortcuts

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