MCPcopy Create free account
hub / github.com/MarioCarrion/todo-api-microservice-example / Find

Method Find

internal/postgresql/task.go:85–125  ·  view source on GitHub ↗

Find returns the requested task by searching its id.

(ctx context.Context, id string)

Source from the content-addressed store, hash-verified

83
84// Find returns the requested task by searching its id.
85func (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.
128func (t *Task) Update(ctx context.Context, id string, params internal.UpdateParams) error {

Callers 3

TestTask_DeleteFunction · 0.95
TestTask_FindFunction · 0.95
TestTask_UpdateFunction · 0.95

Calls 3

WrapErrorfFunction · 0.92
convertPriorityFunction · 0.85
SelectTaskMethod · 0.80

Tested by 3

TestTask_DeleteFunction · 0.76
TestTask_FindFunction · 0.76
TestTask_UpdateFunction · 0.76