Documentation ¶
Index ¶
- func ErrorResponse(c echo.Context, statusCode int, message string, err error) error
- func SuccessResponse(c echo.Context, statusCode int, message string, data any) error
- type AddDeviceRequestBody
- type BaseHandler
- func (h *BaseHandler) AddDevice(c echo.Context) error
- func (h *BaseHandler) Block(c echo.Context) error
- func (h *BaseHandler) Chat(c echo.Context) error
- func (h *BaseHandler) CreateChat(c echo.Context) error
- func (h *BaseHandler) DeleteChat(c echo.Context) error
- func (h *BaseHandler) Follow(c echo.Context) error
- func (h *BaseHandler) GetChat(c echo.Context) error
- func (h *BaseHandler) GetMessages(c echo.Context) error
- func (h *BaseHandler) Login(c echo.Context) error
- func (h *BaseHandler) Logout(c echo.Context) error
- func (h *BaseHandler) RefreshTokens(c echo.Context) error
- func (h *BaseHandler) Registration(c echo.Context) error
- func (h *BaseHandler) Search(c echo.Context) error
- func (h *BaseHandler) Unblock(c echo.Context) error
- func (h *BaseHandler) Unfollow(c echo.Context) error
- func (h *BaseHandler) UpdatePassword(c echo.Context) error
- func (h *BaseHandler) UpdateUsername(c echo.Context) error
- func (h *BaseHandler) UploadImage(c echo.Context) error
- func (h *BaseHandler) User(c echo.Context) error
- type LoginRequestBody
- type MessageResponseBody
- type RefreshTokenRequestBody
- type RegistrationRequestBody
- type Response
- type TokensResponseBody
- type UpdatePasswordRequestBody
- type UpdateUsernameRequestBody
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorResponse ¶
ErrorResponse takes a response status code and arbitrary data and writes a json response to the client in depends on Header Accept and APP_ENV environment variable(has two possible values: dev and prod) - APP_ENV=dev responds debug info level of error - APP_ENV=prod responds just message about error [DEFAULT]
Types ¶
type AddDeviceRequestBody ¶
type BaseHandler ¶
type BaseHandler struct {
// contains filtered or unexported fields
}
func NewBaseHandler ¶
func NewBaseHandler( userRepo models.UserRepository, messageRepo models.MessageRepository, chatRepo models.ChatRepository, tokenService *TokenService.Service, chatService *ChatService.ChatService, ) *BaseHandler
func (*BaseHandler) AddDevice ¶
func (h *BaseHandler) AddDevice(c echo.Context) error
AddDevice godoc @Summary Add device @Description Set device Token(Firebase Cloud Messaging) for push notifications @Tags device @Accept json @Produce application/json @Param password body AddDeviceRequestBody true "raw request body" @Security BearerAuth @Success 200 {object} Response @Failure 400 {object} Response @Failure 401 {object} Response @Failure 409 {object} Response @Failure 500 {object} Response @Router /v1/devices [post]
func (*BaseHandler) Block ¶
func (h *BaseHandler) Block(c echo.Context) error
Block godoc @Summary Block user @Tags user @Accept json @Produce application/json @Param user_id path int true "Blocked User ID" @Security BearerAuth @Success 200 {object} Response @Failure 400 {object} Response @Failure 401 {object} Response @Failure 500 {object} Response @Router /v1/user/{user_id}/block [post]
func (*BaseHandler) Chat ¶
func (h *BaseHandler) Chat(c echo.Context) error
Chat godoc @Summary Chat [WebSocket] @Description Chat with users based on WebSocket @Tags chat @Param token query string true "Access JWT Token" @Param chat body MessageResponseBody true "body should contain content and recipient_id for sending message" @Failure 401 {object} Response @Router /ws/chat [get]
func (*BaseHandler) CreateChat ¶
func (h *BaseHandler) CreateChat(c echo.Context) error
CreateChat godoc @Summary Create Chat by User ID @Tags chat @Accept json @Produce application/json @Param user_id path int true "User ID" @Security BearerAuth @Success 200 {object} Response{data=models.Chat} @Failure 400 {object} Response @Failure 409 {object} Response @Failure 500 {object} Response @Router /v1/user/{user_id}/chat [post]
func (*BaseHandler) DeleteChat ¶
func (h *BaseHandler) DeleteChat(c echo.Context) error
DeleteChat godoc @Summary Delete Chat by ChatID @Tags chat @Accept json @Produce application/json @Param chat_id path int true "Chat ID" @Security BearerAuth @Success 200 {object} Response{data=models.User} @Failure 400 {object} Response @Failure 401 {object} Response @Failure 403 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/chat/{chat_id} [delete]
func (*BaseHandler) Follow ¶
func (h *BaseHandler) Follow(c echo.Context) error
Follow godoc @Summary Follow user @Tags user @Accept json @Produce application/json @Param user_id path int true "Followed User ID" @Security BearerAuth @Success 200 {object} Response{data=models.User} @Failure 400 {object} Response @Failure 401 {object} Response @Failure 500 {object} Response @Router /v1/user/{user_id}/follow [post]
func (*BaseHandler) GetChat ¶
func (h *BaseHandler) GetChat(c echo.Context) error
GetChat godoc @Summary Get Chat by User ID @Tags chat @Accept json @Produce application/json @Param user_id path int true "User ID" @Security BearerAuth @Success 200 {object} Response{data=models.Chat} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/user/{user_id}/chat [get]
func (*BaseHandler) GetMessages ¶
func (h *BaseHandler) GetMessages(c echo.Context) error
GetMessages godoc @Summary Get messages from chat by ChatId @Tags chat @Accept json @Produce application/json @Param chat_id path int true "Chat ID" @Security BearerAuth @Success 200 {object} Response{data=[]models.Message} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/chat/messages/{chat_id} [get]
func (*BaseHandler) Login ¶
func (h *BaseHandler) Login(c echo.Context) error
Login godoc @Summary login user by credentials @Description Username should contain: @Description - lower, upper case latin letters and digits @Description - minimum 8 characters length @Description - maximum 40 characters length @Description Password should contain: @Description - minimum of one small case letter @Description - minimum of one upper case letter @Description - minimum of one digit @Description - minimum of one special character @Description - minimum 8 characters length @Description - maximum 40 characters length @Description Response contain pair JWT tokens, use /v1/tokens/refresh for updating them @Tags auth @Accept json @Produce application/json @Param login body LoginRequestBody true "raw request body" @Success 200 {object} Response{data=TokensResponseBody} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/auth/login [post]
func (*BaseHandler) Logout ¶
func (h *BaseHandler) Logout(c echo.Context) error
Logout godoc @Summary logout user @Tags auth @Accept json @Produce application/json @Security BearerAuth @Success 200 {object} Response @Failure 400 {object} Response @Failure 401 {object} Response @Failure 500 {object} Response @Router /v1/auth/logout [post]
func (*BaseHandler) RefreshTokens ¶
func (h *BaseHandler) RefreshTokens(c echo.Context) error
RefreshTokens godoc @Summary refresh pair JWT tokens @Tags tokens @Accept json @Produce application/json @Param login body RefreshTokenRequestBody true "raw request body, should contain Refresh Token" @Success 200 {object} Response{data=TokensResponseBody} @Failure 400 {object} Response @Failure 401 {object} Response @Failure 500 {object} Response @Router /v1/token/refresh [post]
func (*BaseHandler) Registration ¶
func (h *BaseHandler) Registration(c echo.Context) error
Registration godoc @Summary registration user by credentials @Description Username should contain: @Description - lower, upper case latin letters and digits @Description - minimum 8 characters length @Description - maximum 40 characters length @Description Password should contain: @Description - minimum of one small case letter @Description - minimum of one upper case letter @Description - minimum of one digit @Description - minimum of one special character @Description - minimum 8 characters length @Description - maximum 40 characters length @Tags auth @Accept json @Produce application/json @Param registration body RegistrationRequestBody true "raw request body" @Success 200 {object} Response @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/auth/register [post]
func (*BaseHandler) Search ¶
func (h *BaseHandler) Search(c echo.Context) error
Search godoc @Summary search users @Description Search users by username with autocomplete @Tags search @Accept json @Produce application/json @Param q query string true "query string for search by username, minimum 1 character, maximum 40 characters" @Param type query string false "type of search, default: 'user', available: 'user', 'friend', 'blacklist'" @Param order query string false "order of search, default: 'asc', available: 'asc', 'desc'" @Param limit query int false "limit of search, default: '10', available: '1-1000'" @Security BearerAuth @Success 200 {object} Response{data=[]models.User} @Failure 400 {object} Response @Failure 401 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/search [get]
func (*BaseHandler) Unblock ¶
func (h *BaseHandler) Unblock(c echo.Context) error
Unblock godoc @Summary Unblock user @Tags user @Accept json @Produce application/json @Param user_id path int true "Unblocked User ID" @Security BearerAuth @Success 200 {object} Response{data=models.User} @Failure 400 {object} Response @Failure 401 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/user/{user_id}/block [delete]
func (*BaseHandler) Unfollow ¶
func (h *BaseHandler) Unfollow(c echo.Context) error
Unfollow godoc @Summary Unfollow user @Tags user @Accept json @Produce application/json @Param user_id path int true "Followed User ID" @Security BearerAuth @Success 200 {object} Response{data=models.User} @Failure 400 {object} Response @Failure 401 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/user/{user_id}/follow [delete]
func (*BaseHandler) UpdatePassword ¶
func (h *BaseHandler) UpdatePassword(c echo.Context) error
UpdatePassword godoc @Summary update password @Description OldPassword/NewPassword should contain: @Description - minimum of one small case letter @Description - minimum of one upper case letter @Description - minimum of one digit @Description - minimum of one special character @Description - minimum 8 characters length @Description - maximum 40 characters length @Tags user @Accept json @Produce application/json @Param password body UpdatePasswordRequestBody true "raw request body" @Security BearerAuth @Success 200 {object} Response @Failure 400 {object} Response @Failure 401 {object} Response @Failure 500 {object} Response @Router /v1/user/update-password [put]
func (*BaseHandler) UpdateUsername ¶
func (h *BaseHandler) UpdateUsername(c echo.Context) error
UpdateUsername godoc @Summary update username @Description Username should contain: @Description - lower, upper case latin letters and digits @Description - minimum 8 characters length @Description - maximum 40 characters length @Tags user @Accept json @Produce application/json @Param username body UpdateUsernameRequestBody true "raw request body" @Security BearerAuth @Success 200 {object} Response @Failure 400 {object} Response @Failure 401 {object} Response @Failure 500 {object} Response @Router /v1/user/update-username [put]
func (*BaseHandler) UploadImage ¶
func (h *BaseHandler) UploadImage(c echo.Context) error
UploadImage godoc @Summary Upload user image @Description Uploading user image as file by form-data "image" @Tags user @Param image formData file true "User image file. The preferred size is 315x315px because the image will resize to 315x315px. Max size: 2MB, Allowed types: 'jpg', 'jpeg', 'png', 'gif'" @Security BearerAuth @Success 200 {object} Response @Failure 400 {object} Response @Failure 401 {object} Response @Failure 500 {object} Response @Router /v1/user/upload-image [post]
func (*BaseHandler) User ¶
func (h *BaseHandler) User(c echo.Context) error
User godoc @Summary Get user data @Description Get user data @Tags user @Accept json @Produce application/json @Security BearerAuth @Success 200 {object} Response{data=models.User} @Failure 401 {object} Response @Failure 500 {object} Response @Router /v1/user [get]
type LoginRequestBody ¶
type MessageResponseBody ¶
type RefreshTokenRequestBody ¶
type RefreshTokenRequestBody struct {
RefreshToken string `` /* 185-byte string literal not displayed */
}
type RegistrationRequestBody ¶
type Response ¶
type Response struct { Error bool `json:"error" example:"false"` Message string `json:"message" example:"success operation"` Data any `json:"data,omitempty"` }
Response is the type used for sending JSON around
type TokensResponseBody ¶
type UpdateUsernameRequestBody ¶
type UpdateUsernameRequestBody struct {
Username string `json:"username" example:"username"`
}