Find returns the requested task by searching its id.
(ctx context.Context, id string)
| 83 | |
| 84 | // Find returns the requested task by searching its id. |
| 85 | func (t *Task) Find(ctx context.Context, id string) (internal.Task, error) { |
| 86 | val, err := uuid.Parse(id) |
| 87 | if err != nil { |
| 88 | return internal.Task{}, internal.WrapErrorf(err, internal.ErrorCodeInvalidArgument, "invalid uuid") |
| 89 | } |
| 90 | |
| 91 | res, err := t.q.SelectTask(ctx, val) |
| 92 | if err != nil { |
| 93 | if errors.Is(err, pgx.ErrNoRows) { |
| 94 | return internal.Task{}, internal.WrapErrorf(err, internal.ErrorCodeNotFound, "task not found") |
| 95 | } |
| 96 | |
| 97 | return internal.Task{}, internal.WrapErrorf(err, internal.ErrorCodeUnknown, "select task") |
| 98 | } |
| 99 | |
| 100 | priority, err := convertPriority(res.Priority) |
| 101 | if err != nil { |
| 102 | return internal.Task{}, internal.WrapErrorf(err, internal.ErrorCodeInvalidArgument, "convert priority") |
| 103 | } |
| 104 | |
| 105 | var dates *internal.Dates |
| 106 | if res.StartDate.Valid || res.DueDate.Valid { |
| 107 | dates = &internal.Dates{} |
| 108 | |
| 109 | if res.StartDate.Valid { |
| 110 | dates.Start = &res.StartDate.Time |
| 111 | } |
| 112 | |
| 113 | if res.DueDate.Valid { |
| 114 | dates.Due = &res.DueDate.Time |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return internal.Task{ |
| 119 | ID: res.ID.String(), |
| 120 | Description: res.Description, |
| 121 | Priority: &priority, |
| 122 | Dates: dates, |
| 123 | IsDone: res.Done, |
| 124 | }, nil |
| 125 | } |
| 126 | |
| 127 | // Update updates the existing record with new values. |
| 128 | func (t *Task) Update(ctx context.Context, id string, params internal.UpdateParams) error { |