Documentation ¶
Overview ¶
Package models contains the data structures and functions.
Index ¶
- Variables
- type DatabaseRepository
- func (r DatabaseRepository) CreateNewFrame(frame Frame) error
- func (r DatabaseRepository) CreateNewProject(name string, userID uuid.UUID) (*Project, error)
- func (r DatabaseRepository) CreateNewTeam(team Team) error
- func (r DatabaseRepository) CreateNewUser(auth0ID, login, avatarURL string) (*User, error)
- func (r DatabaseRepository) DeleteTeam(team *Team) error
- func (r DatabaseRepository) GetFrames(userID uuid.UUID) ([]Frame, error)
- func (r DatabaseRepository) GetFramesSince(userID uuid.UUID, date time.Time) ([]Frame, error)
- func (r DatabaseRepository) GetFramesWithQueryBuilder(qb QueryBuilder) (int, []Frame, error)
- func (r DatabaseRepository) GetProjectByID(userID, projectID uuid.UUID) (*Project, error)
- func (r DatabaseRepository) GetProjectByName(userID uuid.UUID, name string) (*Project, error)
- func (r DatabaseRepository) GetProjectWorkloads(userID, projectID uuid.UUID) (*Workloads, error)
- func (r DatabaseRepository) GetProjects(userID uuid.UUID) (Projects, error)
- func (r DatabaseRepository) GetTeamByID(teamID uuid.UUID) (*Team, error)
- func (r DatabaseRepository) GetTeamsWithUsers(userID uuid.UUID) (Teams, error)
- func (r DatabaseRepository) GetUserByAuth0ID(auth0ID string) (*User, error)
- func (r DatabaseRepository) GetUserByToken(token string) (*User, error)
- func (r DatabaseRepository) GetUsersByLoginLike(like string) (Users, error)
- func (r DatabaseRepository) UpdateTeam(team *Team) error
- type Frame
- type Project
- type Projects
- type QueryBuilder
- func (q *QueryBuilder) AddFrom(clause string) *QueryBuilder
- func (q *QueryBuilder) AddJoin(clause string) *QueryBuilder
- func (q *QueryBuilder) AddSelect(clause string) *QueryBuilder
- func (q *QueryBuilder) AddWhere(clause string, val interface{}) *QueryBuilder
- func (q *QueryBuilder) OrderBy(clause string) *QueryBuilder
- func (q *QueryBuilder) Paginate(page, limit int) *QueryBuilder
- func (q *QueryBuilder) ToCountSQL() string
- func (q *QueryBuilder) ToSQL() string
- func (q *QueryBuilder) Values() []interface{}
- type Repository
- type Team
- type TeamInput
- type Teams
- type User
- type Users
- type Workload
- type Workloads
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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.
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).
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 ¶
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 ¶
AddProject adds a project to the team and ensures unicity.
func (*Team) HasProject ¶
HasProject returns true is the team has a given project, false otherwise.
func (*Team) HasUserID ¶
HasUserID returns true if the given user id is part of the team, false otherwise.
func (*Team) SetProjects ¶
SetProjects sets the project of the team.
func (*Team) SetUserIDs ¶
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).
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 ¶
NewUser creates and returns a User instance. This function generates the initial user's API token.
func (*User) IsOwnerOfTeam ¶
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).
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).