handler

package
v0.0.0-...-d6c69a8 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2020 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UserIDCtxKey = &contextKey{"User_id"}
	UserCtxKey   = &contextKey{"User"}
	PageCtxKey   = &contextKey{"Pagination"}
)

Common ctx key.

View Source
var (
	ErrInvalidUserID    = errors.New("INVALID_USER_ID")
	ErrMissingReqFields = errors.New("MISSING_REQUEST_FIELDS")
	ErrInvalidRole      = errors.New("INVALID_ROLE")
)

common error message

Functions

func AcceptDonation

func AcceptDonation(
	repo interface {
		model.HasAcceptDonation
		model.HasCreateOrUpdateStock
	},
) http.HandlerFunc

AcceptDonation accepts donation by given id.

func AuthMiddleware

func AuthMiddleware(next http.Handler) http.Handler

AuthMiddleware to handle request jwt token

func ConfirmPasswordReset

func ConfirmPasswordReset(repo interface {
	model.HasConfirmPasswordResetRequest
}) http.HandlerFunc

ConfirmPasswordReset confirms password reset request.

func CreateAllocation

CreateAllocation creates new allocation.

func CreateItem

func CreateItem(repo interface{ model.HasCreateItem }) http.HandlerFunc

CreateItem creates new item.

func CreateOrUpdateDonation

func CreateOrUpdateDonation(repo interface {
	model.HasCreateOrUpdateDonation
}, action string) http.HandlerFunc

CreateOrUpdateDonation return donations

func CreateOrUpdateStock

func CreateOrUpdateStock(repo interface{ model.HasCreateOrUpdateStock }) http.HandlerFunc

CreateOrUpdateStock creates or updates stock.

func CreateRequest

func CreateRequest(repo interface{ model.HasCreateRequest }) http.HandlerFunc

CreateRequest handles request creation

func CreateRequestItemAllocation

func CreateRequestItemAllocation(repo interface {
	model.HasCreateRequestItemAllocation
}) http.HandlerFunc

CreateRequestItemAllocation create RequestItemAllocation

func CreateUnit

func CreateUnit(repo interface{ model.HasCreateUnit }) http.HandlerFunc

CreateUnit creates new unit.

func DeleteDonation

func DeleteDonation(repo interface{ model.HasDeleteDonation }) http.HandlerFunc

DeleteDonation deletes donation by given donation id.

func DeleteItem

func DeleteItem(repo interface{ model.HasDeleteItem }) http.HandlerFunc

DeleteItem deletes item by given item id.

func DeleteRequest

func DeleteRequest(repo interface{ model.HasDeleteRequest }) http.HandlerFunc

DeleteRequest deletes request by given request id.

func DeleteRequestItemAllocation

func DeleteRequestItemAllocation(repo interface {
	model.HasDeleteRequestItemAllocation
}) http.HandlerFunc

DeleteRequestItemAllocation delete RequestItemAllocation

func DeleteUnit

func DeleteUnit(repo interface{ model.HasDeleteUnit }) http.HandlerFunc

DeleteUnit deletes unit by given id.

func EditRequestItemAllocation

func EditRequestItemAllocation(repo interface {
	model.HasEditRequestItemAllocation
}) http.HandlerFunc

EditRequestItemAllocation edit RequestItemAllocation

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

ErrInvalidRequest to render invalid request error

func ErrRender

func ErrRender(err error) render.Renderer

ErrRender to render common error

func ErrUnauthorized

func ErrUnauthorized(err error) render.Renderer

ErrUnauthorized to render unathorized error

func GetAllAllocations

GetAllAllocations gets all allocations.

func GetAllDonations

func GetAllDonations(
	repo interface {
		model.HasGetAllDonations
		model.HasGetTotalDonationCount
	},
) http.HandlerFunc

GetAllDonations gets all requests.

func GetAllItem

func GetAllItem(repo interface{ model.HasGetAllItem }) http.HandlerFunc

GetAllItem gets all item.

func GetAllRequest

func GetAllRequest(
	repo interface {
		model.HasGetAllRequest
		model.HasGetTotalRequestCount
	},
) http.HandlerFunc

GetAllRequest gets all requests.

func GetAllStock

func GetAllStock(repo interface {
	model.HasGetAllStock
}) http.HandlerFunc

GetAllStock return stocks

func GetAllUnit

func GetAllUnit(repo interface{ model.HasGetAllUnit }) http.HandlerFunc

GetAllUnit gets all unit.

