pgx

package
v0.0.0-...-82802e3 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TestUser1 = &model.User{
		ID:    uuid.New(),
		Pass:  "second_password",
		Email: "testemail1@xd.ru",
	}
	TestUser2 = &model.User{
		ID:    uuid.New(),
		Pass:  "some_passwords",
		Email: "good_email2@example.com",
	}
	TestUser3 = &model.User{
		ID:    uuid.New(),
		Pass:  "some_password",
		Email: TestUser1.Email,
	}

	TestGroup1 = &model.Group{
		ID:          uuid.New(),
		Name:        "test group",
		Owner:       TestUser1.ID,
		Description: "test description",
		CreatedAt:   time.Now(),
	}
	TestGroup2 = &model.Group{
		ID:          uuid.New(),
		Name:        "another test group",
		Owner:       TestUser1.ID,
		Description: "another description",
		CreatedAt:   time.Now(),
	}

	TestToken1 = &model.Token{
		UserID:    TestUser1.ID,
		Token:     "some token",
		ExpiresAt: time.Now().UTC(),
		Expires:   true,
	}
	TestToken2 = &model.Token{
		UserID:    TestUser1.ID,
		Token:     TestToken1.Token,
		ExpiresAt: time.Now().UTC(),
		Expires:   false,
	}
	TestToken3 = &model.Token{
		UserID:    TestUser1.ID,
		Token:     "another token",
		ExpiresAt: time.Now().UTC(),
		Expires:   false,
	}

	TestInvite1 = uuid.New()
	TestInvite2 = uuid.New()

	TestRole1 = &model.Role{
		Members:  3,
		Tasks:    4,
		Reviews:  2,
		Comments: 1,
	}

	// TEST TASKS //
	TestTask1 = &model.Task{
		ID:          uuid.New(),
		Name:        uuid.NewString(),
		Description: uuid.NewString(),
		CreatedAt:   time.Now(),
		CreatedBy:   TestUser1.ID,
		Status:      "NEW",
	}
)

Functions

This section is empty.

Types

type Client

type Client interface {
	// P returns prepared pgx pool connection to database.
	P() *pgxpool.Pool
	// L returns prepared storage zap log.
	L() *zap.Logger
}

func BadCli

func BadCli(t testing.TB) Client

BadCli return client that has pool that not connected to real database.

type GroupRepository

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

GroupRepository ...

func NewGroupRepository

func NewGroupRepository(cli Client) *GroupRepository

NewGroupRepository return new instance of GroupRepository.

func (*GroupRepository) AddUser

func (repo *GroupRepository) AddUser(ctx context.Context, roleID int32, groupID, userID uuid.UUID, isAdmin bool) error

AddUser adds user to group.

func (*GroupRepository) Create

func (repo *GroupRepository) Create(ctx context.Context, group *model.Group) error

Create created new record about group.

Errors: store.ErrGroupAlreadyExists group with provided ID/Name already exists; store.ErrBadData bad foreign key to create group;

func (*GroupRepository) Get

func (repo *GroupRepository) Get(ctx context.Context, id uuid.UUID) (*model.Group, error)

Get return group by id

func (*GroupRepository) GetByUser

func (repo *GroupRepository) GetByUser(ctx context.Context, user uuid.UUID) (groups []*model.Group, err error)

GetByUser ...

func (*GroupRepository) GetRoleOfMember

func (repo *GroupRepository) GetRoleOfMember(ctx context.Context, user, group uuid.UUID) (role *model.Role, err error)

GetRoleOfMember return role of user in provided group.

func (*GroupRepository) GetUserIDs

func (repo *GroupRepository) GetUserIDs(ctx context.Context, group uuid.UUID) (ids []uuid.UUID, err error)

GetUserIDs ...

func (*GroupRepository) TaskExists

func (repo *GroupRepository) TaskExists(ctx context.Context, group, task uuid.UUID) (ok bool)

TaskExists return existence of relation between task and group.

func (*GroupRepository) UserExists

func (repo *GroupRepository) UserExists(ctx context.Context, group, user uuid.UUID) (ok bool)

UserExists ...

type InviteRepository

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

func NewInviteRepository

func NewInviteRepository(cli Client) *InviteRepository

NewInviteRepository create new invite repository that encapsulates logic to store invites.

func (*InviteRepository) Create

func (repo *InviteRepository) Create(ctx context.Context, invite uuid.UUID, role int32, group uuid.UUID, uses int) error

Create stores invite with provided data.

func (*InviteRepository) Exists

func (repo *InviteRepository) Exists(ctx context.Context, invite, group uuid.UUID) (ok bool)

Exists checks existence of invite to group with data.

func (*InviteRepository) Use

func (repo *InviteRepository) Use(ctx context.Context, invite uuid.UUID, user uuid.UUID) error

Use add user to group if invite is right.

type RoleRepository

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

func NewRoleRepository

func NewRoleRepository(cli Client) *RoleRepository

