domain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MACHINERESPONSE_SUCCESS     = "success"
	MACHINERESPONSE_CREATE      = "register"
	MACHINERESPONSE_UNAVAILABLE = "unavailable"
)

Variables

View Source
var (
	ErrInternalError errHttp = errors.New("internal error, try again")

	// PARAMETER INVALID
	ErrUsernameOrPasswordInvalid errHttp = errors.New("username or password invalid")
	ErrUserAlreayExist           errHttp = errors.New("username already exists")
	ErrScopeInvalid              errHttp = errors.New("scope is not valid")
	ErrParamIdNotUuid            errHttp = errors.New("id is not a valid UUID")
	ErrPageQueryParameterInvalid errHttp = errors.New("page query parameter is not a valid integer")
	ErrInvalidParameters         errHttp = errors.New("invalid parameters")
	ErrInvalidQuery              errHttp = errors.New("invalid query")

	// ALREADY EXIST
	ErrServiceAlreayExist errHttp = errors.New("service already exists")
	ErrScopeAlreadyExist  errHttp = errors.New("scope already registered for this user")

	// AUTHORIZATION
	ErrOnlyCreatorCanChange errHttp = errors.New("only creator can change")
	ErrOnlyCreatorCanDelete errHttp = errors.New("only creator can delete")
	ErrUnauthorized         errHttp = errors.New("unauthorized")
	ErrServiceUnavailable   errHttp = errors.New("service unavailable")
	ErrUserIsNotActive      errHttp = errors.New("user is not active")
	ErrForbidden            errHttp = errors.New("forbidden")

	// NOT FOUND
	ErrNoteNotFound    errHttp = errors.New("note not found")
	ErrServiceNotFound errHttp = errors.New("service not found")
	ErrUserNotExist    errHttp = errors.New("user not exist")
	ErrMachineNotFound errHttp = errors.New("machine not found")
)

Functions

This section is empty.

Types

type AuthRequest

type AuthRequest struct {
	Username string `json:"username" validate:"required,min=3,max=50"`
	Password string `json:"password" validate:"required,min=6,max=150"`
}

type AuthResponse

type AuthResponse struct {
	Token  string `json:"access_token"`
	Type   string `json:"typen_type"`
	Expire int64  `json:"expire"`
}

type AuthUsecase

type AuthUsecase interface {
	Autenticate(c context.Context, username, password string) (*User, error)
}

type HttpError

type HttpError struct {
	Message string `json:"message"`
}

func ErrorHttpMessage

func ErrorHttpMessage(m string) *HttpError

func ErrorHttpMessageFromError

func ErrorHttpMessageFromError(err error) *HttpError

type Machine

type Machine struct {
	ID    string `db:"id"`
	Guid  string `db:"guid"`
	Name  string `db:"name"`
	OS    string `db:"os"`
	Query string `db:"query"`

	CreatedAt time.Time `db:"created_at"`
}

type MachineData

type MachineData struct {
	Guid      string `json:"guid" validate:"required,uuid"`
	Name      string `json:"name" validate:"required,max=100"`
	OS        string `json:"os" validate:"required,max=100"`
	Expire    int    `json:"expire" validate:"required"`
	ServiceId string `json:"service_id" validate:"required,uuid4"`
}

type MachineJson

type MachineJson struct {
	ID    string `json:"id"`
	Guid  string `json:"guid"`
	Name  string `json:"name"`
	OS    string `json:"os"`
	Query string `json:"query"`

	CreatedAt time.Time `json:"created_at"`
}

type MachineListQuerys

type MachineListQuerys struct {
	MachineId string `form:"machine_id" json:"machine_id" validate:"omitempty,uuid4"`
	Query     string `form:"q" json:"q" validate:"omitempty,max=100"`
	Page      int    `form:"page" json:"page" validate:"omitempty"`
	OS        string `form:"os" json:"os" validate:"omitempty,max=100"`
}

type MachineListResponse

type MachineListResponse struct {
	Total int           `json:"total"`
	Count int           `json:"count"`
	Page  int           `json:"page"`
	Data  []MachineJson `json:"data"`
}

