From 7cb717dc5fd3110ed69bca688f65bd6d08388353 Mon Sep 17 00:00:00 2001 From: Oliver Braun Date: Fri, 22 May 2026 14:07:44 +0200 Subject: [PATCH 1/4] feat: Add AnnyBooking model and implement fetching and querying functionality - Introduced AnnyBooking model in graph/model/anny.go with relevant fields. - Created fetching logic for Anny bookings from the Anny API in plexams/anny.go, including pagination and room normalization. - Implemented methods for retrieving Anny bookings from the database in plexams/anny_query.go. - Added support for handling booking attributes and metadata, including status reasons and cancelable dates. --- cmd/rooms.go | 34 + db/anny_bookings.go | 96 ++ db/collection.go | 1 + graph/anny.graphqls | 29 + graph/anny.resolvers.go | 21 + graph/generated/generated.go | 2364 +++++++++++++++++++++++++++++----- graph/model/anny.go | 28 + plexams/anny.go | 432 +++++++ plexams/anny_query.go | 81 ++ 9 files changed, 2728 insertions(+), 358 deletions(-) create mode 100644 cmd/rooms.go create mode 100644 db/anny_bookings.go create mode 100644 graph/anny.graphqls create mode 100644 graph/anny.resolvers.go create mode 100644 graph/model/anny.go create mode 100644 plexams/anny.go create mode 100644 plexams/anny_query.go diff --git a/cmd/rooms.go b/cmd/rooms.go new file mode 100644 index 0000000..2fb5d9f --- /dev/null +++ b/cmd/rooms.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + roomsCmd = &cobra.Command{ + Use: "rooms [subcommand]", + Short: "get rooms", + Long: `Get rooms. +anny --- fetch bookings from anny.eu.`, + ValidArgs: []string{"anny"}, + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + p := initPlexamsConfig() + switch args[0] { + case "anny": + err := p.FetchFromAnny() + if err != nil { + panic(err) + } + default: + fmt.Println("info called with unknown sub command") + } + }, + } +) + +func init() { + rootCmd.AddCommand(roomsCmd) +} diff --git a/db/anny_bookings.go b/db/anny_bookings.go new file mode 100644 index 0000000..c643759 --- /dev/null +++ b/db/anny_bookings.go @@ -0,0 +1,96 @@ +package db + +import ( + "context" + "strings" + "time" + + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" +) + +type AnnyBooking struct { + Number string `bson:"number"` + StartDate time.Time `bson:"start_date"` + EndDate time.Time `bson:"end_date"` + BlockerStartDate time.Time `bson:"blocker_start_date"` + BlockerEndDate time.Time `bson:"blocker_end_date"` + ChargedDuration int `bson:"charged_duration"` + Description string `bson:"description"` + CreatedAt time.Time `bson:"created_at"` + UpdatedAt time.Time `bson:"updated_at"` + CanceledAt *time.Time `bson:"canceled_at,omitempty"` + Status string `bson:"status"` + StatusReason any `bson:"status_reason,omitempty"` + IsBlocker bool `bson:"is_blocker"` + CanEdit bool `bson:"can_edit"` + IsEditable bool `bson:"is_editable"` + ManuallyCreated bool `bson:"manually_created"` + Note string `bson:"note"` + Room string `bson:"room,omitempty"` + Self string `bson:"self"` + PersonalizationName string `bson:"personalization_name"` + BookingGroupID string `bson:"booking_group_identifier,omitempty"` + CancelableUntil *time.Time `bson:"cancelable_until,omitempty"` + HasCustomDescription bool `bson:"has_custom_description"` + ResourceID string `bson:"resource_id,omitempty"` +} + +func (db *DB) SaveAnnyBookings(ctx context.Context, bookings []*AnnyBooking) error { + collection := db.Client.Database(db.databaseName).Collection(collectionAnnyBookings) + + err := collection.Drop(ctx) + if err != nil { + return err + } + + entries := make([]interface{}, 0, len(bookings)) + for _, booking := range bookings { + entries = append(entries, booking) + } + + _, err = collection.InsertMany(ctx, entries) + if err != nil { + return err + } + + return nil +} + +func (db *DB) AnnyBookings(ctx context.Context, room *string) ([]*AnnyBooking, error) { + return db.annyBookings(ctx, room) +} + +func (db *DB) AllAnnyBookings(ctx context.Context) ([]*AnnyBooking, error) { + return db.annyBookings(ctx, nil) +} + +func (db *DB) annyBookings(ctx context.Context, room *string) ([]*AnnyBooking, error) { + collection := db.Client.Database(db.databaseName).Collection(collectionAnnyBookings) + + filter := bson.M{} + if room != nil && strings.TrimSpace(*room) != "" { + filter["room"] = strings.ToUpper(strings.ReplaceAll(strings.TrimSpace(*room), " ", "")) + } + + findOptions := options.Find() + findOptions.SetSort(bson.D{{Key: "start_date", Value: 1}}) + + cur, err := collection.Find(ctx, filter, findOptions) + if err != nil { + return nil, err + } + defer cur.Close(ctx) //nolint:errcheck + + bookings := make([]*AnnyBooking, 0) + if err := cur.All(ctx, &bookings); err != nil { + return nil, err + } + + return bookings, nil +} + +func (db *DB) AnnyBookingsCollection(ctx context.Context) *mongo.Collection { + return db.Client.Database(db.databaseName).Collection(collectionAnnyBookings) +} diff --git a/db/collection.go b/db/collection.go index 088fe5a..d8e8816 100644 --- a/db/collection.go +++ b/db/collection.go @@ -16,6 +16,7 @@ const ( collectionNameNTAs = "nta" collectionNamePlan = "plan" collectionNamePlanBackup = "plan_backup" + collectionAnnyBookings = "anny_bookings" collectionStudentRegsPerStudentPlanned = "studentregs_per_student_planned" collectionZpaStudents = "zpastudents" diff --git a/graph/anny.graphqls b/graph/anny.graphqls new file mode 100644 index 0000000..77c8214 --- /dev/null +++ b/graph/anny.graphqls @@ -0,0 +1,29 @@ +extend type Query { + annyBookings(room: String): [AnnyBooking!]! + allAnnyBookings: [AnnyBooking!]! +} + +type AnnyBooking { + number: String! + startDate: Time! + endDate: Time! + blockerStartDate: Time! + blockerEndDate: Time! + chargedDuration: Int! + description: String! + createdAt: Time! + updatedAt: Time! + canceledAt: Time + status: String! + isBlocker: Boolean! + canEdit: Boolean! + isEditable: Boolean! + manuallyCreated: Boolean! + note: String! + room: String + self: String! + personalizationName: String! + bookingGroupIdentifier: String + cancelableUntil: Time + hasCustomDescription: Boolean! +} diff --git a/graph/anny.resolvers.go b/graph/anny.resolvers.go new file mode 100644 index 0000000..1adfd95 --- /dev/null +++ b/graph/anny.resolvers.go @@ -0,0 +1,21 @@ +package graph + +// This file will be automatically regenerated based on the schema, any resolver implementations +// will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.76 + +import ( + "context" + + "github.com/obcode/plexams.go/graph/model" +) + +// AnnyBookings is the resolver for the annyBookings field. +func (r *queryResolver) AnnyBookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error) { + return r.plexams.AnnyBookings(ctx, room) +} + +// AllAnnyBookings is the resolver for the allAnnyBookings field. +func (r *queryResolver) AllAnnyBookings(ctx context.Context) ([]*model.AnnyBooking, error) { + return r.plexams.AllAnnyBookings(ctx) +} diff --git a/graph/generated/generated.go b/graph/generated/generated.go index fcefc80..1d4c81a 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -56,6 +56,31 @@ type ComplexityRoot struct { Ancode func(childComplexity int) int } + AnnyBooking struct { + BlockerEndDate func(childComplexity int) int + BlockerStartDate func(childComplexity int) int + BookingGroupIdentifier func(childComplexity int) int + CanEdit func(childComplexity int) int + CancelableUntil func(childComplexity int) int + CanceledAt func(childComplexity int) int + ChargedDuration func(childComplexity int) int + CreatedAt func(childComplexity int) int + Description func(childComplexity int) int + EndDate func(childComplexity int) int + HasCustomDescription func(childComplexity int) int + IsBlocker func(childComplexity int) int + IsEditable func(childComplexity int) int + ManuallyCreated func(childComplexity int) int + Note func(childComplexity int) int + Number func(childComplexity int) int + PersonalizationName func(childComplexity int) int + Room func(childComplexity int) int + Self func(childComplexity int) int + StartDate func(childComplexity int) int + Status func(childComplexity int) int + UpdatedAt func(childComplexity int) int + } + Conflict struct { AnCode func(childComplexity int) int NumberOfStuds func(childComplexity int) int @@ -371,10 +396,12 @@ type ComplexityRoot struct { } Query struct { + AllAnnyBookings func(childComplexity int) int AllProgramsInPlan func(childComplexity int) int AllSemesterNames func(childComplexity int) int AllowedSlots func(childComplexity int, ancode int) int AncodesInPlan func(childComplexity int) int + AnnyBookings func(childComplexity int, room *string) int AwkwardSlots func(childComplexity int, ancode int) int ConflictingAncodes func(childComplexity int, ancode int) int ConnectedExam func(childComplexity int, ancode int) int @@ -666,6 +693,8 @@ type QueryResolver interface { AllSemesterNames(ctx context.Context) ([]*model.Semester, error) Semester(ctx context.Context) (*model.Semester, error) SemesterConfig(ctx context.Context) (*model.SemesterConfig, error) + AnnyBookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error) + AllAnnyBookings(ctx context.Context) ([]*model.AnnyBooking, error) ConstraintForAncode(ctx context.Context, ancode int) (*model.Constraints, error) ZpaExamsToPlanWithConstraints(ctx context.Context) ([]*model.ZPAExamWithConstraints, error) ConnectedExam(ctx context.Context, ancode int) (*model.ConnectedExam, error) @@ -752,6 +781,160 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.complexity.AnCode.Ancode(childComplexity), true + case "AnnyBooking.blockerEndDate": + if e.complexity.AnnyBooking.BlockerEndDate == nil { + break + } + + return e.complexity.AnnyBooking.BlockerEndDate(childComplexity), true + + case "AnnyBooking.blockerStartDate": + if e.complexity.AnnyBooking.BlockerStartDate == nil { + break + } + + return e.complexity.AnnyBooking.BlockerStartDate(childComplexity), true + + case "AnnyBooking.bookingGroupIdentifier": + if e.complexity.AnnyBooking.BookingGroupIdentifier == nil { + break + } + + return e.complexity.AnnyBooking.BookingGroupIdentifier(childComplexity), true + + case "AnnyBooking.canEdit": + if e.complexity.AnnyBooking.CanEdit == nil { + break + } + + return e.complexity.AnnyBooking.CanEdit(childComplexity), true + + case "AnnyBooking.cancelableUntil": + if e.complexity.AnnyBooking.CancelableUntil == nil { + break + } + + return e.complexity.AnnyBooking.CancelableUntil(childComplexity), true + + case "AnnyBooking.canceledAt": + if e.complexity.AnnyBooking.CanceledAt == nil { + break + } + + return e.complexity.AnnyBooking.CanceledAt(childComplexity), true + + case "AnnyBooking.chargedDuration": + if e.complexity.AnnyBooking.ChargedDuration == nil { + break + } + + return e.complexity.AnnyBooking.ChargedDuration(childComplexity), true + + case "AnnyBooking.createdAt": + if e.complexity.AnnyBooking.CreatedAt == nil { + break + } + + return e.complexity.AnnyBooking.CreatedAt(childComplexity), true + + case "AnnyBooking.description": + if e.complexity.AnnyBooking.Description == nil { + break + } + + return e.complexity.AnnyBooking.Description(childComplexity), true + + case "AnnyBooking.endDate": + if e.complexity.AnnyBooking.EndDate == nil { + break + } + + return e.complexity.AnnyBooking.EndDate(childComplexity), true + + case "AnnyBooking.hasCustomDescription": + if e.complexity.AnnyBooking.HasCustomDescription == nil { + break + } + + return e.complexity.AnnyBooking.HasCustomDescription(childComplexity), true + + case "AnnyBooking.isBlocker": + if e.complexity.AnnyBooking.IsBlocker == nil { + break + } + + return e.complexity.AnnyBooking.IsBlocker(childComplexity), true + + case "AnnyBooking.isEditable": + if e.complexity.AnnyBooking.IsEditable == nil { + break + } + + return e.complexity.AnnyBooking.IsEditable(childComplexity), true + + case "AnnyBooking.manuallyCreated": + if e.complexity.AnnyBooking.ManuallyCreated == nil { + break + } + + return e.complexity.AnnyBooking.ManuallyCreated(childComplexity), true + + case "AnnyBooking.note": + if e.complexity.AnnyBooking.Note == nil { + break + } + + return e.complexity.AnnyBooking.Note(childComplexity), true + + case "AnnyBooking.number": + if e.complexity.AnnyBooking.Number == nil { + break + } + + return e.complexity.AnnyBooking.Number(childComplexity), true + + case "AnnyBooking.personalizationName": + if e.complexity.AnnyBooking.PersonalizationName == nil { + break + } + + return e.complexity.AnnyBooking.PersonalizationName(childComplexity), true + + case "AnnyBooking.room": + if e.complexity.AnnyBooking.Room == nil { + break + } + + return e.complexity.AnnyBooking.Room(childComplexity), true + + case "AnnyBooking.self": + if e.complexity.AnnyBooking.Self == nil { + break + } + + return e.complexity.AnnyBooking.Self(childComplexity), true + + case "AnnyBooking.startDate": + if e.complexity.AnnyBooking.StartDate == nil { + break + } + + return e.complexity.AnnyBooking.StartDate(childComplexity), true + + case "AnnyBooking.status": + if e.complexity.AnnyBooking.Status == nil { + break + } + + return e.complexity.AnnyBooking.Status(childComplexity), true + + case "AnnyBooking.updatedAt": + if e.complexity.AnnyBooking.UpdatedAt == nil { + break + } + + return e.complexity.AnnyBooking.UpdatedAt(childComplexity), true + case "Conflict.ancode": if e.complexity.Conflict.AnCode == nil { break @@ -2263,6 +2446,13 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.complexity.PrimussExamWithCount.StudentRegsCount(childComplexity), true + case "Query.allAnnyBookings": + if e.complexity.Query.AllAnnyBookings == nil { + break + } + + return e.complexity.Query.AllAnnyBookings(childComplexity), true + case "Query.allProgramsInPlan": if e.complexity.Query.AllProgramsInPlan == nil { break @@ -2296,6 +2486,18 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.complexity.Query.AncodesInPlan(childComplexity), true + case "Query.annyBookings": + if e.complexity.Query.AnnyBookings == nil { + break + } + + args, err := ec.field_Query_annyBookings_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.AnnyBookings(childComplexity, args["room"].(*string)), true + case "Query.awkwardSlots": if e.complexity.Query.AwkwardSlots == nil { break @@ -3747,6 +3949,35 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } var sources = []*ast.Source{ + {Name: "../anny.graphqls", Input: `extend type Query { + annyBookings(room: String): [AnnyBooking!]! + allAnnyBookings: [AnnyBooking!]! +} + +type AnnyBooking { + number: String! + startDate: Time! + endDate: Time! + blockerStartDate: Time! + blockerEndDate: Time! + chargedDuration: Int! + description: String! + createdAt: Time! + updatedAt: Time! + canceledAt: Time + status: String! + isBlocker: Boolean! + canEdit: Boolean! + isEditable: Boolean! + manuallyCreated: Boolean! + note: String! + room: String + self: String! + personalizationName: String! + bookingGroupIdentifier: String + cancelableUntil: Time + hasCustomDescription: Boolean! +}`, BuiltIn: false}, {Name: "../constraints.graphqls", Input: `scalar Time extend type Query { @@ -5188,6 +5419,34 @@ func (ec *executionContext) field_Query_allowedSlots_argsAncode( return zeroVal, nil } +func (ec *executionContext) field_Query_annyBookings_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := ec.field_Query_annyBookings_argsRoom(ctx, rawArgs) + if err != nil { + return nil, err + } + args["room"] = arg0 + return args, nil +} +func (ec *executionContext) field_Query_annyBookings_argsRoom( + ctx context.Context, + rawArgs map[string]any, +) (*string, error) { + if _, ok := rawArgs["room"]; !ok { + var zeroVal *string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("room")) + if tmp, ok := rawArgs["room"]; ok { + return ec.unmarshalOString2ᚖstring(ctx, tmp) + } + + var zeroVal *string + return zeroVal, nil +} + func (ec *executionContext) field_Query_awkwardSlots_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -6057,189 +6316,1145 @@ func (ec *executionContext) field_Query_teachers_argsFromZpa( if tmp, ok := rawArgs["fromZPA"]; ok { return ec.unmarshalOBoolean2ᚖbool(ctx, tmp) } - - var zeroVal *bool - return zeroVal, nil + + var zeroVal *bool + return zeroVal, nil +} + +func (ec *executionContext) field_Query_zpaExam_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := ec.field_Query_zpaExam_argsAncode(ctx, rawArgs) + if err != nil { + return nil, err + } + args["ancode"] = arg0 + return args, nil +} +func (ec *executionContext) field_Query_zpaExam_argsAncode( + ctx context.Context, + rawArgs map[string]any, +) (int, error) { + if _, ok := rawArgs["ancode"]; !ok { + var zeroVal int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("ancode")) + if tmp, ok := rawArgs["ancode"]; ok { + return ec.unmarshalNInt2int(ctx, tmp) + } + + var zeroVal int + return zeroVal, nil +} + +func (ec *executionContext) field_Query_zpaExams_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := ec.field_Query_zpaExams_argsFromZpa(ctx, rawArgs) + if err != nil { + return nil, err + } + args["fromZPA"] = arg0 + return args, nil +} +func (ec *executionContext) field_Query_zpaExams_argsFromZpa( + ctx context.Context, + rawArgs map[string]any, +) (*bool, error) { + if _, ok := rawArgs["fromZPA"]; !ok { + var zeroVal *bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("fromZPA")) + if tmp, ok := rawArgs["fromZPA"]; ok { + return ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + } + + var zeroVal *bool + return zeroVal, nil +} + +func (ec *executionContext) field___Directive_args_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := ec.field___Directive_args_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err + } + args["includeDeprecated"] = arg0 + return args, nil +} +func (ec *executionContext) field___Directive_args_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]any, +) (*bool, error) { + if _, ok := rawArgs["includeDeprecated"]; !ok { + var zeroVal *bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + } + + var zeroVal *bool + return zeroVal, nil +} + +func (ec *executionContext) field___Field_args_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := ec.field___Field_args_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err + } + args["includeDeprecated"] = arg0 + return args, nil +} +func (ec *executionContext) field___Field_args_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]any, +) (*bool, error) { + if _, ok := rawArgs["includeDeprecated"]; !ok { + var zeroVal *bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + } + + var zeroVal *bool + return zeroVal, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := ec.field___Type_enumValues_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err + } + args["includeDeprecated"] = arg0 + return args, nil +} +func (ec *executionContext) field___Type_enumValues_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]any, +) (bool, error) { + if _, ok := rawArgs["includeDeprecated"]; !ok { + var zeroVal bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2bool(ctx, tmp) + } + + var zeroVal bool + return zeroVal, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := ec.field___Type_fields_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err + } + args["includeDeprecated"] = arg0 + return args, nil +} +func (ec *executionContext) field___Type_fields_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]any, +) (bool, error) { + if _, ok := rawArgs["includeDeprecated"]; !ok { + var zeroVal bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2bool(ctx, tmp) + } + + var zeroVal bool + return zeroVal, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region ************************** directives.gotpl ************************** + +// endregion ************************** directives.gotpl ************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _AnCode_ancode(ctx context.Context, field graphql.CollectedField, obj *model.AnCode) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnCode_ancode(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Ancode, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnCode_ancode(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnCode", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_number(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_number(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Number, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_number(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_startDate(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_startDate(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.StartDate, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_startDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_endDate(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_endDate(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.EndDate, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_endDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_blockerStartDate(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_blockerStartDate(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.BlockerStartDate, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_blockerStartDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_blockerEndDate(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_blockerEndDate(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.BlockerEndDate, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_blockerEndDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_chargedDuration(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_chargedDuration(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.ChargedDuration, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_chargedDuration(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_description(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_description(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_createdAt(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_createdAt(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.CreatedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_updatedAt(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_updatedAt(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.UpdatedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + fc.Result = res + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_canceledAt(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_canceledAt(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.CanceledAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*time.Time) + fc.Result = res + return ec.marshalOTime2ᚖtimeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_canceledAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_status(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_status(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Status, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_status(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_isBlocker(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_isBlocker(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsBlocker, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_isBlocker(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_canEdit(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_canEdit(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.CanEdit, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_canEdit(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_isEditable(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_isEditable(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsEditable, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_isEditable(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _AnnyBooking_manuallyCreated(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_manuallyCreated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.ManuallyCreated, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AnnyBooking_manuallyCreated(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil } -func (ec *executionContext) field_Query_zpaExam_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { - var err error - args := map[string]any{} - arg0, err := ec.field_Query_zpaExam_argsAncode(ctx, rawArgs) +func (ec *executionContext) _AnnyBooking_note(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_note(ctx, field) if err != nil { - return nil, err + return graphql.Null } - args["ancode"] = arg0 - return args, nil -} -func (ec *executionContext) field_Query_zpaExam_argsAncode( - ctx context.Context, - rawArgs map[string]any, -) (int, error) { - if _, ok := rawArgs["ancode"]; !ok { - var zeroVal int - return zeroVal, nil + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Note, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("ancode")) - if tmp, ok := rawArgs["ancode"]; ok { - return ec.unmarshalNInt2int(ctx, tmp) + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} - var zeroVal int - return zeroVal, nil +func (ec *executionContext) fieldContext_AnnyBooking_note(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil } -func (ec *executionContext) field_Query_zpaExams_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { - var err error - args := map[string]any{} - arg0, err := ec.field_Query_zpaExams_argsFromZpa(ctx, rawArgs) +func (ec *executionContext) _AnnyBooking_room(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_room(ctx, field) if err != nil { - return nil, err + return graphql.Null } - args["fromZPA"] = arg0 - return args, nil -} -func (ec *executionContext) field_Query_zpaExams_argsFromZpa( - ctx context.Context, - rawArgs map[string]any, -) (*bool, error) { - if _, ok := rawArgs["fromZPA"]; !ok { - var zeroVal *bool - return zeroVal, nil + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Room, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("fromZPA")) - if tmp, ok := rawArgs["fromZPA"]; ok { - return ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + if resTmp == nil { + return graphql.Null } + res := resTmp.(string) + fc.Result = res + return ec.marshalOString2string(ctx, field.Selections, res) +} - var zeroVal *bool - return zeroVal, nil +func (ec *executionContext) fieldContext_AnnyBooking_room(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil } -func (ec *executionContext) field___Directive_args_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { - var err error - args := map[string]any{} - arg0, err := ec.field___Directive_args_argsIncludeDeprecated(ctx, rawArgs) +func (ec *executionContext) _AnnyBooking_self(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_self(ctx, field) if err != nil { - return nil, err + return graphql.Null } - args["includeDeprecated"] = arg0 - return args, nil -} -func (ec *executionContext) field___Directive_args_argsIncludeDeprecated( - ctx context.Context, - rawArgs map[string]any, -) (*bool, error) { - if _, ok := rawArgs["includeDeprecated"]; !ok { - var zeroVal *bool - return zeroVal, nil + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.Self, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - if tmp, ok := rawArgs["includeDeprecated"]; ok { - return ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} - var zeroVal *bool - return zeroVal, nil +func (ec *executionContext) fieldContext_AnnyBooking_self(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil } -func (ec *executionContext) field___Field_args_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { - var err error - args := map[string]any{} - arg0, err := ec.field___Field_args_argsIncludeDeprecated(ctx, rawArgs) +func (ec *executionContext) _AnnyBooking_personalizationName(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_personalizationName(ctx, field) if err != nil { - return nil, err + return graphql.Null } - args["includeDeprecated"] = arg0 - return args, nil -} -func (ec *executionContext) field___Field_args_argsIncludeDeprecated( - ctx context.Context, - rawArgs map[string]any, -) (*bool, error) { - if _, ok := rawArgs["includeDeprecated"]; !ok { - var zeroVal *bool - return zeroVal, nil + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.PersonalizationName, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - if tmp, ok := rawArgs["includeDeprecated"]; ok { - return ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} - var zeroVal *bool - return zeroVal, nil +func (ec *executionContext) fieldContext_AnnyBooking_personalizationName(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil } -func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { - var err error - args := map[string]any{} - arg0, err := ec.field___Type_enumValues_argsIncludeDeprecated(ctx, rawArgs) +func (ec *executionContext) _AnnyBooking_bookingGroupIdentifier(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_bookingGroupIdentifier(ctx, field) if err != nil { - return nil, err + return graphql.Null } - args["includeDeprecated"] = arg0 - return args, nil -} -func (ec *executionContext) field___Type_enumValues_argsIncludeDeprecated( - ctx context.Context, - rawArgs map[string]any, -) (bool, error) { - if _, ok := rawArgs["includeDeprecated"]; !ok { - var zeroVal bool - return zeroVal, nil + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.BookingGroupIdentifier, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - if tmp, ok := rawArgs["includeDeprecated"]; ok { - return ec.unmarshalOBoolean2bool(ctx, tmp) + if resTmp == nil { + return graphql.Null } + res := resTmp.(string) + fc.Result = res + return ec.marshalOString2string(ctx, field.Selections, res) +} - var zeroVal bool - return zeroVal, nil +func (ec *executionContext) fieldContext_AnnyBooking_bookingGroupIdentifier(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil } -func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { - var err error - args := map[string]any{} - arg0, err := ec.field___Type_fields_argsIncludeDeprecated(ctx, rawArgs) +func (ec *executionContext) _AnnyBooking_cancelableUntil(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_cancelableUntil(ctx, field) if err != nil { - return nil, err + return graphql.Null } - args["includeDeprecated"] = arg0 - return args, nil -} -func (ec *executionContext) field___Type_fields_argsIncludeDeprecated( - ctx context.Context, - rawArgs map[string]any, -) (bool, error) { - if _, ok := rawArgs["includeDeprecated"]; !ok { - var zeroVal bool - return zeroVal, nil + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return obj.CancelableUntil, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null } - - ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - if tmp, ok := rawArgs["includeDeprecated"]; ok { - return ec.unmarshalOBoolean2bool(ctx, tmp) + if resTmp == nil { + return graphql.Null } - - var zeroVal bool - return zeroVal, nil + res := resTmp.(*time.Time) + fc.Result = res + return ec.marshalOTime2ᚖtimeᚐTime(ctx, field.Selections, res) } -// endregion ***************************** args.gotpl ***************************** - -// region ************************** directives.gotpl ************************** - -// endregion ************************** directives.gotpl ************************** - -// region **************************** field.gotpl ***************************** +func (ec *executionContext) fieldContext_AnnyBooking_cancelableUntil(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AnnyBooking", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Time does not have child fields") + }, + } + return fc, nil +} -func (ec *executionContext) _AnCode_ancode(ctx context.Context, field graphql.CollectedField, obj *model.AnCode) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_AnCode_ancode(ctx, field) +func (ec *executionContext) _AnnyBooking_hasCustomDescription(ctx context.Context, field graphql.CollectedField, obj *model.AnnyBooking) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnnyBooking_hasCustomDescription(ctx, field) if err != nil { return graphql.Null } @@ -6252,7 +7467,7 @@ func (ec *executionContext) _AnCode_ancode(ctx context.Context, field graphql.Co }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { ctx = rctx // use context from middleware stack in children - return obj.Ancode, nil + return obj.HasCustomDescription, nil }) if err != nil { ec.Error(ctx, err) @@ -6264,19 +7479,19 @@ func (ec *executionContext) _AnCode_ancode(ctx context.Context, field graphql.Co } return graphql.Null } - res := resTmp.(int) + res := resTmp.(bool) fc.Result = res - return ec.marshalNInt2int(ctx, field.Selections, res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_AnCode_ancode(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_AnnyBooking_hasCustomDescription(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "AnCode", + Object: "AnnyBooking", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Int does not have child fields") + return nil, errors.New("field of type Boolean does not have child fields") }, } return fc, nil @@ -16471,6 +17686,197 @@ func (ec *executionContext) fieldContext_Query_semesterConfig(_ context.Context, return fc, nil } +func (ec *executionContext) _Query_annyBookings(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_annyBookings(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().AnnyBookings(rctx, fc.Args["room"].(*string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.AnnyBooking) + fc.Result = res + return ec.marshalNAnnyBooking2ᚕᚖgithubᚗcomᚋobcodeᚋplexamsᚗgoᚋgraphᚋmodelᚐAnnyBookingᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_annyBookings(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "number": + return ec.fieldContext_AnnyBooking_number(ctx, field) + case "startDate": + return ec.fieldContext_AnnyBooking_startDate(ctx, field) + case "endDate": + return ec.fieldContext_AnnyBooking_endDate(ctx, field) + case "blockerStartDate": + return ec.fieldContext_AnnyBooking_blockerStartDate(ctx, field) + case "blockerEndDate": + return ec.fieldContext_AnnyBooking_blockerEndDate(ctx, field) + case "chargedDuration": + return ec.fieldContext_AnnyBooking_chargedDuration(ctx, field) + case "description": + return ec.fieldContext_AnnyBooking_description(ctx, field) + case "createdAt": + return ec.fieldContext_AnnyBooking_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_AnnyBooking_updatedAt(ctx, field) + case "canceledAt": + return ec.fieldContext_AnnyBooking_canceledAt(ctx, field) + case "status": + return ec.fieldContext_AnnyBooking_status(ctx, field) + case "isBlocker": + return ec.fieldContext_AnnyBooking_isBlocker(ctx, field) + case "canEdit": + return ec.fieldContext_AnnyBooking_canEdit(ctx, field) + case "isEditable": + return ec.fieldContext_AnnyBooking_isEditable(ctx, field) + case "manuallyCreated": + return ec.fieldContext_AnnyBooking_manuallyCreated(ctx, field) + case "note": + return ec.fieldContext_AnnyBooking_note(ctx, field) + case "room": + return ec.fieldContext_AnnyBooking_room(ctx, field) + case "self": + return ec.fieldContext_AnnyBooking_self(ctx, field) + case "personalizationName": + return ec.fieldContext_AnnyBooking_personalizationName(ctx, field) + case "bookingGroupIdentifier": + return ec.fieldContext_AnnyBooking_bookingGroupIdentifier(ctx, field) + case "cancelableUntil": + return ec.fieldContext_AnnyBooking_cancelableUntil(ctx, field) + case "hasCustomDescription": + return ec.fieldContext_AnnyBooking_hasCustomDescription(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type AnnyBooking", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_annyBookings_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Query_allAnnyBookings(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_allAnnyBookings(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().AllAnnyBookings(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.AnnyBooking) + fc.Result = res + return ec.marshalNAnnyBooking2ᚕᚖgithubᚗcomᚋobcodeᚋplexamsᚗgoᚋgraphᚋmodelᚐAnnyBookingᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_allAnnyBookings(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "number": + return ec.fieldContext_AnnyBooking_number(ctx, field) + case "startDate": + return ec.fieldContext_AnnyBooking_startDate(ctx, field) + case "endDate": + return ec.fieldContext_AnnyBooking_endDate(ctx, field) + case "blockerStartDate": + return ec.fieldContext_AnnyBooking_blockerStartDate(ctx, field) + case "blockerEndDate": + return ec.fieldContext_AnnyBooking_blockerEndDate(ctx, field) + case "chargedDuration": + return ec.fieldContext_AnnyBooking_chargedDuration(ctx, field) + case "description": + return ec.fieldContext_AnnyBooking_description(ctx, field) + case "createdAt": + return ec.fieldContext_AnnyBooking_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_AnnyBooking_updatedAt(ctx, field) + case "canceledAt": + return ec.fieldContext_AnnyBooking_canceledAt(ctx, field) + case "status": + return ec.fieldContext_AnnyBooking_status(ctx, field) + case "isBlocker": + return ec.fieldContext_AnnyBooking_isBlocker(ctx, field) + case "canEdit": + return ec.fieldContext_AnnyBooking_canEdit(ctx, field) + case "isEditable": + return ec.fieldContext_AnnyBooking_isEditable(ctx, field) + case "manuallyCreated": + return ec.fieldContext_AnnyBooking_manuallyCreated(ctx, field) + case "note": + return ec.fieldContext_AnnyBooking_note(ctx, field) + case "room": + return ec.fieldContext_AnnyBooking_room(ctx, field) + case "self": + return ec.fieldContext_AnnyBooking_self(ctx, field) + case "personalizationName": + return ec.fieldContext_AnnyBooking_personalizationName(ctx, field) + case "bookingGroupIdentifier": + return ec.fieldContext_AnnyBooking_bookingGroupIdentifier(ctx, field) + case "cancelableUntil": + return ec.fieldContext_AnnyBooking_cancelableUntil(ctx, field) + case "hasCustomDescription": + return ec.fieldContext_AnnyBooking_hasCustomDescription(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type AnnyBooking", field.Name) + }, + } + return fc, nil +} + func (ec *executionContext) _Query_constraintForAncode(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Query_constraintForAncode(ctx, field) if err != nil { @@ -27896,6 +29302,138 @@ func (ec *executionContext) _AnCode(ctx context.Context, sel ast.SelectionSet, o return out } +var annyBookingImplementors = []string{"AnnyBooking"} + +func (ec *executionContext) _AnnyBooking(ctx context.Context, sel ast.SelectionSet, obj *model.AnnyBooking) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, annyBookingImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("AnnyBooking") + case "number": + out.Values[i] = ec._AnnyBooking_number(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "startDate": + out.Values[i] = ec._AnnyBooking_startDate(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "endDate": + out.Values[i] = ec._AnnyBooking_endDate(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "blockerStartDate": + out.Values[i] = ec._AnnyBooking_blockerStartDate(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "blockerEndDate": + out.Values[i] = ec._AnnyBooking_blockerEndDate(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "chargedDuration": + out.Values[i] = ec._AnnyBooking_chargedDuration(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "description": + out.Values[i] = ec._AnnyBooking_description(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "createdAt": + out.Values[i] = ec._AnnyBooking_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updatedAt": + out.Values[i] = ec._AnnyBooking_updatedAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "canceledAt": + out.Values[i] = ec._AnnyBooking_canceledAt(ctx, field, obj) + case "status": + out.Values[i] = ec._AnnyBooking_status(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "isBlocker": + out.Values[i] = ec._AnnyBooking_isBlocker(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "canEdit": + out.Values[i] = ec._AnnyBooking_canEdit(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "isEditable": + out.Values[i] = ec._AnnyBooking_isEditable(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "manuallyCreated": + out.Values[i] = ec._AnnyBooking_manuallyCreated(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "note": + out.Values[i] = ec._AnnyBooking_note(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "room": + out.Values[i] = ec._AnnyBooking_room(ctx, field, obj) + case "self": + out.Values[i] = ec._AnnyBooking_self(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "personalizationName": + out.Values[i] = ec._AnnyBooking_personalizationName(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "bookingGroupIdentifier": + out.Values[i] = ec._AnnyBooking_bookingGroupIdentifier(ctx, field, obj) + case "cancelableUntil": + out.Values[i] = ec._AnnyBooking_cancelableUntil(ctx, field, obj) + case "hasCustomDescription": + out.Values[i] = ec._AnnyBooking_hasCustomDescription(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + var conflictImplementors = []string{"Conflict"} func (ec *executionContext) _Conflict(ctx context.Context, sel ast.SelectionSet, obj *model.Conflict) graphql.Marshaler { @@ -30334,6 +31872,50 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "annyBookings": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_annyBookings(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "allAnnyBookings": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_allAnnyBookings(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) case "constraintForAncode": field := field @@ -33066,237 +34648,291 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS return out } -var __FieldImplementors = []string{"__Field"} - -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, __FieldImplementors) - - out := graphql.NewFieldSet(fields) - deferred := make(map[string]*graphql.FieldSet) - for i, field := range fields { - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - out.Dispatch(ctx) - if out.Invalids > 0 { - return graphql.Null - } +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __FieldImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___InputValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deprecationReason": + out.Values[i] = ec.___InputValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "description": + out.Values[i] = ec.___Schema_description(ctx, field, obj) + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "specifiedByURL": + out.Values[i] = ec.___Type_specifiedByURL(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + case "isOneOf": + out.Values[i] = ec.___Type_isOneOf(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +// endregion **************************** object.gotpl **************************** - atomic.AddInt32(&ec.deferred, int32(len(deferred))) +// region ***************************** type.gotpl ***************************** - for label, dfs := range deferred { - ec.processDeferredGroup(graphql.DeferredGroup{ - Label: label, - Path: graphql.GetPath(ctx), - FieldSet: dfs, - Context: ctx, - }) +func (ec *executionContext) marshalNAnnyBooking2ᚕᚖgithubᚗcomᚋobcodeᚋplexamsᚗgoᚋgraphᚋmodelᚐAnnyBookingᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.AnnyBooking) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) } - - return out -} - -var __InputValueImplementors = []string{"__InputValue"} - -func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, __InputValueImplementors) - - out := graphql.NewFieldSet(fields) - deferred := make(map[string]*graphql.FieldSet) - for i, field := range fields { - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__InputValue") - case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) - case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___InputValue_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() } - case "deprecationReason": - out.Values[i] = ec.___InputValue_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) + ret[i] = ec.marshalNAnnyBooking2ᚖgithubᚗcomᚋobcodeᚋplexamsᚗgoᚋgraphᚋmodelᚐAnnyBooking(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) } - } - out.Dispatch(ctx) - if out.Invalids > 0 { - return graphql.Null - } - - atomic.AddInt32(&ec.deferred, int32(len(deferred))) - for label, dfs := range deferred { - ec.processDeferredGroup(graphql.DeferredGroup{ - Label: label, - Path: graphql.GetPath(ctx), - FieldSet: dfs, - Context: ctx, - }) } + wg.Wait() - return out -} - -var __SchemaImplementors = []string{"__Schema"} - -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, __SchemaImplementors) - - out := graphql.NewFieldSet(fields) - deferred := make(map[string]*graphql.FieldSet) - for i, field := range fields { - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "description": - out.Values[i] = ec.___Schema_description(ctx, field, obj) - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - default: - panic("unknown field " + strconv.Quote(field.Name)) + for _, e := range ret { + if e == graphql.Null { + return graphql.Null } } - out.Dispatch(ctx) - if out.Invalids > 0 { - return graphql.Null - } - - atomic.AddInt32(&ec.deferred, int32(len(deferred))) - - for label, dfs := range deferred { - ec.processDeferredGroup(graphql.DeferredGroup{ - Label: label, - Path: graphql.GetPath(ctx), - FieldSet: dfs, - Context: ctx, - }) - } - return out + return ret } -var __TypeImplementors = []string{"__Type"} - -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, __TypeImplementors) - - out := graphql.NewFieldSet(fields) - deferred := make(map[string]*graphql.FieldSet) - for i, field := range fields { - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "specifiedByURL": - out.Values[i] = ec.___Type_specifiedByURL(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - case "isOneOf": - out.Values[i] = ec.___Type_isOneOf(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) +func (ec *executionContext) marshalNAnnyBooking2ᚖgithubᚗcomᚋobcodeᚋplexamsᚗgoᚋgraphᚋmodelᚐAnnyBooking(ctx context.Context, sel ast.SelectionSet, v *model.AnnyBooking) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") } - } - out.Dispatch(ctx) - if out.Invalids > 0 { return graphql.Null } - - atomic.AddInt32(&ec.deferred, int32(len(deferred))) - - for label, dfs := range deferred { - ec.processDeferredGroup(graphql.DeferredGroup{ - Label: label, - Path: graphql.GetPath(ctx), - FieldSet: dfs, - Context: ctx, - }) - } - - return out + return ec._AnnyBooking(ctx, sel, v) } -// endregion **************************** object.gotpl **************************** - -// region ***************************** type.gotpl ***************************** - func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v any) (bool, error) { res, err := graphql.UnmarshalBoolean(v) return res, graphql.ErrorOnPath(ctx, err) @@ -36663,6 +38299,18 @@ func (ec *executionContext) marshalOSlot2ᚕᚖgithubᚗcomᚋobcodeᚋplexams return ret } +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v any) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + _ = sel + _ = ctx + res := graphql.MarshalString(v) + return res +} + func (ec *executionContext) unmarshalOString2ᚕstringᚄ(ctx context.Context, v any) ([]string, error) { if v == nil { return nil, nil diff --git a/graph/model/anny.go b/graph/model/anny.go new file mode 100644 index 0000000..225c79e --- /dev/null +++ b/graph/model/anny.go @@ -0,0 +1,28 @@ +package model + +import "time" + +type AnnyBooking struct { + Number string `json:"number"` + StartDate time.Time `json:"startDate"` + EndDate time.Time `json:"endDate"` + BlockerStartDate time.Time `json:"blockerStartDate"` + BlockerEndDate time.Time `json:"blockerEndDate"` + ChargedDuration int `json:"chargedDuration"` + Description string `json:"description"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + CanceledAt *time.Time `json:"canceledAt,omitempty"` + Status string `json:"status"` + IsBlocker bool `json:"isBlocker"` + CanEdit bool `json:"canEdit"` + IsEditable bool `json:"isEditable"` + ManuallyCreated bool `json:"manuallyCreated"` + Note string `json:"note"` + Room string `json:"room,omitempty"` + Self string `json:"self"` + PersonalizationName string `json:"personalizationName"` + BookingGroupIdentifier string `json:"bookingGroupIdentifier,omitempty"` + CancelableUntil *time.Time `json:"cancelableUntil,omitempty"` + HasCustomDescription bool `json:"hasCustomDescription"` +} diff --git a/plexams/anny.go b/plexams/anny.go new file mode 100644 index 0000000..ba65e8a --- /dev/null +++ b/plexams/anny.go @@ -0,0 +1,432 @@ +package plexams + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "os" + "regexp" + "sort" + "strings" + "text/tabwriter" + "time" + + "github.com/obcode/plexams.go/db" + "github.com/spf13/viper" +) + +type AnnyBooking struct { + Number string `json:"number"` + StartDate time.Time `json:"start_date"` + EndDate time.Time `json:"end_date"` + BlockerStartDate time.Time `json:"blocker_start_date"` + BlockerEndDate time.Time `json:"blocker_end_date"` + ChargedDuration int `json:"charged_duration"` + Description string `json:"description"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + CanceledAt *time.Time `json:"canceled_at,omitempty"` + Status string `json:"status"` + StatusReason json.RawMessage `json:"status_reason,omitempty"` + IsBlocker bool `json:"is_blocker"` + CanEdit bool `json:"can_edit"` + IsEditable bool `json:"is_editable"` + ManuallyCreated bool `json:"manually_created"` + Note string `json:"note"` + Room string `json:"room,omitempty"` + Self string `json:"self"` + PersonalizationName string `json:"personalization_name"` + BookingGroupID string `json:"booking_group_identifier,omitempty"` + CancelableUntil *time.Time `json:"cancelable_until,omitempty"` + HasCustomDescription bool `json:"has_custom_description"` + ResourceID string `json:"-"` +} + +type annyBookingRaw struct { + Attributes struct { + Number string `json:"number"` + StartDate string `json:"start_date"` + EndDate string `json:"end_date"` + BlockerStartDate string `json:"blocker_start_date"` + BlockerEndDate string `json:"blocker_end_date"` + ChargedDuration int `json:"charged_duration"` + Description string `json:"description"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` + CanceledAt string `json:"canceled_at"` + Status string `json:"status"` + StatusReason json.RawMessage `json:"status_reason"` + IsBlocker bool `json:"is_blocker"` + CanEdit bool `json:"can_edit"` + IsEditable bool `json:"is_editable"` + ManuallyCreated bool `json:"manually_created"` + Note string `json:"note"` + } `json:"attributes"` + Links struct { + Self string `json:"self"` + } `json:"links"` + Meta struct { + PersonalizationName string `json:"personalization_name"` + BookingGroupID string `json:"booking_group_identifier"` + CancelableUntil string `json:"cancelable_until"` + HasCustomDescription bool `json:"has_custom_description"` + } `json:"meta"` +} + +type annyBookingsPage struct { + Data []annyBookingRaw `json:"data"` + Links struct { + Next string `json:"next"` + } `json:"links"` +} + +func (p *Plexams) FetchFromAnny() error { + token := viper.GetString("anny.token") + personalizationName := strings.TrimSpace(viper.GetString("anny.personalization_name")) + configRooms := viper.GetStringSlice("anny.rooms") + allowedRooms := make(map[string]struct{}, len(configRooms)) + for _, room := range configRooms { + normalizedRoom := normalizeRoomName(room) + if normalizedRoom == "" { + continue + } + allowedRooms[normalizedRoom] = struct{}{} + } + + if strings.TrimSpace(token) == "" { + return fmt.Errorf("anny token is empty") + } + + authToken := strings.TrimSpace(token) + if !strings.HasPrefix(strings.ToLower(authToken), "bearer ") { + authToken = "Bearer " + authToken + } + + endpoint := "https://b.anny.eu/api/v1/bookings" + query := url.Values{} + query.Set("sort", "start_date") + query.Set("page[size]", "100") + query.Set("filter[upcoming_only]", "1") + + nextURL := endpoint + "?" + query.Encode() + allBookings := make([]AnnyBooking, 0) + client := &http.Client{Timeout: 20 * time.Second} + + for nextURL != "" { + req, err := http.NewRequest(http.MethodGet, nextURL, nil) + if err != nil { + return fmt.Errorf("cannot build anny request: %w", err) + } + + req.Header.Set("Accept", "application/vnd.api+json") + req.Header.Set("Authorization", authToken) + + resp, err := client.Do(req) + if err != nil { + return fmt.Errorf("cannot fetch anny bookings: %w", err) + } + + body, readErr := io.ReadAll(resp.Body) + closeErr := resp.Body.Close() + if readErr != nil { + return fmt.Errorf("cannot read anny response body: %w", readErr) + } + if closeErr != nil { + return fmt.Errorf("cannot close anny response body: %w", closeErr) + } + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("anny request failed with status %s: %s", resp.Status, string(body)) + } + + var page annyBookingsPage + if err := json.Unmarshal(body, &page); err != nil { + return fmt.Errorf("cannot decode anny response: %w", err) + } + + for _, raw := range page.Data { + booking, err := annyRawToBooking(raw) + if err != nil { + return err + } + allBookings = append(allBookings, booking) + } + nextURL = page.Links.Next + } + + resourceIDToRoom := make(map[string]string) + for _, booking := range allBookings { + if booking.ResourceID == "" || booking.Room == "" { + continue + } + resourceIDToRoom[booking.ResourceID] = booking.Room + } + + if len(allowedRooms) > 0 { + remainingRooms := make([]string, 0, len(allowedRooms)) + for room := range allowedRooms { + isMapped := false + for _, mappedRoom := range resourceIDToRoom { + if mappedRoom == room { + isMapped = true + break + } + } + if !isMapped { + remainingRooms = append(remainingRooms, room) + } + } + + unknownResourceIDs := make(map[string]struct{}) + for _, booking := range allBookings { + if booking.ResourceID == "" || booking.Room != "" { + continue + } + if _, known := resourceIDToRoom[booking.ResourceID]; known { + continue + } + unknownResourceIDs[booking.ResourceID] = struct{}{} + } + + if len(remainingRooms) == 1 && len(unknownResourceIDs) == 1 { + for resourceID := range unknownResourceIDs { + resourceIDToRoom[resourceID] = remainingRooms[0] + } + } + } + + bookings := make([]AnnyBooking, 0, len(allBookings)) + for _, booking := range allBookings { + if booking.Room == "" { + if inferredRoom, ok := resourceIDToRoom[booking.ResourceID]; ok { + booking.Room = inferredRoom + } + } + + if personalizationName != "" && !strings.EqualFold(strings.TrimSpace(booking.PersonalizationName), personalizationName) { + continue + } + if len(allowedRooms) > 0 { + if _, ok := allowedRooms[normalizeRoomName(booking.Room)]; !ok { + continue + } + } + bookings = append(bookings, booking) + } + + sort.Slice(bookings, func(i, j int) bool { + return bookings[i].StartDate.Before(bookings[j].StartDate) + }) + + if p.dbClient == nil { + return fmt.Errorf("no database configured for saving anny bookings") + } + + dbBookings := make([]*db.AnnyBooking, 0, len(bookings)) + for _, booking := range bookings { + dbBookings = append(dbBookings, annyBookingToDBBooking(booking)) + } + + if err := p.dbClient.SaveAnnyBookings(context.Background(), dbBookings); err != nil { + return fmt.Errorf("cannot save anny bookings: %w", err) + } + + printAnnySummary(bookings, personalizationName) + fmt.Println("Saved to MongoDB collection anny_bookings") + + return nil +} + +func printAnnySummary(bookings []AnnyBooking, personalizationName string) { + roomMap := make(map[string]int) + for _, booking := range bookings { + room := booking.Room + if room == "" { + room = "(unknown)" + } + roomMap[room]++ + } + + roomNames := make([]string, 0, len(roomMap)) + for roomName := range roomMap { + roomNames = append(roomNames, roomName) + } + sort.Strings(roomNames) + + w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) + fmt.Fprintf(w, "Anny-Buchungen für\t%s\t(gesamt %d)\n", personalizationName, len(bookings)) // nolint + fmt.Fprintln(w, "Raum\tAnzahl") // nolint // nolint + for _, roomName := range roomNames { + fmt.Fprintf(w, "%s\t%d\n", roomName, roomMap[roomName]) // nolint + } + + maxRows := len(bookings) + + fmt.Fprintln(w, "") // nolint + fmt.Fprintln(w, "Alle Termine") // nolint + fmt.Fprintln(w, "Datum\tZeit\tRaum\tDauer\tBeschreibung") // nolint + for i := 0; i < maxRows; i++ { + booking := bookings[i] + room := booking.Room + if room == "" { + room = "(unknown)" + } + desc := booking.Description + if len([]rune(desc)) > 36 { + desc = string([]rune(desc)[:36]) + "..." + } + fmt.Fprintf(w, "%s\t%s-%s\t%s\t%d min\t%s\n", // nolint + booking.StartDate.Format("02.01.2006"), + booking.StartDate.Format("15:04"), + booking.EndDate.Format("15:04"), + room, + booking.ChargedDuration, + desc, + ) + } + _ = w.Flush() +} + +func annyRawToBooking(raw annyBookingRaw) (AnnyBooking, error) { + startDate, err := parseRFC3339Local(raw.Attributes.StartDate) + if err != nil { + return AnnyBooking{}, fmt.Errorf("cannot parse start_date %q: %w", raw.Attributes.StartDate, err) + } + + endDate, err := parseRFC3339Local(raw.Attributes.EndDate) + if err != nil { + return AnnyBooking{}, fmt.Errorf("cannot parse end_date %q: %w", raw.Attributes.EndDate, err) + } + + blockerStartDate, err := parseRFC3339Local(raw.Attributes.BlockerStartDate) + if err != nil { + return AnnyBooking{}, fmt.Errorf("cannot parse blocker_start_date %q: %w", raw.Attributes.BlockerStartDate, err) + } + + blockerEndDate, err := parseRFC3339Local(raw.Attributes.BlockerEndDate) + if err != nil { + return AnnyBooking{}, fmt.Errorf("cannot parse blocker_end_date %q: %w", raw.Attributes.BlockerEndDate, err) + } + + createdAt, err := parseRFC3339Local(raw.Attributes.CreatedAt) + if err != nil { + return AnnyBooking{}, fmt.Errorf("cannot parse created_at %q: %w", raw.Attributes.CreatedAt, err) + } + + updatedAt, err := parseRFC3339Local(raw.Attributes.UpdatedAt) + if err != nil { + return AnnyBooking{}, fmt.Errorf("cannot parse updated_at %q: %w", raw.Attributes.UpdatedAt, err) + } + + canceledAt, err := parseRFC3339LocalOptional(raw.Attributes.CanceledAt) + if err != nil { + return AnnyBooking{}, fmt.Errorf("cannot parse canceled_at %q: %w", raw.Attributes.CanceledAt, err) + } + + cancelableUntil, err := parseRFC3339LocalOptional(raw.Meta.CancelableUntil) + if err != nil { + return AnnyBooking{}, fmt.Errorf("cannot parse cancelable_until %q: %w", raw.Meta.CancelableUntil, err) + } + + return AnnyBooking{ + Number: raw.Attributes.Number, + StartDate: startDate, + EndDate: endDate, + BlockerStartDate: blockerStartDate, + BlockerEndDate: blockerEndDate, + ChargedDuration: raw.Attributes.ChargedDuration, + Description: raw.Attributes.Description, + CreatedAt: createdAt, + UpdatedAt: updatedAt, + CanceledAt: canceledAt, + Status: raw.Attributes.Status, + StatusReason: raw.Attributes.StatusReason, + IsBlocker: raw.Attributes.IsBlocker, + CanEdit: raw.Attributes.CanEdit, + IsEditable: raw.Attributes.IsEditable, + ManuallyCreated: raw.Attributes.ManuallyCreated, + Note: raw.Attributes.Note, + Room: extractRoomFromNote(raw.Attributes.Note), + Self: raw.Links.Self, + PersonalizationName: raw.Meta.PersonalizationName, + BookingGroupID: raw.Meta.BookingGroupID, + CancelableUntil: cancelableUntil, + HasCustomDescription: raw.Meta.HasCustomDescription, + ResourceID: extractResourceID(raw.Meta.BookingGroupID), + }, nil +} + +var roomFromNotePattern = regexp.MustCompile(`(?i)ressource:\s*([A-Z])\s*(\d\.[0-9]{3})`) +var resourceIDPattern = regexp.MustCompile(`resource:(\d+)`) + +func extractRoomFromNote(note string) string { + matches := roomFromNotePattern.FindStringSubmatch(note) + if len(matches) != 3 { + return "" + } + room := strings.ToUpper(matches[1]) + matches[2] + return normalizeRoomName(room) +} + +func normalizeRoomName(room string) string { + return strings.ToUpper(strings.ReplaceAll(strings.TrimSpace(room), " ", "")) +} + +func extractResourceID(bookingGroupIdentifier string) string { + matches := resourceIDPattern.FindStringSubmatch(bookingGroupIdentifier) + if len(matches) != 2 { + return "" + } + return matches[1] +} + +func annyBookingToDBBooking(booking AnnyBooking) *db.AnnyBooking { + return &db.AnnyBooking{ + Number: booking.Number, + StartDate: booking.StartDate, + EndDate: booking.EndDate, + BlockerStartDate: booking.BlockerStartDate, + BlockerEndDate: booking.BlockerEndDate, + ChargedDuration: booking.ChargedDuration, + Description: booking.Description, + CreatedAt: booking.CreatedAt, + UpdatedAt: booking.UpdatedAt, + CanceledAt: booking.CanceledAt, + Status: booking.Status, + StatusReason: booking.StatusReason, + IsBlocker: booking.IsBlocker, + CanEdit: booking.CanEdit, + IsEditable: booking.IsEditable, + ManuallyCreated: booking.ManuallyCreated, + Note: booking.Note, + Room: booking.Room, + Self: booking.Self, + PersonalizationName: booking.PersonalizationName, + BookingGroupID: booking.BookingGroupID, + CancelableUntil: booking.CancelableUntil, + HasCustomDescription: booking.HasCustomDescription, + ResourceID: booking.ResourceID, + } +} + +func parseRFC3339Local(value string) (time.Time, error) { + t, err := time.Parse(time.RFC3339, value) + if err != nil { + return time.Time{}, err + } + return t.Local(), nil +} + +func parseRFC3339LocalOptional(value string) (*time.Time, error) { + if strings.TrimSpace(value) == "" { + return nil, nil + } + t, err := parseRFC3339Local(value) + if err != nil { + return nil, err + } + return &t, nil +} diff --git a/plexams/anny_query.go b/plexams/anny_query.go new file mode 100644 index 0000000..08d8cba --- /dev/null +++ b/plexams/anny_query.go @@ -0,0 +1,81 @@ +package plexams + +import ( + "context" + + "github.com/obcode/plexams.go/graph/model" +) + +func (p *Plexams) AnnyBookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error) { + bookings, err := p.dbClient.AnnyBookings(ctx, room) + if err != nil { + return nil, err + } + + result := make([]*model.AnnyBooking, 0, len(bookings)) + for _, booking := range bookings { + result = append(result, &model.AnnyBooking{ + Number: booking.Number, + StartDate: booking.StartDate, + EndDate: booking.EndDate, + BlockerStartDate: booking.BlockerStartDate, + BlockerEndDate: booking.BlockerEndDate, + ChargedDuration: booking.ChargedDuration, + Description: booking.Description, + CreatedAt: booking.CreatedAt, + UpdatedAt: booking.UpdatedAt, + CanceledAt: booking.CanceledAt, + Status: booking.Status, + IsBlocker: booking.IsBlocker, + CanEdit: booking.CanEdit, + IsEditable: booking.IsEditable, + ManuallyCreated: booking.ManuallyCreated, + Note: booking.Note, + Room: booking.Room, + Self: booking.Self, + PersonalizationName: booking.PersonalizationName, + BookingGroupIdentifier: booking.BookingGroupID, + CancelableUntil: booking.CancelableUntil, + HasCustomDescription: booking.HasCustomDescription, + }) + } + + return result, nil +} + +func (p *Plexams) AllAnnyBookings(ctx context.Context) ([]*model.AnnyBooking, error) { + bookings, err := p.dbClient.AllAnnyBookings(ctx) + if err != nil { + return nil, err + } + + result := make([]*model.AnnyBooking, 0, len(bookings)) + for _, booking := range bookings { + result = append(result, &model.AnnyBooking{ + Number: booking.Number, + StartDate: booking.StartDate, + EndDate: booking.EndDate, + BlockerStartDate: booking.BlockerStartDate, + BlockerEndDate: booking.BlockerEndDate, + ChargedDuration: booking.ChargedDuration, + Description: booking.Description, + CreatedAt: booking.CreatedAt, + UpdatedAt: booking.UpdatedAt, + CanceledAt: booking.CanceledAt, + Status: booking.Status, + IsBlocker: booking.IsBlocker, + CanEdit: booking.CanEdit, + IsEditable: booking.IsEditable, + ManuallyCreated: booking.ManuallyCreated, + Note: booking.Note, + Room: booking.Room, + Self: booking.Self, + PersonalizationName: booking.PersonalizationName, + BookingGroupIdentifier: booking.BookingGroupID, + CancelableUntil: booking.CancelableUntil, + HasCustomDescription: booking.HasCustomDescription, + }) + } + + return result, nil +} From 00fd9f53f96ad5609413db30fa213243d001a57b Mon Sep 17 00:00:00 2001 From: Oliver Braun Date: Fri, 22 May 2026 14:36:17 +0200 Subject: [PATCH 2/4] feat: Implement Anny bookings retrieval for EXaHM room slots and fallback to YAML entries --- plexams/rooms.go | 37 +++++++++++++++++++++++++++++++++++++ plexams/rooms_for_slots.go | 19 +++++++++++++++---- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/plexams/rooms.go b/plexams/rooms.go index 1f369c3..8070ef0 100644 --- a/plexams/rooms.go +++ b/plexams/rooms.go @@ -3,6 +3,7 @@ package plexams import ( "context" "fmt" + "strings" "time" "github.com/obcode/plexams.go/graph/model" @@ -34,6 +35,42 @@ type BookedEntry struct { Approved bool } +func (p *Plexams) ExahmRoomsFromAnnyBookings(ctx context.Context) ([]BookedEntry, error) { + dbBookings, err := p.dbClient.AllAnnyBookings(ctx) + if err != nil { + return nil, fmt.Errorf("cannot get anny bookings from db: %w", err) + } + if len(dbBookings) == 0 { + return nil, nil + } + + // Only consider rooms configured under anny.rooms + configRooms := viper.GetStringSlice("anny.rooms") + allowedRooms := make(map[string]struct{}, len(configRooms)) + for _, r := range configRooms { + allowedRooms[strings.ToUpper(strings.ReplaceAll(strings.TrimSpace(r), " ", ""))] = struct{}{} + } + + entries := make([]BookedEntry, 0, len(dbBookings)) + for _, booking := range dbBookings { + if booking.Room == "" { + continue + } + normalizedRoom := strings.ToUpper(strings.ReplaceAll(strings.TrimSpace(booking.Room), " ", "")) + if _, ok := allowedRooms[normalizedRoom]; !ok { + continue + } + entries = append(entries, BookedEntry{ + From: booking.StartDate, + Until: booking.EndDate, + Rooms: []string{booking.Room}, + Approved: booking.Status == "accepted", + }) + } + + return entries, nil +} + func (p *Plexams) ExahmRoomsFromBooked() ([]BookedEntry, error) { bookedInfo := viper.Get("roomconstraints.booked") diff --git a/plexams/rooms_for_slots.go b/plexams/rooms_for_slots.go index 55246d4..5be2718 100644 --- a/plexams/rooms_for_slots.go +++ b/plexams/rooms_for_slots.go @@ -204,11 +204,22 @@ func (p *Plexams) roomsWithRestrictedSlots(globalRooms []*model.Room) (map[strin func (p *Plexams) restrictedSlotsForEXaHMRooms() (map[string]set.Set[SlotNumber], error) { restrictedSlots := make(map[string]set.Set[SlotNumber]) - // EXaHM rooms - bookedEntries, err := p.ExahmRoomsFromBooked() + // EXaHM rooms: prefer Anny bookings from DB, fall back to YAML booked entries + ctx := context.Background() + bookedEntries, err := p.ExahmRoomsFromAnnyBookings(ctx) if err != nil { - log.Error().Err(err).Msg("cannot get exahm rooms from booked") - return nil, err + log.Error().Err(err).Msg("cannot get exahm rooms from anny bookings, falling back to booked in YAML") + bookedEntries = nil + } + if len(bookedEntries) == 0 { + log.Debug().Msg("no anny bookings found, reading booked entries from YAML") + bookedEntries, err = p.ExahmRoomsFromBooked() + if err != nil { + log.Error().Err(err).Msg("cannot get exahm rooms from booked") + return nil, err + } + } else { + log.Debug().Int("count", len(bookedEntries)).Msg("using anny bookings for EXaHM room slots") } for _, entry := range bookedEntries { From cdb62c09076ef137d8d8b77c8337cab1366b1aa7 Mon Sep 17 00:00:00 2001 From: Oliver Braun Date: Fri, 22 May 2026 15:54:31 +0200 Subject: [PATCH 3/4] feat: Update booking retrieval to prioritize Anny bookings with fallback to YAML entries --- plexams/rooms.go | 18 +++++++++++++++++- plexams/validate.go | 23 +++++++++++++++++++---- plexams/validate_rooms.go | 13 ++++++++++--- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/plexams/rooms.go b/plexams/rooms.go index 8070ef0..53fa59c 100644 --- a/plexams/rooms.go +++ b/plexams/rooms.go @@ -64,15 +64,31 @@ func (p *Plexams) ExahmRoomsFromAnnyBookings(ctx context.Context) ([]BookedEntry From: booking.StartDate, Until: booking.EndDate, Rooms: []string{booking.Room}, - Approved: booking.Status == "accepted", + Approved: isApprovedAnnyStatus(booking.Status), }) } return entries, nil } +func isApprovedAnnyStatus(status string) bool { + switch strings.ToLower(strings.TrimSpace(status)) { + case "accepted", "acceptet": + return true + default: + return false + } +} + func (p *Plexams) ExahmRoomsFromBooked() ([]BookedEntry, error) { + if !viper.IsSet("roomconstraints.booked") { + return []BookedEntry{}, nil + } + bookedInfo := viper.Get("roomconstraints.booked") + if bookedInfo == nil { + return []BookedEntry{}, nil + } bookedInfoSlice, ok := bookedInfo.([]interface{}) if !ok { diff --git a/plexams/validate.go b/plexams/validate.go index 7eba522..327d8e3 100644 --- a/plexams/validate.go +++ b/plexams/validate.go @@ -301,10 +301,17 @@ func (p *Plexams) ValidateConstraints() error { } spinner.Message(aurora.Sprintf(aurora.Yellow(" get booked entries"))) - bookedEntries, err := p.ExahmRoomsFromBooked() + bookedEntries, err := p.ExahmRoomsFromAnnyBookings(ctx) if err != nil { - log.Error().Err(err).Msg("cannot get booked entries") - return err + log.Error().Err(err).Msg("cannot get entries from anny_bookings, fallback to booked entries in YAML") + bookedEntries = nil + } + if len(bookedEntries) == 0 { + bookedEntries, err = p.ExahmRoomsFromBooked() + if err != nil { + log.Error().Err(err).Msg("cannot get booked entries") + return err + } } for _, constraint := range constraints { @@ -445,8 +452,16 @@ func (p *Plexams) ValidateConstraints() error { } func (p *Plexams) roomBookedDuringExamTime(bookedEntries []BookedEntry, slot *model.Slot) bool { + if slot == nil { + return false + } + + examStart := slot.Starttime + examEnd := slot.Starttime.Add(90 * time.Minute) + for _, bookedEntry := range bookedEntries { - if bookedEntry.From.Before(slot.Starttime) && bookedEntry.Until.After(slot.Starttime.Add(90*time.Minute)) { + // Inclusive overlap: bookings starting/ending exactly at exam boundaries are valid. + if !bookedEntry.From.After(examStart) && !bookedEntry.Until.Before(examEnd) { return true } } diff --git a/plexams/validate_rooms.go b/plexams/validate_rooms.go index d0b13c2..2ffe862 100644 --- a/plexams/validate_rooms.go +++ b/plexams/validate_rooms.go @@ -184,10 +184,17 @@ func (p *Plexams) ValidateRoomsNeedRequest() error { return err } - bookedEntries, err := p.ExahmRoomsFromBooked() + bookedEntries, err := p.ExahmRoomsFromAnnyBookings(ctx) if err != nil { - log.Error().Err(err).Msg("cannot get booked entries") - return err + log.Error().Err(err).Msg("cannot get entries from anny_bookings, fallback to booked entries in YAML") + bookedEntries = nil + } + if len(bookedEntries) == 0 { + bookedEntries, err = p.ExahmRoomsFromBooked() + if err != nil { + log.Error().Err(err).Msg("cannot get booked entries") + return err + } } for _, bookedEntry := range bookedEntries { From 23bbe2f964dc56f4f9b5e761081e1076558275a4 Mon Sep 17 00:00:00 2001 From: Oliver Braun Date: Fri, 22 May 2026 16:05:03 +0200 Subject: [PATCH 4/4] refactor: Update AnnyBooking model and streamline booking retrieval methods --- db/anny_bookings.go | 39 ++++-------------------- graph/model/anny.go | 50 +++++++++++++++++-------------- plexams/anny.go | 56 +++++++++++++++++----------------- plexams/anny_query.go | 70 ++----------------------------------------- 4 files changed, 63 insertions(+), 152 deletions(-) diff --git a/db/anny_bookings.go b/db/anny_bookings.go index c643759..04b6424 100644 --- a/db/anny_bookings.go +++ b/db/anny_bookings.go @@ -3,41 +3,14 @@ package db import ( "context" "strings" - "time" + "github.com/obcode/plexams.go/graph/model" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) -type AnnyBooking struct { - Number string `bson:"number"` - StartDate time.Time `bson:"start_date"` - EndDate time.Time `bson:"end_date"` - BlockerStartDate time.Time `bson:"blocker_start_date"` - BlockerEndDate time.Time `bson:"blocker_end_date"` - ChargedDuration int `bson:"charged_duration"` - Description string `bson:"description"` - CreatedAt time.Time `bson:"created_at"` - UpdatedAt time.Time `bson:"updated_at"` - CanceledAt *time.Time `bson:"canceled_at,omitempty"` - Status string `bson:"status"` - StatusReason any `bson:"status_reason,omitempty"` - IsBlocker bool `bson:"is_blocker"` - CanEdit bool `bson:"can_edit"` - IsEditable bool `bson:"is_editable"` - ManuallyCreated bool `bson:"manually_created"` - Note string `bson:"note"` - Room string `bson:"room,omitempty"` - Self string `bson:"self"` - PersonalizationName string `bson:"personalization_name"` - BookingGroupID string `bson:"booking_group_identifier,omitempty"` - CancelableUntil *time.Time `bson:"cancelable_until,omitempty"` - HasCustomDescription bool `bson:"has_custom_description"` - ResourceID string `bson:"resource_id,omitempty"` -} - -func (db *DB) SaveAnnyBookings(ctx context.Context, bookings []*AnnyBooking) error { +func (db *DB) SaveAnnyBookings(ctx context.Context, bookings []*model.AnnyBooking) error { collection := db.Client.Database(db.databaseName).Collection(collectionAnnyBookings) err := collection.Drop(ctx) @@ -58,15 +31,15 @@ func (db *DB) SaveAnnyBookings(ctx context.Context, bookings []*AnnyBooking) err return nil } -func (db *DB) AnnyBookings(ctx context.Context, room *string) ([]*AnnyBooking, error) { +func (db *DB) AnnyBookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error) { return db.annyBookings(ctx, room) } -func (db *DB) AllAnnyBookings(ctx context.Context) ([]*AnnyBooking, error) { +func (db *DB) AllAnnyBookings(ctx context.Context) ([]*model.AnnyBooking, error) { return db.annyBookings(ctx, nil) } -func (db *DB) annyBookings(ctx context.Context, room *string) ([]*AnnyBooking, error) { +func (db *DB) annyBookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error) { collection := db.Client.Database(db.databaseName).Collection(collectionAnnyBookings) filter := bson.M{} @@ -83,7 +56,7 @@ func (db *DB) annyBookings(ctx context.Context, room *string) ([]*AnnyBooking, e } defer cur.Close(ctx) //nolint:errcheck - bookings := make([]*AnnyBooking, 0) + bookings := make([]*model.AnnyBooking, 0) if err := cur.All(ctx, &bookings); err != nil { return nil, err } diff --git a/graph/model/anny.go b/graph/model/anny.go index 225c79e..a6a1d23 100644 --- a/graph/model/anny.go +++ b/graph/model/anny.go @@ -1,28 +1,32 @@ package model -import "time" +import ( + "time" +) type AnnyBooking struct { - Number string `json:"number"` - StartDate time.Time `json:"startDate"` - EndDate time.Time `json:"endDate"` - BlockerStartDate time.Time `json:"blockerStartDate"` - BlockerEndDate time.Time `json:"blockerEndDate"` - ChargedDuration int `json:"chargedDuration"` - Description string `json:"description"` - CreatedAt time.Time `json:"createdAt"` - UpdatedAt time.Time `json:"updatedAt"` - CanceledAt *time.Time `json:"canceledAt,omitempty"` - Status string `json:"status"` - IsBlocker bool `json:"isBlocker"` - CanEdit bool `json:"canEdit"` - IsEditable bool `json:"isEditable"` - ManuallyCreated bool `json:"manuallyCreated"` - Note string `json:"note"` - Room string `json:"room,omitempty"` - Self string `json:"self"` - PersonalizationName string `json:"personalizationName"` - BookingGroupIdentifier string `json:"bookingGroupIdentifier,omitempty"` - CancelableUntil *time.Time `json:"cancelableUntil,omitempty"` - HasCustomDescription bool `json:"hasCustomDescription"` + Number string `json:"number" bson:"number"` + StartDate time.Time `json:"startDate" bson:"start_date"` + EndDate time.Time `json:"endDate" bson:"end_date"` + BlockerStartDate time.Time `json:"blockerStartDate" bson:"blocker_start_date"` + BlockerEndDate time.Time `json:"blockerEndDate" bson:"blocker_end_date"` + ChargedDuration int `json:"chargedDuration" bson:"charged_duration"` + Description string `json:"description" bson:"description"` + CreatedAt time.Time `json:"createdAt" bson:"created_at"` + UpdatedAt time.Time `json:"updatedAt" bson:"updated_at"` + CanceledAt *time.Time `json:"canceledAt,omitempty" bson:"canceled_at,omitempty"` + Status string `json:"status" bson:"status"` + StatusReason any `json:"-" bson:"status_reason,omitempty"` + IsBlocker bool `json:"isBlocker" bson:"is_blocker"` + CanEdit bool `json:"canEdit" bson:"can_edit"` + IsEditable bool `json:"isEditable" bson:"is_editable"` + ManuallyCreated bool `json:"manuallyCreated" bson:"manually_created"` + Note string `json:"note" bson:"note"` + Room string `json:"room,omitempty" bson:"room,omitempty"` + Self string `json:"self" bson:"self"` + PersonalizationName string `json:"personalizationName" bson:"personalization_name"` + BookingGroupIdentifier string `json:"bookingGroupIdentifier,omitempty" bson:"booking_group_identifier,omitempty"` + CancelableUntil *time.Time `json:"cancelableUntil,omitempty" bson:"cancelable_until,omitempty"` + HasCustomDescription bool `json:"hasCustomDescription" bson:"has_custom_description"` + ResourceID string `json:"-" bson:"resource_id,omitempty"` } diff --git a/plexams/anny.go b/plexams/anny.go index ba65e8a..5b9abae 100644 --- a/plexams/anny.go +++ b/plexams/anny.go @@ -14,7 +14,7 @@ import ( "text/tabwriter" "time" - "github.com/obcode/plexams.go/db" + "github.com/obcode/plexams.go/graph/model" "github.com/spf13/viper" ) @@ -225,7 +225,7 @@ func (p *Plexams) FetchFromAnny() error { return fmt.Errorf("no database configured for saving anny bookings") } - dbBookings := make([]*db.AnnyBooking, 0, len(bookings)) + dbBookings := make([]*model.AnnyBooking, 0, len(bookings)) for _, booking := range bookings { dbBookings = append(dbBookings, annyBookingToDBBooking(booking)) } @@ -383,32 +383,32 @@ func extractResourceID(bookingGroupIdentifier string) string { return matches[1] } -func annyBookingToDBBooking(booking AnnyBooking) *db.AnnyBooking { - return &db.AnnyBooking{ - Number: booking.Number, - StartDate: booking.StartDate, - EndDate: booking.EndDate, - BlockerStartDate: booking.BlockerStartDate, - BlockerEndDate: booking.BlockerEndDate, - ChargedDuration: booking.ChargedDuration, - Description: booking.Description, - CreatedAt: booking.CreatedAt, - UpdatedAt: booking.UpdatedAt, - CanceledAt: booking.CanceledAt, - Status: booking.Status, - StatusReason: booking.StatusReason, - IsBlocker: booking.IsBlocker, - CanEdit: booking.CanEdit, - IsEditable: booking.IsEditable, - ManuallyCreated: booking.ManuallyCreated, - Note: booking.Note, - Room: booking.Room, - Self: booking.Self, - PersonalizationName: booking.PersonalizationName, - BookingGroupID: booking.BookingGroupID, - CancelableUntil: booking.CancelableUntil, - HasCustomDescription: booking.HasCustomDescription, - ResourceID: booking.ResourceID, +func annyBookingToDBBooking(booking AnnyBooking) *model.AnnyBooking { + return &model.AnnyBooking{ + Number: booking.Number, + StartDate: booking.StartDate, + EndDate: booking.EndDate, + BlockerStartDate: booking.BlockerStartDate, + BlockerEndDate: booking.BlockerEndDate, + ChargedDuration: booking.ChargedDuration, + Description: booking.Description, + CreatedAt: booking.CreatedAt, + UpdatedAt: booking.UpdatedAt, + CanceledAt: booking.CanceledAt, + Status: booking.Status, + StatusReason: booking.StatusReason, + IsBlocker: booking.IsBlocker, + CanEdit: booking.CanEdit, + IsEditable: booking.IsEditable, + ManuallyCreated: booking.ManuallyCreated, + Note: booking.Note, + Room: booking.Room, + Self: booking.Self, + PersonalizationName: booking.PersonalizationName, + BookingGroupIdentifier: booking.BookingGroupID, + CancelableUntil: booking.CancelableUntil, + HasCustomDescription: booking.HasCustomDescription, + ResourceID: booking.ResourceID, } } diff --git a/plexams/anny_query.go b/plexams/anny_query.go index 08d8cba..be53ebe 100644 --- a/plexams/anny_query.go +++ b/plexams/anny_query.go @@ -7,75 +7,9 @@ import ( ) func (p *Plexams) AnnyBookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error) { - bookings, err := p.dbClient.AnnyBookings(ctx, room) - if err != nil { - return nil, err - } - - result := make([]*model.AnnyBooking, 0, len(bookings)) - for _, booking := range bookings { - result = append(result, &model.AnnyBooking{ - Number: booking.Number, - StartDate: booking.StartDate, - EndDate: booking.EndDate, - BlockerStartDate: booking.BlockerStartDate, - BlockerEndDate: booking.BlockerEndDate, - ChargedDuration: booking.ChargedDuration, - Description: booking.Description, - CreatedAt: booking.CreatedAt, - UpdatedAt: booking.UpdatedAt, - CanceledAt: booking.CanceledAt, - Status: booking.Status, - IsBlocker: booking.IsBlocker, - CanEdit: booking.CanEdit, - IsEditable: booking.IsEditable, - ManuallyCreated: booking.ManuallyCreated, - Note: booking.Note, - Room: booking.Room, - Self: booking.Self, - PersonalizationName: booking.PersonalizationName, - BookingGroupIdentifier: booking.BookingGroupID, - CancelableUntil: booking.CancelableUntil, - HasCustomDescription: booking.HasCustomDescription, - }) - } - - return result, nil + return p.dbClient.AnnyBookings(ctx, room) } func (p *Plexams) AllAnnyBookings(ctx context.Context) ([]*model.AnnyBooking, error) { - bookings, err := p.dbClient.AllAnnyBookings(ctx) - if err != nil { - return nil, err - } - - result := make([]*model.AnnyBooking, 0, len(bookings)) - for _, booking := range bookings { - result = append(result, &model.AnnyBooking{ - Number: booking.Number, - StartDate: booking.StartDate, - EndDate: booking.EndDate, - BlockerStartDate: booking.BlockerStartDate, - BlockerEndDate: booking.BlockerEndDate, - ChargedDuration: booking.ChargedDuration, - Description: booking.Description, - CreatedAt: booking.CreatedAt, - UpdatedAt: booking.UpdatedAt, - CanceledAt: booking.CanceledAt, - Status: booking.Status, - IsBlocker: booking.IsBlocker, - CanEdit: booking.CanEdit, - IsEditable: booking.IsEditable, - ManuallyCreated: booking.ManuallyCreated, - Note: booking.Note, - Room: booking.Room, - Self: booking.Self, - PersonalizationName: booking.PersonalizationName, - BookingGroupIdentifier: booking.BookingGroupID, - CancelableUntil: booking.CancelableUntil, - HasCustomDescription: booking.HasCustomDescription, - }) - } - - return result, nil + return p.dbClient.AllAnnyBookings(ctx) }