models

package
v0.0.0-...-00c8e8d Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2018 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package models contains the data structures and functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LimitUsersToReturn is the default number of users to return.
	LimitUsersToReturn = 10
)

Functions

This section is empty.

Types

type DatabaseRepository

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

DatabaseRepository is an implementation of the `Repository` interface with a database.

func (DatabaseRepository) CreateNewFrame

func (r DatabaseRepository) CreateNewFrame(frame Frame) error

CreateNewFrame creates a new frame and persists it.

func (DatabaseRepository) CreateNewProject

func (r DatabaseRepository) CreateNewProject(name string, userID uuid.UUID) (*Project, error)

CreateNewProject creates a new project, persists it and returns it.

func (DatabaseRepository) CreateNewTeam

func (r DatabaseRepository) CreateNewTeam(team Team) error

CreateNewTeam creates a new team and persists it.

func (DatabaseRepository) CreateNewUser

func (r DatabaseRepository) CreateNewUser(auth0ID, login, avatarURL string) (*User, error)

CreateNewUser creates a new user, persists it and returns it.

func (DatabaseRepository) DeleteTeam

func (r DatabaseRepository) DeleteTeam(team *Team) error

DeleteTeam deletes a team, forever.

func (DatabaseRepository) GetFrames

func (r DatabaseRepository) GetFrames(userID uuid.UUID) ([]Frame, error)

GetFrames returns all the user's frames.

func (DatabaseRepository) GetFramesSince

func (r DatabaseRepository) GetFramesSince(userID uuid.UUID, date time.Time) ([]Frame, error)

GetFramesSince returns the user's fraces since date.

func (DatabaseRepository) GetFramesWithQueryBuilder

func (r DatabaseRepository) GetFramesWithQueryBuilder(qb QueryBuilder) (int, []Frame, error)

GetFramesWithQueryBuilder returns the frames matching the query from the QueryBuilder. It returns the number of results as first return value, then the result set paginated.

func (DatabaseRepository) GetProjectByID

func (r DatabaseRepository) GetProjectByID(userID, projectID uuid.UUID) (*Project, error)

GetProjectByID returns a project given its id and user ID.

func (DatabaseRepository) GetProjectByName

func (r DatabaseRepository) GetProjectByName(userID uuid.UUID, name string) (*Project, error)

GetProjectByName returns a project corresponding to `name`.

func (DatabaseRepository) GetProjectWorkloads

func (r DatabaseRepository) GetProjectWorkloads(userID, projectID uuid.UUID) (*Workloads, error)

GetProjectWorkloads returns a set of workloads for a given user and project.

func (DatabaseRepository) GetProjects

func (r DatabaseRepository) GetProjects(userID uuid.UUID) (Projects, error)

GetProjects returns all the user's projects.

func (DatabaseRepository) GetTeamByID

func (r DatabaseRepository) GetTeamByID(teamID uuid.UUID) (*Team, error)

GetTeamByID returns a team.

func (DatabaseRepository) GetTeamsWithUsers

func (r DatabaseRepository) GetTeamsWithUsers(userID uuid.UUID) (Teams, error)

GetTeamsWithUsers returns the user's teams.

func (DatabaseRepository) GetUserByAuth0ID

func (r DatabaseRepository) GetUserByAuth0ID(auth0ID string) (*User, error)

GetUserByAuth0ID returns a user corresponding to the given Auth0 id.

func (DatabaseRepository) GetUserByToken

func (r DatabaseRepository) GetUserByToken(token string) (*User, error)

GetUserByToken returns a user corresponding to the given API token.

func (DatabaseRepository) GetUsersByLoginLike

func (r DatabaseRepository) GetUsersByLoginLike(like string) (Users, error)

GetUsersByLoginLike returns a set of users based on the given login, it is used for autocompletion for instance.

func (DatabaseRepository) UpdateTeam

func (r DatabaseRepository) UpdateTeam(team *Team) error

UpdateTeam updates a team, and also retrieves and sets its Users.

type Frame

type Frame struct {
	ID             uuid.UUID      `db:"id" json:"id"`
	StartAt        time.Time      `db:"start_at" json:"start_at"`
	EndAt          time.Time      `db:"end_at" json:"end_at"`
	ProjectID      uuid.UUID      `db:"project_id" json:"-"`
	SynchronizedAt time.Time      `db:"synchronized_at" json:"-"`
	ProjectName    string         `db:"project_name" json:"project"`
	Tags           pq.StringArray `db:"tags" json:"tags"`
}

