controllers

package
v0.0.0-...-7a7783f Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MB = 1 << 20
)

Stores the MB representation

Variables

This section is empty.

Functions

func NewAPIError

func NewAPIError(e *APIError, w http.ResponseWriter)

NewAPIError creates and sends a error response

func NewAPIResponse

func NewAPIResponse(res *APIResponse, w http.ResponseWriter, code int)

NewAPIResponse creates and sends a normal API response

Types

type APIError

type APIError struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Status  int    `json:"status"`
}

APIError is the struct the struct to use when sending an API error

type APIPagination

type APIPagination struct {
	Total   int      `json:"total"`
	PerPage int      `json:"perPage"`
	MinID   int      `json:"minID"`
	Tags    []string `json:"tags"`
}

APIPagination stores the extra data to return in a pagination response

func (*APIPagination) MarshalJSON

func (p *APIPagination) MarshalJSON() ([]byte, error)

MarshalJSON marshals a APIPagination struct

type APIResponse

type APIResponse struct {
	Success    bool           `json:"success"`
	Message    string         `json:"message,omitempty"`
	Data       interface{}    `json:"data,omitempty"`
	Pagination *APIPagination `json:"pagination,omitempty"`
}

APIResponse is the struct to use when sending an API response

type AuthController

type AuthController struct {
	App *app.App
	repositories.UserRepository
	// contains filtered or unexported fields
}

AuthController holds what's necessary for authentication

func NewAuthController

func NewAuthController(a *app.App, us repositories.UserRepository, jwtService services.JWTAuthService) *AuthController

NewAuthController returns an AuthController struct given the App, user repository, and JWT service

func (*AuthController) Authenticate

func (ac *AuthController) Authenticate(w http.ResponseWriter, r *http.Request)

Authenticate will log in a user

func (*AuthController) Logout

func (ac *AuthController) Logout(w http.ResponseWriter, r *http.Request)

Logout will log out a user

func (*AuthController) LogoutAll

func (ac *AuthController) LogoutAll(w http.ResponseWriter, r *http.Request)

LogoutAll logs out of all users

func (*AuthController) RefreshTokens

func (ac *AuthController) RefreshTokens(w http.ResponseWriter, r *http.Request)

RefreshTokens will refresh JWT tokens if the given refresh token is valid

func (*AuthController) VerifyCaptcha

func (ac *AuthController) VerifyCaptcha(w http.ResponseWriter, r *http.Request)

VerifyCaptcha verifies a clients reCaptcha response token is valid

type ErrorController

type ErrorController struct {
	*app.App
}

ErrorController store the App config

func NewErrorController

func NewErrorController(a *app.App) *ErrorController

NewErrorController returns a new ErrorController struct

func (*ErrorController) NotFound

func (ec *ErrorController) NotFound(w http.ResponseWriter, r *http.Request)

NotFound returns a not found error

type JSONData

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

JSONData stores a representation of JSON data

func GetJSON

func GetJSON(reader io.Reader) (*JSONData, error)

GetJSON returns the JSON data from a given io reader

func (*JSONData) GetBool

func (d *JSONData) GetBool(key string) (bool, error)

GetBool gets the bool value of a key in the given JSON data

func (*JSONData) GetInt

func (d *JSONData) GetInt(key string) (int, error)

GetInt gets the int value of a key in the given JSON data

func (*JSONData) GetString

func (d *JSONData) GetString(key string) (string, error)

GetString gets the string value of a key in the given JSON data

func (*JSONData) GetStringArray

func (d *JSONData) GetStringArray(key string) ([]string, error)

GetStringArray gets the string array value of a key in the given JSON data

type PostController

type PostController struct {
	*app.App
	repositories.PostRepository
	repositories.UserRepository
}

PostController stores the App config and repositories

func NewPostController

NewPostController creates a new post controller

func (*PostController) Create

func (pc *PostController) Create(w http.ResponseWriter, r *http.Request)

Create creates a new post and returns its details

func (*PostController) Delete

func (pc *PostController) Delete(w http.ResponseWriter, r *http.Request)

Delete deletes the post with the given id

