userv1

package
v0.0.0-...-8051343 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound         = errors.New(MessageNotFound)
	ErrWrongPassword    = errors.New(MessageWrongPassword)
	ErrAlreadyExists    = errors.New(MessageAlreadyExists)
	ErrValidationFailed = errors.New(MessageValidationFailed)
)
View Source
var (
	MessageSuccess          = "Success"
	MessageInternalError    = "Internal server error"
	MessageFailedDecodeJSON = "Failed to decode JSON"
)
View Source
var (
	MessageNotFound         = "User not found"
	MessageWrongPassword    = "Wrong password"
	MessageAlreadyExists    = "User already exists"
	MessageValidationFailed = "Validation failed"
	MessageMustAbove18      = "Age must above 18"
)
View Source
var (
	MinName = 3
	MaxName = 50

	MinUsername = 3
	MaxUsername = 30
)
View Source
var SexList = []interface{}{Male, Female}

Functions

func Translate

func Translate(lang string)

Types

type Handler

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

func NewHandler

func NewHandler(cfg config.AppConfig, service Service) *Handler

func (*Handler) CreateUser

func (h *Handler) CreateUser(w http.ResponseWriter, r *http.Request)

func (*Handler) Login

func (h *Handler) Login(w http.ResponseWriter, r *http.Request)

type Repository

type Repository interface {
	Create(ctx context.Context, user *User) (err error)
	GetByUsername(ctx context.Context, username string) (user User, err error)
}

func NewRepository

func NewRepository(db *sql.DB) Repository

type Service

type Service interface {
	Create(ctx context.Context, payload UserCreatePayload) (resp UserAuthentication, err error)
	Login(ctx context.Context, payload UserLoginPayload) (resp UserAuthentication, err error)
}

func NewService

func NewService(cfg config.AppConfig, repository Repository) Service

type Sex

type Sex string
const (
	Male   Sex = "male"
	Female Sex = "female"
)

type User

type User struct {
	ID             uint64    `json:"-"`
	UID            string    `json:"uid"`
	Name           string    `json:"name"`
	Email          string    `json:"email"`
	Username       string    `json:"username"`
	HashedPassword *string   `json:"-"`
	Sex            Sex       `json:"sex"`
	Birthdate      time.Time `json:"birthdate"`
	Verified       bool      `json:"verified"`
	MaxSwipes      int       `json:"maxs_swipes"`
	CreatedAt      time.Time `json:"created_at"`
}

type UserAuthentication

type UserAuthentication struct {
	Token string `json:"token"`
}

type UserAuthenticationResponse

type UserAuthenticationResponse struct {
	servicebase.ResponseBody
	Data *UserAuthentication `json:"data,omitempty"`
}

type UserCreatePayload

type UserCreatePayload struct {
	Name       string `json:"name"`
	Email      string `json:"email"`
	Username   string `json:"username"`
	Password   string `json:"password"`
	Sex        Sex    `json:"sex"`
	Birthdate  string `json:"birthdate"`
	TimeLayout string `json:"-"`
}

func (UserCreatePayload) NewLayoutDateOnly

func (p UserCreatePayload) NewLayoutDateOnly() UserCreatePayload

func (UserCreatePayload) Validate

func (p UserCreatePayload) Validate() error

type UserLoginPayload

type UserLoginPayload struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

func (UserLoginPayload) Validate

func (p UserLoginPayload) Validate() error

type UserResponse

type UserResponse struct {
	servicebase.ResponseBody
	Data *User `json:"data,omitempty"`
}

Jump to

Keyboard shortcuts

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