diff --git a/README.md b/README.md index b22f845..a212dd6 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,19 @@ This repository is structured as a mono repository. - Echo - gqlgen (GraphQL) +# How to Deploy to Production + +## Set up Services on Render +The `render.yaml` is where all configurations are gathered and assosiated with this repository. As soon as a new commit is added to `master` branch, the depolyment is triggered. + +## Set up database on Superbase +`Flamingo Armond` uses [Superbase](https://supabase.com/) for the [Database (Postgres)](https://supabase.com/database) and [Auth](https://supabase.com/auth). All configurations and environment valuables are configured on the dashboard. Grab configurations from `.env` file and apply them here, such as database name, user name, user password, SSL enablement, e.g. + +## Set up Auth on Superbase +1. Create `Client ID` and `Client Secret` on `Google` +1. Navigate to the dashboard on `Superbase` and chose `Google Auth` +1. Fill out `Client ID` , `Client Secret` and `Authorized Client IDs` + # Run Locally ``` make server diff --git a/backend/db/migrations/20240704123000_create_users_and_cards_tables.sql b/backend/db/migrations/20240704123000_create_users_and_cards_tables.sql index 58ad654..a454b4d 100644 --- a/backend/db/migrations/20240704123000_create_users_and_cards_tables.sql +++ b/backend/db/migrations/20240704123000_create_users_and_cards_tables.sql @@ -42,6 +42,7 @@ CREATE TABLE IF NOT EXISTS cardgroup_users ( cardgroup_id BIGINT NOT NULL, user_id BIGINT NOT NULL, + state INT DEFAULT 1, created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (cardgroup_id, user_id), @@ -50,6 +51,7 @@ CREATE TABLE IF NOT EXISTS cardgroup_users ); CREATE INDEX idx_cardgroup_users_cardgroup_id ON cardgroup_users(cardgroup_id); CREATE INDEX idx_cardgroup_users_user_id ON cardgroup_users(user_id); +CREATE INDEX idx_cardgroup_users_state ON cardgroup_users(state); CREATE TABLE IF NOT EXISTS roles ( @@ -73,6 +75,18 @@ CREATE TABLE IF NOT EXISTS user_roles CREATE INDEX idx_user_roles_user_id ON user_roles(user_id); CREATE INDEX idx_user_roles_role_id ON user_roles(role_id); +CREATE TABLE IF NOT EXISTS swipe_records +( + id BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL, + direction TEXT NOT NULL, + created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE +); +CREATE INDEX idx_swipe_records_id ON swipe_records(id); +CREATE INDEX idx_swipe_records_user_id ON swipe_records(user_id); + -- +goose statementbegin -- When the updated column is not changed, assign NULL CREATE FUNCTION trg_update_timestamp_none() RETURNS trigger AS @@ -160,4 +174,5 @@ DROP TABLE IF EXISTS roles; DROP TABLE IF EXISTS cardgroup_users; DROP TABLE IF EXISTS cards; DROP TABLE IF EXISTS cardgroups; -DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS swipe_records; +DROP TABLE IF EXISTS users; \ No newline at end of file diff --git a/backend/graph/dataloader.go b/backend/graph/dataloader.go index 1861a33..1ec7278 100644 --- a/backend/graph/dataloader.go +++ b/backend/graph/dataloader.go @@ -11,10 +11,11 @@ import ( ) type Loaders struct { - CardLoader dataloader.Interface[int64, *model.Card] - UserLoader dataloader.Interface[int64, *model.User] - RoleLoader dataloader.Interface[int64, *model.Role] - CardGroupLoader dataloader.Interface[int64, *model.CardGroup] + CardLoader dataloader.Interface[int64, *model.Card] + UserLoader dataloader.Interface[int64, *model.User] + RoleLoader dataloader.Interface[int64, *model.Role] + CardGroupLoader dataloader.Interface[int64, *model.CardGroup] + SwipeRecordLoader dataloader.Interface[int64, *model.SwipeRecord] } func NewLoaders(srv services.Services) *Loaders { @@ -22,12 +23,14 @@ func NewLoaders(srv services.Services) *Loaders { userBatcher := &userBatcher{Srv: srv} roleBatcher := &roleBatcher{Srv: srv} cardGroupBatcher := &cardGroupBatcher{Srv: srv} + swipeRecordBatcher := &swipeRecordBatcher{Srv: srv} return &Loaders{ - CardLoader: dataloader.NewBatchedLoader[int64, *model.Card](cardBatcher.BatchGetCards), - UserLoader: dataloader.NewBatchedLoader[int64, *model.User](userBatcher.BatchGetUsers), - RoleLoader: dataloader.NewBatchedLoader[int64, *model.Role](roleBatcher.BatchGetRoles), - CardGroupLoader: dataloader.NewBatchedLoader[int64, *model.CardGroup](cardGroupBatcher.BatchGetCardGroups), + CardLoader: dataloader.NewBatchedLoader[int64, *model.Card](cardBatcher.BatchGetCards), + UserLoader: dataloader.NewBatchedLoader[int64, *model.User](userBatcher.BatchGetUsers), + RoleLoader: dataloader.NewBatchedLoader[int64, *model.Role](roleBatcher.BatchGetRoles), + CardGroupLoader: dataloader.NewBatchedLoader[int64, *model.CardGroup](cardGroupBatcher.BatchGetCardGroups), + SwipeRecordLoader: dataloader.NewBatchedLoader[int64, *model.SwipeRecord](swipeRecordBatcher.BatchGetSwipeRecords), } } @@ -138,3 +141,30 @@ func (c *cardGroupBatcher) BatchGetCardGroups(ctx context.Context, keys []int64) } return results } + +type swipeRecordBatcher struct { + Srv services.Services +} + +func (s *swipeRecordBatcher) BatchGetSwipeRecords(ctx context.Context, keys []int64) []*dataloader.Result[*model.SwipeRecord] { + swipeRecords, err := s.Srv.GetSwipeRecordsByIDs(ctx, keys) + if err != nil { + logger.Logger.ErrorContext(ctx, "No swipe records found", err) + return make([]*dataloader.Result[*model.SwipeRecord], len(keys)) + } + + swipeRecordMap := make(map[int64]*model.SwipeRecord) + for _, swipeRecord := range swipeRecords { + swipeRecordMap[swipeRecord.ID] = swipeRecord + } + + results := make([]*dataloader.Result[*model.SwipeRecord], len(keys)) + for i, key := range keys { + if swipeRecord, ok := swipeRecordMap[key]; ok { + results[i] = &dataloader.Result[*model.SwipeRecord]{Data: swipeRecord} + } else { + results[i] = &dataloader.Result[*model.SwipeRecord]{Error: errors.New("swipe record not found")} + } + } + return results +} diff --git a/backend/graph/db/model.go b/backend/graph/db/model.go index 5da351d..c1f9fb0 100644 --- a/backend/graph/db/model.go +++ b/backend/graph/db/model.go @@ -43,3 +43,11 @@ type Role struct { Created time.Time `gorm:"column:created;autoCreateTime"` Updated time.Time `gorm:"column:updated;autoCreateTime"` } + +type SwipeRecord struct { + ID int64 `gorm:"column:id;primaryKey" validate:"number"` + UserID int64 `gorm:"column:user_id" validate:"number"` + Direction string `gorm:"column:direction;not null" validate:"required"` + Created time.Time `gorm:"column:created;autoCreateTime"` + Updated time.Time `gorm:"column:updated;autoCreateTime"` +} diff --git a/backend/graph/db/swiperecord.go b/backend/graph/db/swiperecord.go new file mode 100644 index 0000000..65291d0 --- /dev/null +++ b/backend/graph/db/swiperecord.go @@ -0,0 +1,55 @@ +package db + +import ( + customValidator "backend/pkg/validator" + "fmt" + "github.com/go-playground/validator/v10" + "github.com/m-mizutani/goerr" + "gorm.io/gorm" + "time" +) + +// BeforeCreate hook to validate the SwipeRecord fields +func (s *SwipeRecord) BeforeCreate(tx *gorm.DB) (err error) { + return s.validateAtCreate(s) +} + +// BeforeUpdate hook to validate the SwipeRecord fields +func (s *SwipeRecord) BeforeUpdate(tx *gorm.DB) (err error) { + return s.validateStruct(s) +} + +// validateStruct validates the entire SwipeRecord struct +func (s *SwipeRecord) validateStruct(swipeRecord *SwipeRecord) error { + v := customValidator.NewValidateWrapper() + err := v.Validator().Struct(swipeRecord) + if err != nil { + for _, err := range err.(validator.ValidationErrors) { + return goerr.Wrap(err, fmt.Sprintf("Field validation for '%s' failed on the '%s' tag", err.Field(), err.Tag())) + } + } + return nil +} + +// validateAtCreate validates specific fields during the creation of a SwipeRecord +func (s *SwipeRecord) validateAtCreate(swipeRecord *SwipeRecord) error { + v := customValidator.NewValidateWrapper() + + err := v.Validator().Var(swipeRecord.UserID, "required") + if err != nil { + return goerr.Wrap(err, fmt.Sprintf("Field validation for 'user_id' failed %+v", err)) + } + + err = v.Validator().Var(swipeRecord.Direction, "required,oneof=left right up down") // Assuming 'Direction' has specific allowed values + if err != nil { + return goerr.Wrap(err, fmt.Sprintf("Field validation for 'direction' failed %+v", err)) + } + + return nil +} + +// AfterUpdate hook to update the timestamp in the same transaction +func (s *SwipeRecord) AfterUpdate(tx *gorm.DB) (err error) { + tx.Model(&SwipeRecord{}).Where("id = ?", s.ID).Update("updated", time.Now()) + return nil +} diff --git a/backend/graph/generated.go b/backend/graph/generated.go index a4da6f2..91c1a37 100644 --- a/backend/graph/generated.go +++ b/backend/graph/generated.go @@ -103,16 +103,19 @@ type ComplexityRoot struct { CreateCard func(childComplexity int, input model.NewCard) int CreateCardGroup func(childComplexity int, input model.NewCardGroup) int CreateRole func(childComplexity int, input model.NewRole) int + CreateSwipeRecord func(childComplexity int, input model.NewSwipeRecord) int CreateUser func(childComplexity int, input model.NewUser) int DeleteCard func(childComplexity int, id int64) int DeleteCardGroup func(childComplexity int, id int64) int DeleteRole func(childComplexity int, id int64) int + DeleteSwipeRecord func(childComplexity int, id int64) int DeleteUser func(childComplexity int, id int64) int RemoveRoleFromUser func(childComplexity int, userID int64, roleID int64) int RemoveUserFromCardGroup func(childComplexity int, userID int64, cardGroupID int64) int UpdateCard func(childComplexity int, id int64, input model.NewCard) int UpdateCardGroup func(childComplexity int, id int64, input model.NewCardGroup) int UpdateRole func(childComplexity int, id int64, input model.NewRole) int + UpdateSwipeRecord func(childComplexity int, id int64, input model.NewSwipeRecord) int UpdateUser func(childComplexity int, id int64, input model.NewUser) int } @@ -129,6 +132,8 @@ type ComplexityRoot struct { CardGroupsByUser func(childComplexity int, userID int64, first *int, after *int64, last *int, before *int64) int CardsByCardGroup func(childComplexity int, cardGroupID int64, first *int, after *int64, last *int, before *int64) int Role func(childComplexity int, id int64) int + SwipeRecord func(childComplexity int, id int64) int + SwipeRecords func(childComplexity int, userID int64, first *int, after *int64, last *int, before *int64) int User func(childComplexity int, id int64) int UserRole func(childComplexity int, userID int64) int UsersByRole func(childComplexity int, roleID int64, first *int, after *int64, last *int, before *int64) int @@ -154,6 +159,26 @@ type ComplexityRoot struct { Node func(childComplexity int) int } + SwipeRecord struct { + Created func(childComplexity int) int + Direction func(childComplexity int) int + ID func(childComplexity int) int + Updated func(childComplexity int) int + UserID func(childComplexity int) int + } + + SwipeRecordConnection struct { + Edges func(childComplexity int) int + Nodes func(childComplexity int) int + PageInfo func(childComplexity int) int + TotalCount func(childComplexity int) int + } + + SwipeRecordEdge struct { + Cursor func(childComplexity int) int + Node func(childComplexity int) int + } + User struct { CardGroups func(childComplexity int, first *int, after *int64, last *int, before *int64) int Created func(childComplexity int) int @@ -200,16 +225,21 @@ type MutationResolver interface { RemoveUserFromCardGroup(ctx context.Context, userID int64, cardGroupID int64) (*model.CardGroup, error) AssignRoleToUser(ctx context.Context, userID int64, roleID int64) (*model.User, error) RemoveRoleFromUser(ctx context.Context, userID int64, roleID int64) (*model.User, error) + CreateSwipeRecord(ctx context.Context, input model.NewSwipeRecord) (*model.SwipeRecord, error) + UpdateSwipeRecord(ctx context.Context, id int64, input model.NewSwipeRecord) (*model.SwipeRecord, error) + DeleteSwipeRecord(ctx context.Context, id int64) (*bool, error) } type QueryResolver interface { Card(ctx context.Context, id int64) (*model.Card, error) CardGroup(ctx context.Context, id int64) (*model.CardGroup, error) Role(ctx context.Context, id int64) (*model.Role, error) User(ctx context.Context, id int64) (*model.User, error) + SwipeRecord(ctx context.Context, id int64) (*model.SwipeRecord, error) CardsByCardGroup(ctx context.Context, cardGroupID int64, first *int, after *int64, last *int, before *int64) (*model.CardConnection, error) UserRole(ctx context.Context, userID int64) (*model.Role, error) CardGroupsByUser(ctx context.Context, userID int64, first *int, after *int64, last *int, before *int64) (*model.CardGroupConnection, error) UsersByRole(ctx context.Context, roleID int64, first *int, after *int64, last *int, before *int64) (*model.UserConnection, error) + SwipeRecords(ctx context.Context, userID int64, first *int, after *int64, last *int, before *int64) (*model.SwipeRecordConnection, error) } type RoleResolver interface { Users(ctx context.Context, obj *model.Role, first *int, after *int64, last *int, before *int64) (*model.UserConnection, error) @@ -497,6 +527,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.CreateRole(childComplexity, args["input"].(model.NewRole)), true + case "Mutation.createSwipeRecord": + if e.complexity.Mutation.CreateSwipeRecord == nil { + break + } + + args, err := ec.field_Mutation_createSwipeRecord_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.CreateSwipeRecord(childComplexity, args["input"].(model.NewSwipeRecord)), true + case "Mutation.createUser": if e.complexity.Mutation.CreateUser == nil { break @@ -545,6 +587,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.DeleteRole(childComplexity, args["id"].(int64)), true + case "Mutation.deleteSwipeRecord": + if e.complexity.Mutation.DeleteSwipeRecord == nil { + break + } + + args, err := ec.field_Mutation_deleteSwipeRecord_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.DeleteSwipeRecord(childComplexity, args["id"].(int64)), true + case "Mutation.deleteUser": if e.complexity.Mutation.DeleteUser == nil { break @@ -617,6 +671,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.UpdateRole(childComplexity, args["id"].(int64), args["input"].(model.NewRole)), true + case "Mutation.updateSwipeRecord": + if e.complexity.Mutation.UpdateSwipeRecord == nil { + break + } + + args, err := ec.field_Mutation_updateSwipeRecord_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.UpdateSwipeRecord(childComplexity, args["id"].(int64), args["input"].(model.NewSwipeRecord)), true + case "Mutation.updateUser": if e.complexity.Mutation.UpdateUser == nil { break @@ -717,6 +783,30 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Role(childComplexity, args["id"].(int64)), true + case "Query.swipeRecord": + if e.complexity.Query.SwipeRecord == nil { + break + } + + args, err := ec.field_Query_swipeRecord_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.SwipeRecord(childComplexity, args["id"].(int64)), true + + case "Query.swipeRecords": + if e.complexity.Query.SwipeRecords == nil { + break + } + + args, err := ec.field_Query_swipeRecords_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.SwipeRecords(childComplexity, args["userID"].(int64), args["first"].(*int), args["after"].(*int64), args["last"].(*int), args["before"].(*int64)), true + case "Query.user": if e.complexity.Query.User == nil { break @@ -835,6 +925,83 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.RoleEdge.Node(childComplexity), true + case "SwipeRecord.created": + if e.complexity.SwipeRecord.Created == nil { + break + } + + return e.complexity.SwipeRecord.Created(childComplexity), true + + case "SwipeRecord.direction": + if e.complexity.SwipeRecord.Direction == nil { + break + } + + return e.complexity.SwipeRecord.Direction(childComplexity), true + + case "SwipeRecord.id": + if e.complexity.SwipeRecord.ID == nil { + break + } + + return e.complexity.SwipeRecord.ID(childComplexity), true + + case "SwipeRecord.updated": + if e.complexity.SwipeRecord.Updated == nil { + break + } + + return e.complexity.SwipeRecord.Updated(childComplexity), true + + case "SwipeRecord.userId": + if e.complexity.SwipeRecord.UserID == nil { + break + } + + return e.complexity.SwipeRecord.UserID(childComplexity), true + + case "SwipeRecordConnection.edges": + if e.complexity.SwipeRecordConnection.Edges == nil { + break + } + + return e.complexity.SwipeRecordConnection.Edges(childComplexity), true + + case "SwipeRecordConnection.nodes": + if e.complexity.SwipeRecordConnection.Nodes == nil { + break + } + + return e.complexity.SwipeRecordConnection.Nodes(childComplexity), true + + case "SwipeRecordConnection.pageInfo": + if e.complexity.SwipeRecordConnection.PageInfo == nil { + break + } + + return e.complexity.SwipeRecordConnection.PageInfo(childComplexity), true + + case "SwipeRecordConnection.totalCount": + if e.complexity.SwipeRecordConnection.TotalCount == nil { + break + } + + return e.complexity.SwipeRecordConnection.TotalCount(childComplexity), true + + case "SwipeRecordEdge.cursor": + if e.complexity.SwipeRecordEdge.Cursor == nil { + break + } + + return e.complexity.SwipeRecordEdge.Cursor(childComplexity), true + + case "SwipeRecordEdge.node": + if e.complexity.SwipeRecordEdge.Node == nil { + break + } + + return e.complexity.SwipeRecordEdge.Node(childComplexity), true + case "User.cardGroups": if e.complexity.User.CardGroups == nil { break @@ -940,6 +1107,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputNewCard, ec.unmarshalInputNewCardGroup, ec.unmarshalInputNewRole, + ec.unmarshalInputNewSwipeRecord, ec.unmarshalInputNewUser, ) first := true @@ -1234,6 +1402,21 @@ func (ec *executionContext) field_Mutation_createRole_args(ctx context.Context, return args, nil } +func (ec *executionContext) field_Mutation_createSwipeRecord_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 model.NewSwipeRecord + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg0, err = ec.unmarshalNNewSwipeRecord2backendᚋgraphᚋmodelᚐNewSwipeRecord(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_createUser_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1294,6 +1477,21 @@ func (ec *executionContext) field_Mutation_deleteRole_args(ctx context.Context, return args, nil } +func (ec *executionContext) field_Mutation_deleteSwipeRecord_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int64 + if tmp, ok := rawArgs["id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + arg0, err = ec.unmarshalNID2int64(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_deleteUser_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1429,6 +1627,30 @@ func (ec *executionContext) field_Mutation_updateRole_args(ctx context.Context, return args, nil } +func (ec *executionContext) field_Mutation_updateSwipeRecord_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int64 + if tmp, ok := rawArgs["id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + arg0, err = ec.unmarshalNID2int64(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + var arg1 model.NewSwipeRecord + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg1, err = ec.unmarshalNNewSwipeRecord2backendᚋgraphᚋmodelᚐNewSwipeRecord(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_updateUser_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1615,6 +1837,72 @@ func (ec *executionContext) field_Query_role_args(ctx context.Context, rawArgs m return args, nil } +func (ec *executionContext) field_Query_swipeRecord_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int64 + if tmp, ok := rawArgs["id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + arg0, err = ec.unmarshalNID2int64(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_swipeRecords_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int64 + if tmp, ok := rawArgs["userID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("userID")) + arg0, err = ec.unmarshalNID2int64(ctx, tmp) + if err != nil { + return nil, err + } + } + args["userID"] = arg0 + var arg1 *int + if tmp, ok := rawArgs["first"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("first")) + arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["first"] = arg1 + var arg2 *int64 + if tmp, ok := rawArgs["after"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + arg2, err = ec.unmarshalOID2ᚖint64(ctx, tmp) + if err != nil { + return nil, err + } + } + args["after"] = arg2 + var arg3 *int + if tmp, ok := rawArgs["last"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("last")) + arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["last"] = arg3 + var arg4 *int64 + if tmp, ok := rawArgs["before"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("before")) + arg4, err = ec.unmarshalOID2ᚖint64(ctx, tmp) + if err != nil { + return nil, err + } + } + args["before"] = arg4 + return args, nil +} + func (ec *executionContext) field_Query_userRole_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -4200,8 +4488,8 @@ func (ec *executionContext) fieldContext_Mutation_removeRoleFromUser(ctx context return fc, nil } -func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graphql.CollectedField, obj *model.PageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_PageInfo_endCursor(ctx, field) +func (ec *executionContext) _Mutation_createSwipeRecord(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_createSwipeRecord(ctx, field) if err != nil { return graphql.Null } @@ -4214,7 +4502,7 @@ func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graph }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.EndCursor, nil + return ec.resolvers.Mutation().CreateSwipeRecord(rctx, fc.Args["input"].(model.NewSwipeRecord)) }) if err != nil { ec.Error(ctx, err) @@ -4223,26 +4511,49 @@ func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graph if resTmp == nil { return graphql.Null } - res := resTmp.(*int64) + res := resTmp.(*model.SwipeRecord) fc.Result = res - return ec.marshalOID2ᚖint64(ctx, field.Selections, res) + return ec.marshalOSwipeRecord2ᚖbackendᚋgraphᚋmodelᚐSwipeRecord(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_PageInfo_endCursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_createSwipeRecord(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "PageInfo", + Object: "Mutation", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type ID does not have child fields") + switch field.Name { + case "id": + return ec.fieldContext_SwipeRecord_id(ctx, field) + case "userId": + return ec.fieldContext_SwipeRecord_userId(ctx, field) + case "direction": + return ec.fieldContext_SwipeRecord_direction(ctx, field) + case "created": + return ec.fieldContext_SwipeRecord_created(ctx, field) + case "updated": + return ec.fieldContext_SwipeRecord_updated(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type SwipeRecord", 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_Mutation_createSwipeRecord_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } return fc, nil } -func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *model.PageInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_PageInfo_hasNextPage(ctx, field) +func (ec *executionContext) _Mutation_updateSwipeRecord(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_updateSwipeRecord(ctx, field) if err != nil { return graphql.Null } @@ -4255,31 +4566,188 @@ func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field gra }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.HasNextPage, nil + return ec.resolvers.Mutation().UpdateSwipeRecord(rctx, fc.Args["id"].(int64), fc.Args["input"].(model.NewSwipeRecord)) }) 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) + res := resTmp.(*model.SwipeRecord) fc.Result = res - return ec.marshalNBoolean2bool(ctx, field.Selections, res) + return ec.marshalOSwipeRecord2ᚖbackendᚋgraphᚋmodelᚐSwipeRecord(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_PageInfo_hasNextPage(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_updateSwipeRecord(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "PageInfo", + Object: "Mutation", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Boolean does not have child fields") + switch field.Name { + case "id": + return ec.fieldContext_SwipeRecord_id(ctx, field) + case "userId": + return ec.fieldContext_SwipeRecord_userId(ctx, field) + case "direction": + return ec.fieldContext_SwipeRecord_direction(ctx, field) + case "created": + return ec.fieldContext_SwipeRecord_created(ctx, field) + case "updated": + return ec.fieldContext_SwipeRecord_updated(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type SwipeRecord", 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_Mutation_updateSwipeRecord_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteSwipeRecord(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deleteSwipeRecord(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().DeleteSwipeRecord(rctx, fc.Args["id"].(int64)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*bool) + fc.Result = res + return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_deleteSwipeRecord(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + 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_Mutation_deleteSwipeRecord_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graphql.CollectedField, obj *model.PageInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PageInfo_endCursor(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EndCursor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*int64) + fc.Result = res + return ec.marshalOID2ᚖint64(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PageInfo_endCursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PageInfo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *model.PageInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PageInfo_hasNextPage(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.HasNextPage, 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_PageInfo_hasNextPage(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PageInfo", + 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 @@ -4638,6 +5106,70 @@ func (ec *executionContext) fieldContext_Query_user(ctx context.Context, field g return fc, nil } +func (ec *executionContext) _Query_swipeRecord(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_swipeRecord(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().SwipeRecord(rctx, fc.Args["id"].(int64)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.SwipeRecord) + fc.Result = res + return ec.marshalOSwipeRecord2ᚖbackendᚋgraphᚋmodelᚐSwipeRecord(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_swipeRecord(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 "id": + return ec.fieldContext_SwipeRecord_id(ctx, field) + case "userId": + return ec.fieldContext_SwipeRecord_userId(ctx, field) + case "direction": + return ec.fieldContext_SwipeRecord_direction(ctx, field) + case "created": + return ec.fieldContext_SwipeRecord_created(ctx, field) + case "updated": + return ec.fieldContext_SwipeRecord_updated(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type SwipeRecord", 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_swipeRecord_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Query_cardsByCardGroup(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Query_cardsByCardGroup(ctx, field) if err != nil { @@ -4888,6 +5420,68 @@ func (ec *executionContext) fieldContext_Query_usersByRole(ctx context.Context, return fc, nil } +func (ec *executionContext) _Query_swipeRecords(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_swipeRecords(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().SwipeRecords(rctx, fc.Args["userID"].(int64), fc.Args["first"].(*int), fc.Args["after"].(*int64), fc.Args["last"].(*int), fc.Args["before"].(*int64)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.SwipeRecordConnection) + fc.Result = res + return ec.marshalOSwipeRecordConnection2ᚖbackendᚋgraphᚋmodelᚐSwipeRecordConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_swipeRecords(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 "edges": + return ec.fieldContext_SwipeRecordConnection_edges(ctx, field) + case "nodes": + return ec.fieldContext_SwipeRecordConnection_nodes(ctx, field) + case "pageInfo": + return ec.fieldContext_SwipeRecordConnection_pageInfo(ctx, field) + case "totalCount": + return ec.fieldContext_SwipeRecordConnection_totalCount(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type SwipeRecordConnection", 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_swipeRecords_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Query___type(ctx, field) if err != nil { @@ -4948,22 +5542,560 @@ func (ec *executionContext) fieldContext_Query___type(ctx context.Context, field return nil, fmt.Errorf("no field named %q was found under type __Type", 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___type_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { - ec.Error(ctx, err) - return fc, err - } + 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___type_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___schema(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectSchema() + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Schema) + fc.Result = res + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query___schema(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "description": + return ec.fieldContext___Schema_description(ctx, field) + case "types": + return ec.fieldContext___Schema_types(ctx, field) + case "queryType": + return ec.fieldContext___Schema_queryType(ctx, field) + case "mutationType": + return ec.fieldContext___Schema_mutationType(ctx, field) + case "subscriptionType": + return ec.fieldContext___Schema_subscriptionType(ctx, field) + case "directives": + return ec.fieldContext___Schema_directives(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Schema", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _Role_id(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Role_id(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, 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.(int64) + fc.Result = res + return ec.marshalNID2int64(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Role_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Role", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Role_name(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Role_name(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, 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_Role_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Role", + 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) _Role_created(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Role_created(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Created, 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_Role_created(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Role", + 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) _Role_updated(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Role_updated(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Updated, 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_Role_updated(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Role", + 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) _Role_users(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Role_users(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Role().Users(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*int64), fc.Args["last"].(*int), fc.Args["before"].(*int64)) + }) + 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.UserConnection) + fc.Result = res + return ec.marshalNUserConnection2ᚖbackendᚋgraphᚋmodelᚐUserConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Role_users(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Role", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "edges": + return ec.fieldContext_UserConnection_edges(ctx, field) + case "nodes": + return ec.fieldContext_UserConnection_nodes(ctx, field) + case "pageInfo": + return ec.fieldContext_UserConnection_pageInfo(ctx, field) + case "totalCount": + return ec.fieldContext_UserConnection_totalCount(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type UserConnection", 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_Role_users_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _RoleConnection_edges(ctx context.Context, field graphql.CollectedField, obj *model.RoleConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_RoleConnection_edges(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Edges, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]*model.RoleEdge) + fc.Result = res + return ec.marshalORoleEdge2ᚕᚖbackendᚋgraphᚋmodelᚐRoleEdge(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_RoleConnection_edges(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "RoleConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "cursor": + return ec.fieldContext_RoleEdge_cursor(ctx, field) + case "node": + return ec.fieldContext_RoleEdge_node(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type RoleEdge", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _RoleConnection_nodes(ctx context.Context, field graphql.CollectedField, obj *model.RoleConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_RoleConnection_nodes(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Nodes, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]*model.Role) + fc.Result = res + return ec.marshalORole2ᚕᚖbackendᚋgraphᚋmodelᚐRole(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_RoleConnection_nodes(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "RoleConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Role_id(ctx, field) + case "name": + return ec.fieldContext_Role_name(ctx, field) + case "created": + return ec.fieldContext_Role_created(ctx, field) + case "updated": + return ec.fieldContext_Role_updated(ctx, field) + case "users": + return ec.fieldContext_Role_users(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Role", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _RoleConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.RoleConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_RoleConnection_pageInfo(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PageInfo, 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.(*model.PageInfo) + fc.Result = res + return ec.marshalNPageInfo2ᚖbackendᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_RoleConnection_pageInfo(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "RoleConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "endCursor": + return ec.fieldContext_PageInfo_endCursor(ctx, field) + case "hasNextPage": + return ec.fieldContext_PageInfo_hasNextPage(ctx, field) + case "hasPreviousPage": + return ec.fieldContext_PageInfo_hasPreviousPage(ctx, field) + case "startCursor": + return ec.fieldContext_PageInfo_startCursor(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PageInfo", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _RoleConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *model.RoleConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_RoleConnection_totalCount(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.TotalCount, 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_RoleConnection_totalCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "RoleConnection", + 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) _RoleEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *model.RoleEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_RoleEdge_cursor(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) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Cursor, 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.(int64) + fc.Result = res + return ec.marshalNID2int64(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_RoleEdge_cursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "RoleEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } return fc, nil } -func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Query___schema(ctx, field) +func (ec *executionContext) _RoleEdge_node(ctx context.Context, field graphql.CollectedField, obj *model.RoleEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_RoleEdge_node(ctx, field) if err != nil { return graphql.Null } @@ -4976,49 +6108,50 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.introspectSchema() + return obj.Node, 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.(*introspection.Schema) + res := resTmp.(*model.Role) fc.Result = res - return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) + return ec.marshalNRole2ᚖbackendᚋgraphᚋmodelᚐRole(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Query___schema(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_RoleEdge_node(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Query", + Object: "RoleEdge", Field: field, - IsMethod: true, + IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { - case "description": - return ec.fieldContext___Schema_description(ctx, field) - case "types": - return ec.fieldContext___Schema_types(ctx, field) - case "queryType": - return ec.fieldContext___Schema_queryType(ctx, field) - case "mutationType": - return ec.fieldContext___Schema_mutationType(ctx, field) - case "subscriptionType": - return ec.fieldContext___Schema_subscriptionType(ctx, field) - case "directives": - return ec.fieldContext___Schema_directives(ctx, field) + case "id": + return ec.fieldContext_Role_id(ctx, field) + case "name": + return ec.fieldContext_Role_name(ctx, field) + case "created": + return ec.fieldContext_Role_created(ctx, field) + case "updated": + return ec.fieldContext_Role_updated(ctx, field) + case "users": + return ec.fieldContext_Role_users(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type __Schema", field.Name) + return nil, fmt.Errorf("no field named %q was found under type Role", field.Name) }, } return fc, nil } -func (ec *executionContext) _Role_id(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Role_id(ctx, field) +func (ec *executionContext) _SwipeRecord_id(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecord) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecord_id(ctx, field) if err != nil { return graphql.Null } @@ -5048,9 +6181,9 @@ func (ec *executionContext) _Role_id(ctx context.Context, field graphql.Collecte return ec.marshalNID2int64(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Role_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecord_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Role", + Object: "SwipeRecord", Field: field, IsMethod: false, IsResolver: false, @@ -5061,8 +6194,8 @@ func (ec *executionContext) fieldContext_Role_id(_ context.Context, field graphq return fc, nil } -func (ec *executionContext) _Role_name(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Role_name(ctx, field) +func (ec *executionContext) _SwipeRecord_userId(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecord) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecord_userId(ctx, field) if err != nil { return graphql.Null } @@ -5075,7 +6208,7 @@ func (ec *executionContext) _Role_name(ctx context.Context, field graphql.Collec }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Name, nil + return obj.UserID, nil }) if err != nil { ec.Error(ctx, err) @@ -5087,26 +6220,26 @@ func (ec *executionContext) _Role_name(ctx context.Context, field graphql.Collec } return graphql.Null } - res := resTmp.(string) + res := resTmp.(int64) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNID2int64(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Role_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecord_userId(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Role", + Object: "SwipeRecord", 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 nil, errors.New("field of type ID does not have child fields") }, } return fc, nil } -func (ec *executionContext) _Role_created(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Role_created(ctx, field) +func (ec *executionContext) _SwipeRecord_direction(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecord) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecord_direction(ctx, field) if err != nil { return graphql.Null } @@ -5119,7 +6252,7 @@ func (ec *executionContext) _Role_created(ctx context.Context, field graphql.Col }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Created, nil + return obj.Direction, nil }) if err != nil { ec.Error(ctx, err) @@ -5131,26 +6264,26 @@ func (ec *executionContext) _Role_created(ctx context.Context, field graphql.Col } return graphql.Null } - res := resTmp.(time.Time) + res := resTmp.(string) fc.Result = res - return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Role_created(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecord_direction(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Role", + Object: "SwipeRecord", 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 nil, errors.New("field of type String does not have child fields") }, } return fc, nil } -func (ec *executionContext) _Role_updated(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Role_updated(ctx, field) +func (ec *executionContext) _SwipeRecord_created(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecord) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecord_created(ctx, field) if err != nil { return graphql.Null } @@ -5163,7 +6296,7 @@ func (ec *executionContext) _Role_updated(ctx context.Context, field graphql.Col }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Updated, nil + return obj.Created, nil }) if err != nil { ec.Error(ctx, err) @@ -5180,9 +6313,9 @@ func (ec *executionContext) _Role_updated(ctx context.Context, field graphql.Col return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Role_updated(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecord_created(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Role", + Object: "SwipeRecord", Field: field, IsMethod: false, IsResolver: false, @@ -5193,8 +6326,8 @@ func (ec *executionContext) fieldContext_Role_updated(_ context.Context, field g return fc, nil } -func (ec *executionContext) _Role_users(ctx context.Context, field graphql.CollectedField, obj *model.Role) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Role_users(ctx, field) +func (ec *executionContext) _SwipeRecord_updated(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecord) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecord_updated(ctx, field) if err != nil { return graphql.Null } @@ -5207,7 +6340,7 @@ func (ec *executionContext) _Role_users(ctx context.Context, field graphql.Colle }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Role().Users(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*int64), fc.Args["last"].(*int), fc.Args["before"].(*int64)) + return obj.Updated, nil }) if err != nil { ec.Error(ctx, err) @@ -5219,47 +6352,26 @@ func (ec *executionContext) _Role_users(ctx context.Context, field graphql.Colle } return graphql.Null } - res := resTmp.(*model.UserConnection) + res := resTmp.(time.Time) fc.Result = res - return ec.marshalNUserConnection2ᚖbackendᚋgraphᚋmodelᚐUserConnection(ctx, field.Selections, res) + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Role_users(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecord_updated(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Role", + Object: "SwipeRecord", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "edges": - return ec.fieldContext_UserConnection_edges(ctx, field) - case "nodes": - return ec.fieldContext_UserConnection_nodes(ctx, field) - case "pageInfo": - return ec.fieldContext_UserConnection_pageInfo(ctx, field) - case "totalCount": - return ec.fieldContext_UserConnection_totalCount(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type UserConnection", field.Name) + return nil, errors.New("field of type Time does not have child fields") }, } - 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_Role_users_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { - ec.Error(ctx, err) - return fc, err - } return fc, nil } -func (ec *executionContext) _RoleConnection_edges(ctx context.Context, field graphql.CollectedField, obj *model.RoleConnection) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_RoleConnection_edges(ctx, field) +func (ec *executionContext) _SwipeRecordConnection_edges(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecordConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecordConnection_edges(ctx, field) if err != nil { return graphql.Null } @@ -5281,32 +6393,32 @@ func (ec *executionContext) _RoleConnection_edges(ctx context.Context, field gra if resTmp == nil { return graphql.Null } - res := resTmp.([]*model.RoleEdge) + res := resTmp.([]*model.SwipeRecordEdge) fc.Result = res - return ec.marshalORoleEdge2ᚕᚖbackendᚋgraphᚋmodelᚐRoleEdge(ctx, field.Selections, res) + return ec.marshalOSwipeRecordEdge2ᚕᚖbackendᚋgraphᚋmodelᚐSwipeRecordEdge(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_RoleConnection_edges(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecordConnection_edges(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "RoleConnection", + Object: "SwipeRecordConnection", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "cursor": - return ec.fieldContext_RoleEdge_cursor(ctx, field) + return ec.fieldContext_SwipeRecordEdge_cursor(ctx, field) case "node": - return ec.fieldContext_RoleEdge_node(ctx, field) + return ec.fieldContext_SwipeRecordEdge_node(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type RoleEdge", field.Name) + return nil, fmt.Errorf("no field named %q was found under type SwipeRecordEdge", field.Name) }, } return fc, nil } -func (ec *executionContext) _RoleConnection_nodes(ctx context.Context, field graphql.CollectedField, obj *model.RoleConnection) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_RoleConnection_nodes(ctx, field) +func (ec *executionContext) _SwipeRecordConnection_nodes(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecordConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecordConnection_nodes(ctx, field) if err != nil { return graphql.Null } @@ -5328,38 +6440,38 @@ func (ec *executionContext) _RoleConnection_nodes(ctx context.Context, field gra if resTmp == nil { return graphql.Null } - res := resTmp.([]*model.Role) + res := resTmp.([]*model.SwipeRecord) fc.Result = res - return ec.marshalORole2ᚕᚖbackendᚋgraphᚋmodelᚐRole(ctx, field.Selections, res) + return ec.marshalOSwipeRecord2ᚕᚖbackendᚋgraphᚋmodelᚐSwipeRecord(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_RoleConnection_nodes(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecordConnection_nodes(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "RoleConnection", + Object: "SwipeRecordConnection", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "id": - return ec.fieldContext_Role_id(ctx, field) - case "name": - return ec.fieldContext_Role_name(ctx, field) + return ec.fieldContext_SwipeRecord_id(ctx, field) + case "userId": + return ec.fieldContext_SwipeRecord_userId(ctx, field) + case "direction": + return ec.fieldContext_SwipeRecord_direction(ctx, field) case "created": - return ec.fieldContext_Role_created(ctx, field) + return ec.fieldContext_SwipeRecord_created(ctx, field) case "updated": - return ec.fieldContext_Role_updated(ctx, field) - case "users": - return ec.fieldContext_Role_users(ctx, field) + return ec.fieldContext_SwipeRecord_updated(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type Role", field.Name) + return nil, fmt.Errorf("no field named %q was found under type SwipeRecord", field.Name) }, } return fc, nil } -func (ec *executionContext) _RoleConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.RoleConnection) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_RoleConnection_pageInfo(ctx, field) +func (ec *executionContext) _SwipeRecordConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecordConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecordConnection_pageInfo(ctx, field) if err != nil { return graphql.Null } @@ -5389,9 +6501,9 @@ func (ec *executionContext) _RoleConnection_pageInfo(ctx context.Context, field return ec.marshalNPageInfo2ᚖbackendᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_RoleConnection_pageInfo(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecordConnection_pageInfo(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "RoleConnection", + Object: "SwipeRecordConnection", Field: field, IsMethod: false, IsResolver: false, @@ -5412,8 +6524,8 @@ func (ec *executionContext) fieldContext_RoleConnection_pageInfo(_ context.Conte return fc, nil } -func (ec *executionContext) _RoleConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *model.RoleConnection) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_RoleConnection_totalCount(ctx, field) +func (ec *executionContext) _SwipeRecordConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecordConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecordConnection_totalCount(ctx, field) if err != nil { return graphql.Null } @@ -5443,9 +6555,9 @@ func (ec *executionContext) _RoleConnection_totalCount(ctx context.Context, fiel return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_RoleConnection_totalCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecordConnection_totalCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "RoleConnection", + Object: "SwipeRecordConnection", Field: field, IsMethod: false, IsResolver: false, @@ -5456,8 +6568,8 @@ func (ec *executionContext) fieldContext_RoleConnection_totalCount(_ context.Con return fc, nil } -func (ec *executionContext) _RoleEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *model.RoleEdge) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_RoleEdge_cursor(ctx, field) +func (ec *executionContext) _SwipeRecordEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecordEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecordEdge_cursor(ctx, field) if err != nil { return graphql.Null } @@ -5487,9 +6599,9 @@ func (ec *executionContext) _RoleEdge_cursor(ctx context.Context, field graphql. return ec.marshalNID2int64(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_RoleEdge_cursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecordEdge_cursor(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "RoleEdge", + Object: "SwipeRecordEdge", Field: field, IsMethod: false, IsResolver: false, @@ -5500,8 +6612,8 @@ func (ec *executionContext) fieldContext_RoleEdge_cursor(_ context.Context, fiel return fc, nil } -func (ec *executionContext) _RoleEdge_node(ctx context.Context, field graphql.CollectedField, obj *model.RoleEdge) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_RoleEdge_node(ctx, field) +func (ec *executionContext) _SwipeRecordEdge_node(ctx context.Context, field graphql.CollectedField, obj *model.SwipeRecordEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SwipeRecordEdge_node(ctx, field) if err != nil { return graphql.Null } @@ -5526,31 +6638,31 @@ func (ec *executionContext) _RoleEdge_node(ctx context.Context, field graphql.Co } return graphql.Null } - res := resTmp.(*model.Role) + res := resTmp.(*model.SwipeRecord) fc.Result = res - return ec.marshalNRole2ᚖbackendᚋgraphᚋmodelᚐRole(ctx, field.Selections, res) + return ec.marshalNSwipeRecord2ᚖbackendᚋgraphᚋmodelᚐSwipeRecord(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_RoleEdge_node(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SwipeRecordEdge_node(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "RoleEdge", + Object: "SwipeRecordEdge", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "id": - return ec.fieldContext_Role_id(ctx, field) - case "name": - return ec.fieldContext_Role_name(ctx, field) + return ec.fieldContext_SwipeRecord_id(ctx, field) + case "userId": + return ec.fieldContext_SwipeRecord_userId(ctx, field) + case "direction": + return ec.fieldContext_SwipeRecord_direction(ctx, field) case "created": - return ec.fieldContext_Role_created(ctx, field) + return ec.fieldContext_SwipeRecord_created(ctx, field) case "updated": - return ec.fieldContext_Role_updated(ctx, field) - case "users": - return ec.fieldContext_Role_users(ctx, field) + return ec.fieldContext_SwipeRecord_updated(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type Role", field.Name) + return nil, fmt.Errorf("no field named %q was found under type SwipeRecord", field.Name) }, } return fc, nil @@ -8106,6 +9218,54 @@ func (ec *executionContext) unmarshalInputNewRole(ctx context.Context, obj inter return it, nil } +func (ec *executionContext) unmarshalInputNewSwipeRecord(ctx context.Context, obj interface{}) (model.NewSwipeRecord, error) { + var it model.NewSwipeRecord + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"userId", "direction", "created", "updated"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "userId": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("userId")) + data, err := ec.unmarshalNID2int64(ctx, v) + if err != nil { + return it, err + } + it.UserID = data + case "direction": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("direction")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Direction = data + case "created": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("created")) + data, err := ec.unmarshalNTime2timeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.Created = data + case "updated": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updated")) + data, err := ec.unmarshalNTime2timeᚐTime(ctx, v) + if err != nil { + return it, err + } + it.Updated = data + } + } + + return it, nil +} + func (ec *executionContext) unmarshalInputNewUser(ctx context.Context, obj interface{}) (model.NewUser, error) { var it model.NewUser asMap := map[string]interface{}{} @@ -8665,6 +9825,18 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_removeRoleFromUser(ctx, field) }) + case "createSwipeRecord": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createSwipeRecord(ctx, field) + }) + case "updateSwipeRecord": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updateSwipeRecord(ctx, field) + }) + case "deleteSwipeRecord": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteSwipeRecord(ctx, field) + }) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -8764,7 +9936,45 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_card(ctx, field) + res = ec._Query_card(ctx, field) + 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 "cardGroup": + field := field + + innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_cardGroup(ctx, field) + 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 "role": + field := field + + innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_role(ctx, field) return res } @@ -8774,7 +9984,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "cardGroup": + case "user": field := field innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { @@ -8783,7 +9993,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_cardGroup(ctx, field) + res = ec._Query_user(ctx, field) return res } @@ -8793,7 +10003,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "role": + case "swipeRecord": field := field innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { @@ -8802,7 +10012,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_role(ctx, field) + res = ec._Query_swipeRecord(ctx, field) return res } @@ -8812,7 +10022,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "user": + case "cardsByCardGroup": field := field innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { @@ -8821,7 +10031,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_user(ctx, field) + res = ec._Query_cardsByCardGroup(ctx, field) return res } @@ -8831,7 +10041,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "cardsByCardGroup": + case "userRole": field := field innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { @@ -8840,7 +10050,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_cardsByCardGroup(ctx, field) + res = ec._Query_userRole(ctx, field) return res } @@ -8850,7 +10060,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "userRole": + case "cardGroupsByUser": field := field innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { @@ -8859,7 +10069,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_userRole(ctx, field) + res = ec._Query_cardGroupsByUser(ctx, field) return res } @@ -8869,7 +10079,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "cardGroupsByUser": + case "usersByRole": field := field innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { @@ -8878,7 +10088,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_cardGroupsByUser(ctx, field) + res = ec._Query_usersByRole(ctx, field) return res } @@ -8888,7 +10098,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) - case "usersByRole": + case "swipeRecords": field := field innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { @@ -8897,7 +10107,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._Query_usersByRole(ctx, field) + res = ec._Query_swipeRecords(ctx, field) return res } @@ -9120,6 +10330,157 @@ func (ec *executionContext) _RoleEdge(ctx context.Context, sel ast.SelectionSet, return out } +var swipeRecordImplementors = []string{"SwipeRecord"} + +func (ec *executionContext) _SwipeRecord(ctx context.Context, sel ast.SelectionSet, obj *model.SwipeRecord) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, swipeRecordImplementors) + + 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("SwipeRecord") + case "id": + out.Values[i] = ec._SwipeRecord_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "userId": + out.Values[i] = ec._SwipeRecord_userId(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "direction": + out.Values[i] = ec._SwipeRecord_direction(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "created": + out.Values[i] = ec._SwipeRecord_created(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updated": + out.Values[i] = ec._SwipeRecord_updated(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 swipeRecordConnectionImplementors = []string{"SwipeRecordConnection"} + +func (ec *executionContext) _SwipeRecordConnection(ctx context.Context, sel ast.SelectionSet, obj *model.SwipeRecordConnection) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, swipeRecordConnectionImplementors) + + 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("SwipeRecordConnection") + case "edges": + out.Values[i] = ec._SwipeRecordConnection_edges(ctx, field, obj) + case "nodes": + out.Values[i] = ec._SwipeRecordConnection_nodes(ctx, field, obj) + case "pageInfo": + out.Values[i] = ec._SwipeRecordConnection_pageInfo(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "totalCount": + out.Values[i] = ec._SwipeRecordConnection_totalCount(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 swipeRecordEdgeImplementors = []string{"SwipeRecordEdge"} + +func (ec *executionContext) _SwipeRecordEdge(ctx context.Context, sel ast.SelectionSet, obj *model.SwipeRecordEdge) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, swipeRecordEdgeImplementors) + + 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("SwipeRecordEdge") + case "cursor": + out.Values[i] = ec._SwipeRecordEdge_cursor(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "node": + out.Values[i] = ec._SwipeRecordEdge_node(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 userImplementors = []string{"User"} func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *model.User) graphql.Marshaler { @@ -9808,6 +11169,11 @@ func (ec *executionContext) unmarshalNNewRole2backendᚋgraphᚋmodelᚐNewRole( return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNNewSwipeRecord2backendᚋgraphᚋmodelᚐNewSwipeRecord(ctx context.Context, v interface{}) (model.NewSwipeRecord, error) { + res, err := ec.unmarshalInputNewSwipeRecord(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNNewUser2backendᚋgraphᚋmodelᚐNewUser(ctx context.Context, v interface{}) (model.NewUser, error) { res, err := ec.unmarshalInputNewUser(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -9862,6 +11228,16 @@ func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.S return res } +func (ec *executionContext) marshalNSwipeRecord2ᚖbackendᚋgraphᚋmodelᚐSwipeRecord(ctx context.Context, sel ast.SelectionSet, v *model.SwipeRecord) 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") + } + return graphql.Null + } + return ec._SwipeRecord(ctx, sel, v) +} + func (ec *executionContext) unmarshalNTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { res, err := graphql.UnmarshalTime(v) return res, graphql.ErrorOnPath(ctx, err) @@ -10568,6 +11944,109 @@ func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel as return res } +func (ec *executionContext) marshalOSwipeRecord2ᚕᚖbackendᚋgraphᚋmodelᚐSwipeRecord(ctx context.Context, sel ast.SelectionSet, v []*model.SwipeRecord) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + 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() + } + ret[i] = ec.marshalOSwipeRecord2ᚖbackendᚋgraphᚋmodelᚐSwipeRecord(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + return ret +} + +func (ec *executionContext) marshalOSwipeRecord2ᚖbackendᚋgraphᚋmodelᚐSwipeRecord(ctx context.Context, sel ast.SelectionSet, v *model.SwipeRecord) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._SwipeRecord(ctx, sel, v) +} + +func (ec *executionContext) marshalOSwipeRecordConnection2ᚖbackendᚋgraphᚋmodelᚐSwipeRecordConnection(ctx context.Context, sel ast.SelectionSet, v *model.SwipeRecordConnection) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._SwipeRecordConnection(ctx, sel, v) +} + +func (ec *executionContext) marshalOSwipeRecordEdge2ᚕᚖbackendᚋgraphᚋmodelᚐSwipeRecordEdge(ctx context.Context, sel ast.SelectionSet, v []*model.SwipeRecordEdge) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + 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() + } + ret[i] = ec.marshalOSwipeRecordEdge2ᚖbackendᚋgraphᚋmodelᚐSwipeRecordEdge(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + return ret +} + +func (ec *executionContext) marshalOSwipeRecordEdge2ᚖbackendᚋgraphᚋmodelᚐSwipeRecordEdge(ctx context.Context, sel ast.SelectionSet, v *model.SwipeRecordEdge) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._SwipeRecordEdge(ctx, sel, v) +} + func (ec *executionContext) marshalOUser2ᚕᚖbackendᚋgraphᚋmodelᚐUser(ctx context.Context, sel ast.SelectionSet, v []*model.User) graphql.Marshaler { if v == nil { return graphql.Null diff --git a/backend/graph/model/models_gen.go b/backend/graph/model/models_gen.go index 991408e..16ce36c 100644 --- a/backend/graph/model/models_gen.go +++ b/backend/graph/model/models_gen.go @@ -78,6 +78,13 @@ type NewRole struct { Updated time.Time `json:"updated"` } +type NewSwipeRecord struct { + UserID int64 `json:"userId" validate:"required"` + Direction string `json:"direction" validate:"required"` + Created time.Time `json:"created"` + Updated time.Time `json:"updated"` +} + type NewUser struct { Name string `json:"name" validate:"required,fl_name,min=1"` RoleIds []int64 `json:"role_ids"` @@ -115,6 +122,26 @@ type RoleEdge struct { Node *Role `json:"node" validate:"-"` } +type SwipeRecord struct { + ID int64 `json:"id"` + UserID int64 `json:"userId"` + Direction string `json:"direction" validate:"required"` + Created time.Time `json:"created"` + Updated time.Time `json:"updated"` +} + +type SwipeRecordConnection struct { + Edges []*SwipeRecordEdge `json:"edges,omitempty" validate:"-"` + Nodes []*SwipeRecord `json:"nodes,omitempty" validate:"-"` + PageInfo *PageInfo `json:"pageInfo"` + TotalCount int `json:"totalCount"` +} + +type SwipeRecordEdge struct { + Cursor int64 `json:"cursor"` + Node *SwipeRecord `json:"node" validate:"-"` +} + type User struct { ID int64 `json:"id"` Name string `json:"name" validate:"required,fl_name,min=1"` diff --git a/backend/graph/schema.graphqls b/backend/graph/schema.graphqls index b26a34b..b92ace2 100644 --- a/backend/graph/schema.graphqls +++ b/backend/graph/schema.graphqls @@ -97,6 +97,26 @@ type CardGroupConnection { totalCount: Int! } +type SwipeRecord { + id: ID! + userId: ID! + direction: String! @validation(format: "required") + created: Time! + updated: Time! +} + +type SwipeRecordEdge { + cursor: ID! + node: SwipeRecord! @validation(format: "-") +} + +type SwipeRecordConnection { + edges: [SwipeRecordEdge] @validation(format: "-") + nodes: [SwipeRecord] @validation(format: "-") + pageInfo: PageInfo! + totalCount: Int! +} + input NewCard { front: String! @validation(format: "required,min=1") back: String! @validation(format: "required,min=1") @@ -108,7 +128,7 @@ input NewCard { } input NewCardGroup { - name: String!, @validation(format: "required,min=1") + name: String! @validation(format: "required,min=1") card_ids: [ID!] user_ids: [ID!]! created: Time!, @@ -116,7 +136,7 @@ input NewCardGroup { } input NewUser { - name: String!, @validation(format: "required,fl_name,min=1") + name: String! @validation(format: "required,fl_name,min=1") role_ids: [ID!]! created: Time!, updated: Time!, @@ -128,17 +148,27 @@ input NewRole { updated: Time!, } +input NewSwipeRecord { + userId: ID! @validation(format: "required") + direction: String! @validation(format: "required") + created: Time! + updated: Time! +} + + type Query { - card(id: ID!): Card - cardGroup(id: ID!): CardGroup - role(id: ID!): Role - user(id: ID!): User - cardsByCardGroup(cardGroupID: ID!, first: Int, after: ID, last: Int, before: ID): CardConnection - userRole(userID: ID!): Role - cardGroupsByUser(userID: ID!, first: Int, after: ID, last: Int, before: ID): CardGroupConnection - usersByRole(roleID: ID!, first: Int, after: ID, last: Int, before: ID): UserConnection -} -# Mutation Type + card(id: ID!): Card + cardGroup(id: ID!): CardGroup + role(id: ID!): Role + user(id: ID!): User + swipeRecord(id: ID!): SwipeRecord + cardsByCardGroup(cardGroupID: ID!, first: Int, after: ID, last: Int, before: ID): CardConnection + userRole(userID: ID!): Role + cardGroupsByUser(userID: ID!, first: Int, after: ID, last: Int, before: ID): CardGroupConnection + usersByRole(roleID: ID!, first: Int, after: ID, last: Int, before: ID): UserConnection + swipeRecords(userID: ID!,first: Int, after: ID, last: Int, before: ID): SwipeRecordConnection +} + type Mutation { createCard(input: NewCard!): Card updateCard(id: ID!, input: NewCard!): Card @@ -156,4 +186,7 @@ type Mutation { removeUserFromCardGroup(userID: ID!, cardGroupID: ID!): CardGroup assignRoleToUser(userID: ID!, roleID: ID!): User removeRoleFromUser(userID: ID!, roleID: ID!): User -} \ No newline at end of file + createSwipeRecord(input: NewSwipeRecord!): SwipeRecord + updateSwipeRecord(id: ID!, input: NewSwipeRecord!): SwipeRecord + deleteSwipeRecord(id: ID!): Boolean +} diff --git a/backend/graph/schema.resolvers.go b/backend/graph/schema.resolvers.go index be6a56a..3abab10 100644 --- a/backend/graph/schema.resolvers.go +++ b/backend/graph/schema.resolvers.go @@ -8,6 +8,7 @@ import ( "backend/graph/model" "context" "fmt" + "github.com/m-mizutani/goerr" ) @@ -247,6 +248,27 @@ func (r *mutationResolver) RemoveRoleFromUser(ctx context.Context, userID int64, return r.Srv.RemoveRoleFromUser(ctx, userID, roleID) } +// CreateSwipeRecord is the resolver for the createSwipeRecord field. +func (r *mutationResolver) CreateSwipeRecord(ctx context.Context, input model.NewSwipeRecord) (*model.SwipeRecord, error) { + if err := r.VW.ValidateStruct(input); err != nil { + return nil, goerr.Wrap(err, "invalid input CreateSwipeRecord") + } + return r.Srv.CreateSwipeRecord(ctx, input) +} + +// UpdateSwipeRecord is the resolver for the updateSwipeRecord field. +func (r *mutationResolver) UpdateSwipeRecord(ctx context.Context, id int64, input model.NewSwipeRecord) (*model.SwipeRecord, error) { + if err := r.VW.ValidateStruct(input); err != nil { + return nil, goerr.Wrap(err, "invalid input UpdateSwipeRecord") + } + return r.Srv.UpdateSwipeRecord(ctx, id, input) +} + +// DeleteSwipeRecord is the resolver for the deleteSwipeRecord field. +func (r *mutationResolver) DeleteSwipeRecord(ctx context.Context, id int64) (*bool, error) { + return r.Srv.DeleteSwipeRecord(ctx, id) +} + // Card is the resolver for the card field. func (r *queryResolver) Card(ctx context.Context, id int64) (*model.Card, error) { // Use DataLoader to fetch the Card by ID @@ -290,6 +312,18 @@ func (r *queryResolver) User(ctx context.Context, id int64) (*model.User, error) return user, nil } +// SwipeRecord is the resolver for the swipeRecord field. +func (r *queryResolver) SwipeRecord(ctx context.Context, id int64) (*model.SwipeRecord, error) { + // Use DataLoader to fetch the SwipeRecord by ID + thunk := r.Loaders.SwipeRecordLoader.Load(ctx, id) + swipeRecord, err := thunk() + if err != nil { + return nil, goerr.Wrap(err, "fetch by SwipeRecord") + } + + return swipeRecord, nil +} + // CardsByCardGroup is the resolver for the cardsByCardGroup field. func (r *queryResolver) CardsByCardGroup(ctx context.Context, cardGroupID int64, first *int, after *int64, last *int, before *int64) (*model.CardConnection, error) { return r.Srv.PaginatedCardsByCardGroup(ctx, cardGroupID, first, after, last, before) @@ -310,6 +344,11 @@ func (r *queryResolver) UsersByRole(ctx context.Context, roleID int64, first *in return r.Srv.PaginatedUsersByRole(ctx, roleID, first, after, last, before) } +// SwipeRecords is the resolver for the swipeRecords field. +func (r *queryResolver) SwipeRecords(ctx context.Context, userID int64, first *int, after *int64, last *int, before *int64) (*model.SwipeRecordConnection, error) { + return r.Srv.PaginatedSwipeRecordsByUser(ctx, userID, first, after, last, before) +} + // Users is the resolver for the users field in Role. func (r *roleResolver) Users(ctx context.Context, obj *model.Role, first *int, after *int64, last *int, before *int64) (*model.UserConnection, error) { var userIDs []int64 diff --git a/backend/graph/services/card.go b/backend/graph/services/card.go index e7ea923..4e99a99 100644 --- a/backend/graph/services/card.go +++ b/backend/graph/services/card.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "log/slog" "strings" "time" @@ -52,7 +53,7 @@ func (s *cardService) GetCardByID(ctx context.Context, id int64) (*model.Card, e if err := s.db.WithContext(ctx).First(&card, id).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { err := fmt.Errorf("card not found") - logger.Logger.ErrorContext(ctx, "Card not found: %d", id) + logger.Logger.ErrorContext(ctx, "Card not found:", slog.String("id", fmt.Sprintf("%d", id))) return nil, err } logger.Logger.ErrorContext(ctx, "Failed to get card by ID", err) @@ -79,7 +80,7 @@ func (s *cardService) CreateCard(ctx context.Context, input model.NewCard) (*mod func (s *cardService) UpdateCard(ctx context.Context, id int64, input model.NewCard) (*model.Card, error) { var card repository.Card if err := s.db.WithContext(ctx).First(&card, id).Error; err != nil { - logger.Logger.ErrorContext(ctx, "Card does not exist: %d", id) + logger.Logger.ErrorContext(ctx, "Card does not exist", slog.String("id", fmt.Sprintf("%d", id))) return nil, err } card.Front = input.Front diff --git a/backend/graph/services/role.go b/backend/graph/services/role.go index 562da45..43383c0 100644 --- a/backend/graph/services/role.go +++ b/backend/graph/services/role.go @@ -178,8 +178,8 @@ func (s *roleService) PaginatedRolesByUser(ctx context.Context, userID int64, fi } if err := query.Association("Roles").Find(&roles).Error; err != nil { - logger.Logger.ErrorContext(ctx, "Error retrieving paginated roles by user", err) - return nil, fmt.Errorf("error %+v", err) + logger.Logger.ErrorContext(ctx, "Error retrieving paginated roles by user", "error", err) + return nil, fmt.Errorf("error %+v", err()) } var edges []*model.RoleEdge diff --git a/backend/graph/services/service.go b/backend/graph/services/service.go index 0a57df6..0b5f844 100644 --- a/backend/graph/services/service.go +++ b/backend/graph/services/service.go @@ -12,6 +12,7 @@ type Services interface { CardGroupService UserService RoleService + SwipeRecordService } type CardService interface { @@ -61,18 +62,31 @@ type RoleService interface { GetRolesByIDs(ctx context.Context, ids []int64) ([]*model.Role, error) } +type SwipeRecordService interface { + GetSwipeRecordByID(ctx context.Context, id int64) (*model.SwipeRecord, error) + CreateSwipeRecord(ctx context.Context, input model.NewSwipeRecord) (*model.SwipeRecord, error) + UpdateSwipeRecord(ctx context.Context, id int64, input model.NewSwipeRecord) (*model.SwipeRecord, error) + DeleteSwipeRecord(ctx context.Context, id int64) (*bool, error) + SwipeRecords(ctx context.Context) ([]*model.SwipeRecord, error) + SwipeRecordsByUser(ctx context.Context, userID int64) ([]*model.SwipeRecord, error) + PaginatedSwipeRecordsByUser(ctx context.Context, userID int64, first *int, after *int64, last *int, before *int64) (*model.SwipeRecordConnection, error) + GetSwipeRecordsByIDs(ctx context.Context, ids []int64) ([]*model.SwipeRecord, error) +} + type services struct { *cardService *cardGroupService *userService *roleService + *swipeRecordService } func New(db *gorm.DB) Services { return &services{ - cardService: &cardService{db: db, defaultLimit: 20}, - cardGroupService: &cardGroupService{db: db, defaultLimit: 20}, - userService: &userService{db: db, defaultLimit: 20}, - roleService: &roleService{db: db, defaultLimit: 20}, + cardService: &cardService{db: db, defaultLimit: 20}, + cardGroupService: &cardGroupService{db: db, defaultLimit: 20}, + userService: &userService{db: db, defaultLimit: 20}, + roleService: &roleService{db: db, defaultLimit: 20}, + swipeRecordService: &swipeRecordService{db: db, defaultLimit: 20}, } } diff --git a/backend/graph/services/swiperecord.go b/backend/graph/services/swiperecord.go new file mode 100644 index 0000000..2606693 --- /dev/null +++ b/backend/graph/services/swiperecord.go @@ -0,0 +1,193 @@ +package services + +import ( + repository "backend/graph/db" + "backend/graph/model" + "backend/pkg/logger" + "context" + "errors" + "fmt" + "strings" + "time" + + "gorm.io/gorm" +) + +type swipeRecordService struct { + db *gorm.DB + defaultLimit int +} + +func convertToGormSwipeRecord(input model.NewSwipeRecord) *repository.SwipeRecord { + return &repository.SwipeRecord{ + UserID: input.UserID, + Direction: input.Direction, + Created: input.Created, + Updated: input.Updated, + } +} + +func convertToSwipeRecord(swipeRecord repository.SwipeRecord) *model.SwipeRecord { + return &model.SwipeRecord{ + ID: swipeRecord.ID, + UserID: swipeRecord.UserID, + Direction: swipeRecord.Direction, + Created: swipeRecord.Created, + Updated: swipeRecord.Updated, + } +} + +func (s *swipeRecordService) GetSwipeRecordByID(ctx context.Context, id int64) (*model.SwipeRecord, error) { + var swipeRecord repository.SwipeRecord + if err := s.db.WithContext(ctx).First(&swipeRecord, id).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + err := fmt.Errorf("swipe record not found") + logger.Logger.ErrorContext(ctx, "Swipe record not found:", "id", id) + return nil, err + } + logger.Logger.ErrorContext(ctx, "Failed to get swipe record by ID", err) + return nil, err + } + return convertToSwipeRecord(swipeRecord), nil +} + +func (s *swipeRecordService) CreateSwipeRecord(ctx context.Context, input model.NewSwipeRecord) (*model.SwipeRecord, error) { + gormSwipeRecord := convertToGormSwipeRecord(input) + result := s.db.WithContext(ctx).Create(gormSwipeRecord) + if result.Error != nil { + if strings.Contains(result.Error.Error(), "foreign key constraint") { + err := fmt.Errorf("invalid swipe ID or card ID") + logger.Logger.ErrorContext(ctx, "Failed to create swipe record: invalid swipe ID or card ID", err) + return nil, err + } + logger.Logger.ErrorContext(ctx, "Failed to create swipe record", result.Error) + return nil, result.Error + } + return convertToSwipeRecord(*gormSwipeRecord), nil +} + +func (s *swipeRecordService) UpdateSwipeRecord(ctx context.Context, id int64, input model.NewSwipeRecord) (*model.SwipeRecord, error) { + var swipeRecord repository.SwipeRecord + if err := s.db.WithContext(ctx).First(&swipeRecord, id).Error; err != nil { + logger.Logger.ErrorContext(ctx, "Swipe record does not exist: ", "id", id) + return nil, err + } + swipeRecord.Direction = input.Direction + swipeRecord.Updated = time.Now() + + if err := s.db.WithContext(ctx).Save(&swipeRecord).Error; err != nil { + logger.Logger.ErrorContext(ctx, "Failed to save swipe record", err) + return nil, err + } + return convertToSwipeRecord(swipeRecord), nil +} + +func (s *swipeRecordService) DeleteSwipeRecord(ctx context.Context, id int64) (*bool, error) { + result := s.db.WithContext(ctx).Delete(&repository.SwipeRecord{}, id) + if result.Error != nil { + logger.Logger.ErrorContext(ctx, "Failed to delete swipe record", result.Error) + return nil, result.Error + } + + success := result.RowsAffected > 0 + if !success { + err := fmt.Errorf("record not found") + logger.Logger.ErrorContext(ctx, "Swipe record not found for deletion", err) + return &success, err + } + + return &success, nil +} + +func (s *swipeRecordService) SwipeRecords(ctx context.Context) ([]*model.SwipeRecord, error) { + var swipeRecords []repository.SwipeRecord + if err := s.db.WithContext(ctx).Find(&swipeRecords).Error; err != nil { + logger.Logger.ErrorContext(ctx, "Failed to retrieve swipe records", err) + return nil, err + } + var gqlSwipeRecords []*model.SwipeRecord + for _, swipeRecord := range swipeRecords { + gqlSwipeRecords = append(gqlSwipeRecords, convertToSwipeRecord(swipeRecord)) + } + return gqlSwipeRecords, nil +} + +func (s *swipeRecordService) SwipeRecordsByUser(ctx context.Context, userID int64) ([]*model.SwipeRecord, error) { + var swipeRecords []repository.SwipeRecord + if err := s.db.WithContext(ctx).Where("user_id = ?", userID).Find(&swipeRecords).Error; err != nil { + logger.Logger.ErrorContext(ctx, "Failed to retrieve swipe records by user ID", err) + return nil, err + } + var gqlSwipeRecords []*model.SwipeRecord + for _, swipeRecord := range swipeRecords { + gqlSwipeRecords = append(gqlSwipeRecords, convertToSwipeRecord(swipeRecord)) + } + return gqlSwipeRecords, nil +} + +func (s *swipeRecordService) PaginatedSwipeRecordsByUser(ctx context.Context, userID int64, first *int, after *int64, last *int, before *int64) (*model.SwipeRecordConnection, error) { + var swipeRecords []repository.SwipeRecord + query := s.db.WithContext(ctx).Where("user_id = ?", userID) + + if after != nil { + query = query.Where("id > ?", *after) + } + if before != nil { + query = query.Where("id < ?", *before) + } + if first != nil { + query = query.Order("id asc").Limit(*first) + } else if last != nil { + query = query.Order("id desc").Limit(*last) + } else { + query = query.Order("id asc").Limit(s.defaultLimit) + } + + if err := query.Find(&swipeRecords).Error; err != nil { + logger.Logger.ErrorContext(ctx, "Failed to retrieve paginated swipe records by user ID", err) + return nil, err + } + + var edges []*model.SwipeRecordEdge + var nodes []*model.SwipeRecord + for _, swipeRecord := range swipeRecords { + node := convertToSwipeRecord(swipeRecord) + edges = append(edges, &model.SwipeRecordEdge{ + Cursor: swipeRecord.ID, + Node: node, + }) + nodes = append(nodes, node) + } + + pageInfo := &model.PageInfo{} + if len(swipeRecords) > 0 { + pageInfo.HasNextPage = len(swipeRecords) == s.defaultLimit + pageInfo.HasPreviousPage = len(swipeRecords) == s.defaultLimit + if len(edges) > 0 { + pageInfo.StartCursor = &edges[0].Cursor + pageInfo.EndCursor = &edges[len(edges)-1].Cursor + } + } + + return &model.SwipeRecordConnection{ + Edges: edges, + Nodes: nodes, + PageInfo: pageInfo, + TotalCount: len(swipeRecords), + }, nil +} + +func (s *swipeRecordService) GetSwipeRecordsByIDs(ctx context.Context, ids []int64) ([]*model.SwipeRecord, error) { + var swipeRecords []*repository.SwipeRecord + if err := s.db.WithContext(ctx).Where("id IN ?", ids).Find(&swipeRecords).Error; err != nil { + logger.Logger.ErrorContext(ctx, "Failed to retrieve swipe records by IDs", err) + return nil, err + } + + var gqlSwipeRecords []*model.SwipeRecord + for _, swipeRecord := range swipeRecords { + gqlSwipeRecords = append(gqlSwipeRecords, convertToSwipeRecord(*swipeRecord)) + } + + return gqlSwipeRecords, nil +} diff --git a/backend/graph/services/swiperecord_test.go b/backend/graph/services/swiperecord_test.go new file mode 100644 index 0000000..3aa38b5 --- /dev/null +++ b/backend/graph/services/swiperecord_test.go @@ -0,0 +1,231 @@ +package services_test + +import ( + "backend/graph/model" + "backend/graph/services" + "backend/testutils" + "context" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + "gorm.io/gorm" + "testing" + "time" +) + +type SwipeRecordTestSuite struct { + suite.Suite + db *gorm.DB + sv services.SwipeRecordService + userID int64 + cardGroup *model.CardGroup + cleanup func() +} + +func (suite *SwipeRecordTestSuite) SetupSuite() { + // Setup context + ctx := context.Background() + + // Set up the test database + pg, cleanup, err := testutils.SetupTestDB(ctx, "user", "password", "dbname") + if err != nil { + suite.T().Fatalf("Failed to setup test database: %+v", err) + } + suite.cleanup = func() { + cleanup(migrationFilePath) + } + + // Run migrations + if err := pg.RunGooseMigrationsUp(migrationFilePath); err != nil { + suite.T().Fatalf("Failed to run migrations: %+v", err) + } + + // Setup service + suite.db = pg.GetDB() + suite.sv = services.New(suite.db) + + // Create a user and card group + userService := suite.sv.(services.UserService) + cardGroupService := suite.sv.(services.CardGroupService) + roleService := suite.sv.(services.RoleService) + + createdGroup, err := testutils.CreateUserAndCardGroup(ctx, userService, cardGroupService, roleService) + if err != nil { + suite.T().Fatalf("Failed to create user and card group: %+v", err) + } + suite.userID = createdGroup.Users.Nodes[0].ID + suite.cardGroup = createdGroup +} + +func (suite *SwipeRecordTestSuite) TearDownSuite() { + suite.cleanup() +} + +func (suite *SwipeRecordTestSuite) SetupSubTest() { + t := suite.T() + t.Helper() + testutils.RunServersTest(t, suite.db, nil) +} + +func (suite *SwipeRecordTestSuite) TestSwipeRecordService() { + swipeRecordService := suite.sv.(services.SwipeRecordService) + ctx := context.Background() + t := suite.T() + t.Helper() + + suite.Run("Normal_CreateSwipeRecord", func() { + newSwipeRecord := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "left", + Created: time.Now(), + Updated: time.Now(), + } + + createdSwipeRecord, err := swipeRecordService.CreateSwipeRecord(ctx, newSwipeRecord) + + assert.NoError(t, err) + assert.Equal(t, "left", createdSwipeRecord.Direction) + }) + + suite.Run("Error_CreateSwipeRecord", func() { + newSwipeRecord := model.NewSwipeRecord{ + UserID: 0, // Invalid UserID + Direction: "", + } + + createdSwipeRecord, err := swipeRecordService.CreateSwipeRecord(ctx, newSwipeRecord) + + assert.Error(t, err) + assert.Nil(t, createdSwipeRecord) + }) + + suite.Run("Normal_GetSwipeRecordByID", func() { + newSwipeRecord := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "left", + Created: time.Now(), + Updated: time.Now(), + } + createdSwipeRecord, _ := swipeRecordService.CreateSwipeRecord(ctx, newSwipeRecord) + + fetchedSwipeRecord, err := swipeRecordService.GetSwipeRecordByID(ctx, createdSwipeRecord.ID) + + assert.NoError(t, err) + assert.Equal(t, createdSwipeRecord.ID, fetchedSwipeRecord.ID) + }) + + suite.Run("Error_GetSwipeRecordByID", func() { + fetchedSwipeRecord, err := swipeRecordService.GetSwipeRecordByID(ctx, -1) // Invalid ID + + assert.Error(t, err) + assert.Nil(t, fetchedSwipeRecord) + }) + + suite.Run("Normal_UpdateSwipeRecord", func() { + newSwipeRecord := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "left", + Created: time.Now(), + Updated: time.Now(), + } + createdSwipeRecord, _ := swipeRecordService.CreateSwipeRecord(ctx, newSwipeRecord) + + updateSwipeRecord := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "right", + } + + updatedSwipeRecord, err := swipeRecordService.UpdateSwipeRecord(ctx, createdSwipeRecord.ID, updateSwipeRecord) + + assert.NoError(t, err) + assert.Equal(t, "right", updatedSwipeRecord.Direction) + }) + + suite.Run("Error_UpdateSwipeRecord", func() { + updateSwipeRecord := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "right", + } + + updatedSwipeRecord, err := swipeRecordService.UpdateSwipeRecord(ctx, -1, updateSwipeRecord) // Invalid ID + + assert.Error(t, err) + assert.Nil(t, updatedSwipeRecord) + }) + + suite.Run("Normal_DeleteSwipeRecord", func() { + newSwipeRecord := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "left", + Created: time.Now(), + Updated: time.Now(), + } + createdSwipeRecord, _ := swipeRecordService.CreateSwipeRecord(ctx, newSwipeRecord) + + deleted, err := swipeRecordService.DeleteSwipeRecord(ctx, createdSwipeRecord.ID) + + assert.NoError(t, err) + assert.True(t, *deleted) + }) + + suite.Run("Error_DeleteSwipeRecord", func() { + deleted, err := swipeRecordService.DeleteSwipeRecord(ctx, -1) // Invalid ID + + assert.Error(t, err) + assert.False(t, *deleted) + }) + + suite.Run("Normal_ListSwipeRecords", func() { + newSwipeRecord1 := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "left", + Created: time.Now(), + Updated: time.Now(), + } + newSwipeRecord2 := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "right", + Created: time.Now(), + Updated: time.Now(), + } + swipeRecordService.CreateSwipeRecord(ctx, newSwipeRecord1) + swipeRecordService.CreateSwipeRecord(ctx, newSwipeRecord2) + + swipeRecords, err := swipeRecordService.SwipeRecords(ctx) + + assert.NoError(t, err) + assert.Len(t, swipeRecords, 2) + }) + + suite.Run("Normal_ListSwipeRecordsByUser", func() { + newSwipeRecord1 := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "left", + Created: time.Now(), + Updated: time.Now(), + } + newSwipeRecord2 := model.NewSwipeRecord{ + UserID: suite.userID, + Direction: "right", + Created: time.Now(), + Updated: time.Now(), + } + swipeRecordService.CreateSwipeRecord(ctx, newSwipeRecord1) + swipeRecordService.CreateSwipeRecord(ctx, newSwipeRecord2) + + swipeRecords, err := swipeRecordService.SwipeRecordsByUser(ctx, suite.userID) + + assert.NoError(t, err) + assert.Len(t, swipeRecords, 2) + }) + + suite.Run("Error_ListSwipeRecordsByUser", func() { + swipeRecords, err := swipeRecordService.SwipeRecordsByUser(ctx, -1) // Invalid UserID + + assert.Error(t, err) + assert.Nil(t, swipeRecords) + }) +} + +func TestSwipeRecordTestSuite(t *testing.T) { + suite.Run(t, new(SwipeRecordTestSuite)) +}