Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gql: add field "assignedSchedules" to type "User" #3231

Merged
merged 22 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions gadb/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

148 changes: 144 additions & 4 deletions graphql2/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions graphql2/graphqlapp/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -81,14 +82,37 @@ func (q *Query) Schedule(ctx context.Context, id string) (*schedule.Schedule, er
return (*App)(q).FindOneSchedule(ctx, id)
}

func (s *Schedule) Shifts(ctx context.Context, raw *schedule.Schedule, start, end time.Time) ([]oncall.Shift, error) {
func (s *Schedule) Shifts(ctx context.Context, raw *schedule.Schedule, start, end time.Time, userIDs []string) ([]oncall.Shift, error) {
if end.Before(start) {
return nil, validation.NewFieldError("EndTime", "must be after StartTime")
}
if end.After(start.AddDate(0, 0, 50)) {
return nil, validation.NewFieldError("EndTime", "cannot be more than 50 days past StartTime")
}
return s.OnCallStore.HistoryBySchedule(ctx, raw.ID, start, end)

err := validate.ManyUUID("userID", userIDs, 50)
if err != nil {
return nil, err
}

shifts, err := s.OnCallStore.HistoryBySchedule(ctx, raw.ID, start, end)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment, but should we avoid "magic numbers" like the 50 used here and above in end.After(start.AddDate(0, 0, 50?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's an issue with most of our calls to validate.ManyUUID, so I'm going to document that for its own issue, if possible

if err != nil {
return nil, err
}

// filter by slice of userIDs if given
if userIDs != nil {
var filteredShifts []oncall.Shift
for _, shift := range shifts {
if slices.Contains(userIDs, shift.UserID) {
filteredShifts = append(filteredShifts, shift)
}
}

return filteredShifts, nil
}

return shifts, nil
}

func (s *Schedule) TemporarySchedules(ctx context.Context, raw *schedule.Schedule) ([]schedule.TemporarySchedule, error) {
Expand Down
Loading