Documentation
¶
Index ¶
- type API
- func (a *API) Create(w http.ResponseWriter, r *http.Request)
- func (a *API) Delete(w http.ResponseWriter, r *http.Request)
- func (a *API) List(w http.ResponseWriter, r *http.Request)
- func (a *API) Read(w http.ResponseWriter, r *http.Request)
- func (a *API) Update(w http.ResponseWriter, r *http.Request)
- type Book
- type Books
- type DTO
- type Form
- type Repository
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 (*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 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"` }
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.
Click to show internal directories.
Click to hide internal directories.