feat: change url structure to use short ids instead of full uuids

This commit is contained in:
Jordan Knott
2021-11-04 13:36:46 -05:00
parent f9a5007104
commit df6140a10f
32 changed files with 613 additions and 289 deletions

View File

@ -86,6 +86,7 @@ type Project struct {
CreatedAt time.Time `json:"created_at"`
Name string `json:"name"`
PublicOn sql.NullTime `json:"public_on"`
ShortID string `json:"short_id"`
}
type ProjectLabel struct {
@ -132,6 +133,7 @@ type Task struct {
Complete bool `json:"complete"`
CompletedAt sql.NullTime `json:"completed_at"`
HasTime bool `json:"has_time"`
ShortID string `json:"short_id"`
}
type TaskActivity struct {

View File

@ -12,7 +12,7 @@ import (
)
const createPersonalProject = `-- name: CreatePersonalProject :one
INSERT INTO project(team_id, created_at, name) VALUES (null, $1, $2) RETURNING project_id, team_id, created_at, name, public_on
INSERT INTO project(team_id, created_at, name) VALUES (null, $1, $2) RETURNING project_id, team_id, created_at, name, public_on, short_id
`
type CreatePersonalProjectParams struct {
@ -29,6 +29,7 @@ func (q *Queries) CreatePersonalProject(ctx context.Context, arg CreatePersonalP
&i.CreatedAt,
&i.Name,
&i.PublicOn,
&i.ShortID,
)
return i, err
}
@ -80,7 +81,7 @@ func (q *Queries) CreateProjectMember(ctx context.Context, arg CreateProjectMemb
}
const createTeamProject = `-- name: CreateTeamProject :one
INSERT INTO project(team_id, created_at, name) VALUES ($1, $2, $3) RETURNING project_id, team_id, created_at, name, public_on
INSERT INTO project(team_id, created_at, name) VALUES ($1, $2, $3) RETURNING project_id, team_id, created_at, name, public_on, short_id
`
type CreateTeamProjectParams struct {
@ -98,6 +99,7 @@ func (q *Queries) CreateTeamProject(ctx context.Context, arg CreateTeamProjectPa
&i.CreatedAt,
&i.Name,
&i.PublicOn,
&i.ShortID,
)
return i, err
}
@ -135,7 +137,7 @@ func (q *Queries) DeleteProjectMember(ctx context.Context, arg DeleteProjectMemb
}
const getAllProjectsForTeam = `-- name: GetAllProjectsForTeam :many
SELECT project_id, team_id, created_at, name, public_on FROM project WHERE team_id = $1
SELECT project_id, team_id, created_at, name, public_on, short_id FROM project WHERE team_id = $1
`
func (q *Queries) GetAllProjectsForTeam(ctx context.Context, teamID uuid.UUID) ([]Project, error) {
@ -153,6 +155,7 @@ func (q *Queries) GetAllProjectsForTeam(ctx context.Context, teamID uuid.UUID) (
&i.CreatedAt,
&i.Name,
&i.PublicOn,
&i.ShortID,
); err != nil {
return nil, err
}
@ -168,7 +171,7 @@ func (q *Queries) GetAllProjectsForTeam(ctx context.Context, teamID uuid.UUID) (
}
const getAllTeamProjects = `-- name: GetAllTeamProjects :many
SELECT project_id, team_id, created_at, name, public_on FROM project WHERE team_id IS NOT null
SELECT project_id, team_id, created_at, name, public_on, short_id FROM project WHERE team_id IS NOT null
`
func (q *Queries) GetAllTeamProjects(ctx context.Context) ([]Project, error) {
@ -186,6 +189,7 @@ func (q *Queries) GetAllTeamProjects(ctx context.Context) ([]Project, error) {
&i.CreatedAt,
&i.Name,
&i.PublicOn,
&i.ShortID,
); err != nil {
return nil, err
}
@ -201,7 +205,7 @@ func (q *Queries) GetAllTeamProjects(ctx context.Context) ([]Project, error) {
}
const getAllVisibleProjectsForUserID = `-- name: GetAllVisibleProjectsForUserID :many
SELECT project.project_id, project.team_id, project.created_at, project.name, project.public_on FROM project LEFT JOIN
SELECT project.project_id, project.team_id, project.created_at, project.name, project.public_on, project.short_id FROM project LEFT JOIN
project_member ON project_member.project_id = project.project_id WHERE project_member.user_id = $1
`
@ -220,6 +224,7 @@ func (q *Queries) GetAllVisibleProjectsForUserID(ctx context.Context, userID uui
&i.CreatedAt,
&i.Name,
&i.PublicOn,
&i.ShortID,
); err != nil {
return nil, err
}
@ -298,7 +303,7 @@ func (q *Queries) GetMemberProjectIDsForUserID(ctx context.Context, userID uuid.
}
const getPersonalProjectsForUserID = `-- name: GetPersonalProjectsForUserID :many
SELECT project.project_id, project.team_id, project.created_at, project.name, project.public_on FROM project
SELECT project.project_id, project.team_id, project.created_at, project.name, project.public_on, project.short_id FROM project
LEFT JOIN personal_project ON personal_project.project_id = project.project_id
WHERE personal_project.user_id = $1
`
@ -318,6 +323,7 @@ func (q *Queries) GetPersonalProjectsForUserID(ctx context.Context, userID uuid.
&i.CreatedAt,
&i.Name,
&i.PublicOn,
&i.ShortID,
); err != nil {
return nil, err
}
@ -333,7 +339,7 @@ func (q *Queries) GetPersonalProjectsForUserID(ctx context.Context, userID uuid.
}
const getProjectByID = `-- name: GetProjectByID :one
SELECT project_id, team_id, created_at, name, public_on FROM project WHERE project_id = $1
SELECT project_id, team_id, created_at, name, public_on, short_id FROM project WHERE project_id = $1
`
func (q *Queries) GetProjectByID(ctx context.Context, projectID uuid.UUID) (Project, error) {
@ -345,10 +351,22 @@ func (q *Queries) GetProjectByID(ctx context.Context, projectID uuid.UUID) (Proj
&i.CreatedAt,
&i.Name,
&i.PublicOn,
&i.ShortID,
)
return i, err
}
const getProjectIDByShortID = `-- name: GetProjectIDByShortID :one
SELECT project_id FROM project WHERE short_id = $1
`
func (q *Queries) GetProjectIDByShortID(ctx context.Context, shortID string) (uuid.UUID, error) {
row := q.db.QueryRowContext(ctx, getProjectIDByShortID, shortID)
var project_id uuid.UUID
err := row.Scan(&project_id)
return project_id, err
}
const getProjectMemberInvitedIDByEmail = `-- name: GetProjectMemberInvitedIDByEmail :one
SELECT email, invited_on, project_member_invited_id FROM user_account_invited AS uai
inner join project_member_invited AS pmi
@ -489,7 +507,7 @@ func (q *Queries) GetUserRolesForProject(ctx context.Context, arg GetUserRolesFo
}
const setPublicOn = `-- name: SetPublicOn :one
UPDATE project SET public_on = $2 WHERE project_id = $1 RETURNING project_id, team_id, created_at, name, public_on
UPDATE project SET public_on = $2 WHERE project_id = $1 RETURNING project_id, team_id, created_at, name, public_on, short_id
`
type SetPublicOnParams struct {
@ -506,6 +524,7 @@ func (q *Queries) SetPublicOn(ctx context.Context, arg SetPublicOnParams) (Proje
&i.CreatedAt,
&i.Name,
&i.PublicOn,
&i.ShortID,
)
return i, err
}
@ -535,7 +554,7 @@ func (q *Queries) UpdateProjectMemberRole(ctx context.Context, arg UpdateProject
}
const updateProjectNameByID = `-- name: UpdateProjectNameByID :one
UPDATE project SET name = $2 WHERE project_id = $1 RETURNING project_id, team_id, created_at, name, public_on
UPDATE project SET name = $2 WHERE project_id = $1 RETURNING project_id, team_id, created_at, name, public_on, short_id
`
type UpdateProjectNameByIDParams struct {
@ -552,6 +571,7 @@ func (q *Queries) UpdateProjectNameByID(ctx context.Context, arg UpdateProjectNa
&i.CreatedAt,
&i.Name,
&i.PublicOn,
&i.ShortID,
)
return i, err
}

View File

@ -94,6 +94,7 @@ type Querier interface {
GetNotifiedByID(ctx context.Context, notifiedID uuid.UUID) (GetNotifiedByIDRow, error)
GetPersonalProjectsForUserID(ctx context.Context, userID uuid.UUID) ([]Project, error)
GetProjectByID(ctx context.Context, projectID uuid.UUID) (Project, error)
GetProjectIDByShortID(ctx context.Context, shortID string) (uuid.UUID, error)
GetProjectIDForTask(ctx context.Context, taskID uuid.UUID) (uuid.UUID, error)
GetProjectIDForTaskChecklist(ctx context.Context, taskChecklistID uuid.UUID) (uuid.UUID, error)
GetProjectIDForTaskChecklistItem(ctx context.Context, taskChecklistItemID uuid.UUID) (uuid.UUID, error)
@ -119,6 +120,7 @@ type Querier interface {
GetTaskChecklistsForTask(ctx context.Context, taskID uuid.UUID) ([]TaskChecklist, error)
GetTaskGroupByID(ctx context.Context, taskGroupID uuid.UUID) (TaskGroup, error)
GetTaskGroupsForProject(ctx context.Context, projectID uuid.UUID) ([]TaskGroup, error)
GetTaskIDByShortID(ctx context.Context, shortID string) (uuid.UUID, error)
GetTaskLabelByID(ctx context.Context, taskLabelID uuid.UUID) (TaskLabel, error)
GetTaskLabelForTaskByProjectLabelID(ctx context.Context, arg GetTaskLabelForTaskByProjectLabelIDParams) (TaskLabel, error)
GetTaskLabelsForTaskID(ctx context.Context, taskID uuid.UUID) ([]TaskLabel, error)

View File

@ -1,6 +1,9 @@
-- name: GetAllTeamProjects :many
SELECT * FROM project WHERE team_id IS NOT null;
-- name: GetProjectIDByShortID :one
SELECT project_id FROM project WHERE short_id = $1;
-- name: GetAllProjectsForTeam :many
SELECT * FROM project WHERE team_id = $1;

View File

@ -4,6 +4,9 @@ SELECT * FROM task_watcher WHERE user_id = $1 AND task_id = $2;
-- name: CreateTaskWatcher :one
INSERT INTO task_watcher (user_id, task_id, watched_at) VALUES ($1, $2, $3) RETURNING *;
-- name: GetTaskIDByShortID :one
SELECT task_id FROM task WHERE short_id = $1;
-- name: DeleteTaskWatcher :exec
DELETE FROM task_watcher WHERE user_id = $1 AND task_id = $2;
@ -54,7 +57,7 @@ SELECT project_id FROM task
WHERE task_id = $1;
-- name: GetProjectInfoForTask :one
SELECT project.project_id, project.name FROM task
SELECT project.short_id AS project_short_id, project.name, task.short_id AS task_short_id FROM task
INNER JOIN task_group ON task_group.task_group_id = task.task_group_id
INNER JOIN project ON task_group.project_id = project.project_id
WHERE task_id = $1;

View File

@ -14,7 +14,7 @@ import (
const createTask = `-- name: CreateTask :one
INSERT INTO task (task_group_id, created_at, name, position)
VALUES($1, $2, $3, $4) RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time
VALUES($1, $2, $3, $4) RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id
`
type CreateTaskParams struct {
@ -43,13 +43,14 @@ func (q *Queries) CreateTask(ctx context.Context, arg CreateTaskParams) (Task, e
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
)
return i, err
}
const createTaskAll = `-- name: CreateTaskAll :one
INSERT INTO task (task_group_id, created_at, name, position, description, complete, due_date)
VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time
VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id
`
type CreateTaskAllParams struct {
@ -84,6 +85,7 @@ func (q *Queries) CreateTaskAll(ctx context.Context, arg CreateTaskAllParams) (T
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
)
return i, err
}
@ -197,7 +199,7 @@ func (q *Queries) DeleteTasksByTaskGroupID(ctx context.Context, taskGroupID uuid
}
const getAllTasks = `-- name: GetAllTasks :many
SELECT task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time FROM task
SELECT task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id FROM task
`
func (q *Queries) GetAllTasks(ctx context.Context) ([]Task, error) {
@ -220,6 +222,7 @@ func (q *Queries) GetAllTasks(ctx context.Context) ([]Task, error) {
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
); err != nil {
return nil, err
}
@ -235,7 +238,7 @@ func (q *Queries) GetAllTasks(ctx context.Context) ([]Task, error) {
}
const getAssignedTasksDueDateForUserID = `-- name: GetAssignedTasksDueDateForUserID :many
SELECT task.task_id, task.task_group_id, task.created_at, task.name, task.position, task.description, task.due_date, task.complete, task.completed_at, task.has_time FROM task_assigned
SELECT task.task_id, task.task_group_id, task.created_at, task.name, task.position, task.description, task.due_date, task.complete, task.completed_at, task.has_time, task.short_id FROM task_assigned
INNER JOIN task ON task.task_id = task_assigned.task_id
INNER JOIN task_group ON task_group.task_group_id = task.task_group_id
WHERE user_id = $1
@ -279,6 +282,7 @@ func (q *Queries) GetAssignedTasksDueDateForUserID(ctx context.Context, arg GetA
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
); err != nil {
return nil, err
}
@ -294,7 +298,7 @@ func (q *Queries) GetAssignedTasksDueDateForUserID(ctx context.Context, arg GetA
}
const getAssignedTasksProjectForUserID = `-- name: GetAssignedTasksProjectForUserID :many
SELECT task.task_id, task.task_group_id, task.created_at, task.name, task.position, task.description, task.due_date, task.complete, task.completed_at, task.has_time FROM task_assigned
SELECT task.task_id, task.task_group_id, task.created_at, task.name, task.position, task.description, task.due_date, task.complete, task.completed_at, task.has_time, task.short_id FROM task_assigned
INNER JOIN task ON task.task_id = task_assigned.task_id
INNER JOIN task_group ON task_group.task_group_id = task.task_group_id
WHERE user_id = $1
@ -338,6 +342,7 @@ func (q *Queries) GetAssignedTasksProjectForUserID(ctx context.Context, arg GetA
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
); err != nil {
return nil, err
}
@ -446,26 +451,27 @@ func (q *Queries) GetProjectIdMappings(ctx context.Context, dollar_1 []uuid.UUID
}
const getProjectInfoForTask = `-- name: GetProjectInfoForTask :one
SELECT project.project_id, project.name FROM task
SELECT project.short_id AS project_short_id, project.name, task.short_id AS task_short_id FROM task
INNER JOIN task_group ON task_group.task_group_id = task.task_group_id
INNER JOIN project ON task_group.project_id = project.project_id
WHERE task_id = $1
`
type GetProjectInfoForTaskRow struct {
ProjectID uuid.UUID `json:"project_id"`
Name string `json:"name"`
ProjectShortID string `json:"project_short_id"`
Name string `json:"name"`
TaskShortID string `json:"task_short_id"`
}
func (q *Queries) GetProjectInfoForTask(ctx context.Context, taskID uuid.UUID) (GetProjectInfoForTaskRow, error) {
row := q.db.QueryRowContext(ctx, getProjectInfoForTask, taskID)
var i GetProjectInfoForTaskRow
err := row.Scan(&i.ProjectID, &i.Name)
err := row.Scan(&i.ProjectShortID, &i.Name, &i.TaskShortID)
return i, err
}
const getRecentlyAssignedTaskForUserID = `-- name: GetRecentlyAssignedTaskForUserID :many
SELECT task.task_id, task.task_group_id, task.created_at, task.name, task.position, task.description, task.due_date, task.complete, task.completed_at, task.has_time FROM task_assigned INNER JOIN
SELECT task.task_id, task.task_group_id, task.created_at, task.name, task.position, task.description, task.due_date, task.complete, task.completed_at, task.has_time, task.short_id FROM task_assigned INNER JOIN
task ON task.task_id = task_assigned.task_id WHERE user_id = $1
AND $4::boolean = true OR (
$4::boolean = false AND complete = $2 AND (
@ -507,6 +513,7 @@ func (q *Queries) GetRecentlyAssignedTaskForUserID(ctx context.Context, arg GetR
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
); err != nil {
return nil, err
}
@ -522,7 +529,7 @@ func (q *Queries) GetRecentlyAssignedTaskForUserID(ctx context.Context, arg GetR
}
const getTaskByID = `-- name: GetTaskByID :one
SELECT task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time FROM task WHERE task_id = $1
SELECT task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id FROM task WHERE task_id = $1
`
func (q *Queries) GetTaskByID(ctx context.Context, taskID uuid.UUID) (Task, error) {
@ -539,10 +546,22 @@ func (q *Queries) GetTaskByID(ctx context.Context, taskID uuid.UUID) (Task, erro
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
)
return i, err
}
const getTaskIDByShortID = `-- name: GetTaskIDByShortID :one
SELECT task_id FROM task WHERE short_id = $1
`
func (q *Queries) GetTaskIDByShortID(ctx context.Context, shortID string) (uuid.UUID, error) {
row := q.db.QueryRowContext(ctx, getTaskIDByShortID, shortID)
var task_id uuid.UUID
err := row.Scan(&task_id)
return task_id, err
}
const getTaskWatcher = `-- name: GetTaskWatcher :one
SELECT task_watcher_id, task_id, user_id, watched_at FROM task_watcher WHERE user_id = $1 AND task_id = $2
`
@ -565,7 +584,7 @@ func (q *Queries) GetTaskWatcher(ctx context.Context, arg GetTaskWatcherParams)
}
const getTasksForTaskGroupID = `-- name: GetTasksForTaskGroupID :many
SELECT task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time FROM task WHERE task_group_id = $1
SELECT task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id FROM task WHERE task_group_id = $1
`
func (q *Queries) GetTasksForTaskGroupID(ctx context.Context, taskGroupID uuid.UUID) ([]Task, error) {
@ -588,6 +607,7 @@ func (q *Queries) GetTasksForTaskGroupID(ctx context.Context, taskGroupID uuid.U
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
); err != nil {
return nil, err
}
@ -603,7 +623,7 @@ func (q *Queries) GetTasksForTaskGroupID(ctx context.Context, taskGroupID uuid.U
}
const setTaskComplete = `-- name: SetTaskComplete :one
UPDATE task SET complete = $2, completed_at = $3 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time
UPDATE task SET complete = $2, completed_at = $3 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id
`
type SetTaskCompleteParams struct {
@ -626,6 +646,7 @@ func (q *Queries) SetTaskComplete(ctx context.Context, arg SetTaskCompleteParams
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
)
return i, err
}
@ -656,7 +677,7 @@ func (q *Queries) UpdateTaskComment(ctx context.Context, arg UpdateTaskCommentPa
}
const updateTaskDescription = `-- name: UpdateTaskDescription :one
UPDATE task SET description = $2 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time
UPDATE task SET description = $2 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id
`
type UpdateTaskDescriptionParams struct {
@ -678,12 +699,13 @@ func (q *Queries) UpdateTaskDescription(ctx context.Context, arg UpdateTaskDescr
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
)
return i, err
}
const updateTaskDueDate = `-- name: UpdateTaskDueDate :one
UPDATE task SET due_date = $2, has_time = $3 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time
UPDATE task SET due_date = $2, has_time = $3 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id
`
type UpdateTaskDueDateParams struct {
@ -706,12 +728,13 @@ func (q *Queries) UpdateTaskDueDate(ctx context.Context, arg UpdateTaskDueDatePa
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
)
return i, err
}
const updateTaskLocation = `-- name: UpdateTaskLocation :one
UPDATE task SET task_group_id = $2, position = $3 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time
UPDATE task SET task_group_id = $2, position = $3 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id
`
type UpdateTaskLocationParams struct {
@ -734,12 +757,13 @@ func (q *Queries) UpdateTaskLocation(ctx context.Context, arg UpdateTaskLocation
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
)
return i, err
}
const updateTaskName = `-- name: UpdateTaskName :one
UPDATE task SET name = $2 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time
UPDATE task SET name = $2 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id
`
type UpdateTaskNameParams struct {
@ -761,12 +785,13 @@ func (q *Queries) UpdateTaskName(ctx context.Context, arg UpdateTaskNameParams)
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
)
return i, err
}
const updateTaskPosition = `-- name: UpdateTaskPosition :one
UPDATE task SET position = $2 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time
UPDATE task SET position = $2 WHERE task_id = $1 RETURNING task_id, task_group_id, created_at, name, position, description, due_date, complete, completed_at, has_time, short_id
`
type UpdateTaskPositionParams struct {
@ -788,6 +813,7 @@ func (q *Queries) UpdateTaskPosition(ctx context.Context, arg UpdateTaskPosition
&i.Complete,
&i.CompletedAt,
&i.HasTime,
&i.ShortID,
)
return i, err
}