controller

package
v0.0.0-...-80d63af Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activator

type Activator interface {
	Activate(ctx context.Context, req *request.Activation) error
	Resend(ctx context.Context, req *request.ResendActivation) error
}

Activator interface

type Auth

type Auth interface {
	Signin(ctx context.Context, req *request.Signin) (*response.Signin, error)
	Signup(ctx context.Context, req *request.Signup) error
}

Auth interface

type AuthController

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

AuthController is a controller for authentication.

func NewAuthController

func NewAuthController(
	auth Auth,
	act Activator,
	pass PasswordResetHandler,
	valid validation.Validator,
	eh httphandling.HTTPErrorHandler,
	log logger.Logger,
) *AuthController

NewAuthController creates a new AuthController instance.

func (*AuthController) Activate

func (ctrl *AuthController) Activate(w http.ResponseWriter, r *http.Request) error

Activate @Summary Activate Account @Tags Authentication @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/auth/activation/activate [post]

func (*AuthController) RegisterRoutes

func (ctrl *AuthController) RegisterRoutes(router chi.Router)

RegisterRoutes registers authentication routes.

func (*AuthController) Replace

func (ctrl *AuthController) Replace(w http.ResponseWriter, r *http.Request) error

Replace @Summary Replace Password @Tags Authentication @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/auth/password/replace [post]

func (*AuthController) Resend

func (ctrl *AuthController) Resend(w http.ResponseWriter, r *http.Request) error

Resend @Summary Resend Activation Mail @Tags Authentication @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/auth/activation/resend [post]

func (*AuthController) Reset

func (ctrl *AuthController) Reset(w http.ResponseWriter, r *http.Request) error

Reset @Summary Reset Password @Tags Authentication @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/auth/password/reset [post]

func (*AuthController) Signin

func (ctrl *AuthController) Signin(w http.ResponseWriter, r *http.Request) error

Signin @Summary Signin @Tags Authentication @Accept json @Produce json @Param signin body request.Signin true "Signin" @Success 200 {object} response.Signin @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/auth/signin [post]

func (*AuthController) Signup

func (ctrl *AuthController) Signup(w http.ResponseWriter, r *http.Request) error

Signup @Summary Signup @Tags Authentication @Accept json @Produce json @Param signup body request.Signup true "Signup" @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/auth/signup [post]

type AuthorController

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

AuthorController is a controller for author

func NewAuthorController

func NewAuthorController(
	reader AuthorReader,
	writer AuthorWriter,
	valid validation.Validator,
	handler httphandling.HTTPErrorHandler,
	log logger.Logger,
) *AuthorController

NewAuthorController creates new author controller

func (*AuthorController) CreateAuthor

func (ctrl *AuthorController) CreateAuthor(w http.ResponseWriter, r *http.Request) error

CreateAuthor creates author @Summary Create author @Tags Author @Security BearerAuth @Accept json @Produce json @Param author body request.CreateAuthor true "Author" @Success 200 {object} response.Author @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/author [post]

func (*AuthorController) DeleteAuthor

func (ctrl *AuthorController) DeleteAuthor(w http.ResponseWriter, r *http.Request) error

DeleteAuthor deletes author @Summary Delete author @Tags Author @Security BearerAuth @Param authorID path int true "Author ID" @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 404 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/author/{authorID} [delete]

func (*AuthorController) GetAuthor

func (ctrl *AuthorController) GetAuthor(w http.ResponseWriter, r *http.Request) error

GetAuthor gets author by id @Summary Get author by id @Tags Author @Security BearerAuth @Produce json @Param authorID path int true "Author ID" @Success 200 {object} response.Author @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 404 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/author/{authorID} [get]

func (*AuthorController) GetAuthors

func (ctrl *AuthorController) GetAuthors(w http.ResponseWriter, r *http.Request) error

GetAuthors gets authors @Summary Get authors @Tags Author @Security BearerAuth @Produce json @Success 200 {array} response.ListAuthor @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/author [get]

func (*AuthorController) RegisterRoutes

func (ctrl *AuthorController) RegisterRoutes(router chi.Router)

RegisterRoutes registers author routes

func (*AuthorController) UpdateAuthor

func (ctrl *AuthorController) UpdateAuthor(w http.ResponseWriter, r *http.Request) error

UpdateAuthor updates author @Summary Update author @Tags Author @Security BearerAuth @Accept json @Param authorID path int true "Author ID" @Param author body request.UpdateAuthor true "Author" @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 404 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/author/{authorID} [put]

type AuthorReader

type AuthorReader interface {
	GetAuthors(ctx context.Context) ([]response.ListAuthor, error)
	GetAuthor(ctx context.Context, authorID types.ID) (*response.Author, error)
}

AuthorReader is an interface for author reader

type AuthorWriter

