user

package
v0.0.0-...-ebd03d0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound                 = errors.New("user not found")
	ErrWrongPassword                = errors.New("wrong password")
	ErrUserPhoneNumberAlreadyExists = errors.New("user phone number already exists")
	ErrUserEmailAlreadyExists       = errors.New("user email already exists")
	ErrUserHasEmail                 = errors.New("user already has email")
	ErrUserHasPhoneNumber           = errors.New("user already has phone number")
	ErrValidationFailed             = errors.New("validation failed")
	ErrCredentialMustExists         = errors.New("credential must be one of phone/email")
)
View Source
var (
	SortByFriendCount string = "friendCount"
	SortByCreatedAt   string = "createdAt"
)

Functions

This section is empty.

Types

type CreateUserPayload

type CreateUserPayload struct {
	CredentialType  string `json:"credentialType"`
	CredentialValue string `json:"credentialValue"`
	Name            string `json:"name"`
	Password        string `json:"password"`
}

func (CreateUserPayload) Validate

func (p CreateUserPayload) Validate() error

type Handler

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

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) CreateUser

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

func (*Handler) LinkEmail

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

func (*Handler) LinkPhoneNumber

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

func (*Handler) ListUser

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

func (*Handler) Login

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

func (*Handler) Update

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

type LinkEmailPayload

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

func (LinkEmailPayload) Validate

func (p LinkEmailPayload) Validate() error

type LinkPhoneNumberPayload

type LinkPhoneNumberPayload struct {
	Phone string `json:"phone"`
}

func (LinkPhoneNumberPayload) Validate

func (p LinkPhoneNumberPayload) Validate() error

type ListUserPayload

type ListUserPayload struct {
	OnlyFriend  bool
	UserID      string
	Search      string `schema:"search" binding:"omitempty"`
	Limit       int
	Offset      int
	SortBy      string
	OrderBy     string
	WithoutUser bool
}

type LoginPayload

type LoginPayload struct {
	CredentialType  string `json:"credentialType"`
	CredentialValue string `json:"credentialValue"`
	Password        string `json:"password"`
}

func (LoginPayload) Validate

func (p LoginPayload) Validate() error

type Repository

type Repository interface {
	CreateWithEmail(ctx context.Context, user *User) error
	CreateWithPhoneNumber(ctx context.Context, user *User) error
	GetByEmail(ctx context.Context, email string) (*User, error)
	GetByPhoneNumber(ctx context.Context, phoneNumber string) (*User, error)
	GetByID(ctx context.Context, id string) (*User, error)
	Update(ctx context.Context, user *User) error
	List(ctx context.Context, filter ListUserPayload) ([]UserListResponse, *response.Pagination, error)
}

func NewRepository

func NewRepository(db *db.DB) Repository

type Service

type Service interface {
	Create(ctx context.Context, req CreateUserPayload) (*UserRegisterResponse, error)
	Login(ctx context.Context, req LoginPayload) (*UserLoginResponse, error)
	LinkEmail(ctx context.Context, req LinkEmailPayload, userID string) error
	LinkPhoneNumber(ctx context.Context, req LinkPhoneNumberPayload, userID string) error
	Update(ctx context.Context, req UpdateUserPayload, userID string) error
	List(ctx context.Context, req ListUserPayload) ([]UserListResponse, *response.Pagination, error)
}

func NewService

func NewService(repository Repository) Service

type UpdateUserPayload

type UpdateUserPayload struct {
	ImageURL string `json:"imageUrl"`
	Name     string `json:"name"`
}

func (UpdateUserPayload) Validate

func (p UpdateUserPayload) Validate() error

type User

type User struct {
	ID             string
	Name           string
	Email          *string
	PhoneNumber    *string
	FriendCount    int
	ImageURL       *string
	HashedPassword string
	CreatedAt      time.Time
}

type UserCommentResponse

type UserCommentResponse struct {
	ID          *string `json:"userId"`
	Name        *string `json:"name"`
	ImageURL    *string `json:"imageUrl"`
	FriendCount *int    `json:"friendCount"`
}

type UserGetResponse

type UserGetResponse struct {
	ID          string    `json:"userId"`
	Name        string    `json:"name"`
	ImageURL    *string   `json:"imageUrl"`
	FriendCount int       `json:"friendCount"`
	CreatedAt   time.Time `json:"createdAt"`
}

type UserListResponse

type UserListResponse struct {
	ID          string    `json:"userId"`
	Name        string    `json:"name"`
	ImageURL    *string   `json:"imageUrl"`
	FriendCount int       `json:"friendCount"`
	CreatedAt   time.Time `json:"createdAt"`
}

type UserLoginResponse

type UserLoginResponse struct {
	Email       string `json:"email"`
	Phone       string `json:"phone"`
	Name        string `json:"name"`
	AccessToken string `json:"accessToken"`
}

type UserRegisterResponse

type UserRegisterResponse struct {
	Email       *string `json:"email,omitempty"`
	Phone       *string `json:"phone,omitempty"`
	Name        string  `json:"name"`
	AccessToken string  `json:"accessToken"`
}

Jump to

Keyboard shortcuts

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