type MachineRepository

type MachineRepository interface {
	Create(ctx context.Context, guid, name, os, query string) error
	FindByGuid(ctx context.Context, guid string) (*Machine, error)
	List(ctx context.Context, q MachineListQuerys) ([]Machine, error)
	FindById(ctx context.Context, id string) (*Machine, error)
	Count(ctx context.Context) (int, error)
	UpdateName(ctx context.Context, id, name string) error
}

type MachineRequest

type MachineRequest struct {
	Data string `json:"data" validate:"required,min=32,base64"`
}

type MachineResponse

type MachineResponse struct {
	Status          string `json:"status"`
	Message         string `json:"message"`
	Identify        string `json:"identify"`
	ServiceIdentify string `json:"service_identify"`
	Name            string `json:"name"`
}

type MachineRule

type MachineRule struct {
	MachineId string    `db:"machine_id"`
	ServiceId string    `db:"service_id"`
	Expire    int       `db:"expire"`
	CreatedAt time.Time `db:"created_at"`
}

type MachineRuleJson

type MachineRuleJson struct {
	MachineId string    `json:"machine_id"`
	ServiceId string    `json:"service_id"`
	Expire    int       `json:"expire"`
	CreatedAt time.Time `json:"created_at"`
}

type MachineUpdateNameRequest

type MachineUpdateNameRequest struct {
	Name string `json:"name" validate:"required,max=100"`
	Id   string `json:"id" validate:"required,uuid4"`
}

type MachineUsecase

type MachineUsecase interface {
	Create(ctx context.Context, md *MachineData) error
	FindByGuid(ctx context.Context, guid string) (*Machine, error)
	List(ctx context.Context, q MachineListQuerys) ([]MachineJson, error)
	Detail(ctx context.Context, id string) (*MachineJson, error)
	Count(ctx context.Context) (int, error)
	UpdateName(ctx context.Context, id, name string) error
}

type MiddleSETERequest added in v0.1.0

type MiddleSETERequest struct {
	Data string `json:"data" validate:"required"`
}

type Notes

type Notes struct {
	ID        string    `db:"id"`
	Text      string    `db:"text"`
	MachineId string    `db:"machine_id"`
	UserId    string    `db:"user_id"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

type NotesCreateRequest

type NotesCreateRequest struct {
	Text      string `json:"text" validate:"required,min=1,max=5000"`
	MachineId string `json:"machine_id" validate:"required,uuid"`
}

type NotesDeleteRequest

type NotesDeleteRequest struct {
	ID string `json:"id" validate:"required,uuid"`
}

type NotesList

type NotesList struct {
	ID        string    `db:"id"`
	Text      string    `db:"text"`
	MachineId string    `db:"machine_id"`
	UserId    string    `db:"user_id"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
	UserName  string    `db:"user_name"`
}

type NotesListJson