type AuthorWriter interface {
	CreateAuthor(ctx context.Context, req *request.CreateAuthor) (*response.CreateAuthor, error)
	UpdateAuthor(ctx context.Context, authorID types.ID, author *request.UpdateAuthor) error
	DeleteAuthor(ctx context.Context, authorID types.ID) error
}

AuthorWriter is an interface for author writer

type BookController

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

BookController is a controller for book

func NewBookController

func NewBookController(
	reader BookReader,
	writer BookWriter,
	valid validation.Validator,
	handler httphandling.HTTPErrorHandler,
	log logger.Logger,
) *BookController

NewBookController creates new book controller

func (*BookController) CreateBook

func (ctrl *BookController) CreateBook(w http.ResponseWriter, r *http.Request) error

CreateBook creates a new book @Summary Create a new book @Tags Books @Security BearerAuth @Accept json @Produce json @Param book body request.CreateBook true "Book" @Success 200 {object} response.CreateBook @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 404 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/book [post]

func (*BookController) DeleteBook

func (ctrl *BookController) DeleteBook(w http.ResponseWriter, r *http.Request) error

DeleteBook deletes a book @Summary Delete a book @Tags Books @Security BearerAuth @Param bookID path int true "Book ID" @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 404 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/book/{bookID} [delete]

func (*BookController) GetBook

func (ctrl *BookController) GetBook(w http.ResponseWriter, r *http.Request) error

GetBook gets book by id @Summary Get book by id @Tags Books @Security BearerAuth @Produce json @Param bookID path int true "Book ID" @Success 200 {object} response.Book @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 404 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/book/{bookID} [get]

func (*BookController) GetBooks

func (ctrl *BookController) GetBooks(w http.ResponseWriter, r *http.Request) error

GetBooks gets books @Summary Get books @Tags Books @Security BearerAuth @Produce json @Success 200 {array} response.ListBook @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/book [get]

func (*BookController) RegisterRoutes

func (ctrl *BookController) RegisterRoutes(router chi.Router)

RegisterRoutes registers routes

func (*BookController) UpdateBook

func (ctrl *BookController) UpdateBook(w http.ResponseWriter, r *http.Request) error

UpdateBook updates a book @Summary Update a book @Tags Books @Security BearerAuth @Accept json @Param bookID path int true "Book ID" @Param book body request.UpdateBook true "Book" @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 404 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /v1/book/{bookID} [put]

type BookReader

type BookReader interface {
	GetBook(ctx context.Context, bookID types.ID) (*response.Book, error)
	GetBooks(ctx context.Context) ([]response.ListBook, error)
}

BookReader is an interface for book reader

type BookWriter

type BookWriter interface {
	CreateBook(ctx context.Context, req *request.CreateBook) (*response.CreateBook, error)
	UpdateBook(ctx context.Context, bookID types.ID, req *request.UpdateBook) error
	DeleteBook(ctx context.Context, bookID types.ID) error
}

BookWriter is an interface for book writer

type Controllers

type Controllers struct {
	AuthController   *AuthController
	UserController   *UserController
	BookController   *BookController
	AuthorController *AuthorController
}

type PasswordResetHandler

type PasswordResetHandler interface {
	Reset(ctx context.Context, req *request.ResetPassword) error
	Replace(ctx context.Context, req *request.ReplacePassword) error
}

PasswordResetHandler interface

type UserController

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

UserController is a controller for user

func NewUserController

func NewUserController(
	reader UserReader,
	writer UserWriter,
	valid validation.Validator,
	eh httphandling.HTTPErrorHandler,
	log logger.Logger,
) *UserController

NewUserController creates a new UserController instance.

func (*UserController) GetUser

func (ctrl *UserController) GetUser(w http.ResponseWriter, r *http.Request) error

GetUser returns user @Tags User @Security BearerAuth @Produce json @Success 200 {object} response.User @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /user [get]

func (*UserController) RegisterRoutes

func (ctrl *UserController) RegisterRoutes(router chi.Router)

RegisterRoutes registers routes for user controller

func (*UserController) UpdateInfo

func (ctrl *UserController) UpdateInfo(w http.ResponseWriter, r *http.Request) error

UpdateInfo updates user info @Tags User @Security BearerAuth @Accept json @Param user body request.UserData true "User" @Success 200 "OK" @Failure 400 {object} response.ProblemDetail @Failure 401 {object} response.ProblemDetail @Failure 403 {object} response.ProblemDetail @Failure 500 {object} response.ProblemDetail @Router /user/info [put]

type UserReader

type UserReader interface {
	GetUser(ctx context.Context) response.User
}

UserReader is an interface for user reader

type UserWriter

type UserWriter interface {
	UpdateInfo(ctx context.Context, req *request.UserData) error
}

UserWriter is an interface for user writer

Jump to

Keyboard shortcuts

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