controllers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserKey              = "user"
	IsAdminKey           = "isAdmin"
	UserRepositoryKey    = "userRepository"
	MessageRepositoryKey = "messageRepository"
	LatestRepositoryKey  = "latestRepository"
)

Variables

View Source
var (
	ErrInvalidMessageId     = internal.NewBadRequestError("invalid message id")
	ErrMissingAuthorization = internal.NewHttpError(403, "Forbidden not authorized")
)
View Source
var (
	ErrInvalidUsername    = internal.NewHttpError(http.StatusNotFound, "invalid username")
	ErrIncorrectPassword  = internal.NewHttpError(http.StatusUnauthorized, "incorrect password")
	ErrMissingCredentials = internal.NewHttpError(http.StatusUnauthorized, "missing authentication credentials")
)
View Source
var (
	ErrInvalidEmail = internal.NewHttpError(http.StatusUnprocessableEntity, "email address is not valid")
)

Functions

func AuthRequired

func AuthRequired() gin.HandlerFunc

func AuthorizationRequired

func AuthorizationRequired() gin.HandlerFunc

func CORSMiddleware

func CORSMiddleware() gin.HandlerFunc

func FlagMessageById

func FlagMessageById(c *gin.Context)

func FollowGetController

func FollowGetController(c *gin.Context)

func FollowPostController

func FollowPostController(c *gin.Context)

Adds the current user as follower of the given user.

func GetAllMessages

func GetAllMessages(c *gin.Context)

func GetAuthState

func GetAuthState(c *gin.Context) (string, error)

func GetFeedMessages

func GetFeedMessages(c *gin.Context)

func GetMessages

func GetMessages(c *gin.Context)

GetMessages returns the latest messages, limited by the number of messages per page.

func GetUserMessages

func GetUserMessages(c *gin.Context)

GetUserMessages returns the latest messages by the user, limited by the number of messages per page.

func GetUserOrAdmin

func GetUserOrAdmin(c *gin.Context, userRepository database.IUserRepository) (*models.User, error)

func LatestController

func LatestController(c *gin.Context)

func LoggingMiddleware

func LoggingMiddleware() gin.HandlerFunc

func LoginGet

func LoginGet(c *gin.Context)

Logs the user in. Essentially a test of the AuthRequired middleware.

func PostUserMessage

func PostUserMessage(c *gin.Context)

PostUserMessage posts a non-empty message, with the current UTC time.

func RegisterController

func RegisterController(c *gin.Context)

func SetupRouter

func SetupRouter(openDatabase database.OpenDatabaseFunc) *gin.Engine

func UpdateLatestMiddleware

func UpdateLatestMiddleware(c *gin.Context)

Types

type FollowRequestBody

type FollowRequestBody struct {
	Follow   string `form:"follow" json:"follow"`
	Unfollow string `form:"unfollow" json:"unfollow"`
}

type PostUserMessageRequestBody

type PostUserMessageRequestBody struct {
	Content string `form:"content" json:"content" binding:"required"`
}

type RegisterRequestBody

type RegisterRequestBody struct {
	Username string `form:"username" json:"username" binding:"required"`
	Email    string `form:"email" json:"email" binding:"required"`
	Password string `form:"pwd" json:"pwd" binding:"required"`
}

Jump to

Keyboard shortcuts

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