database

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Board

type Board struct {
	Owner        BoardOwner    `json:"owner"`
	Name         string        `json:"board_name"`
	Contributors []Contributor // LoadBoardContributors() by person_id from contributor table
	Tasks        []Task
	Tags         []Tag
	ID           uint32 `json:"board_id"`
}

Board - board model struct.

func (Board) Small

func (b Board) Small() SmallBoard

Small - return SmallBoard representation of Person.

type BoardManager

type BoardManager interface {
	Create(ctx context.Context, board Board) (Board, error)
	DeleteByID(ctx context.Context, boardID uint32) error
	GetByID(ctx context.Context, boardID uint32) (Board, error)
	AddContributorToBoard(ctx context.Context, contrib Contributor, board Board) (Board, error)
	RemoveContributorFromBoard(ctx context.Context, contrib Contributor, board Board) (Board, error)
	AddTaskToBoard(ctx context.Context, task Task, board Board) (Board, error)
	RemoveTaskFromBoard(ctx context.Context, task Task, board Board) (Board, error)
	AddTagToBoard(ctx context.Context, tag Tag, board Board) (Board, error)
	RemoveTagFromBoard(ctx context.Context, tag Tag, board Board) (Board, error)
}

BoardManager - interface for interacting with board table in db.

type BoardModel

type BoardModel struct {
	DB DBConn
}

BoardModel - struct that implements BoardManager interface for interacting with board table in db.

func (BoardModel) AddContributorToBoard

func (bm BoardModel) AddContributorToBoard(ctx context.Context, contrib Contributor, board Board) (Board, error)

AddContributorToBoard - adds row in contributor table with values (person.ID, board.ID).

func (BoardModel) AddTagToBoard

func (bm BoardModel) AddTagToBoard(ctx context.Context, tag Tag, board Board) (Board, error)

AddTagToBoard - add tag to table 'tag' in db with board_id = board.ID.

func (BoardModel) AddTaskToBoard

func (bm BoardModel) AddTaskToBoard(ctx context.Context, task Task, board Board) (Board, error)

AddTaskToBoard - add task to table 'task' in db with board_id = board.ID.

func (BoardModel) Create

func (bm BoardModel) Create(ctx context.Context, board Board) (Board, error)

Create - Creates new row in table 'board'. Returning created Board.

func (BoardModel) DeleteByID

func (bm BoardModel) DeleteByID(ctx context.Context, boardID uint32) error

DeleteByID - deletes row from table 'board'.

func (BoardModel) GetByID

func (bm BoardModel) GetByID(ctx context.Context, boardID uint32) (Board, error)

GetByID - searching for board in DB by ID, returning finded Board.

func (BoardModel) RemoveContributorFromBoard

func (bm BoardModel) RemoveContributorFromBoard(ctx context.Context, contrib Contributor, board Board) (Board, error)

RemoveContributorFromBoard - removes row in contributor table with values (person.ID, board.ID).

func (BoardModel) RemoveTagFromBoard

func (bm BoardModel) RemoveTagFromBoard(ctx context.Context, tag Tag, board Board) (Board, error)

RemoveTagFromBoard - removes task from board.

func (BoardModel) RemoveTaskFromBoard

func (bm BoardModel) RemoveTaskFromBoard(ctx context.Context, task Task, board Board) (Board, error)

RemoveTaskFromBoard - removes task from board.

type BoardOwner

type BoardOwner SmallPerson

BoardOwner - other name for SmallPerson struct, used for representing board owner in Board struct.

type Contributor

type Contributor struct {
	Username  string
	FirstName string
	LastName  string
	Email     string
	ID        uint32
}

Contributor - struct that used to represent contributors(persons) in Board.Contributors field.

type DB

type DB struct {
	System SystemManager
	Person PersonManager
	Board  BoardManager
	Task   TaskManager
	Tag    TagManager
}

DB - struct for interacting with database.

func NewDB

func NewDB(dbConn DBConn) DB

NewDB - returning new initilized DB.

type DBConn

type DBConn interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
}

DBConn - interface for data models to interact with db.

type Person

