domain

package
v0.0.0-...-0efd02e Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInternalServerError will throw if any the Internal Server Error happen
	ErrInternalServerError = errors.New("internal server error")
	// ErrNotFound will throw if the requested item is not exists
	ErrNotFound = errors.New("your requested item is not found")
	// ErrNoAffected will throw if no rows were affected
	ErrNoAffected = errors.New("no rows were affected")
	// ErrConflict will throw if the current action already exists
	ErrConflict = errors.New("your item already exist")
	// ErrBadParamInput will throw if the given request-body or params is not valid
	ErrBadParamInput = errors.New("given param is not valid")
	// ErrAuthenticationFailure will throw if authentication goes wrong
	ErrAuthenticationFailure = errors.New("authentication failed")
	// ErrForbidden will throw if user tries to do something that he is not
	// authorized to do
	ErrForbidden = errors.New("attempted action is not allowed")
)

Functions

func GetStatusCode

func GetStatusCode(err error, logger *zap.Logger) int

GetStatusCode gets http code from error

Types

type CreateURL

type CreateURL struct {
	ID             *string    `json:"id" validate:"omitempty,linkid,min=7,max=20"`
	Link           string     `json:"link" validate:"required,url"`
	ExpirationDate *time.Time `json:"expiration_date" validate:"omitempty,gt"`
	UserID         string     `json:"-"`
}

CreateURL represents data to create new URL

type CreateUser

type CreateUser struct {
	FullName string `json:"full_name" validate:"omitempty,max=30"`
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required,min=8,max=30"`
}

CreateUser represents data to create new User

type ResponseError

type ResponseError struct {
	Error  string                                 `json:"error"`
	Fields validator.ValidationErrorsTranslations `json:"fields,omitempty"`
}

ResponseError represent the response error struct

type URL

type URL struct {
	ID             string    `json:"id" bson:"_id"`
	Link           string    `json:"link" bson:"link"`
	ExpirationDate time.Time `json:"expiration_date" bson:"expiration_date"`
	UserID         string    `json:"user_id" bson:"user_id"`
	CreatedAt      time.Time `json:"created_at" bson:"created_at"`
	UpdatedAt      time.Time `json:"updated_at" bson:"updated_at"`
}

URL represents the URL model

type URLRepository

type URLRepository interface {
	GetByID(ctx context.Context, id string) (*URL, error)
	Update(ctx context.Context, url *URL) error
	Store(ctx context.Context, u *URL) error
	Delete(ctx context.Context, id string) error
}

URLRepository represents the URL's repository contract

type URLUsecase

type URLUsecase interface {
	GetByID(ctx context.Context, id string) (*URL, error)
	Update(ctx context.Context, updateURL UpdateURL, user *auth.Claims) error
	Store(ctx context.Context, createURL CreateURL) (*URL, error)
	Delete(ctx context.Context, id string, user *auth.Claims) error
}

URLUsecase represents the URL's usecases

type UpdateURL

type UpdateURL struct {
	ID             string    `json:"id" validate:"required,linkid,max=20"`
	ExpirationDate time.Time `json:"expiration_date" validate:"required,gt"`
}

UpdateURL represents data to update URL

type UpdateUser

type UpdateUser struct {
	ID              primitive.ObjectID `json:"id" validate:"required"`
	FullName        *string            `json:"full_name" validate:"omitempty,max=30"`
	Email           *string            `json:"email" validate:"omitempty,email"`
	CurrentPassword string             `json:"current_password" validate:"required,min=8,max=30"`
	NewPassword     *string            `json:"new_password" validate:"omitempty,min=8,max=30"`
}

UpdateUser represents data to update User

type User

type User struct {
	ID             primitive.ObjectID `json:"id" bson:"_id"`
	FullName       string             `json:"full_name" bson:"full_name"`
	Email          string             `json:"email" bson:"email"`
	HashedPassword string             `json:"-" bson:"hashed_password"`
	Roles          []string           `json:"roles" bson:"roles"`
	CreatedAt      time.Time          `json:"created_at" bson:"created_at"`
	UpdatedAt      time.Time          `json:"updated_at" bson:"updated_at"`
}

User represents the User model

type UserRepository

type UserRepository interface {
	GetByID(ctx context.Context, id primitive.ObjectID) (*User, error)
	GetByEmail(ctx context.Context, email string) (*User, error)
	Update(ctx context.Context, user *User) error
	Create(ctx context.Context, user *User) error
	Delete(ctx context.Context, id primitive.ObjectID) error
}

UserRepository represents the User's repository contract

type UserUsecase

type UserUsecase interface {
	GetByID(ctx context.Context, id string) (*User, error)
	Update(ctx context.Context, user UpdateUser, claims *auth.Claims) error
	Create(ctx context.Context, user CreateUser) (*User, error)
	Delete(ctx context.Context, id string) error
	Authenticate(ctx context.Context, now time.Time, email, password string) (*auth.Claims, error)
}

UserUsecase represents the User's usecases

Jump to

Keyboard shortcuts

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