type NotesListJson struct {
	ID        string    `json:"id"`
	Text      string    `json:"text"`
	MachineId string    `json:"machine_id"`
	UserId    string    `json:"user_id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	UserName  string    `json:"user_name"`
}

type NotesListResponse

type NotesListResponse struct {
	Total int             `json:"total"`
	Count int             `json:"count"`
	Page  int             `json:"page"`
	Data  []NotesListJson `json:"data"`
}

type NotesRepository

type NotesRepository interface {
	Create(c context.Context, text, machineId, userId string) error
	FindById(c context.Context, id string) (Notes, error)
	ListByMachineId(c context.Context, machineId string, page int) ([]NotesList, error)
	ChangeNote(c context.Context, id, text string) error
	Delete(c context.Context, id string) error
	CountByMachineId(c context.Context, machineId string) (int, error)
}

type NotesUpdateRequest

type NotesUpdateRequest struct {
	Text string `json:"text" validate:"required"`
	ID   string `json:"id" validate:"required,uuid"`
}

type NotesUsecase

type NotesUsecase interface {
	Create(c context.Context, text, machineId, userId string) error
	ListByMachineId(c context.Context, machineId string, page int) ([]NotesListJson, error)
	ChangeNote(c context.Context, id, userId, text string) error
	Delete(c context.Context, userId, noteId string) error
	CountByMachineId(c context.Context, machineId string) (int, error)
}

type RuleActivesResponse

type RuleActivesResponse struct {
	MachineId string                `json:"machine_id"`
	Total     int                   `json:"total"`
	Data      []RuleJoinServiceJson `json:"data"`
}

type RuleCreateRequest

type RuleCreateRequest struct {
	MachineId string `json:"machine_id" validate:"required,uuid4"`
	ServiceId string `json:"service_id" validate:"required,uuid4"`
	Expire    int    `json:"expire" validate:"required,gte=0"`
}

type RuleCreateResponse

type RuleCreateResponse struct {
	MachineId string `json:"machine_id"`
	ServiceId string `json:"service_id"`
	Expire    int    `json:"expire"`
}

type RuleHistoryResponse

type RuleHistoryResponse struct {
	MachineId string            `json:"machine_id"`
	Total     int               `json:"total"`
	Count     int               `json:"count"`
	Page      int               `json:"page"`
	Data      []MachineRuleJson `json:"data"`
}

type RuleJoinService

type RuleJoinService struct {
	ServiceName string    `db:"service_name"`
	MachineId   string    `db:"machine_id"`
	ServiceId   string    `db:"service_id"`
	Expire      int       `db:"expire"`
	CreatedAt   time.Time `db:"created_at"`
}

type RuleJoinServiceJson

type RuleJoinServiceJson struct {
	ServiceName string    `json:"service_name"`
	MachineId   string    `json:"machine_id"`
	ServiceId   string    `json:"service_id"`
	Expire      int       `json:"expire"`
	CreatedAt   time.Time `json:"created_at"`
}

type RuleListResponse

type RuleListResponse struct {
	Total int                   `json:"total"`
	Count int                   `json:"count"`
	Page  int                   `json:"page"`
	Data  []RuleJoinServiceJson `json:"data"`
}

type RuleRemoveRequest

type RuleRemoveRequest struct {
	MachineId string `json:"machine_id" validate:"required,uuid4"`
	ServiceId string `json:"service_id" validate:"required,uuid4"`
}

type RuleRepository

type RuleRepository interface {
	Create(ctx context.Context, machineId, serviceId string, expire int) error
	History(ctx context.Context, machineId string, serviceId string, page int) ([]MachineRule, error)
	Count(ctx context.Context) (int, error)
	CountByMachineId(ctx context.Context, machineId string, serviceId string) (int, error)
	List(ctx context.Context, page int, onlyActives bool) ([]RuleJoinService, error)
	Invalidate(ctx context.Context, machineId, serviceId string) error
	Actives(ctx context.Context, machineId string) ([]RuleJoinService, error)
	ActiveByMachineIdAndServiceId(ctx context.Context, machineId, serviceId string) (*MachineRule, error)
	CountOnlyActives(ctx context.Context) (int, error)
}

type RuleUsecase

type RuleUsecase interface {
	Create(ctx context.Context, machineId, serviceId string, expire int) error
	History(ctx context.Context, machineId string, serviceId string, page int) ([]MachineRuleJson, error)
	Count(ctx context.Context) (int, error)
	CountByMachineId(ctx context.Context, machineId string, serviceId string) (int, error)
	List(ctx context.Context, page int, onlyActives bool) ([]RuleJoinServiceJson, error)
	Remove(ctx context.Context, machineId, serviceId string) error
	Actives(ctx context.Context, machineId string) ([]RuleJoinServiceJson, error)
	ActiveByMachineIdAndServiceId(ctx context.Context, machineId, serviceId string) (*MachineRule, error)
	CountOnlyActives(ctx context.Context) (int, error)
}

type Service

type Service struct {
	ID          string    `db:"id"`
	Name        string    `db:"name"`
	Description *string   `db:"description"`
	CreatedAt   time.Time `db:"created_at"`
}

type ServiceCreateRequest

type ServiceCreateRequest struct {
	Name        string `json:"name" validate:"required,gte=3,lte=50"`
	Description string `json:"description"`
}

type ServiceJson

type ServiceJson struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Description *string   `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
}

