Create a new tasks module with full CRUD operations, supporting both regular tasks and etapes (phases). Implements task hierarchy with parent-child relationships, assignees, and due dates. Includes database schema with validation triggers, SQLC query generation, in-memory repository implementation, HTTP handlers, view templates, and comprehensive test coverage.
619 lines
13 KiB
Go
619 lines
13 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: queries.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const clearTaskChildrenParent = `-- name: ClearTaskChildrenParent :execrows
|
|
UPDATE public.tasks
|
|
SET parent_task_id = NULL, updated_at = now()
|
|
WHERE parent_task_id = $1
|
|
AND owner_id = $2
|
|
AND deleted_at IS NULL
|
|
`
|
|
|
|
type ClearTaskChildrenParentParams struct {
|
|
ParentTaskID pgtype.UUID `db:"parent_task_id"`
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
}
|
|
|
|
func (q *Queries) ClearTaskChildrenParent(ctx context.Context, arg ClearTaskChildrenParentParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, clearTaskChildrenParent, arg.ParentTaskID, arg.OwnerID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const createAuthUser = `-- name: CreateAuthUser :one
|
|
INSERT INTO auth.users (
|
|
id,
|
|
email,
|
|
encrypted_password,
|
|
raw_user_meta_data,
|
|
created_at,
|
|
updated_at
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
jsonb_build_object('display_name', $4::text),
|
|
now(),
|
|
now()
|
|
)
|
|
RETURNING id
|
|
`
|
|
|
|
type CreateAuthUserParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Email string `db:"email"`
|
|
EncryptedPassword string `db:"encrypted_password"`
|
|
DisplayName string `db:"display_name"`
|
|
}
|
|
|
|
func (q *Queries) CreateAuthUser(ctx context.Context, arg CreateAuthUserParams) (uuid.UUID, error) {
|
|
row := q.db.QueryRow(ctx, createAuthUser,
|
|
arg.ID,
|
|
arg.Email,
|
|
arg.EncryptedPassword,
|
|
arg.DisplayName,
|
|
)
|
|
var id uuid.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const createSession = `-- name: CreateSession :exec
|
|
INSERT INTO auth.sessions (
|
|
id,
|
|
session_token,
|
|
user_id,
|
|
created_at,
|
|
updated_at,
|
|
expires_at
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
now(),
|
|
now(),
|
|
$4
|
|
)
|
|
`
|
|
|
|
type CreateSessionParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
SessionToken string `db:"session_token"`
|
|
UserID uuid.UUID `db:"user_id"`
|
|
ExpiresAt pgtype.Timestamptz `db:"expires_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) error {
|
|
_, err := q.db.Exec(ctx, createSession,
|
|
arg.ID,
|
|
arg.SessionToken,
|
|
arg.UserID,
|
|
arg.ExpiresAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const createTablo = `-- name: CreateTablo :one
|
|
INSERT INTO public.tablos (
|
|
id,
|
|
owner_id,
|
|
name,
|
|
color,
|
|
status,
|
|
created_at,
|
|
updated_at
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
now(),
|
|
now()
|
|
)
|
|
RETURNING id, owner_id, name, color, status, created_at, updated_at, deleted_at
|
|
`
|
|
|
|
type CreateTabloParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
Name string `db:"name"`
|
|
Color string `db:"color"`
|
|
Status string `db:"status"`
|
|
}
|
|
|
|
func (q *Queries) CreateTablo(ctx context.Context, arg CreateTabloParams) (Tablo, error) {
|
|
row := q.db.QueryRow(ctx, createTablo,
|
|
arg.ID,
|
|
arg.OwnerID,
|
|
arg.Name,
|
|
arg.Color,
|
|
arg.Status,
|
|
)
|
|
var i Tablo
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.OwnerID,
|
|
&i.Name,
|
|
&i.Color,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createTask = `-- name: CreateTask :one
|
|
INSERT INTO public.tasks (
|
|
id,
|
|
tablo_id,
|
|
owner_id,
|
|
title,
|
|
description,
|
|
status,
|
|
assignee_id,
|
|
is_etape,
|
|
parent_task_id,
|
|
due_date,
|
|
created_at,
|
|
updated_at
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
now(),
|
|
now()
|
|
)
|
|
RETURNING id, tablo_id, owner_id, title, description, status, assignee_id, is_etape, parent_task_id, due_date, created_at, updated_at, deleted_at
|
|
`
|
|
|
|
type CreateTaskParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
TabloID uuid.UUID `db:"tablo_id"`
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
Title string `db:"title"`
|
|
Description string `db:"description"`
|
|
Status string `db:"status"`
|
|
AssigneeID pgtype.UUID `db:"assignee_id"`
|
|
IsEtape bool `db:"is_etape"`
|
|
ParentTaskID pgtype.UUID `db:"parent_task_id"`
|
|
DueDate pgtype.Date `db:"due_date"`
|
|
}
|
|
|
|
func (q *Queries) CreateTask(ctx context.Context, arg CreateTaskParams) (Task, error) {
|
|
row := q.db.QueryRow(ctx, createTask,
|
|
arg.ID,
|
|
arg.TabloID,
|
|
arg.OwnerID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Status,
|
|
arg.AssigneeID,
|
|
arg.IsEtape,
|
|
arg.ParentTaskID,
|
|
arg.DueDate,
|
|
)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TabloID,
|
|
&i.OwnerID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Status,
|
|
&i.AssigneeID,
|
|
&i.IsEtape,
|
|
&i.ParentTaskID,
|
|
&i.DueDate,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteSessionByToken = `-- name: DeleteSessionByToken :execrows
|
|
DELETE FROM auth.sessions
|
|
WHERE session_token = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteSessionByToken(ctx context.Context, sessionToken string) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteSessionByToken, sessionToken)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const getAuthUserByEmail = `-- name: GetAuthUserByEmail :one
|
|
SELECT id, email, encrypted_password, created_at, updated_at
|
|
FROM auth.users
|
|
WHERE email = $1
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetAuthUserByEmailRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Email string `db:"email"`
|
|
EncryptedPassword string `db:"encrypted_password"`
|
|
CreatedAt pgtype.Timestamptz `db:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `db:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetAuthUserByEmail(ctx context.Context, email string) (GetAuthUserByEmailRow, error) {
|
|
row := q.db.QueryRow(ctx, getAuthUserByEmail, email)
|
|
var i GetAuthUserByEmailRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.EncryptedPassword,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPublicUserByID = `-- name: GetPublicUserByID :one
|
|
SELECT id, email, created_at, updated_at, display_name
|
|
FROM public.users
|
|
WHERE id = $1
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetPublicUserByID(ctx context.Context, id uuid.UUID) (User, error) {
|
|
row := q.db.QueryRow(ctx, getPublicUserByID, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DisplayName,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getSessionByToken = `-- name: GetSessionByToken :one
|
|
SELECT id, session_token, user_id, created_at, updated_at, expires_at
|
|
FROM auth.sessions
|
|
WHERE session_token = $1
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetSessionByToken(ctx context.Context, sessionToken string) (AuthSession, error) {
|
|
row := q.db.QueryRow(ctx, getSessionByToken, sessionToken)
|
|
var i AuthSession
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SessionToken,
|
|
&i.UserID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getTaskByID = `-- name: GetTaskByID :one
|
|
SELECT id, tablo_id, owner_id, title, description, status, assignee_id, is_etape, parent_task_id, due_date, created_at, updated_at, deleted_at
|
|
FROM public.tasks
|
|
WHERE id = $1
|
|
AND owner_id = $2
|
|
AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetTaskByIDParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
}
|
|
|
|
func (q *Queries) GetTaskByID(ctx context.Context, arg GetTaskByIDParams) (Task, error) {
|
|
row := q.db.QueryRow(ctx, getTaskByID, arg.ID, arg.OwnerID)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TabloID,
|
|
&i.OwnerID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Status,
|
|
&i.AssigneeID,
|
|
&i.IsEtape,
|
|
&i.ParentTaskID,
|
|
&i.DueDate,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listTablos = `-- name: ListTablos :many
|
|
SELECT id, owner_id, name, color, status, created_at, updated_at, deleted_at
|
|
FROM public.tablos
|
|
WHERE owner_id = $1
|
|
AND deleted_at IS NULL
|
|
AND (
|
|
$2::text IS NULL OR status = $2::text
|
|
)
|
|
AND (
|
|
$3::text IS NULL OR name ILIKE '%' || $3::text || '%'
|
|
)
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
type ListTablosParams struct {
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
Status pgtype.Text `db:"status"`
|
|
Query pgtype.Text `db:"query"`
|
|
}
|
|
|
|
func (q *Queries) ListTablos(ctx context.Context, arg ListTablosParams) ([]Tablo, error) {
|
|
rows, err := q.db.Query(ctx, listTablos, arg.OwnerID, arg.Status, arg.Query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Tablo
|
|
for rows.Next() {
|
|
var i Tablo
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.OwnerID,
|
|
&i.Name,
|
|
&i.Color,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listTasksByOwner = `-- name: ListTasksByOwner :many
|
|
SELECT id, tablo_id, owner_id, title, description, status, assignee_id, is_etape, parent_task_id, due_date, created_at, updated_at, deleted_at
|
|
FROM public.tasks
|
|
WHERE owner_id = $1
|
|
AND deleted_at IS NULL
|
|
ORDER BY created_at ASC
|
|
`
|
|
|
|
func (q *Queries) ListTasksByOwner(ctx context.Context, ownerID uuid.UUID) ([]Task, error) {
|
|
rows, err := q.db.Query(ctx, listTasksByOwner, ownerID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Task
|
|
for rows.Next() {
|
|
var i Task
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.TabloID,
|
|
&i.OwnerID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Status,
|
|
&i.AssigneeID,
|
|
&i.IsEtape,
|
|
&i.ParentTaskID,
|
|
&i.DueDate,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listTasksByTablo = `-- name: ListTasksByTablo :many
|
|
SELECT id, tablo_id, owner_id, title, description, status, assignee_id, is_etape, parent_task_id, due_date, created_at, updated_at, deleted_at
|
|
FROM public.tasks
|
|
WHERE owner_id = $1
|
|
AND tablo_id = $2
|
|
AND deleted_at IS NULL
|
|
ORDER BY created_at ASC
|
|
`
|
|
|
|
type ListTasksByTabloParams struct {
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
TabloID uuid.UUID `db:"tablo_id"`
|
|
}
|
|
|
|
func (q *Queries) ListTasksByTablo(ctx context.Context, arg ListTasksByTabloParams) ([]Task, error) {
|
|
rows, err := q.db.Query(ctx, listTasksByTablo, arg.OwnerID, arg.TabloID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Task
|
|
for rows.Next() {
|
|
var i Task
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.TabloID,
|
|
&i.OwnerID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Status,
|
|
&i.AssigneeID,
|
|
&i.IsEtape,
|
|
&i.ParentTaskID,
|
|
&i.DueDate,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const softDeleteTablo = `-- name: SoftDeleteTablo :execrows
|
|
UPDATE public.tablos
|
|
SET deleted_at = now(), updated_at = now()
|
|
WHERE id = $1
|
|
AND owner_id = $2
|
|
AND deleted_at IS NULL
|
|
`
|
|
|
|
type SoftDeleteTabloParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
}
|
|
|
|
func (q *Queries) SoftDeleteTablo(ctx context.Context, arg SoftDeleteTabloParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, softDeleteTablo, arg.ID, arg.OwnerID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const softDeleteTask = `-- name: SoftDeleteTask :execrows
|
|
UPDATE public.tasks
|
|
SET deleted_at = now(), updated_at = now()
|
|
WHERE id = $1
|
|
AND owner_id = $2
|
|
AND deleted_at IS NULL
|
|
`
|
|
|
|
type SoftDeleteTaskParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
}
|
|
|
|
func (q *Queries) SoftDeleteTask(ctx context.Context, arg SoftDeleteTaskParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, softDeleteTask, arg.ID, arg.OwnerID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const updateTablo = `-- name: UpdateTablo :execrows
|
|
UPDATE public.tablos
|
|
SET name = $3,
|
|
color = $4,
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
AND owner_id = $2
|
|
AND deleted_at IS NULL
|
|
`
|
|
|
|
type UpdateTabloParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
Name string `db:"name"`
|
|
Color string `db:"color"`
|
|
}
|
|
|
|
func (q *Queries) UpdateTablo(ctx context.Context, arg UpdateTabloParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, updateTablo,
|
|
arg.ID,
|
|
arg.OwnerID,
|
|
arg.Name,
|
|
arg.Color,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const updateTask = `-- name: UpdateTask :one
|
|
UPDATE public.tasks
|
|
SET
|
|
title = $3,
|
|
description = $4,
|
|
status = $5,
|
|
due_date = $6,
|
|
assignee_id = $7,
|
|
parent_task_id = $8,
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
AND owner_id = $2
|
|
AND deleted_at IS NULL
|
|
RETURNING id, tablo_id, owner_id, title, description, status, assignee_id, is_etape, parent_task_id, due_date, created_at, updated_at, deleted_at
|
|
`
|
|
|
|
type UpdateTaskParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
OwnerID uuid.UUID `db:"owner_id"`
|
|
Title string `db:"title"`
|
|
Description string `db:"description"`
|
|
Status string `db:"status"`
|
|
DueDate pgtype.Date `db:"due_date"`
|
|
AssigneeID pgtype.UUID `db:"assignee_id"`
|
|
ParentTaskID pgtype.UUID `db:"parent_task_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) (Task, error) {
|
|
row := q.db.QueryRow(ctx, updateTask,
|
|
arg.ID,
|
|
arg.OwnerID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Status,
|
|
arg.DueDate,
|
|
arg.AssigneeID,
|
|
arg.ParentTaskID,
|
|
)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TabloID,
|
|
&i.OwnerID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Status,
|
|
&i.AssigneeID,
|
|
&i.IsEtape,
|
|
&i.ParentTaskID,
|
|
&i.DueDate,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
)
|
|
return i, err
|
|
}
|