func GetDonation

func GetDonation(donationRepo interface{ model.HasGetDonation }) http.HandlerFunc

GetDonation handles get donation detail given id.

func GetRequest

func GetRequest(repo interface{ model.HasGetRequest }) http.HandlerFunc

GetRequest handles get request detail

func GetUserDonations

func GetUserDonations(
	repo interface {
		model.HasGetUserDonations
		model.HasGetTotalUserDonationCount
	},
) http.HandlerFunc

GetUserDonations gets all user donations.

func GetUserRequests

func GetUserRequests(
	repo interface {
		model.HasGetUserRequests
		model.HasGetTotalUserRequestCount
	},
) http.HandlerFunc

GetUserRequests gets all user requests.

func Login

func Login(repo interface{ model.HasGetUserByEmail }) http.HandlerFunc

Login handler

func PaginationCtx

func PaginationCtx(next http.Handler) http.Handler

PaginationCtx middleware is used to exctract page and size query param

func RefreshToken

func RefreshToken(w http.ResponseWriter, r *http.Request)

RefreshToken refreshes jwt token.

func Register

func Register(repo interface {
	model.HasCreateNewUser
	model.HasGetUserByEmail
}) http.HandlerFunc

Register new user handler

func ResetPassword

func ResetPassword(repo interface {
	model.HasCreatePasswordResetRequest
}) http.HandlerFunc

ResetPassword creates new password reset request.

func SendEmail

func SendEmail(subject string, body string, receiver string) error

SendEmail sends email given body and receiver.

func SendPasswordResetConfirmationMail

func SendPasswordResetConfirmationMail(userEmail string, requestID string) error

SendPasswordResetConfirmationMail sends password reset confirmation mail.

func UpdateDonation

func UpdateDonation(repo interface{ model.HasUpdateDonation }) http.HandlerFunc

UpdateDonation handles donation update

func UpdateRequest

func UpdateRequest(repo interface{ model.HasUpdateRequest }) http.HandlerFunc

UpdateRequest handles request update

func UserCtx

func UserCtx(repo interface{ model.HasGetUserByID }) func(http.Handler) http.Handler

UserCtx middleware is used to extract user information from jwt.

Types

type API

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

API provides application resources and handlers.

func NewAPI

func NewAPI(db *sql.DB) *API

NewAPI configures and returns application API.

func (*API) Cmd

func (api *API) Cmd(args []string)

Cmd handles command from terminal.

func (*API) Router

func (api *API) Router() *chi.Mux

Router provides application routes.

type AllocationDataPage

type AllocationDataPage struct {
	Data  []*model.AllocationData `boil:"data" json:"data"`
	Pages *Page                   `boil:"pages" json:"pages"`
}

AllocationDataPage struct

type AllocationResource

AllocationResource struct

type AuthResource

type AuthResource struct {
	*model.UserDatastore
	*model.PasswordResetRequestDatastore
}

AuthResource holds user data store information.

type ConfirmResetPasswordRequest

type ConfirmResetPasswordRequest struct {
	NewPassword string `json:"newPassword"`
}

ConfirmResetPasswordRequest struct

func (*ConfirmResetPasswordRequest) Bind

Bind ConfirmResetPasswordRequest (newPassword) [Required]

type CreateAllocationRequest

type CreateAllocationRequest struct {
	RequestID       string                     `json:"requestID"`
	Date            time.Time                  `json:"date"`
	PhotoURL        string                     `json:"photoURL"`
	AllocationItems models.AllocationItemSlice `json:"items"`
}

CreateAllocationRequest struct

func (*CreateAllocationRequest) Bind

func (req *CreateAllocationRequest) Bind(r *http.Request) error

Bind CreateAllocationRequest ([]AllocationItem) [Required]

type CreateDonationRequest

type CreateDonationRequest struct {
	DonationItems []*models.DonationItem `json:"donationItems"`
}

CreateDonationRequest struct

func (*CreateDonationRequest) Bind

func (req *CreateDonationRequest) Bind(r *http.Request) error

Bind RegisterRequest ([]RequestItem) [Required]

type CreateItemRequest

type CreateItemRequest struct {
	*models.Item
}

CreateItemRequest struct

func (*CreateItemRequest) Bind

func (req *CreateItemRequest) Bind(r *http.Request) error

Bind CreateItemRequest (name) [Required]

type CreateRequestRequest

type CreateRequestRequest struct {
	RequestItems models.RequestItemSlice `json:"requestItems"`
}

