-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththread_member.go
76 lines (60 loc) · 2.32 KB
/
thread_member.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package elation
import (
"context"
"fmt"
"net/http"
"strconv"
"time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
type ThreadMemberServicer interface {
Find(ctx context.Context, opts *FindThreadMembersOptions) (*Response[[]*ThreadMember], *http.Response, error)
Get(ctx context.Context, id int64) (*ThreadMember, *http.Response, error)
}
var _ ThreadMemberServicer = (*ThreadMemberService)(nil)
type ThreadMemberService struct {
client *HTTPClient
}
type ThreadMember struct {
ID int64 `json:"id"` //: 346292316,
Thread int64 `json:"thread"` //: 346226779,
User *int64 `json:"user"` //: 6,
Group *int64 `json:"group"` //: null,
Status string `json:"status"` //: "Addressed",
AckTime *time.Time `json:"ack_time"` //: null
}
type FindThreadMembersOptions struct {
*Pagination
Patient []int64 `url:"patient,omitempty"`
Practice []int64 `url:"practice,omitempty"`
User []int64 `url:"user,omitempty"`
Group []int64 `url:"group,omitempty"`
Status string `url:"status,omitempty"`
AckTime time.Time `url:"ack_time,omitempty"`
}
func (s *ThreadMemberService) Find(ctx context.Context, opts *FindThreadMembersOptions) (*Response[[]*ThreadMember], *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "find thread members", trace.WithSpanKind(trace.SpanKindClient))
defer span.End()
out := &Response[[]*ThreadMember]{}
res, err := s.client.request(ctx, http.MethodGet, "/thread_members", opts, nil, &out)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "error making request")
return nil, res, fmt.Errorf("making request: %w", err)
}
return out, res, nil
}
func (s *ThreadMemberService) Get(ctx context.Context, id int64) (*ThreadMember, *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "get thread member", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.Int64("elation.thread_member_id", id)))
defer span.End()
out := &ThreadMember{}
res, err := s.client.request(ctx, http.MethodGet, "/thread_members/"+strconv.FormatInt(id, 10), nil, nil, &out)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "error making request")
return nil, res, fmt.Errorf("making request: %w", err)
}
return out, res, nil
}