api

package
v0.0.0-...-3c0f6d4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 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 AuthHandler

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

AuthHandler

func NewAuthHandler

func NewAuthHandler(config *config.Config, authService AuthService, sessionService SessionService, logger logger.Logger) *AuthHandler

AuthHandler constructor

func (*AuthHandler) Delete

func (h *AuthHandler) Delete() echo.HandlerFunc

Delete godoc @Summary Delete user account @Description some description @Tags Auth @Accept json @Param id path int true "user_id" @Produce json @Success 200 {string} string "ok" @Failure 500 {object} httpe.RestError @Router /auth/{id} [delete]

func (*AuthHandler) FindUsersByName

func (h *AuthHandler) FindUsersByName() echo.HandlerFunc

FindUsersByName godoc @Summary Find by name @Description Find user by name @Tags Auth @Accept json @Param name query string false "username" Format(username) @Produce json @Success 200 {object} entity.UsersList @Failure 500 {object} httpe.RestError @Router /auth/find [get]

func (*AuthHandler) GetCSRFToken

func (h *AuthHandler) GetCSRFToken() echo.HandlerFunc

GetCSRFToken godoc @Summary Get CSRF token @Description Get CSRF token, required auth session cookie @Tags Auth @Accept json @Produce json @Success 200 {string} string "Ok" @Failure 500 {object} httpe.RestError @Router /auth/token [get]

func (*AuthHandler) GetMe

func (h *AuthHandler) GetMe() echo.HandlerFunc

GetMe godoc @Summary Get user by id @Description Get current user by id @Tags Auth @Accept json @Produce json @Success 200 {object} entity.User @Failure 500 {object} httpe.RestError @Router /auth/me [get]

func (*AuthHandler) GetUserByID

func (h *AuthHandler) GetUserByID() echo.HandlerFunc

GetUserByID godoc @Summary get user by id @Description get string by ID @Tags Auth @Accept json @Produce json @Param id path int true "user_id" @Success 200 {object} entity.User @Failure 500 {object} httpe.RestError @Router /auth/{id} [get]

func (*AuthHandler) GetUsers

func (h *AuthHandler) GetUsers() echo.HandlerFunc

GetUsers godoc @Summary Get users @Description Get the list of all users @Tags Auth @Accept json @Param page query int false "page number" Format(page) @Param size query int false "number of elements per page" Format(size) @Param orderBy query int false "filter name" Format(orderBy) @Produce json @Success 200 {object} entity.UsersList @Failure 500 {object} httpe.RestError @Router /auth/all [get]

func (*AuthHandler) Login

func (h *AuthHandler) Login() echo.HandlerFunc

Login godoc @Summary Login new user @Description login user, returns user and set session @Tags Auth @Accept json @Produce json @Success 200 {object} entity.User @Router /auth/login [post]

func (*AuthHandler) Logout

func (h *AuthHandler) Logout() echo.HandlerFunc

Logout godoc @Summary Logout user @Description logout user removing session @Tags Auth @Accept json @Produce json @Success 200 {string} string "ok" @Router /auth/logout [post]

func (*AuthHandler) Register

func (h *AuthHandler) Register() echo.HandlerFunc

Register godoc @Summary Register new user @Description register new user, returns user and token @Tags Auth @Accept json @Produce json @Success 201 {object} entity.User @Router /auth/register [post]

func (*AuthHandler) Update

func (h *AuthHandler) Update() echo.HandlerFunc

Update godoc @Summary Update user @Description update existing user @Tags Auth @Accept json @Param id path int true "user_id" @Produce json @Success 200 {object} entity.User @Router /auth/{id} [put]

type AuthService

type AuthService interface {
	Register(ctx context.Context, user *entity.User) (*entity.UserWithToken, error)
	Update(ctx context.Context, user *entity.User) (*entity.User, error)
	Delete(ctx context.Context, userID uuid.UUID) error
	GetUserByID(ctx context.Context, userID uuid.UUID) (*entity.User, error)
	FindUsersByName(ctx context.Context, name string, pq *utils.PaginationQuery) (*entity.UsersList, error)
	GetUsers(ctx context.Context, pq *utils.PaginationQuery) (*entity.UsersList, error)
	Login(ctx context.Context, user *entity.User) (*entity.UserWithToken, error)
}

Auth Service interface

type CommentsHandler

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

Comments Handler

func NewCommentsHandler

func NewCommentsHandler(commentsService CommentsService, config *config.Config, logger logger.Logger) *CommentsHandler

Comments Handler constructor

func (*CommentsHandler) Create

func (h *CommentsHandler) Create() echo.HandlerFunc

Create godoc @Summary Create new comment @Description create new comment @Tags Comments @Accept json @Produce json @Success 201 {object} entity.Comment @Failure 500 {object} httpe.RestErr @Router /comments [post]

func (*CommentsHandler) Delete

func (h *CommentsHandler) Delete() echo.HandlerFunc

Delete godoc @Summary Delete comment @Description delete comment @Tags Comments @Accept json @Produce json @Param id path int true "comment_id" @Success 200 {string} string "ok" @Failure 500 {object} httpe.RestErr @Router /comments/{id} [delete]

func (*CommentsHandler) GetAllByNewsID