func (*PostController) GetByID

func (pc *PostController) GetByID(w http.ResponseWriter, r *http.Request)

GetByID returns the post with the given ID

func (*PostController) GetByIDAdmin

func (pc *PostController) GetByIDAdmin(w http.ResponseWriter, r *http.Request)

GetByIDAdmin returns the post with the given ID including hidden posts

func (*PostController) GetBySlug

func (pc *PostController) GetBySlug(w http.ResponseWriter, r *http.Request)

GetBySlug returns the post with the given slug

func (*PostController) GetBySlugAdmin

func (pc *PostController) GetBySlugAdmin(w http.ResponseWriter, r *http.Request)

GetBySlugAdmin returns the post with the given slug including hidden posts

func (*PostController) GetPage

func (pc *PostController) GetPage(w http.ResponseWriter, r *http.Request)

GetPage returns a keyset pagaination page based on the given post maxID in the page

func (*PostController) GetPageAdmin

func (pc *PostController) GetPageAdmin(w http.ResponseWriter, r *http.Request)

GetPageAdmin returns a keyset pagaination page based on the given post maxID in the page including hidden posts

func (*PostController) Search

func (pc *PostController) Search(w http.ResponseWriter, r *http.Request)

Search for posts using title and tags. Will not return nil data if search is successful.

func (*PostController) Update

func (pc *PostController) Update(w http.ResponseWriter, r *http.Request)

Update updates the post with the given id and returns its new details

type UploadController

type UploadController struct{}

UploadController is empty (nothing needed)

func NewUploadController

func NewUploadController() *UploadController

NewUploadController returns a new UploadController

func (*UploadController) UploadImage

func (uc *UploadController) UploadImage(w http.ResponseWriter, r *http.Request)

UploadImage uploads an image to the server

func (*UploadController) UploadVideo

func (uc *UploadController) UploadVideo(w http.ResponseWriter, r *http.Request)

UploadVideo uploads a video to the server

type UploadImageResponse

type UploadImageResponse struct {
	ImageURL string `json:"imageUrl"`
}

UploadImageResponse is the response struct for an image upload

type UploadVideoResponse

type UploadVideoResponse struct {
	VideoURL string `json:"videoUrl"`
}

UploadVideoResponse is the response struct for an video upload

type UserController

type UserController struct {
	*app.App
	repositories.UserRepository
	repositories.PostRepository
}

UserController stores the App config and repositories

func NewUserController

NewUserController creates a new user controller

func (*UserController) Create

func (uc *UserController) Create(w http.ResponseWriter, r *http.Request)

Create will create a new user

func (*UserController) CreateFirstAdmin

func (uc *UserController) CreateFirstAdmin(w http.ResponseWriter, r *http.Request)

CreateFirstAdmin will only create the first admin, requires no auth

func (*UserController) Delete

func (uc *UserController) Delete(w http.ResponseWriter, r *http.Request)

Delete deletes the given uid user

func (*UserController) GetAll

func (uc *UserController) GetAll(w http.ResponseWriter, r *http.Request)

GetAll returns the list of all users (no usernames)

func (*UserController) GetAllDetailed

func (uc *UserController) GetAllDetailed(w http.ResponseWriter, r *http.Request)

GetAllDetailed returns the list of all users with all details

func (*UserController) GetByID

func (uc *UserController) GetByID(w http.ResponseWriter, r *http.Request)

GetByID returns the basic user info for the given uid

func (*UserController) GetByIDDetailed

func (uc *UserController) GetByIDDetailed(w http.ResponseWriter, r *http.Request)

GetByIDDetailed returns all user info for the given uid

func (*UserController) HelloWorld

func (uc *UserController) HelloWorld(w http.ResponseWriter, r *http.Request)

HelloWorld is the response used on pings

func (*UserController) Profile

func (uc *UserController) Profile(w http.ResponseWriter, r *http.Request)

Profile will return the current user's UID for the given bearer token

func (*UserController) Update

func (uc *UserController) Update(w http.ResponseWriter, r *http.Request)

Update updates the given uid user's info

Jump to

Keyboard shortcuts

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