controllers

package
v0.0.0-...-04c0119 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandlers

func NewHandlers(r *Repository)

NewHandlers sets the handler repository.

Types

type LoginUser

type LoginUser struct {
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required,min=8,max=24"`
}

LoginUser is the type for authentication-request bodies

type Repository

type Repository struct {
	App *config.AppConfig
	DB  database.DatabaseRepo
}

Repository represents the handler repository to share the app configuragion.

var Repo *Repository

Repo is the repository to share the app configuration.

func NewMongoDBRepo

func NewMongoDBRepo(a *config.AppConfig, db *mongo.Database) *Repository

NewMongoDBRepo returns a new instance of a repository for the mongo driver.

func NewTestDBRepo

func NewTestDBRepo(a *config.AppConfig) *Repository

NewTestDBRepo returns a new repository for testing purposes.

func (*Repository) DeletePost

func (m *Repository) DeletePost(w http.ResponseWriter, r *http.Request)

DeletePost deletes a post by its ID.

func (*Repository) DeleteUser

func (m *Repository) DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser is the handler for deleting a user from the database by its ID.

func (*Repository) GetAllPosts

func (m *Repository) GetAllPosts(w http.ResponseWriter, r *http.Request)

GetAllPosts is the handler for retrieving all posts.

func (*Repository) GetPaginatedPosts

func (m *Repository) GetPaginatedPosts(w http.ResponseWriter, r *http.Request)

GetPaginatedPost is the handler for retrieving a paginated slice of posts.

func (*Repository) GetPostById

func (m *Repository) GetPostById(w http.ResponseWriter, r *http.Request)

GetPostById is the handler for getting a post by its ID.

func (*Repository) GetUserById

func (m *Repository) GetUserById(w http.ResponseWriter, r *http.Request)

GetUserById is the handler for retrieving a user from the database using its ID.

func (*Repository) InsertPost

func (m *Repository) InsertPost(w http.ResponseWriter, r *http.Request)

InsertPost is the handler for adding posts.

func (*Repository) InsertUser

func (m *Repository) InsertUser(w http.ResponseWriter, r *http.Request)

InsertUser is the handler for inserting a user into the database.

func (*Repository) Login

func (m *Repository) Login(w http.ResponseWriter, r *http.Request)

Login is the handler for logging a user in with the given email and password. Sets a cookie if successful or an error message.

func (*Repository) Logout

func (m *Repository) Logout(w http.ResponseWriter, r *http.Request)

Logout logs the user out

func (*Repository) StatusHandler

func (m *Repository) StatusHandler(w http.ResponseWriter, r *http.Request)

StatusHandler is the handler for getting the apps status information.

func (*Repository) UpdatePostById

func (m *Repository) UpdatePostById(w http.ResponseWriter, r *http.Request)

UpdatePostById is the handler for updating a post by its ID. The body of the update needs either the text or the title of the post.

func (*Repository) UpdateUserById

func (m *Repository) UpdateUserById(w http.ResponseWriter, r *http.Request)

UpdateUserById is the handler for updating a user in database by its ID. The body of the update needs either the name, email, password, or user-roles.

Jump to

Keyboard shortcuts

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