type Person struct {
	Username      string       `json:"username"`
	FirstName     string       `json:"first_name"`
	LastName      string       `json:"last_name"`
	Email         string       `json:"email"`
	PasswordHash  string       `json:"password_hash"`
	Boards        []SmallBoard // LoadPersonBoards(), by board_id from contributor table
	AssignedTasks []Task       // LoadPersonAssignedTasks(), from executor_id in task
	ID            uint32       `json:"person_id"`
}

Person - person model struct.

func (*Person) IsContributor

func (p *Person) IsContributor(contrib Contributor) bool

IsContributor - checks if p of type Person represent same row from db as contrib of type Contributor.

func (Person) Small

func (p Person) Small() SmallPerson

Small - return SmallPerson representation of Person.

type PersonManager

type PersonManager interface {
	Create(ctx context.Context, person Person) (Person, error)
	DeleteByID(ctx context.Context, personID uint32) error
	GetByID(ctx context.Context, personID uint32) (Person, error)
	GetByEmail(ctx context.Context, email string) (Person, error)
	GetByUsername(ctx context.Context, username string) (Person, error)
}

PersonManager - interface for interacting with person table in db.

type PersonModel

type PersonModel struct {
	DB DBConn
}

PersonModel - struct that implements PersonManager interface for interacting with person table in db.

func (PersonModel) Create

func (pm PersonModel) Create(ctx context.Context, person Person) (Person, error)

Create - Creates new row in table 'person'. Returning created Person.

func (PersonModel) DeleteByID

func (pm PersonModel) DeleteByID(ctx context.Context, personID uint32) error

DeleteByID - deletes row from table 'person'.

func (PersonModel) GetByEmail

func (pm PersonModel) GetByEmail(ctx context.Context, email string) (Person, error)

GetByEmail - searching for person in DB by email, returning finded Person.

func (PersonModel) GetByID

func (pm PersonModel) GetByID(ctx context.Context, personID uint32) (Person, error)

GetByID - searching for person in DB by id, returning finded Person.

func (PersonModel) GetByUsername

func (pm PersonModel) GetByUsername(ctx context.Context, username string) (Person, error)

GetByUsername - searching for person in DB by username, returning finded Person.

type SmallBoard

type SmallBoard struct {
	Name  string
	Owner BoardOwner
	ID    uint32
}

SmallBoard - is a struct, that used to save board data in some other structs, when we don't need to save all board information like contributors, tasks, tags.

type SmallPerson

