Fix BASE_URL config loading, add tasks/projects; robust .env path resolution
- Config: try ENV_FILE, .env, ../.env for loading; trim trailing slash from BaseURL - Log BASE_URL at server startup for verification - .env.example: document BASE_URL - Tasks, projects, tags, migrations and related API/handlers Made-with: Cursor
This commit is contained in:
687
internal/repository/tasks.sql.go
Normal file
687
internal/repository/tasks.sql.go
Normal file
@@ -0,0 +1,687 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: tasks.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const countSubtasksByStatus = `-- name: CountSubtasksByStatus :one
|
||||
SELECT
|
||||
COUNT(*) FILTER (WHERE status = 'done') AS done_count,
|
||||
COUNT(*) AS total_count
|
||||
FROM tasks
|
||||
WHERE parent_id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type CountSubtasksByStatusRow struct {
|
||||
DoneCount int64 `json:"done_count"`
|
||||
TotalCount int64 `json:"total_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountSubtasksByStatus(ctx context.Context, parentID pgtype.UUID) (CountSubtasksByStatusRow, error) {
|
||||
row := q.db.QueryRow(ctx, countSubtasksByStatus, parentID)
|
||||
var i CountSubtasksByStatusRow
|
||||
err := row.Scan(&i.DoneCount, &i.TotalCount)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createTask = `-- name: CreateTask :one
|
||||
INSERT INTO tasks (id, owner_id, title, description, status, priority, due_date, project_id, parent_id, sort_order, recurrence_rule)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||
RETURNING id, owner_id, title, description, status, priority, due_date, completed_at, created_at, updated_at, deleted_at, project_id, parent_id, sort_order, recurrence_rule
|
||||
`
|
||||
|
||||
type CreateTaskParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
Status string `json:"status"`
|
||||
Priority string `json:"priority"`
|
||||
DueDate pgtype.Timestamptz `json:"due_date"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
ParentID pgtype.UUID `json:"parent_id"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
RecurrenceRule pgtype.Text `json:"recurrence_rule"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateTask(ctx context.Context, arg CreateTaskParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, createTask,
|
||||
arg.ID,
|
||||
arg.OwnerID,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Status,
|
||||
arg.Priority,
|
||||
arg.DueDate,
|
||||
arg.ProjectID,
|
||||
arg.ParentID,
|
||||
arg.SortOrder,
|
||||
arg.RecurrenceRule,
|
||||
)
|
||||
var i Task
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getTaskByID = `-- name: GetTaskByID :one
|
||||
SELECT id, owner_id, title, description, status, priority, due_date, completed_at, created_at, updated_at, deleted_at, project_id, parent_id, sort_order, recurrence_rule FROM tasks
|
||||
WHERE id = $1 AND owner_id = $2 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetTaskByIDParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"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.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getTaskByIDForUpdate = `-- name: GetTaskByIDForUpdate :one
|
||||
SELECT id, owner_id, title, description, status, priority, due_date, completed_at, created_at, updated_at, deleted_at, project_id, parent_id, sort_order, recurrence_rule FROM tasks
|
||||
WHERE id = $1 AND owner_id = $2 AND deleted_at IS NULL
|
||||
FOR UPDATE
|
||||
`
|
||||
|
||||
type GetTaskByIDForUpdateParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTaskByIDForUpdate(ctx context.Context, arg GetTaskByIDForUpdateParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, getTaskByIDForUpdate, arg.ID, arg.OwnerID)
|
||||
var i Task
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const hardDeleteTask = `-- name: HardDeleteTask :exec
|
||||
DELETE FROM tasks WHERE id = $1 AND owner_id = $2
|
||||
`
|
||||
|
||||
type HardDeleteTaskParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) HardDeleteTask(ctx context.Context, arg HardDeleteTaskParams) error {
|
||||
_, err := q.db.Exec(ctx, hardDeleteTask, arg.ID, arg.OwnerID)
|
||||
return err
|
||||
}
|
||||
|
||||
const listSubtasks = `-- name: ListSubtasks :many
|
||||
SELECT id, owner_id, title, description, status, priority, due_date, completed_at, created_at, updated_at, deleted_at, project_id, parent_id, sort_order, recurrence_rule FROM tasks
|
||||
WHERE parent_id = $1 AND owner_id = $2 AND deleted_at IS NULL
|
||||
ORDER BY sort_order ASC, created_at ASC
|
||||
`
|
||||
|
||||
type ListSubtasksParams struct {
|
||||
ParentID pgtype.UUID `json:"parent_id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListSubtasks(ctx context.Context, arg ListSubtasksParams) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, listSubtasks, arg.ParentID, arg.OwnerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTasks = `-- name: ListTasks :many
|
||||
SELECT t.id, t.owner_id, t.title, t.description, t.status, t.priority, t.due_date, t.completed_at, t.created_at, t.updated_at, t.deleted_at, t.project_id, t.parent_id, t.sort_order, t.recurrence_rule FROM tasks t
|
||||
WHERE t.owner_id = $1
|
||||
AND t.deleted_at IS NULL
|
||||
AND t.parent_id IS NULL
|
||||
AND ($2::TEXT IS NULL OR t.status = $2::TEXT)
|
||||
AND ($3::TEXT IS NULL OR t.priority = $3::TEXT)
|
||||
AND ($4::UUID IS NULL OR t.project_id = $4::UUID)
|
||||
AND ($5::TIMESTAMPTZ IS NULL OR t.due_date >= $5::TIMESTAMPTZ)
|
||||
AND ($6::TIMESTAMPTZ IS NULL OR t.due_date <= $6::TIMESTAMPTZ)
|
||||
AND (
|
||||
$7::TIMESTAMPTZ IS NULL
|
||||
OR (t.created_at, t.id) < ($7::TIMESTAMPTZ, $8::UUID)
|
||||
)
|
||||
ORDER BY t.created_at DESC, t.id DESC
|
||||
LIMIT $9
|
||||
`
|
||||
|
||||
type ListTasksParams struct {
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
Status pgtype.Text `json:"status"`
|
||||
Priority pgtype.Text `json:"priority"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
DueFrom pgtype.Timestamptz `json:"due_from"`
|
||||
DueTo pgtype.Timestamptz `json:"due_to"`
|
||||
CursorTime pgtype.Timestamptz `json:"cursor_time"`
|
||||
CursorID pgtype.UUID `json:"cursor_id"`
|
||||
Lim int32 `json:"lim"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTasks(ctx context.Context, arg ListTasksParams) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, listTasks,
|
||||
arg.OwnerID,
|
||||
arg.Status,
|
||||
arg.Priority,
|
||||
arg.ProjectID,
|
||||
arg.DueFrom,
|
||||
arg.DueTo,
|
||||
arg.CursorTime,
|
||||
arg.CursorID,
|
||||
arg.Lim,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTasksByDueDate = `-- name: ListTasksByDueDate :many
|
||||
SELECT t.id, t.owner_id, t.title, t.description, t.status, t.priority, t.due_date, t.completed_at, t.created_at, t.updated_at, t.deleted_at, t.project_id, t.parent_id, t.sort_order, t.recurrence_rule FROM tasks t
|
||||
WHERE t.owner_id = $1
|
||||
AND t.deleted_at IS NULL
|
||||
AND t.parent_id IS NULL
|
||||
AND ($2::TEXT IS NULL OR t.status = $2::TEXT)
|
||||
AND ($3::TEXT IS NULL OR t.priority = $3::TEXT)
|
||||
AND ($4::UUID IS NULL OR t.project_id = $4::UUID)
|
||||
AND ($5::TIMESTAMPTZ IS NULL OR t.due_date >= $5::TIMESTAMPTZ)
|
||||
AND ($6::TIMESTAMPTZ IS NULL OR t.due_date <= $6::TIMESTAMPTZ)
|
||||
ORDER BY COALESCE(t.due_date, '9999-12-31'::timestamptz) ASC NULLS LAST, t.id ASC
|
||||
LIMIT $7
|
||||
`
|
||||
|
||||
type ListTasksByDueDateParams struct {
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
Status pgtype.Text `json:"status"`
|
||||
Priority pgtype.Text `json:"priority"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
DueFrom pgtype.Timestamptz `json:"due_from"`
|
||||
DueTo pgtype.Timestamptz `json:"due_to"`
|
||||
Lim int32 `json:"lim"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTasksByDueDate(ctx context.Context, arg ListTasksByDueDateParams) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, listTasksByDueDate,
|
||||
arg.OwnerID,
|
||||
arg.Status,
|
||||
arg.Priority,
|
||||
arg.ProjectID,
|
||||
arg.DueFrom,
|
||||
arg.DueTo,
|
||||
arg.Lim,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTasksByPriority = `-- name: ListTasksByPriority :many
|
||||
SELECT t.id, t.owner_id, t.title, t.description, t.status, t.priority, t.due_date, t.completed_at, t.created_at, t.updated_at, t.deleted_at, t.project_id, t.parent_id, t.sort_order, t.recurrence_rule FROM tasks t
|
||||
WHERE t.owner_id = $1
|
||||
AND t.deleted_at IS NULL
|
||||
AND t.parent_id IS NULL
|
||||
AND ($2::TEXT IS NULL OR t.status = $2::TEXT)
|
||||
AND ($3::TEXT IS NULL OR t.priority = $3::TEXT)
|
||||
AND ($4::UUID IS NULL OR t.project_id = $4::UUID)
|
||||
AND ($5::TIMESTAMPTZ IS NULL OR t.due_date >= $5::TIMESTAMPTZ)
|
||||
AND ($6::TIMESTAMPTZ IS NULL OR t.due_date <= $6::TIMESTAMPTZ)
|
||||
ORDER BY CASE t.priority
|
||||
WHEN 'critical' THEN 1
|
||||
WHEN 'high' THEN 2
|
||||
WHEN 'medium' THEN 3
|
||||
WHEN 'low' THEN 4
|
||||
ELSE 5
|
||||
END ASC, t.created_at DESC, t.id DESC
|
||||
LIMIT $7
|
||||
`
|
||||
|
||||
type ListTasksByPriorityParams struct {
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
Status pgtype.Text `json:"status"`
|
||||
Priority pgtype.Text `json:"priority"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
DueFrom pgtype.Timestamptz `json:"due_from"`
|
||||
DueTo pgtype.Timestamptz `json:"due_to"`
|
||||
Lim int32 `json:"lim"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTasksByPriority(ctx context.Context, arg ListTasksByPriorityParams) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, listTasksByPriority,
|
||||
arg.OwnerID,
|
||||
arg.Status,
|
||||
arg.Priority,
|
||||
arg.ProjectID,
|
||||
arg.DueFrom,
|
||||
arg.DueTo,
|
||||
arg.Lim,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTasksWithRecurrence = `-- name: ListTasksWithRecurrence :many
|
||||
SELECT id, owner_id, title, description, status, priority, due_date, completed_at, created_at, updated_at, deleted_at, project_id, parent_id, sort_order, recurrence_rule FROM tasks
|
||||
WHERE owner_id = $1 AND deleted_at IS NULL
|
||||
AND recurrence_rule IS NOT NULL
|
||||
AND parent_id IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) ListTasksWithRecurrence(ctx context.Context, ownerID pgtype.UUID) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, listTasksWithRecurrence, ownerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTasksWithTag = `-- name: ListTasksWithTag :many
|
||||
SELECT DISTINCT t.id, t.owner_id, t.title, t.description, t.status, t.priority, t.due_date, t.completed_at, t.created_at, t.updated_at, t.deleted_at, t.project_id, t.parent_id, t.sort_order, t.recurrence_rule FROM tasks t
|
||||
JOIN task_tags tt ON tt.task_id = t.id
|
||||
WHERE t.owner_id = $1
|
||||
AND t.deleted_at IS NULL
|
||||
AND t.parent_id IS NULL
|
||||
AND tt.tag_id = ANY($2)
|
||||
AND ($3::TEXT IS NULL OR t.status = $3::TEXT)
|
||||
AND ($4::UUID IS NULL OR t.project_id = $4::UUID)
|
||||
ORDER BY t.created_at DESC, t.id DESC
|
||||
LIMIT $5
|
||||
`
|
||||
|
||||
type ListTasksWithTagParams struct {
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
TagIds pgtype.UUID `json:"tag_ids"`
|
||||
Status pgtype.Text `json:"status"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Lim int32 `json:"lim"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTasksWithTag(ctx context.Context, arg ListTasksWithTagParams) ([]Task, error) {
|
||||
rows, err := q.db.Query(ctx, listTasksWithTag,
|
||||
arg.OwnerID,
|
||||
arg.TagIds,
|
||||
arg.Status,
|
||||
arg.ProjectID,
|
||||
arg.Lim,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Task{}
|
||||
for rows.Next() {
|
||||
var i Task
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const markTaskComplete = `-- name: MarkTaskComplete :one
|
||||
UPDATE tasks
|
||||
SET status = 'done', completed_at = now(), updated_at = now()
|
||||
WHERE id = $1 AND owner_id = $2 AND deleted_at IS NULL
|
||||
RETURNING id, owner_id, title, description, status, priority, due_date, completed_at, created_at, updated_at, deleted_at, project_id, parent_id, sort_order, recurrence_rule
|
||||
`
|
||||
|
||||
type MarkTaskCompleteParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) MarkTaskComplete(ctx context.Context, arg MarkTaskCompleteParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, markTaskComplete, arg.ID, arg.OwnerID)
|
||||
var i Task
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const markTaskUncomplete = `-- name: MarkTaskUncomplete :one
|
||||
UPDATE tasks
|
||||
SET status = COALESCE($3, 'todo'), completed_at = NULL, updated_at = now()
|
||||
WHERE id = $1 AND owner_id = $2 AND deleted_at IS NULL
|
||||
RETURNING id, owner_id, title, description, status, priority, due_date, completed_at, created_at, updated_at, deleted_at, project_id, parent_id, sort_order, recurrence_rule
|
||||
`
|
||||
|
||||
type MarkTaskUncompleteParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
NewStatus pgtype.Text `json:"new_status"`
|
||||
}
|
||||
|
||||
func (q *Queries) MarkTaskUncomplete(ctx context.Context, arg MarkTaskUncompleteParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, markTaskUncomplete, arg.ID, arg.OwnerID, arg.NewStatus)
|
||||
var i Task
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const softDeleteTask = `-- name: SoftDeleteTask :exec
|
||||
UPDATE tasks SET deleted_at = now(), updated_at = now()
|
||||
WHERE id = $1 AND owner_id = $2 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type SoftDeleteTaskParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) SoftDeleteTask(ctx context.Context, arg SoftDeleteTaskParams) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteTask, arg.ID, arg.OwnerID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateTask = `-- name: UpdateTask :one
|
||||
UPDATE tasks
|
||||
SET title = COALESCE($1, title),
|
||||
description = COALESCE($2, description),
|
||||
status = COALESCE($3, status),
|
||||
priority = COALESCE($4, priority),
|
||||
due_date = $5,
|
||||
project_id = $6,
|
||||
sort_order = COALESCE($7, sort_order),
|
||||
recurrence_rule = $8,
|
||||
updated_at = now()
|
||||
WHERE id = $9 AND owner_id = $10 AND deleted_at IS NULL
|
||||
RETURNING id, owner_id, title, description, status, priority, due_date, completed_at, created_at, updated_at, deleted_at, project_id, parent_id, sort_order, recurrence_rule
|
||||
`
|
||||
|
||||
type UpdateTaskParams struct {
|
||||
Title pgtype.Text `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
Status pgtype.Text `json:"status"`
|
||||
Priority pgtype.Text `json:"priority"`
|
||||
DueDate pgtype.Timestamptz `json:"due_date"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
SortOrder pgtype.Int4 `json:"sort_order"`
|
||||
RecurrenceRule pgtype.Text `json:"recurrence_rule"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, updateTask,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Status,
|
||||
arg.Priority,
|
||||
arg.DueDate,
|
||||
arg.ProjectID,
|
||||
arg.SortOrder,
|
||||
arg.RecurrenceRule,
|
||||
arg.ID,
|
||||
arg.OwnerID,
|
||||
)
|
||||
var i Task
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Status,
|
||||
&i.Priority,
|
||||
&i.DueDate,
|
||||
&i.CompletedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.ProjectID,
|
||||
&i.ParentID,
|
||||
&i.SortOrder,
|
||||
&i.RecurrenceRule,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user