handlers

package
v0.0.0-...-6fbf478 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Setup

func Setup(ctx context.Context, cfg *viper.Viper, router *gin.Engine, pathToTemplates string, mongoBooksClient datastore.Books,
	mongoUsersClient datastore.Users, redisBooksClient datastore.Redis, m Middleware, cs CookieStore) *gin.Engine

Types

type AuthHandler

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

func NewAuthHandler

func NewAuthHandler(ctx context.Context, cfg *viper.Viper, store datastore.Users, redisStore datastore.Redis) *AuthHandler

func (*AuthHandler) SignIn

func (h *AuthHandler) SignIn(ctx *gin.Context)

swagger:operation POST /signin auth signUser Signs in a user --- consumes: - application/json produces: - application/json parameters:

  • name: credentials in: body name: User description: The user credentials schema: "$ref": "#/definitions/User"

responses:

'200':
    description: Successful operation
    parameters:
    - name: books_api_token
      in: cookie
      description: The user's session cookie/token
'400':
    description: invalid input
'401':
    description: unauthorised
'500':
    description: internal server error

func (*AuthHandler) SignOut

func (h *AuthHandler) SignOut(ctx *gin.Context)

swagger:operation POST /signout auth signUser Signs out a user --- responses:

'200':
    description: Successful operation
'400':
    description: invalid input
'401':
    description: unauthorised
'500':
    description: internal server error

type BooksHandler

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

BooksHandler provides a struct to wrap the api around

func NewBooksHandler

func NewBooksHandler(ctx context.Context, cfg *viper.Viper, mongoDBStore datastore.Books, redisStore datastore.Redis) *BooksHandler

func (*BooksHandler) DeleteBook

func (handler *BooksHandler) DeleteBook(ctx *gin.Context)

swagger:operation DELETE /books/{id} books deleteBook Delete an existing book --- parameters:

  • name: id in: path description: ID of the book required: true type: string
  • name: Authorization in: header name: Authorization description: Auth header, where the JWT token should be provided type: string example: someJWTToken required: true

consumes: - application/json produces: - application/json responses:

'200':
    message: "Book has been deleted"
'404':
    error: "book not found"

func (*BooksHandler) GetBook

func (handler *BooksHandler) GetBook(ctx *gin.Context)

swagger:operation GET /books/{id} books getBook Returns a book --- parameters:

  • name: id in: path description: ID of the book required: true type: string

consumes: - application/json produces: - application/json responses:

'200':
    schema:
      items:
           "$ref": "#/definitions/Book"
'500':
    error: error description

func (*BooksHandler) ListBooks

func (handler *BooksHandler) ListBooks(ctx *gin.Context)

swagger:operation GET /books books listBooks Returns list of books --- consumes: - application/json produces: - application/json responses:

'200':
    description: Successful operation
    schema:
      type: array
      items:
           "$ref": "#/definitions/Book"
'500':
    description: internal server error

func (*BooksHandler) NewBook

func (handler *BooksHandler) NewBook(ctx *gin.Context)

swagger:operation POST /books books addBook Adds a new book --- consumes: - application/json produces: - application/json parameters:

  • name: book in: body name: Book description: The new book to create schema: "$ref": "#/definitions/Book"
  • name: Authorization in: header name: Authorization description: Auth header, where the JWT token should be provided type: string example: someJWTToken required: true

responses:

'201':
    description: Successful operation
    schema:
      type: array
      items:
           "$ref": "#/definitions/Book"
'400':
    description: invalid input
'500':
    description: internal server error

func (*BooksHandler) SearchBooks

func (handler *BooksHandler) SearchBooks(ctx *gin.Context)

swagger:operation GET /books/search books searchBooks Filters list of books by tag --- parameters:

  • name: tag in: query description: tag to filter on required: false type: string

consumes: - application/json produces: - application/json responses:

'200':
    description: Successful operation
    schema:
      type: array
      items:
           "$ref": "#/definitions/Book"

func (*BooksHandler) UpdateBook

func (handler *BooksHandler) UpdateBook(ctx *gin.Context)

swagger:operation PUT /books/{id} books updateBook Update an existing book --- parameters:

  • name: id in: path description: ID of the book required: true type: string

consumes: - application/json produces: - application/json parameters:

  • name: book in: body name: Book description: The new book to create schema: "$ref": "#/definitions/Book"
  • name: Authorization in: header name: Authorization description: Auth header, where the JWT token should be provided type: string example: someJWTToken required: true

responses:

'200':
    description: Successful operation
    schema:
      type: array
      items:
           "$ref": "#/definitions/Book"
'400':
    description: Invalid input
'404':
    description: book not found
'500':
    description: internal server error

type CookieStore

type CookieStore interface {
	NewCookieStore() (redisStore.Store, error)
}

type Middleware

type Middleware interface {
	AuthJWTMiddleware(cfg *viper.Viper) gin.HandlerFunc
	AuthCookieMiddleware() gin.HandlerFunc
}

Jump to

Keyboard shortcuts

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