type ServiceListResponse

type ServiceListResponse struct {
	Count int           `json:"count"`
	Total int           `json:"total"`
	Page  int           `json:"page"`
	Data  []ServiceJson `json:"data"`
}

type ServiceRemoveRequest

type ServiceRemoveRequest struct {
	ID string `json:"id" validate:"required,uuid"`
}

type ServiceRepository

type ServiceRepository interface {
	Create(ctx context.Context, name, description string) error
	List(ctx context.Context, page int) ([]Service, error)
	Remove(ctx context.Context, id string) error
	FindByName(ctx context.Context, name string) (*Service, error)
	FindById(ctx context.Context, id string) (*Service, error)
	Count(ctx context.Context) (int, error)
}

type ServiceUsecase

type ServiceUsecase interface {
	Create(ctx context.Context, name, description string) error
	List(ctx context.Context, page int) ([]ServiceJson, error)
	Remove(ctx context.Context, id string) error
	FindByName(ctx context.Context, name string) (*Service, error)
	FindById(ctx context.Context, id string) (*Service, error)
	Count(ctx context.Context) (int, error)
}

type User

type User struct {
	ID       string   `db:"id"`
	Name     string   `db:"name"`
	Username string   `db:"username"`
	Password string   `db:"password"`
	Status   bool     `db:"status"`
	Scope    []string `db:"scope"`

	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

type UserChangePasswordRequest

type UserChangePasswordRequest struct {
	NewPassword string `json:"password" validate:"required,min=6,max=150"`
}

type UserChangePasswordResponse

type UserChangePasswordResponse struct {
	Message string `json:"message"`
}

type UserCreate

type UserCreate struct {
	Name       string
	Username   string
	Password   string
	Scope      []string
	RegisterId string
}

type UserCremoveScopeRequest

type UserCremoveScopeRequest struct {
	Scope  string `json:"scope" validate:"required"`
	UserId string `json:"user_id" validate:"required,uuid"`
}

type UserJson

type UserJson struct {
	ID       string   `json:"id"`
	Name     string   `json:"name"`
	Username string   `json:"username"`
	Status   bool     `json:"status"`
	Scope    []string `json:"scope"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type UserListResponse

type UserListResponse struct {
	Total int        `json:"total"`
	Count int        `json:"count"`
	Page  int        `json:"page"`
	Data  []UserJson `json:"data"`
}

type UserRegisterRequest

type UserRegisterRequest struct {
	Name     string `json:"name" validate:"alphanum,max=50"`
	Username string `json:"username" validate:"required,min=3,max=50"`
	Password string `json:"password" validate:"required,min=6,max=150"`
}

type UserRepository

type UserRepository interface {
	Create(c context.Context, u *User) error
	FindByUsername(c context.Context, username string) (*User, error)
	UpdatePassword(c context.Context, id, password string) error
	FindById(c context.Context, id string) (*User, error)
	List(c context.Context, page int) ([]User, error)
	AddScope(c context.Context, id, s string) error
	RemoveScope(c context.Context, id, s string) error
	ChangeStatus(c context.Context, id string) error
	Count(c context.Context) (int, error)
	Delete(c context.Context, id string) error
}

type UserUsecase

type UserUsecase interface {
	Create(c context.Context, userCreate *UserCreate) error
	FindByUsername(c context.Context, username string) (*User, error)
	FindById(c context.Context, id string) (*User, error)
	UpdatePassword(c context.Context, id, password string) error
	ExistUsername(c context.Context, username string) bool
	List(c context.Context, page int) ([]UserJson, error)
	AddScopeWithUserId(c context.Context, id, s string) error
	RemoveScopeWithUserId(c context.Context, id, s string) error
	Disable(c context.Context, id string) error
	Enable(c context.Context, id string) error
	Count(c context.Context) (int, error)
	DeleteById(c context.Context, id string) error
	DeleteByUsername(c context.Context, username string) error
}

Jump to

Keyboard shortcuts

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