func (h *CommentsHandler) GetAllByNewsID() echo.HandlerFunc

GetAllByNewsID godoc @Summary Get comments by news @Description Get all comment by news id @Tags Comments @Accept json @Produce json @Param id path int true "news_id" @Param page query int false "page number" Format(page) @Param size query int false "number of elements per page" Format(size) @Param orderBy query int false "filter name" Format(orderBy) @Success 200 {object} entity.CommentsList @Failure 500 {object} httpe.RestErr @Router /comments/byNewsId/{id} [get]

func (*CommentsHandler) GetByID

func (h *CommentsHandler) GetByID() echo.HandlerFunc

GetByID godoc @Summary Get comment @Description Get comment by id @Tags Comments @Accept json @Produce json @Param id path int true "comment_id" @Success 200 {object} entity.Comment @Failure 500 {object} httpe.RestErr @Router /comments/{id} [get]

func (*CommentsHandler) Update

func (h *CommentsHandler) Update() echo.HandlerFunc

Update godoc @Summary Update comment @Description update new comment @Tags Comments @Accept json @Produce json @Param id path int true "comment_id" @Success 200 {object} entity.Comment @Failure 500 {object} httpe.RestErr @Router /comments/{id} [put]

type CommentsService

type CommentsService interface {
	Create(ctx context.Context, comments *entity.Comment) (*entity.Comment, error)
	Update(ctx context.Context, comments *entity.Comment) (*entity.Comment, error)
	GetAllByNewsID(ctx context.Context, newsID uuid.UUID, pq *utils.PaginationQuery) (*entity.CommentsList, error)
	GetByID(ctx context.Context, commentID uuid.UUID) (*entity.CommentBase, error)
	Delete(ctx context.Context, commentID uuid.UUID) error
}

Comments Service interface

type Deps

type Deps struct {
	AuthService     AuthService
	NewsService     NewsService
	CommentsService CommentsService
	SessionService  SessionService
	Config          *config.Config
	Logger          logger.Logger
}

type Handlers

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

func NewHandlers

func NewHandlers(deps Deps) *Handlers

func (*Handlers) Init

func (h *Handlers) Init(e *echo.Echo) error

type NewsHandler

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

NewsHandler

func NewNewsHandler

func NewNewsHandler(newsService NewsService, config *config.Config, logger logger.Logger) *NewsHandler

NewsHandler constructor

func (*NewsHandler) Create

func (h *NewsHandler) Create() echo.HandlerFunc

Create godoc @Summary Create news @Description Create news handler @Tags News @Accept json @Produce json @Success 201 {object} entity.News @Router /news/create [post]

func (*NewsHandler) Delete

func (h *NewsHandler) Delete() echo.HandlerFunc

Delete godoc @Summary Delete news @Description Delete by id news handler @Tags News @Accept json @Produce json @Param id path int true "news_id" @Success 200 {string} string "ok" @Router /news/{id} [delete]

func (*NewsHandler) GetNews

func (h *NewsHandler) GetNews() echo.HandlerFunc

GetNews godoc @Summary Get all news @Description Get all news with pagination @Tags News @Accept json @Produce json @Param page query int false "page number" Format(page) @Param size query int false "number of elements per page" Format(size) @Param orderBy query int false "filter name" Format(orderBy) @Success 200 {object} entity.NewsList @Router /news [get]

func (*NewsHandler) GetNewsByID

func (h *NewsHandler) GetNewsByID() echo.HandlerFunc

GetByID godoc @Summary Get by id news @Description Get by id news handler @Tags News @Accept json @Produce json @Param id path int true "news_id" @Success 200 {object} entity.News @Router /news/{id} [get]

func (*NewsHandler) SearchNews

func (h *NewsHandler) SearchNews() echo.HandlerFunc

SearchByTitle godoc @Summary Search by title @Description Search news by title @Tags News @Accept json @Produce json @Param page query int false "page number" Format(page) @Param size query int false "number of elements per page" Format(size) @Param orderBy query int false "filter name" Format(orderBy) @Success 200 {object} entity.NewsList @Router /news/search [get]

func (*NewsHandler) Update

func (h *NewsHandler) Update() echo.HandlerFunc

Update godoc @Summary Update news @Description Update news handler @Tags News @Accept json @Produce json @Param id path int true "news_id" @Success 200 {object} entity.News @Router /news/{id} [put]

type NewsService

type NewsService interface {
	Create(ctx context.Context, news *entity.News) (*entity.News, error)
	Update(ctx context.Context, news *entity.News) (*entity.News, error)
	GetNews(ctx context.Context, pq *utils.PaginationQuery) (*entity.NewsList, error)
	GetNewsByID(ctx context.Context, newsID uuid.UUID) (*entity.NewsBase, error)
	SearchNews(ctx context.Context, title string, pq *utils.PaginationQuery) (*entity.NewsList, error)
	Delete(ctx context.Context, newsID uuid.UUID) error
}

News service interface

type SessionService

type SessionService interface {
	CreateSession(ctx context.Context, session *entity.Session, expire int) (string, error)
	GetSessionByID(ctx context.Context, sessionID string) (*entity.Session, error)
	DeleteSessionByID(ctx context.Context, sessionID string) error
}

Session service interface

Jump to

Keyboard shortcuts

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