type SmallPerson struct {
	Username  string `json:"username"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	ID        uint32 `json:"person_id"`
}

SmallPerson - is a struct, that used to save person data in some other structs, when we don't need to save all person information like password, board, assigned tasks and other.

type Subtask

type Subtask struct {
	Name         string `json:"subtask_name"`
	ID           uint32 `json:"subtask_id"`
	ParentTaskID uint32 `json:"parent_task_id"`
}

Subtask - subtask model struct.

type SystemManager

type SystemManager interface {
	RecreateAllTables(ctx context.Context) error
	IsTableExist(ctx context.Context, tableName string) (bool, error)
}

SystemManager - interface for interacting with db structure.

type SystemModel

type SystemModel struct {
	DB DBConn
}

SystemModel - struct that implements SystemManager interface for interacting with database structure.

func (SystemModel) IsTableExist

func (sm SystemModel) IsTableExist(ctx context.Context, tableName string) (bool, error)

IsTableExist - returning `true` if table exist in 'public' scheme, else `false`.

func (SystemModel) RecreateAllTables

func (sm SystemModel) RecreateAllTables(ctx context.Context) error

RecreateAllTables - drops previously created table and creates tables required by the GoKan.

type Tag

type Tag struct {
	Name        string `json:"tag_name"`
	Description string `json:"tag_description"`
	ID          uint32 `json:"tag_id"`
	BoardID     uint32 `json:"board_id"`
}

Tag - tag model struct.

type TagManager

type TagManager interface {
	Create(ctx context.Context, tag Tag) (Tag, error)
	DeleteByID(ctx context.Context, tagID uint32) error
	GetByID(ctx context.Context, tagID uint32) (Tag, error)
}

TagManager - interface for interacting with tag table in db.

type TagModel

type TagModel struct {
	DB DBConn
}

TagModel - struct that implements TagManager interface for interacting with tag table in db.

func (TagModel) Create

func (tm TagModel) Create(ctx context.Context, tag Tag) (Tag, error)

Create - Creates new row in table 'tag'. Returning created Person.

Don't use directly, to create new tag use BoardModel.AddTagToBoard.

func (TagModel) DeleteByID

func (tm TagModel) DeleteByID(ctx context.Context, tagID uint32) error

DeleteByID - deletes row from table 'tag'.

func (TagModel) GetByID

func (tm TagModel) GetByID(ctx context.Context, tagID uint32) (Tag, error)

GetByID - searching for tag in DB by ID, returning finded Tag.

type Task

type Task struct {
	Assignees   []TaskAssignee
	Author      TaskAuthor `json:"author"`
	Name        string     `json:"task_name"`
	Description string     `json:"task_description"`
	Subtasks    []Subtask
	Tags        []Tag
	ID          uint32 `json:"task_id"`
	BoardID     uint32 `json:"board_id"`
}

Task - task model struct.

type TaskAssignee

type TaskAssignee SmallPerson

TaskAssignee - other name for SmallPerson struct, used for representing task executor in Task struct.

type TaskAuthor

type TaskAuthor SmallPerson

TaskAuthor - other name for SmallPerson struct, used for representing task author in Task struct.

type TaskManager

type TaskManager interface {
	Create(ctx context.Context, task Task) (Task, error)
	DeleteByID(ctx context.Context, taskID uint32) error
	GetByID(ctx context.Context, taskID uint32) (Task, error)
	AddTagToTask(ctx context.Context, tag Tag, task Task) (Task, error)
	RemoveTagFromTask(ctx context.Context, tag Tag, task Task) (Task, error)
	AddAssigneeToTask(ctx context.Context, assignee TaskAssignee, task Task) (Task, error)
	RemoveAssignFromTask(ctx context.Context, person TaskAssignee, task Task) (Task, error)
	AddSubtaskToTask(ctx context.Context, subtask Subtask, task Task) (Task, error)
	RemoveSubtaskFromTask(ctx context.Context, subtask Subtask, task Task) (Task, error)
}

TaskManager - interface for interacting with task table in db.

type TaskModel

type TaskModel struct {
	DB DBConn
}

TaskModel - struct that implements TaskManager interface for interacting with task table in db.

func (TaskModel) AddAssigneeToTask

func (tm TaskModel) AddAssigneeToTask(ctx context.Context, assignee TaskAssignee, task Task) (Task, error)

AddAssigneeToTask - assigning task to person in assignee table.

func (TaskModel) AddSubtaskToTask

func (tm TaskModel) AddSubtaskToTask(ctx context.Context, subtask Subtask, task Task) (Task, error)

AddSubtaskToTask - add subtask to task in subtask table.

func (TaskModel) AddTagToTask

func (tm TaskModel) AddTagToTask(ctx context.Context, tag Tag, task Task) (Task, error)

AddTagToTask - add tag to task in task_tag table.

func (TaskModel) Create

func (tm TaskModel) Create(ctx context.Context, t Task) (Task, error)

Create - Creates new row in table 'task' with values from `t` fields, Returning created Task.

Don't use directly, to create new task use BoardModel.AddTaskToBoard.

func (TaskModel) DeleteByID

func (tm TaskModel) DeleteByID(ctx context.Context, taskID uint32) error

DeleteByID - deletes row from table 'task'.

func (TaskModel) GetByID

func (tm TaskModel) GetByID(ctx context.Context, taskID uint32) (Task, error)

GetByID - searching for task with task_id=taskID, returning Task.

func (TaskModel) RemoveAssignFromTask

func (tm TaskModel) RemoveAssignFromTask(ctx context.Context, assignee TaskAssignee, task Task) (Task, error)

RemoveAssignFromTask - removes row from assignee table;.

func (TaskModel) RemoveSubtaskFromTask

func (tm TaskModel) RemoveSubtaskFromTask(ctx context.Context, subtask Subtask, task Task) (Task, error)

RemoveSubtaskFromTask - removes row from subtask table;.

func (TaskModel) RemoveTagFromTask

func (tm TaskModel) RemoveTagFromTask(ctx context.Context, tag Tag, task Task) (Task, error)

RemoveTagFromTask - removes row from task_tag table;.

Jump to

Keyboard shortcuts

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