Frame is a data structure for representing time frames.

type Project

type Project struct {
	ID     uuid.UUID `db:"id" json:"id"`
	Name   string    `json:"name"`
	UserID uuid.UUID `db:"user_id" json:"-"`
}

Project is a structure representing a project. Usually, frames are associated to a project, and a project is owned by a user.

func NewProject

func NewProject(name string, userID uuid.UUID) *Project

NewProject creates and returns a Project instance.

type Projects

type Projects struct {
	Projects []Project `json:"projects"`
}

Projects is a structure representing a set of projects. Its purpose is mainly to ease the JSON serialization (to return a root key).

func NewProjects

func NewProjects() Projects

NewProjects returns an instance of NewProjects.

type QueryBuilder

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

QueryBuilder represents a SQL query that is built by calling functions to it.

func NewQueryBuilder

func NewQueryBuilder() QueryBuilder

NewQueryBuilder returns a new QueryBuilder.

func (*QueryBuilder) AddFrom

func (q *QueryBuilder) AddFrom(clause string) *QueryBuilder

AddFrom adds a FROM clause to the query.

func (*QueryBuilder) AddJoin

func (q *QueryBuilder) AddJoin(clause string) *QueryBuilder

AddJoin adds a JOIN clause to the query.

func (*QueryBuilder) AddSelect

func (q *QueryBuilder) AddSelect(clause string) *QueryBuilder

AddSelect adds a SELECT clause to the query.

func (*QueryBuilder) AddWhere

func (q *QueryBuilder) AddWhere(clause string, val interface{}) *QueryBuilder

AddWhere adds a WHERE clause to the query.

func (*QueryBuilder) OrderBy

func (q *QueryBuilder) OrderBy(clause string) *QueryBuilder

OrderBy adds the ORDER BY clause to the query.

func (*QueryBuilder) Paginate

func (q *QueryBuilder) Paginate(page, limit int) *QueryBuilder

Paginate adds limit and offset to the query.

func (*QueryBuilder) ToCountSQL

func (q *QueryBuilder) ToCountSQL() string

ToCountSQL returns the COUNT SQL query as a string, which does not contain any LIMIT/OFFSET, and the SELECT clause is `COUNT(*)`. This is useful to retrieve the number of results of a given query.

func (*QueryBuilder) ToSQL

func (q *QueryBuilder) ToSQL() string

ToSQL returns the resulting SQL query as a string.

func (*QueryBuilder) Values

func (q *QueryBuilder) Values() []interface{}

Values returns the parameter values of the query.

type Repository

type Repository interface {
	// GetFrames returns all the user's frames.
	GetFrames(userID uuid.UUID) ([]Frame, error)
	// GetFramesSince returns the user's fraces since date.
	GetFramesSince(userID uuid.UUID, date time.Time) ([]Frame, error)
	// CreateNewFrame creates a new frame and persists it.
	CreateNewFrame(frame Frame) error
	// GetFramesWithQueryBuilder returns the frames matching the query from the
	// QueryBuilder. It returns the number of results as first return value,
	// then the result set paginated.
	GetFramesWithQueryBuilder(qb QueryBuilder) (int, []Frame, error)

	// CreateNewProject creates a new project, persists it and returns it.
	CreateNewProject(name string, userID uuid.UUID) (*Project, error)
	// GetProjects returns all the user's projects.
	GetProjects(userID uuid.UUID) (Projects, error)
	// GetProjectByName returns a project corresponding to `name`.
	GetProjectByName(userID uuid.UUID, name string) (*Project, error)
	// GetProjectByID returns a project given its id and user ID.
	GetProjectByID(userID, projectID uuid.UUID) (*Project, error)

	// CreateNewUser creates a new user, persists it and returns it.
	CreateNewUser(auth0ID, login, avatarURL string) (*User, error)
	// GetUserByAuth0ID returns a user corresponding to the given Auth0 id.
	GetUserByAuth0ID(auth0ID string) (*User, error)
	// GetUserByToken returns a user corresponding to the given API token.
	GetUserByToken(token string) (*User, error)
	// GetUsersByLoginLike returns a set of users based on the given login, it
	// is used for autocompletion for instance.
	GetUsersByLoginLike(login string) (Users, error)

	// GetTeamsWithUsers returns the user's teams.
	GetTeamsWithUsers(userID uuid.UUID) (Teams, error)
	// CreateNewTeam creates a new team and persists it.
	CreateNewTeam(team Team) error
	// GetTeamByID returns a team.
	GetTeamByID(teamID uuid.UUID) (*Team, error)
	// UpdateTeam updates a team, and also retrieves and sets its Users.
	UpdateTeam(team *Team) error
	// DeleteTeam deletes a team, forever.
	DeleteTeam(team *Team) error

	// GetProjectWorkloads returns a set of workloads for a given user and project.
	GetProjectWorkloads(userID, projectID uuid.UUID) (*Workloads, error)
}