CreateRequestRequest struct

func (*CreateRequestRequest) Bind

func (req *CreateRequestRequest) Bind(r *http.Request) error

Bind RegisterRequest ([]RequestItem) [Required]

type CreateUnitRequest

type CreateUnitRequest struct {
	*models.Unit
}

CreateUnitRequest struct

func (*CreateUnitRequest) Bind

func (req *CreateUnitRequest) Bind(r *http.Request) error

Bind CreateUnitRequest (name) [Required]

type DonationDataPage

type DonationDataPage struct {
	Data  []*model.DonationData `boil:"data" json:"data"`
	Pages *Page                 `boil:"pages" json:"pages"`
}

DonationDataPage struct

type DonationResource

type DonationResource struct {
	*model.DonationDataStore
	*model.UserDatastore
	*model.StockDataStore
}

DonationResource struct

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"`
	HTTPStatusCode int   `json:"-"`

	StatusText string `json:"status"`
	AppCode    int64  `json:"code,omitempty"`
	ErrorText  string `json:"error,omitempty"`
}

ErrResponse contains err, http_status_code, status_text, app_code, error_text

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

Render error response

type ItemResource

type ItemResource struct {
	*model.ItemDatastore
	*model.UserDatastore
}

ItemResource holds item data store information.

type LoginRequest

type LoginRequest struct {
	*models.User
}

LoginRequest struct

func (*LoginRequest) Bind

func (req *LoginRequest) Bind(r *http.Request) error

Bind LoginRequest (Username, Password) [Required]

type LoginResponse

type LoginResponse struct {
	User *models.User `json:"user"`
	JWT  string       `json:"jwt,omitempty"`
}

LoginResponse struct

type Page

type Page struct {
	Current int  `boil:"current" json:"current"`
	Total   int  `boil:"total" json:"total"`
	First   bool `boil:"first" json:"first"`
	Last    bool `boil:"last" json:"last"`
}

Page struct

type Paging

type Paging struct {
	Page int
	Size int
}

Paging struct

func (*Paging) Offset

func (p *Paging) Offset() int

Offset returns offset.

func (*Paging) Pages

func (p *Paging) Pages(totalCount int64) *Page

Pages returns page.

type RegisterRequest

type RegisterRequest struct {
	*models.User
}

RegisterRequest struct

func (*RegisterRequest) Bind

func (req *RegisterRequest) Bind(r *http.Request) error

Bind RegisterRequest (Username, Password) [Required]

type RequestDataPage

type RequestDataPage struct {
	Data  []*model.RequestData `boil:"data" json:"data"`
	Pages *Page                `boil:"pages" json:"pages"`
}

RequestDataPage struct

type RequestResource

RequestResource holds request data store.

type ResetPasswordRequest

type ResetPasswordRequest struct {
	Email string `json:"email"`
}

ResetPasswordRequest struct

func (*ResetPasswordRequest) Bind

func (req *ResetPasswordRequest) Bind(r *http.Request) error

Bind ResetPasswordRequest (email) [Required]

type StockDataPage

type StockDataPage struct {
	Data  []*model.StockData `boil:"data" json:"data"`
	Pages *Page              `boil:"pages" json:"pages"`
}

StockDataPage struct

type StockRequest

type StockRequest struct {
	*models.Stock
}

StockRequest struct

func (*StockRequest) Bind

func (req *StockRequest) Bind(r *http.Request) error

Bind StockRequest

type StockResource

type StockResource struct {
	*model.StockDataStore
	*model.UserDatastore
}

StockResource holds stock data store information.

type UnitResource

type UnitResource struct {
	*model.UnitDatastore
	*model.UserDatastore
}

UnitResource holds unit data store information.

type UpdateDonationRequest

type UpdateDonationRequest struct {
	DonationItems models.DonationItemSlice `json:"donationItems"`
}

UpdateDonationRequest struct

func (*UpdateDonationRequest) Bind

func (req *UpdateDonationRequest) Bind(r *http.Request) error

Bind UpdateDonation ([]DonationItem) [Required]

type UpdateRequestRequest

type UpdateRequestRequest struct {
	RequestItems models.RequestItemSlice `json:"requestItems"`
}

UpdateRequestRequest struct

func (*UpdateRequestRequest) Bind

func (req *UpdateRequestRequest) Bind(r *http.Request) error

Bind UpdateRequest ([]RequestItem) [Required]

Jump to

Keyboard shortcuts

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