handler

package
v0.0.0-...-3978a51 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, r *http.Request, msg string, err error)

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any)

Types

type AccountHandler

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

AccountHandler is the handler for the account service

func NewAccount

func NewAccount(svc AccountService, logger *logrus.Logger, authSvc AuthService) *AccountHandler

NewAccount creates a new account handler

func (*AccountHandler) RegisterRoutes

func (h *AccountHandler) RegisterRoutes(r *http.ServeMux)

RegisterRoutes connects the handlers to the router

type AccountService

type AccountService interface {
	Create(userID int64) error
	GetAllByUserID(userID, offset, limit int64) ([]internal.Account, error)
	GetByID(userID int64, accountID int64) (internal.Account, error)
	DeleteByID(userID, accountID int64) error
	UpdateBalanceByID(userID int64, accountID int64, balance internal.USD) (internal.Account, error)
}

AccountService defines the methods that the account handler will use

type AuthHandler

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

func NewAuth

func NewAuth(svc AuthService, logger *logrus.Logger) *AuthHandler

func (*AuthHandler) RegisterRoutes

func (h *AuthHandler) RegisterRoutes(r *http.ServeMux)

type AuthService

type AuthService interface {
	// Login returns user id and jwt token
	Login(email, password string) (int64, string, error)
	// Register hashes password and saves user
	Register(u internal.User) error
	WithJWTMiddleware(handlerFunc http.HandlerFunc) http.HandlerFunc
	CreateJWT(userID int64) (string, error)
}

type BalanceUpdateRequest

type BalanceUpdateRequest struct {
	Amount internal.USD `json:"amount" validate:"required"`
}

type DataResponse

type DataResponse struct {
	Data *[]internal.User `json:"data,omitempty"`
}

type ErrorResponse

type ErrorResponse struct {
	Error       string         `json:"error,omitempty"`
	Validations map[string]any `json:"validations,omitempty"`
}

type LoginUserRequest

type LoginUserRequest struct {
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required"`
}

LoginUserRequest defines the request payload for logging in a user

type PartialUpdateUserRequest

type PartialUpdateUserRequest struct {
	FirstName string `json:"firstName"`
	LastName  string `json:"lastName"`
	Email     string `json:"email"`
	Password  string `json:"password"`
}

type RegisterUserRequest

type RegisterUserRequest struct {
	FirstName string `json:"firstName" validate:"required"`
	LastName  string `json:"lastName" validate:"required"`
	Email     string `json:"email" validate:"required,email"`
	Password  string `json:"password" validate:"required,min=8,max=64"`
}

RegisterUserRequest defines the request payload for registering a new user

type UserHandler

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

UserHandler is the handler for the user service

func NewUser

func NewUser(svc UserService, logger *logrus.Logger, authSvc AuthService) *UserHandler

NewUser creates a new user handler

func (*UserHandler) RegisterRoutes

func (h *UserHandler) RegisterRoutes(r *http.ServeMux)

RegisterRoutes connects the handlers to the router

type UserService

type UserService interface {
	GetAll(limit, offset int64) ([]internal.User, error)
	Get(id int64) (internal.User, error)
	GetByEmail(email string) (internal.User, error)
	Create(user internal.User) error
	Delete(id int64) error
	Update(id int64, user internal.User) (internal.User, error)
	PartialUpdate(id int64, user internal.User) (internal.User, error)
}

UserService defines the methods that the user handler will use

Jump to

Keyboard shortcuts

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