-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecurring_event_group.go
160 lines (128 loc) · 5.99 KB
/
recurring_event_group.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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 RecurringEventGroupServicer interface {
Create(ctx context.Context, create *RecurringEventGroupCreate) (*RecurringEventGroup, *http.Response, error)
Find(ctx context.Context, opts *FindRecurringEventGroupsOptions) (*Response[[]*RecurringEventGroup], *http.Response, error)
Get(ctx context.Context, id int64) (*RecurringEventGroup, *http.Response, error)
Update(ctx context.Context, id int64, update *RecurringEventGroupUpdate) (*RecurringEventGroup, *http.Response, error)
Delete(ctx context.Context, id int64) (*http.Response, error)
}
var _ RecurringEventGroupServicer = (*RecurringEventGroupService)(nil)
type RecurringEventGroupService struct {
client *HTTPClient
}
type RecurringEventGroupSchedule struct {
ID int64 `json:"id"`
SeriesStart string `json:"series_start"`
SeriesStop string `json:"series_stop"`
EventTime string `json:"event_time"`
Physician int64 `json:"physician"`
Duration int `json:"duration"`
Repeats string `json:"repeats"`
DOWMonday bool `json:"dow_monday"`
DOWTuesday bool `json:"dow_tuesday"`
DOWWednesday bool `json:"dow_wednesday"`
DOWThursday bool `json:"dow_thursday"`
DOWFriday bool `json:"dow_friday"`
DOWSaturday bool `json:"dow_saturday"`
DOWSunday bool `json:"dow_sunday"`
Description string `json:"description"`
CreatedDate time.Time `json:"created_date"`
}
type RecurringEventGroup struct {
ID int64 `json:"id"`
Practice int64 `json:"practice"`
CreatedDate time.Time `json:"created_date"`
DeletedDate *time.Time `json:"deleted_date"`
Description string `json:"description"`
Reason string `json:"reason"`
Schedules []*RecurringEventGroupSchedule `json:"schedules"`
TimeSlotType TimeSlotType `json:"time_slot_type"`
}
type RecurringEventGroupCreate struct {
Practice int64 `json:"practice"`
Reason string `json:"reason"`
Schedules []*RecurringEventGroupSchedule `json:"schedules"`
TimeSlotType TimeSlotType `json:"time_slot_type"`
}
func (s *RecurringEventGroupService) Create(ctx context.Context, create *RecurringEventGroupCreate) (*RecurringEventGroup, *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "create recurring event group", trace.WithSpanKind(trace.SpanKindClient))
defer span.End()
out := &RecurringEventGroup{}
res, err := s.client.request(ctx, http.MethodPost, "/recurring_event_groups", nil, create, &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
}
type FindRecurringEventGroupsOptions struct {
*Pagination
Physician []int64 `url:"physician,omitempty,comma"`
Practice []int64 `url:"practice,omitempty,comma"`
Reason string `url:"reason,omitempty"`
StartDate string `url:"start_date,omitempty"`
EndDate string `url:"end_date,omitempty"`
TimeSlotType TimeSlotType `url:"time_slot_type,omitempty"`
}
func (s *RecurringEventGroupService) Find(ctx context.Context, opts *FindRecurringEventGroupsOptions) (*Response[[]*RecurringEventGroup], *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "find recurring event groups", trace.WithSpanKind(trace.SpanKindClient))
defer span.End()
out := &Response[[]*RecurringEventGroup]{}
res, err := s.client.request(ctx, http.MethodGet, "/recurring_event_groups", 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 *RecurringEventGroupService) Get(ctx context.Context, id int64) (*RecurringEventGroup, *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "get recurring event group", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.Int64("elation.recurring_event_group_id", id)))
defer span.End()
out := &RecurringEventGroup{}
res, err := s.client.request(ctx, http.MethodGet, "/recurring_event_groups/"+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
}
type RecurringEventGroupUpdate struct {
Reason string `json:"reason"`
Schedules []*RecurringEventGroupSchedule `json:"schedules"`
}
func (s *RecurringEventGroupService) Update(ctx context.Context, id int64, update *RecurringEventGroupUpdate) (*RecurringEventGroup, *http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "update recurring event group", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.Int64("elation.recurring_event_group_id", id)))
defer span.End()
out := &RecurringEventGroup{}
res, err := s.client.request(ctx, http.MethodPatch, "/recurring_event_groups/"+strconv.FormatInt(id, 10), nil, update, &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 *RecurringEventGroupService) Delete(ctx context.Context, id int64) (*http.Response, error) {
ctx, span := s.client.tracer.Start(ctx, "delete recurring event group", trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(attribute.Int64("elation.recurring_event_group_id", id)))
defer span.End()
res, err := s.client.request(ctx, http.MethodDelete, "/recurring_event_groups/"+strconv.FormatInt(id, 10), nil, nil, nil)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "error making request")
return res, fmt.Errorf("making request: %w", err)
}
return res, nil
}