Repository is the main model interface, exposing all functions to manipulate the different data structures.

func NewDatabaseRepository

func NewDatabaseRepository(db *sqlx.DB) Repository

NewDatabaseRepository returns an instance of `DatabaseRepository`.

type Team

type Team struct {
	ID       uuid.UUID      `db:"id" json:"id"`
	Name     string         `db:"name" json:"name"`
	Projects pq.StringArray `db:"projects" json:"projects"`
	UserIDs  []uuid.UUID    `db:"user_ids" json:"-"`
	OwnerID  uuid.UUID      `db:"owner_id" json:"owner_id"`
	Users    []User         `db:"-" json:"users"`
}

Team is a structure representing a Crick team, i.e. a set of users and projects shared among them. NOTE: right now, projects are shared without any permission granted by the users, as soon as they have a project named that is contained into the Projects of the team.

func NewTeamFromInput

func NewTeamFromInput(in TeamInput, ownerID uuid.UUID) Team

NewTeamFromInput instanciates a new Team based on the given TeamInput. Each Team must have a User who is a owner, hence the need for a ownerID.

func (*Team) AddProject

func (t *Team) AddProject(project string)

AddProject adds a project to the team and ensures unicity.

func (*Team) AddUser

func (t *Team) AddUser(u User)

AddUser adds a given User to the team.

func (*Team) AddUserID

func (t *Team) AddUserID(ID uuid.UUID)

AddUserID adds a user ID to the team and ensures unicity.

func (*Team) HasProject

func (t *Team) HasProject(project string) bool

HasProject returns true is the team has a given project, false otherwise.

func (*Team) HasUserID

func (t *Team) HasUserID(id uuid.UUID) bool

HasUserID returns true if the given user id is part of the team, false otherwise.

func (*Team) SetProjects

func (t *Team) SetProjects(projects []string)

SetProjects sets the project of the team.

func (*Team) SetUserIDs

func (t *Team) SetUserIDs(userIDs []uuid.UUID)

SetUserIDs sets the user IDs of the team.

type TeamInput

type TeamInput struct {
	ID       uuid.UUID   `json:"id"`
	Name     string      `json:"name"`
	Projects []string    `json:"projects"`
	UserIDs  []uuid.UUID `json:"user_ids"`
}

TeamInput is a structure representing the data received by a handler when a Team is about to be created or updated. Its purpose is to unmarshal the request data into this structure.

type Teams

type Teams struct {
	Teams []Team `json:"teams"`
}

Teams is a structure representing a set of teams. Its purpose is mainly to ease the JSON serialization (to return a root key).

func NewTeams

func NewTeams() Teams

NewTeams returns an instance of NewTeams.

type User

type User struct {
	ID        uuid.UUID `db:"id" json:"id"`
	Auth0ID   string    `db:"auth0_id" json:"-"`
	Login     string    `db:"login" json:"login"`
	APIToken  string    `db:"api_token" json:"-"`
	AvatarURL string    `db:"avatar_url" json:"avatar_url"`
}

User is a structure representing a Crick user.

func NewUser

func NewUser(auth0ID, login, avatarURL string) *User

NewUser creates and returns a User instance. This function generates the initial user's API token.

func (*User) IsOwnerOfTeam

func (u *User) IsOwnerOfTeam(t Team) bool

IsOwnerOfTeam returns true if the user is owner of the given team, false otherwise.

type Users

type Users struct {
	Users []User `json:"users"`
}

Users is a structure representing a set of users. Its purpose is mainly to ease the JSON serialization (to return a root key).

func NewUsers

func NewUsers() Users

NewUsers returns an instance of NewUsers.

type Workload

type Workload struct {
	Date     time.Time `db:"date" json:"date"`
	Workload int       `db:"workload" json:"workload"`
}

Workload is a structure representing a worload by day. A workload follows a scale from 1 to 4, and gives an indication on how much work has been done that day (on a specific task).

type Workloads

type Workloads []Workload

Workloads is a set of workloads.

Jump to

Keyboard shortcuts

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