user

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthRequest

type AuthRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

AuthRequest handles data for /auth/login

type AuthResponse

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

AuthResponse is the response DTO for the auth resource

type Repository

type Repository struct {
	DB *gorm.DB // this can be any gorm instance
}

Repository concrete type

func (Repository) Create

func (r Repository) Create(user *User) error

func (Repository) Delete

func (r Repository) Delete(id int) (err error)

func (Repository) FindAll

func (r Repository) FindAll() (users *gorm.DB, err error)

func (Repository) FindById

func (r Repository) FindById(id int) (user User, err error)

func (Repository) FindOneByEmail

func (r Repository) FindOneByEmail(email string) (user User, err error)

type Request

type Request struct {
	ID    uint   `json:"id"`
	Email string `json:"email"`
	Name  string `json:"name"`
}

UserRequest handles data for PUT/POST in /users

type Response

type Response struct {
	Email string `json:"email"`
	Name  string `json:"name"`
}

UserResponse handles data for POST in /user

type Service

type Service struct {
	Repository UserRepository
}

func (Service) CreateUser

func (s Service) CreateUser(user *User) (*Response, error)

CreateUser on app

func (Service) DeleteUser

func (s Service) DeleteUser(id int) error

func (Service) GetUserByEmail

func (s Service) GetUserByEmail(email string) (user User, err error)

func (Service) GetUserById

func (s Service) GetUserById(id int) (user User, err error)

func (Service) UpdateUser

func (s Service) UpdateUser(user *User, id int) (err error)

func (Service) UpdateUserPassword

func (s Service) UpdateUserPassword(user *User, id int) (err error)

type User

type User struct {
	gorm.Model
	Email    string `gorm:"unique_index;not null" json:"email"`
	Name     string `json:"name"`
	Password string `gorm:"not null" json:"password,omitempty"`
}

User is the model for the DB

type UserRepository

type UserRepository interface {
	FindAll() (users *gorm.DB, err error)
	FindOneByEmail(email string) (user User, err error)
	FindById(id int) (user User, err error)
	Create(user *User) error
	Delete(id int) error
}

UserRepository Contract

func NewUserRepository

func NewUserRepository() UserRepository

NewUserRepository repository postgres implementation

type UserService

type UserService interface {
	CreateUser(user *User) (*Response, error)
	UpdateUser(user *User, id int) error
	DeleteUser(id int) error
	GetUserByEmail(email string) (user User, err error)
	GetUserById(id int) (user User, err error)
}

func NewUserService

func NewUserService() (service UserService)

Jump to

Keyboard shortcuts

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