func (*RoleRepository) Create

func (repo *RoleRepository) Create(ctx context.Context, role *model.Role) error

func (*RoleRepository) Get

func (repo *RoleRepository) Get(ctx context.Context, role *model.Role) error

type Store

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

Store is implementation of storage Interface.

func New

func New(
	client Client,
	user *UserRepository,
	group *GroupRepository,
	token *TokenRepository,
	task *TaskRepository,
	invite *InviteRepository,
	role *RoleRepository,
) *Store

New ...

func (*Store) Close

func (store *Store) Close()

Close is helper function to close connection.

func (*Store) Group

func (store *Store) Group() store.GroupRepository

Group return group repository.

func (*Store) Invite

func (store *Store) Invite() store.InviteRepository

Invite return invite repository.

func (*Store) Ping

func (store *Store) Ping(ctx context.Context) error

Ping checks connection to database.

func (*Store) Role

func (store *Store) Role() store.RoleRepository

func (*Store) Task

func (store *Store) Task() store.TaskRepository

Task return task repository

func (*Store) Token

func (store *Store) Token() store.TokenRepository

Token return token repository.

func (*Store) User

func (store *Store) User() store.UserRepository

User returns user repository.

type TaskRepository

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

func NewTaskRepository

func NewTaskRepository(cli Client) *TaskRepository

NewTaskRepository return newly initialized object of task repository

func (*TaskRepository) AddToGroup

func (repo *TaskRepository) AddToGroup(ctx context.Context, task, group uuid.UUID) error

AddToGroup add relation task-group.

func (*TaskRepository) AddToUser

func (repo *TaskRepository) AddToUser(ctx context.Context, from, task, to uuid.UUID) error

AddToUser add task to user.

Arguments summary info: from - is id of user who is doing addition; task - is task id; to - is id of user who will receive task.

func (*TaskRepository) AllByGroupAndUser

func (repo *TaskRepository) AllByGroupAndUser(ctx context.Context, group uuid.UUID, user uuid.UUID) ([]*model.Task, error)

AllByGroupAndUser return all related to user tasks.

func (*TaskRepository) AllByUser

func (repo *TaskRepository) AllByUser(ctx context.Context, user uuid.UUID) ([]*model.Task, error)

AllByUser return all tasks related to user.

Task will be returned to user if this cases: * User is admin of group to which task is related; * user is related to group; * user has permission to read tasks in group where task is created.

func (*TaskRepository) Create

func (repo *TaskRepository) Create(ctx context.Context, task *model.Task) error

Create stores task model to vault.

func (*TaskRepository) Exists

func (repo *TaskRepository) Exists(ctx context.Context, id uuid.UUID) (ok bool)

Exists return existence of task with provided id.

func (*TaskRepository) ForceAddToUser

func (repo *TaskRepository) ForceAddToUser(ctx context.Context, userID, taskID uuid.UUID) error

ForceAddToUser add task to user without any permission checks in it.

func (*TaskRepository) GetByUserAndID

func (repo *TaskRepository) GetByUserAndID(ctx context.Context, user, task uuid.UUID) (*model.Task, error)

GetByUserAndID return tasks if it related to user.

Task will be returned to user if this cases: * User is admin of group to which task is related; * user is related to group; * user has permission to read tasks in group where task is created.

type TokenRepository

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

func NewTokenRepository

func NewTokenRepository(cli Client) *TokenRepository

NewTokenRepository is constructor of token repository.

func (*TokenRepository) Create

func (repo *TokenRepository) Create(ctx context.Context, token *model.Token) error

Create stores token to vault.

func (*TokenRepository) Get

func (repo *TokenRepository) Get(ctx context.Context, token string) (*model.Token, error)

Get return token with provided body.

type UserRepository

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

UserRepository ...

func NewUserRepository

func NewUserRepository(cli Client) *UserRepository

NewUserRepository ...

func (*UserRepository) AddToGroup

func (repo *UserRepository) AddToGroup(ctx context.Context, user, group uuid.UUID, r *model.Role, isAdmin bool) error

AddToGroup ...

func (*UserRepository) Create

func (repo *UserRepository) Create(
	ctx context.Context,
	u *model.User,
) error

Create creates record about user into db.

repo.RegisterUser(context.Background(), &model.User{ID: uuid.New(), Name: "name", Pass: "password"})

func (*UserRepository) Exists

func (repo *UserRepository) Exists(ctx context.Context, id string) bool

Exists checks if user exist with provided id or username. Returns boolean statement that shows existing of user.

func (*UserRepository) Get

func (repo *UserRepository) Get(ctx context.Context, id uuid.UUID) (u *model.User, err error)

Get return user by id

func (*UserRepository) GetByEmail

func (repo *UserRepository) GetByEmail(
	ctx context.Context,
	email string,
) (
	u *model.User,
	err error,
)

GetByEmail return user with provided username. If user does not exist returns store.ErrNotFound error

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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