From 66973589605f902eb5c392b89ee431f54cfa600c Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Mon, 8 Feb 2021 12:41:58 -0500 Subject: [PATCH] Add Filters! --- go.mod | 1 + go.sum | 2 + graph/generated/generated.go | 1021 +++++++++++----------------------- graph/model/models_gen.go | 146 ++--- graph/schema.graphqls | 82 ++- graph/schema.resolvers.go | 65 ++- internal/db/filters.go | 193 +++++++ internal/db/media_items.go | 9 +- 8 files changed, 664 insertions(+), 855 deletions(-) create mode 100644 internal/db/filters.go diff --git a/go.mod b/go.mod index 810144d..34eab88 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/dsoprea/go-exif/v3 v3.0.0-20201216222538-db167117f483 github.com/gabriel-vasile/mimetype v1.1.2 github.com/google/uuid v1.1.5 + github.com/iancoleman/strcase v0.1.3 github.com/lestrrat-go/jwx v1.0.8 github.com/mattn/go-sqlite3 v1.14.6 github.com/sirupsen/logrus v1.7.0 diff --git a/go.sum b/go.sum index fee82df..e6f8078 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,8 @@ github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplb github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/iancoleman/strcase v0.1.3 h1:dJBk1m2/qjL1twPLf68JND55vvivMupZ4wIzE8CTdBw= +github.com/iancoleman/strcase v0.1.3/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 3c9fec9..2b29157 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -53,6 +53,7 @@ type ComplexityRoot struct { ID func(childComplexity int) int Name func(childComplexity int) int UpdatedAt func(childComplexity int) int + UserID func(childComplexity int) int } AlbumResponse struct { @@ -135,6 +136,7 @@ type ComplexityRoot struct { ID func(childComplexity int) int Name func(childComplexity int) int UpdatedAt func(childComplexity int) int + UserID func(childComplexity int) int } TagResponse struct { @@ -228,6 +230,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Album.UpdatedAt(childComplexity), true + case "Album.userID": + if e.complexity.Album.UserID == nil { + break + } + + return e.complexity.Album.UserID(childComplexity), true + case "AlbumResponse.data": if e.complexity.AlbumResponse.Data == nil { break @@ -672,6 +681,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Tag.UpdatedAt(childComplexity), true + case "Tag.userID": + if e.complexity.Tag.UserID == nil { + break + } + + return e.complexity.Tag.UserID(childComplexity), true + case "TagResponse.data": if e.complexity.TagResponse.Data == nil { break @@ -906,8 +922,8 @@ input TimeFilter { notEqualTo: Time lessThan: Time lessThanOrEqualTo: Time - moreThan: Time - moreThanOrEqualTo: Time + greaterThan: Time + greaterThanOrEqualTo: Time } input IntFilter { @@ -915,10 +931,8 @@ input IntFilter { notEqualTo: Int lessThan: Int lessThanOrEqualTo: Int - moreThan: Int - moreThanOrEqualTo: Int - in: [Int!] - notIn: [Int!] + greaterThan: Int + greaterThanOrEqualTo: Int } input FloatFilter { @@ -926,10 +940,8 @@ input FloatFilter { notEqualTo: Float lessThan: Float lessThanOrEqualTo: Float - moreThan: Float - moreThanOrEqualTo: Float - in: [Float!] - notIn: [Float!] + greaterThan: Float + greaterThanOrEqualTo: Float } input BooleanFilter { @@ -940,49 +952,32 @@ input BooleanFilter { input IDFilter { equalTo: ID notEqualTo: ID - in: [ID!] - notIn: [ID!] } input StringFilter { equalTo: String notEqualTo: String - startWith: String - notStartWith: String - endWith: String - notEndWith: String - contain: String - notContain: String - in: [String!] - notIn: [String!] - - startWithStrict: String - notStartWithStrict: String - endWithStrict: String - notEndWithStrict: String - containStrict: String - notContainStrict: String + startsWith: String + notStartsWith: String + endsWith: String + notEndsWith: String + contains: String + notContains: String } input RoleFilter { equalTo: Role notEqualTo: Role - in: [Role!] - notIn: [Role!] } input DeviceTypeFilter { equalTo: DeviceType notEqualTo: DeviceType - in: [DeviceType!] - notIn: [DeviceType!] } input AuthTypeFilter { equalTo: AuthType notEqualTo: AuthType - in: [AuthType!] - notIn: [AuthType!] } # ------------------------------------------------------------ @@ -1010,8 +1005,8 @@ type Device { updatedAt: Time name: String! @meta(gorm: "not null") type: DeviceType! @meta(gorm: "default:Unknown;not null") - userID: ID! @meta(gorm: "not null") refreshKey: String @isPrivate + userID: ID! @meta(gorm: "not null") } type MediaItem { @@ -1019,21 +1014,22 @@ type MediaItem { createdAt: Time updatedAt: Time exifDate: Time - latitude: Float - longitude: Float + latitude: Float @meta(gorm: "precision:5") + longitude: Float @meta(gorm: "precision:5") isVideo: Boolean! @meta(gorm: "default:false;not null") fileName: String! @meta(gorm: "not null") origName: String! @meta(gorm: "not null") - tags: [Tag] @meta(gorm: "many2many:media_tags") - albums: [Album] @meta(gorm: "many2many:media_albums") + tags: [Tag] @meta(gorm: "many2many:media_tags;foreignKey:ID,UserID;References:ID") + albums: [Album] @meta(gorm: "many2many:media_albums;foreignKey:ID,UserID;Refrences:ID") userID: ID! @meta(gorm: "not null") } type Tag { - id: ID! @meta(gorm: "primaryKey;not null") + id: ID! @meta(gorm: "primaryKey;not null") createdAt: Time updatedAt: Time - name: String! @meta(gorm: "unique;not null") + name: String! @meta(gorm: "unique;not null") + userID: ID! @meta(gorm: "not null") } type Album { @@ -1041,7 +1037,7 @@ type Album { createdAt: Time updatedAt: Time name: String! @meta(gorm: "unique;not null") - # userID: ID! @meta(gorm: "not null") + userID: ID! @meta(gorm: "not null") } # ------------------------------------------------------------ @@ -1058,8 +1054,8 @@ input UserFilter { role: RoleFilter authType: AuthTypeFilter - and: UserFilter - or: UserFilter + # and: UserFilter + # or: UserFilter } input MediaItemFilter { @@ -1074,8 +1070,8 @@ input MediaItemFilter { tags: TagFilter albums: AlbumFilter - and: MediaItemFilter - or: MediaItemFilter + # and: MediaItemFilter + # or: MediaItemFilter } input DeviceFilter { @@ -1085,8 +1081,8 @@ input DeviceFilter { name: StringFilter type: DeviceTypeFilter - and: MediaItemFilter - or: MediaItemFilter + # and: MediaItemFilter + # or: MediaItemFilter } input TagFilter { @@ -1095,8 +1091,8 @@ input TagFilter { updatedAt: TimeFilter name: StringFilter - and: MediaItemFilter - or: MediaItemFilter + # and: MediaItemFilter + # or: MediaItemFilter } input AlbumFilter { @@ -1105,8 +1101,8 @@ input AlbumFilter { updatedAt: TimeFilter name: StringFilter - and: MediaItemFilter - or: MediaItemFilter + # and: MediaItemFilter + # or: MediaItemFilter } # ------------------------------------------------------------ @@ -1958,6 +1954,65 @@ func (ec *executionContext) _Album_name(ctx context.Context, field graphql.Colle return ec.marshalNString2string(ctx, field.Selections, res) } +func (ec *executionContext) _Album_userID(ctx context.Context, field graphql.CollectedField, obj *model.Album) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Album", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.UserID, nil + } + directive1 := func(ctx context.Context) (interface{}, error) { + gorm, err := ec.unmarshalOString2ᚖstring(ctx, "not null") + if err != nil { + return nil, err + } + if ec.directives.Meta == nil { + return nil, errors.New("directive meta is not implemented") + } + return ec.directives.Meta(ctx, obj, directive0, gorm) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(string); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp) + }) + 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.marshalNID2string(ctx, field.Selections, res) +} + func (ec *executionContext) _AlbumResponse_data(ctx context.Context, field graphql.CollectedField, obj *model.AlbumResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -2365,6 +2420,58 @@ func (ec *executionContext) _Device_type(ctx context.Context, field graphql.Coll return ec.marshalNDeviceType2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceType(ctx, field.Selections, res) } +func (ec *executionContext) _Device_refreshKey(ctx context.Context, field graphql.CollectedField, obj *model.Device) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Device", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.RefreshKey, nil + } + directive1 := func(ctx context.Context) (interface{}, error) { + if ec.directives.IsPrivate == nil { + return nil, errors.New("directive isPrivate is not implemented") + } + return ec.directives.IsPrivate(ctx, obj, directive0) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(*string); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + func (ec *executionContext) _Device_userID(ctx context.Context, field graphql.CollectedField, obj *model.Device) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -2424,58 +2531,6 @@ func (ec *executionContext) _Device_userID(ctx context.Context, field graphql.Co return ec.marshalNID2string(ctx, field.Selections, res) } -func (ec *executionContext) _Device_refreshKey(ctx context.Context, field graphql.CollectedField, obj *model.Device) (ret graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - fc := &graphql.FieldContext{ - Object: "Device", - Field: field, - Args: nil, - IsMethod: false, - IsResolver: false, - } - - ctx = graphql.WithFieldContext(ctx, fc) - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - directive0 := func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.RefreshKey, nil - } - directive1 := func(ctx context.Context) (interface{}, error) { - if ec.directives.IsPrivate == nil { - return nil, errors.New("directive isPrivate is not implemented") - } - return ec.directives.IsPrivate(ctx, obj, directive0) - } - - tmp, err := directive1(rctx) - if err != nil { - return nil, graphql.ErrorOnPath(ctx, err) - } - if tmp == nil { - return nil, nil - } - if data, ok := tmp.(*string); ok { - return data, nil - } - return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp) - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*string) - fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) -} - func (ec *executionContext) _DeviceResponse_data(ctx context.Context, field graphql.CollectedField, obj *model.DeviceResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -2715,8 +2770,32 @@ func (ec *executionContext) _MediaItem_latitude(ctx context.Context, field graph ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Latitude, nil + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Latitude, nil + } + directive1 := func(ctx context.Context) (interface{}, error) { + gorm, err := ec.unmarshalOString2ᚖstring(ctx, "precision:5") + if err != nil { + return nil, err + } + if ec.directives.Meta == nil { + return nil, errors.New("directive meta is not implemented") + } + return ec.directives.Meta(ctx, obj, directive0, gorm) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(*float64); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be *float64`, tmp) }) if err != nil { ec.Error(ctx, err) @@ -2747,8 +2826,32 @@ func (ec *executionContext) _MediaItem_longitude(ctx context.Context, field grap ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Longitude, nil + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Longitude, nil + } + directive1 := func(ctx context.Context) (interface{}, error) { + gorm, err := ec.unmarshalOString2ᚖstring(ctx, "precision:5") + if err != nil { + return nil, err + } + if ec.directives.Meta == nil { + return nil, errors.New("directive meta is not implemented") + } + return ec.directives.Meta(ctx, obj, directive0, gorm) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(*float64); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be *float64`, tmp) }) if err != nil { ec.Error(ctx, err) @@ -2961,7 +3064,7 @@ func (ec *executionContext) _MediaItem_tags(ctx context.Context, field graphql.C return obj.Tags, nil } directive1 := func(ctx context.Context) (interface{}, error) { - gorm, err := ec.unmarshalOString2ᚖstring(ctx, "many2many:media_tags") + gorm, err := ec.unmarshalOString2ᚖstring(ctx, "many2many:media_tags;foreignKey:ID,UserID;References:ID") if err != nil { return nil, err } @@ -3017,7 +3120,7 @@ func (ec *executionContext) _MediaItem_albums(ctx context.Context, field graphql return obj.Albums, nil } directive1 := func(ctx context.Context) (interface{}, error) { - gorm, err := ec.unmarshalOString2ᚖstring(ctx, "many2many:media_albums") + gorm, err := ec.unmarshalOString2ᚖstring(ctx, "many2many:media_albums;foreignKey:ID,UserID;Refrences:ID") if err != nil { return nil, err } @@ -4626,6 +4729,65 @@ func (ec *executionContext) _Tag_name(ctx context.Context, field graphql.Collect return ec.marshalNString2string(ctx, field.Selections, res) } +func (ec *executionContext) _Tag_userID(ctx context.Context, field graphql.CollectedField, obj *model.Tag) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Tag", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.UserID, nil + } + directive1 := func(ctx context.Context) (interface{}, error) { + gorm, err := ec.unmarshalOString2ᚖstring(ctx, "not null") + if err != nil { + return nil, err + } + if ec.directives.Meta == nil { + return nil, errors.New("directive meta is not implemented") + } + return ec.directives.Meta(ctx, obj, directive0, gorm) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(string); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp) + }) + 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.marshalNID2string(ctx, field.Selections, res) +} + func (ec *executionContext) _TagResponse_data(ctx context.Context, field graphql.CollectedField, obj *model.TagResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -6472,22 +6634,6 @@ func (ec *executionContext) unmarshalInputAlbumFilter(ctx context.Context, obj i if err != nil { return it, err } - case "and": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("and")) - it.And, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, v) - if err != nil { - return it, err - } - case "or": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("or")) - it.Or, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, v) - if err != nil { - return it, err - } } } @@ -6516,22 +6662,6 @@ func (ec *executionContext) unmarshalInputAuthTypeFilter(ctx context.Context, ob if err != nil { return it, err } - case "in": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("in")) - it.In, err = ec.unmarshalOAuthType2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthTypeᚄ(ctx, v) - if err != nil { - return it, err - } - case "notIn": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notIn")) - it.NotIn, err = ec.unmarshalOAuthType2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthTypeᚄ(ctx, v) - if err != nil { - return it, err - } } } @@ -6612,22 +6742,6 @@ func (ec *executionContext) unmarshalInputDeviceFilter(ctx context.Context, obj if err != nil { return it, err } - case "and": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("and")) - it.And, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, v) - if err != nil { - return it, err - } - case "or": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("or")) - it.Or, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, v) - if err != nil { - return it, err - } } } @@ -6656,22 +6770,6 @@ func (ec *executionContext) unmarshalInputDeviceTypeFilter(ctx context.Context, if err != nil { return it, err } - case "in": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("in")) - it.In, err = ec.unmarshalODeviceType2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceTypeᚄ(ctx, v) - if err != nil { - return it, err - } - case "notIn": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notIn")) - it.NotIn, err = ec.unmarshalODeviceType2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceTypeᚄ(ctx, v) - if err != nil { - return it, err - } } } @@ -6716,35 +6814,19 @@ func (ec *executionContext) unmarshalInputFloatFilter(ctx context.Context, obj i if err != nil { return it, err } - case "moreThan": + case "greaterThan": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("moreThan")) - it.MoreThan, err = ec.unmarshalOFloat2ᚖfloat64(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("greaterThan")) + it.GreaterThan, err = ec.unmarshalOFloat2ᚖfloat64(ctx, v) if err != nil { return it, err } - case "moreThanOrEqualTo": + case "greaterThanOrEqualTo": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("moreThanOrEqualTo")) - it.MoreThanOrEqualTo, err = ec.unmarshalOFloat2ᚖfloat64(ctx, v) - if err != nil { - return it, err - } - case "in": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("in")) - it.In, err = ec.unmarshalOFloat2ᚕfloat64ᚄ(ctx, v) - if err != nil { - return it, err - } - case "notIn": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notIn")) - it.NotIn, err = ec.unmarshalOFloat2ᚕfloat64ᚄ(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("greaterThanOrEqualTo")) + it.GreaterThanOrEqualTo, err = ec.unmarshalOFloat2ᚖfloat64(ctx, v) if err != nil { return it, err } @@ -6776,22 +6858,6 @@ func (ec *executionContext) unmarshalInputIDFilter(ctx context.Context, obj inte if err != nil { return it, err } - case "in": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("in")) - it.In, err = ec.unmarshalOID2ᚕstringᚄ(ctx, v) - if err != nil { - return it, err - } - case "notIn": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notIn")) - it.NotIn, err = ec.unmarshalOID2ᚕstringᚄ(ctx, v) - if err != nil { - return it, err - } } } @@ -6836,35 +6902,19 @@ func (ec *executionContext) unmarshalInputIntFilter(ctx context.Context, obj int if err != nil { return it, err } - case "moreThan": + case "greaterThan": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("moreThan")) - it.MoreThan, err = ec.unmarshalOInt2ᚖint(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("greaterThan")) + it.GreaterThan, err = ec.unmarshalOInt2ᚖint(ctx, v) if err != nil { return it, err } - case "moreThanOrEqualTo": + case "greaterThanOrEqualTo": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("moreThanOrEqualTo")) - it.MoreThanOrEqualTo, err = ec.unmarshalOInt2ᚖint(ctx, v) - if err != nil { - return it, err - } - case "in": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("in")) - it.In, err = ec.unmarshalOInt2ᚕintᚄ(ctx, v) - if err != nil { - return it, err - } - case "notIn": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notIn")) - it.NotIn, err = ec.unmarshalOInt2ᚕintᚄ(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("greaterThanOrEqualTo")) + it.GreaterThanOrEqualTo, err = ec.unmarshalOInt2ᚖint(ctx, v) if err != nil { return it, err } @@ -6960,22 +7010,6 @@ func (ec *executionContext) unmarshalInputMediaItemFilter(ctx context.Context, o if err != nil { return it, err } - case "and": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("and")) - it.And, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, v) - if err != nil { - return it, err - } - case "or": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("or")) - it.Or, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, v) - if err != nil { - return it, err - } } } @@ -7148,22 +7182,6 @@ func (ec *executionContext) unmarshalInputRoleFilter(ctx context.Context, obj in if err != nil { return it, err } - case "in": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("in")) - it.In, err = ec.unmarshalORole2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐRoleᚄ(ctx, v) - if err != nil { - return it, err - } - case "notIn": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notIn")) - it.NotIn, err = ec.unmarshalORole2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐRoleᚄ(ctx, v) - if err != nil { - return it, err - } } } @@ -7192,115 +7210,51 @@ func (ec *executionContext) unmarshalInputStringFilter(ctx context.Context, obj if err != nil { return it, err } - case "startWith": + case "startsWith": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("startWith")) - it.StartWith, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("startsWith")) + it.StartsWith, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "notStartWith": + case "notStartsWith": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notStartWith")) - it.NotStartWith, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notStartsWith")) + it.NotStartsWith, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "endWith": + case "endsWith": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("endWith")) - it.EndWith, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("endsWith")) + it.EndsWith, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "notEndWith": + case "notEndsWith": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notEndWith")) - it.NotEndWith, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notEndsWith")) + it.NotEndsWith, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "contain": + case "contains": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("contain")) - it.Contain, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("contains")) + it.Contains, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "notContain": + case "notContains": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notContain")) - it.NotContain, err = ec.unmarshalOString2ᚖstring(ctx, v) - if err != nil { - return it, err - } - case "in": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("in")) - it.In, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) - if err != nil { - return it, err - } - case "notIn": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notIn")) - it.NotIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) - if err != nil { - return it, err - } - case "startWithStrict": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("startWithStrict")) - it.StartWithStrict, err = ec.unmarshalOString2ᚖstring(ctx, v) - if err != nil { - return it, err - } - case "notStartWithStrict": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notStartWithStrict")) - it.NotStartWithStrict, err = ec.unmarshalOString2ᚖstring(ctx, v) - if err != nil { - return it, err - } - case "endWithStrict": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("endWithStrict")) - it.EndWithStrict, err = ec.unmarshalOString2ᚖstring(ctx, v) - if err != nil { - return it, err - } - case "notEndWithStrict": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notEndWithStrict")) - it.NotEndWithStrict, err = ec.unmarshalOString2ᚖstring(ctx, v) - if err != nil { - return it, err - } - case "containStrict": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("containStrict")) - it.ContainStrict, err = ec.unmarshalOString2ᚖstring(ctx, v) - if err != nil { - return it, err - } - case "notContainStrict": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notContainStrict")) - it.NotContainStrict, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notContains")) + it.NotContains, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } @@ -7348,22 +7302,6 @@ func (ec *executionContext) unmarshalInputTagFilter(ctx context.Context, obj int if err != nil { return it, err } - case "and": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("and")) - it.And, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, v) - if err != nil { - return it, err - } - case "or": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("or")) - it.Or, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, v) - if err != nil { - return it, err - } } } @@ -7408,19 +7346,19 @@ func (ec *executionContext) unmarshalInputTimeFilter(ctx context.Context, obj in if err != nil { return it, err } - case "moreThan": + case "greaterThan": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("moreThan")) - it.MoreThan, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("greaterThan")) + it.GreaterThan, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "moreThanOrEqualTo": + case "greaterThanOrEqualTo": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("moreThanOrEqualTo")) - it.MoreThanOrEqualTo, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("greaterThanOrEqualTo")) + it.GreaterThanOrEqualTo, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } @@ -7500,22 +7438,6 @@ func (ec *executionContext) unmarshalInputUserFilter(ctx context.Context, obj in if err != nil { return it, err } - case "and": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("and")) - it.And, err = ec.unmarshalOUserFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUserFilter(ctx, v) - if err != nil { - return it, err - } - case "or": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("or")) - it.Or, err = ec.unmarshalOUserFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUserFilter(ctx, v) - if err != nil { - return it, err - } } } @@ -7555,6 +7477,11 @@ func (ec *executionContext) _Album(ctx context.Context, sel ast.SelectionSet, ob if out.Values[i] == graphql.Null { invalids++ } + case "userID": + out.Values[i] = ec._Album_userID(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -7656,13 +7583,13 @@ func (ec *executionContext) _Device(ctx context.Context, sel ast.SelectionSet, o if out.Values[i] == graphql.Null { invalids++ } + case "refreshKey": + out.Values[i] = ec._Device_refreshKey(ctx, field, obj) case "userID": out.Values[i] = ec._Device_userID(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } - case "refreshKey": - out.Values[i] = ec._Device_refreshKey(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -8113,6 +8040,11 @@ func (ec *executionContext) _Tag(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { invalids++ } + case "userID": + out.Values[i] = ec._Tag_userID(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -8603,21 +8535,6 @@ func (ec *executionContext) marshalNDeviceType2reichardᚗioᚋimaginiᚋgraph return v } -func (ec *executionContext) unmarshalNFloat2float64(ctx context.Context, v interface{}) (float64, error) { - res, err := graphql.UnmarshalFloat(v) - return res, graphql.ErrorOnPath(ctx, err) -} - -func (ec *executionContext) marshalNFloat2float64(ctx context.Context, sel ast.SelectionSet, v float64) graphql.Marshaler { - res := graphql.MarshalFloat(v) - if res == graphql.Null { - if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { - ec.Errorf(ctx, "must not be null") - } - } - return res -} - func (ec *executionContext) unmarshalNID2string(ctx context.Context, v interface{}) (string, error) { res, err := graphql.UnmarshalID(v) return res, graphql.ErrorOnPath(ctx, err) @@ -9086,70 +9003,6 @@ func (ec *executionContext) unmarshalOAlbumFilter2ᚖreichardᚗioᚋimaginiᚋg return &res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) unmarshalOAuthType2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthTypeᚄ(ctx context.Context, v interface{}) ([]model.AuthType, error) { - if v == nil { - return nil, nil - } - var vSlice []interface{} - if v != nil { - if tmp1, ok := v.([]interface{}); ok { - vSlice = tmp1 - } else { - vSlice = []interface{}{v} - } - } - var err error - res := make([]model.AuthType, len(vSlice)) - for i := range vSlice { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNAuthType2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthType(ctx, vSlice[i]) - if err != nil { - return nil, err - } - } - return res, nil -} - -func (ec *executionContext) marshalOAuthType2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []model.AuthType) 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.marshalNAuthType2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthType(ctx, sel, v[i]) - } - if isLen1 { - f(i) - } else { - go f(i) - } - - } - wg.Wait() - return ret -} - func (ec *executionContext) unmarshalOAuthType2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthType(ctx context.Context, v interface{}) (*model.AuthType, error) { if v == nil { return nil, nil @@ -9301,70 +9154,6 @@ func (ec *executionContext) unmarshalODeviceFilter2ᚖreichardᚗioᚋimaginiᚋ return &res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) unmarshalODeviceType2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceTypeᚄ(ctx context.Context, v interface{}) ([]model.DeviceType, error) { - if v == nil { - return nil, nil - } - var vSlice []interface{} - if v != nil { - if tmp1, ok := v.([]interface{}); ok { - vSlice = tmp1 - } else { - vSlice = []interface{}{v} - } - } - var err error - res := make([]model.DeviceType, len(vSlice)) - for i := range vSlice { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNDeviceType2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceType(ctx, vSlice[i]) - if err != nil { - return nil, err - } - } - return res, nil -} - -func (ec *executionContext) marshalODeviceType2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []model.DeviceType) 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.marshalNDeviceType2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceType(ctx, sel, v[i]) - } - if isLen1 { - f(i) - } else { - go f(i) - } - - } - wg.Wait() - return ret -} - func (ec *executionContext) unmarshalODeviceType2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceType(ctx context.Context, v interface{}) (*model.DeviceType, error) { if v == nil { return nil, nil @@ -9389,42 +9178,6 @@ func (ec *executionContext) unmarshalODeviceTypeFilter2ᚖreichardᚗioᚋimagin return &res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) unmarshalOFloat2ᚕfloat64ᚄ(ctx context.Context, v interface{}) ([]float64, error) { - if v == nil { - return nil, nil - } - var vSlice []interface{} - if v != nil { - if tmp1, ok := v.([]interface{}); ok { - vSlice = tmp1 - } else { - vSlice = []interface{}{v} - } - } - var err error - res := make([]float64, len(vSlice)) - for i := range vSlice { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNFloat2float64(ctx, vSlice[i]) - if err != nil { - return nil, err - } - } - return res, nil -} - -func (ec *executionContext) marshalOFloat2ᚕfloat64ᚄ(ctx context.Context, sel ast.SelectionSet, v []float64) graphql.Marshaler { - if v == nil { - return graphql.Null - } - ret := make(graphql.Array, len(v)) - for i := range v { - ret[i] = ec.marshalNFloat2float64(ctx, sel, v[i]) - } - - return ret -} - func (ec *executionContext) unmarshalOFloat2ᚖfloat64(ctx context.Context, v interface{}) (*float64, error) { if v == nil { return nil, nil @@ -9507,42 +9260,6 @@ func (ec *executionContext) unmarshalOIDFilter2ᚖreichardᚗioᚋimaginiᚋgrap return &res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) unmarshalOInt2ᚕintᚄ(ctx context.Context, v interface{}) ([]int, error) { - if v == nil { - return nil, nil - } - var vSlice []interface{} - if v != nil { - if tmp1, ok := v.([]interface{}); ok { - vSlice = tmp1 - } else { - vSlice = []interface{}{v} - } - } - var err error - res := make([]int, len(vSlice)) - for i := range vSlice { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNInt2int(ctx, vSlice[i]) - if err != nil { - return nil, err - } - } - return res, nil -} - -func (ec *executionContext) marshalOInt2ᚕintᚄ(ctx context.Context, sel ast.SelectionSet, v []int) graphql.Marshaler { - if v == nil { - return graphql.Null - } - ret := make(graphql.Array, len(v)) - for i := range v { - ret[i] = ec.marshalNInt2int(ctx, sel, v[i]) - } - - return ret -} - func (ec *executionContext) unmarshalOInt2ᚖint(ctx context.Context, v interface{}) (*int, error) { if v == nil { return nil, nil @@ -9653,70 +9370,6 @@ func (ec *executionContext) unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimagini return &res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) unmarshalORole2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐRoleᚄ(ctx context.Context, v interface{}) ([]model.Role, error) { - if v == nil { - return nil, nil - } - var vSlice []interface{} - if v != nil { - if tmp1, ok := v.([]interface{}); ok { - vSlice = tmp1 - } else { - vSlice = []interface{}{v} - } - } - var err error - res := make([]model.Role, len(vSlice)) - for i := range vSlice { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, vSlice[i]) - if err != nil { - return nil, err - } - } - return res, nil -} - -func (ec *executionContext) marshalORole2ᚕreichardᚗioᚋimaginiᚋgraphᚋmodelᚐRoleᚄ(ctx context.Context, sel ast.SelectionSet, v []model.Role) 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.marshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, sel, v[i]) - } - if isLen1 { - f(i) - } else { - go f(i) - } - - } - wg.Wait() - return ret -} - func (ec *executionContext) unmarshalORole2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx context.Context, v interface{}) (*model.Role, error) { if v == nil { return nil, nil @@ -9750,42 +9403,6 @@ func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.S return graphql.MarshalString(v) } -func (ec *executionContext) unmarshalOString2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { - if v == nil { - return nil, nil - } - var vSlice []interface{} - if v != nil { - if tmp1, ok := v.([]interface{}); ok { - vSlice = tmp1 - } else { - vSlice = []interface{}{v} - } - } - var err error - res := make([]string, len(vSlice)) - for i := range vSlice { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNString2string(ctx, vSlice[i]) - if err != nil { - return nil, err - } - } - return res, nil -} - -func (ec *executionContext) marshalOString2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { - if v == nil { - return graphql.Null - } - ret := make(graphql.Array, len(v)) - for i := range v { - ret[i] = ec.marshalNString2string(ctx, sel, v[i]) - } - - return ret -} - func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { if v == nil { return nil, nil diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 6b3fa1e..a2cdbbc 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -16,15 +16,14 @@ type Album struct { CreatedAt *time.Time `json:"createdAt" ` UpdatedAt *time.Time `json:"updatedAt" ` Name string `json:"name" gorm:"unique;not null"` + UserID string `json:"userID" gorm:"not null"` } type AlbumFilter struct { - ID *IDFilter `json:"id" ` - CreatedAt *TimeFilter `json:"createdAt" ` - UpdatedAt *TimeFilter `json:"updatedAt" ` - Name *StringFilter `json:"name" ` - And *MediaItemFilter `json:"and" ` - Or *MediaItemFilter `json:"or" ` + ID *IDFilter `json:"id" ` + CreatedAt *TimeFilter `json:"createdAt" ` + UpdatedAt *TimeFilter `json:"updatedAt" ` + Name *StringFilter `json:"name" ` } type AlbumResponse struct { @@ -39,10 +38,8 @@ type AuthResponse struct { } type AuthTypeFilter struct { - EqualTo *AuthType `json:"equalTo" ` - NotEqualTo *AuthType `json:"notEqualTo" ` - In []AuthType `json:"in" ` - NotIn []AuthType `json:"notIn" ` + EqualTo *AuthType `json:"equalTo" ` + NotEqualTo *AuthType `json:"notEqualTo" ` } type BooleanFilter struct { @@ -56,8 +53,8 @@ type Device struct { UpdatedAt *time.Time `json:"updatedAt" ` Name string `json:"name" gorm:"not null"` Type DeviceType `json:"type" gorm:"default:Unknown;not null"` - UserID string `json:"userID" gorm:"not null"` RefreshKey *string `json:"refreshKey" ` + UserID string `json:"userID" gorm:"not null"` } type DeviceFilter struct { @@ -66,8 +63,6 @@ type DeviceFilter struct { UpdatedAt *TimeFilter `json:"updatedAt" ` Name *StringFilter `json:"name" ` Type *DeviceTypeFilter `json:"type" ` - And *MediaItemFilter `json:"and" ` - Or *MediaItemFilter `json:"or" ` } type DeviceResponse struct { @@ -76,39 +71,31 @@ type DeviceResponse struct { } type DeviceTypeFilter struct { - EqualTo *DeviceType `json:"equalTo" ` - NotEqualTo *DeviceType `json:"notEqualTo" ` - In []DeviceType `json:"in" ` - NotIn []DeviceType `json:"notIn" ` + EqualTo *DeviceType `json:"equalTo" ` + NotEqualTo *DeviceType `json:"notEqualTo" ` } type FloatFilter struct { - EqualTo *float64 `json:"equalTo" ` - NotEqualTo *float64 `json:"notEqualTo" ` - LessThan *float64 `json:"lessThan" ` - LessThanOrEqualTo *float64 `json:"lessThanOrEqualTo" ` - MoreThan *float64 `json:"moreThan" ` - MoreThanOrEqualTo *float64 `json:"moreThanOrEqualTo" ` - In []float64 `json:"in" ` - NotIn []float64 `json:"notIn" ` + EqualTo *float64 `json:"equalTo" ` + NotEqualTo *float64 `json:"notEqualTo" ` + LessThan *float64 `json:"lessThan" ` + LessThanOrEqualTo *float64 `json:"lessThanOrEqualTo" ` + GreaterThan *float64 `json:"greaterThan" ` + GreaterThanOrEqualTo *float64 `json:"greaterThanOrEqualTo" ` } type IDFilter struct { - EqualTo *string `json:"equalTo" ` - NotEqualTo *string `json:"notEqualTo" ` - In []string `json:"in" ` - NotIn []string `json:"notIn" ` + EqualTo *string `json:"equalTo" ` + NotEqualTo *string `json:"notEqualTo" ` } type IntFilter struct { - EqualTo *int `json:"equalTo" ` - NotEqualTo *int `json:"notEqualTo" ` - LessThan *int `json:"lessThan" ` - LessThanOrEqualTo *int `json:"lessThanOrEqualTo" ` - MoreThan *int `json:"moreThan" ` - MoreThanOrEqualTo *int `json:"moreThanOrEqualTo" ` - In []int `json:"in" ` - NotIn []int `json:"notIn" ` + EqualTo *int `json:"equalTo" ` + NotEqualTo *int `json:"notEqualTo" ` + LessThan *int `json:"lessThan" ` + LessThanOrEqualTo *int `json:"lessThanOrEqualTo" ` + GreaterThan *int `json:"greaterThan" ` + GreaterThanOrEqualTo *int `json:"greaterThanOrEqualTo" ` } type MediaItem struct { @@ -116,29 +103,27 @@ type MediaItem struct { CreatedAt *time.Time `json:"createdAt" ` UpdatedAt *time.Time `json:"updatedAt" ` ExifDate *time.Time `json:"exifDate" ` - Latitude *float64 `json:"latitude" ` - Longitude *float64 `json:"longitude" ` + Latitude *float64 `json:"latitude" gorm:"precision:5"` + Longitude *float64 `json:"longitude" gorm:"precision:5"` IsVideo bool `json:"isVideo" gorm:"default:false;not null"` FileName string `json:"fileName" gorm:"not null"` OrigName string `json:"origName" gorm:"not null"` - Tags []*Tag `json:"tags" gorm:"many2many:media_tags"` - Albums []*Album `json:"albums" gorm:"many2many:media_albums"` + Tags []*Tag `json:"tags" gorm:"many2many:media_tags;foreignKey:ID,UserID;References:ID"` + Albums []*Album `json:"albums" gorm:"many2many:media_albums;foreignKey:ID,UserID;Refrences:ID"` UserID string `json:"userID" gorm:"not null"` } type MediaItemFilter struct { - ID *IDFilter `json:"id" ` - CreatedAt *TimeFilter `json:"createdAt" ` - UpdatedAt *TimeFilter `json:"updatedAt" ` - ExifDate *TimeFilter `json:"exifDate" ` - Latitude *FloatFilter `json:"latitude" ` - Longitude *FloatFilter `json:"longitude" ` - IsVideo *BooleanFilter `json:"isVideo" ` - OrigName *StringFilter `json:"origName" ` - Tags *TagFilter `json:"tags" ` - Albums *AlbumFilter `json:"albums" ` - And *MediaItemFilter `json:"and" ` - Or *MediaItemFilter `json:"or" ` + ID *IDFilter `json:"id" ` + CreatedAt *TimeFilter `json:"createdAt" ` + UpdatedAt *TimeFilter `json:"updatedAt" ` + ExifDate *TimeFilter `json:"exifDate" ` + Latitude *FloatFilter `json:"latitude" ` + Longitude *FloatFilter `json:"longitude" ` + IsVideo *BooleanFilter `json:"isVideo" ` + OrigName *StringFilter `json:"origName" ` + Tags *TagFilter `json:"tags" ` + Albums *AlbumFilter `json:"albums" ` } type MediaItemResponse struct { @@ -177,29 +162,19 @@ type PageInfo struct { } type RoleFilter struct { - EqualTo *Role `json:"equalTo" ` - NotEqualTo *Role `json:"notEqualTo" ` - In []Role `json:"in" ` - NotIn []Role `json:"notIn" ` + EqualTo *Role `json:"equalTo" ` + NotEqualTo *Role `json:"notEqualTo" ` } type StringFilter struct { - EqualTo *string `json:"equalTo" ` - NotEqualTo *string `json:"notEqualTo" ` - StartWith *string `json:"startWith" ` - NotStartWith *string `json:"notStartWith" ` - EndWith *string `json:"endWith" ` - NotEndWith *string `json:"notEndWith" ` - Contain *string `json:"contain" ` - NotContain *string `json:"notContain" ` - In []string `json:"in" ` - NotIn []string `json:"notIn" ` - StartWithStrict *string `json:"startWithStrict" ` - NotStartWithStrict *string `json:"notStartWithStrict" ` - EndWithStrict *string `json:"endWithStrict" ` - NotEndWithStrict *string `json:"notEndWithStrict" ` - ContainStrict *string `json:"containStrict" ` - NotContainStrict *string `json:"notContainStrict" ` + EqualTo *string `json:"equalTo" ` + NotEqualTo *string `json:"notEqualTo" ` + StartsWith *string `json:"startsWith" ` + NotStartsWith *string `json:"notStartsWith" ` + EndsWith *string `json:"endsWith" ` + NotEndsWith *string `json:"notEndsWith" ` + Contains *string `json:"contains" ` + NotContains *string `json:"notContains" ` } type Tag struct { @@ -207,15 +182,14 @@ type Tag struct { CreatedAt *time.Time `json:"createdAt" ` UpdatedAt *time.Time `json:"updatedAt" ` Name string `json:"name" gorm:"unique;not null"` + UserID string `json:"userID" gorm:"not null"` } type TagFilter struct { - ID *IDFilter `json:"id" ` - CreatedAt *TimeFilter `json:"createdAt" ` - UpdatedAt *TimeFilter `json:"updatedAt" ` - Name *StringFilter `json:"name" ` - And *MediaItemFilter `json:"and" ` - Or *MediaItemFilter `json:"or" ` + ID *IDFilter `json:"id" ` + CreatedAt *TimeFilter `json:"createdAt" ` + UpdatedAt *TimeFilter `json:"updatedAt" ` + Name *StringFilter `json:"name" ` } type TagResponse struct { @@ -224,12 +198,12 @@ type TagResponse struct { } type TimeFilter struct { - EqualTo *time.Time `json:"equalTo" ` - NotEqualTo *time.Time `json:"notEqualTo" ` - LessThan *time.Time `json:"lessThan" ` - LessThanOrEqualTo *time.Time `json:"lessThanOrEqualTo" ` - MoreThan *time.Time `json:"moreThan" ` - MoreThanOrEqualTo *time.Time `json:"moreThanOrEqualTo" ` + EqualTo *time.Time `json:"equalTo" ` + NotEqualTo *time.Time `json:"notEqualTo" ` + LessThan *time.Time `json:"lessThan" ` + LessThanOrEqualTo *time.Time `json:"lessThanOrEqualTo" ` + GreaterThan *time.Time `json:"greaterThan" ` + GreaterThanOrEqualTo *time.Time `json:"greaterThanOrEqualTo" ` } type User struct { @@ -256,8 +230,6 @@ type UserFilter struct { LastName *StringFilter `json:"lastName" ` Role *RoleFilter `json:"role" ` AuthType *AuthTypeFilter `json:"authType" ` - And *UserFilter `json:"and" ` - Or *UserFilter `json:"or" ` } type UserResponse struct { diff --git a/graph/schema.graphqls b/graph/schema.graphqls index 7501878..c3448f0 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -56,8 +56,8 @@ input TimeFilter { notEqualTo: Time lessThan: Time lessThanOrEqualTo: Time - moreThan: Time - moreThanOrEqualTo: Time + greaterThan: Time + greaterThanOrEqualTo: Time } input IntFilter { @@ -65,10 +65,8 @@ input IntFilter { notEqualTo: Int lessThan: Int lessThanOrEqualTo: Int - moreThan: Int - moreThanOrEqualTo: Int - in: [Int!] - notIn: [Int!] + greaterThan: Int + greaterThanOrEqualTo: Int } input FloatFilter { @@ -76,10 +74,8 @@ input FloatFilter { notEqualTo: Float lessThan: Float lessThanOrEqualTo: Float - moreThan: Float - moreThanOrEqualTo: Float - in: [Float!] - notIn: [Float!] + greaterThan: Float + greaterThanOrEqualTo: Float } input BooleanFilter { @@ -90,49 +86,32 @@ input BooleanFilter { input IDFilter { equalTo: ID notEqualTo: ID - in: [ID!] - notIn: [ID!] } input StringFilter { equalTo: String notEqualTo: String - startWith: String - notStartWith: String - endWith: String - notEndWith: String - contain: String - notContain: String - in: [String!] - notIn: [String!] - - startWithStrict: String - notStartWithStrict: String - endWithStrict: String - notEndWithStrict: String - containStrict: String - notContainStrict: String + startsWith: String + notStartsWith: String + endsWith: String + notEndsWith: String + contains: String + notContains: String } input RoleFilter { equalTo: Role notEqualTo: Role - in: [Role!] - notIn: [Role!] } input DeviceTypeFilter { equalTo: DeviceType notEqualTo: DeviceType - in: [DeviceType!] - notIn: [DeviceType!] } input AuthTypeFilter { equalTo: AuthType notEqualTo: AuthType - in: [AuthType!] - notIn: [AuthType!] } # ------------------------------------------------------------ @@ -160,8 +139,8 @@ type Device { updatedAt: Time name: String! @meta(gorm: "not null") type: DeviceType! @meta(gorm: "default:Unknown;not null") - userID: ID! @meta(gorm: "not null") refreshKey: String @isPrivate + userID: ID! @meta(gorm: "not null") } type MediaItem { @@ -169,21 +148,22 @@ type MediaItem { createdAt: Time updatedAt: Time exifDate: Time - latitude: Float - longitude: Float + latitude: Float @meta(gorm: "precision:5") + longitude: Float @meta(gorm: "precision:5") isVideo: Boolean! @meta(gorm: "default:false;not null") fileName: String! @meta(gorm: "not null") origName: String! @meta(gorm: "not null") - tags: [Tag] @meta(gorm: "many2many:media_tags") - albums: [Album] @meta(gorm: "many2many:media_albums") + tags: [Tag] @meta(gorm: "many2many:media_tags;foreignKey:ID,UserID;References:ID") + albums: [Album] @meta(gorm: "many2many:media_albums;foreignKey:ID,UserID;Refrences:ID") userID: ID! @meta(gorm: "not null") } type Tag { - id: ID! @meta(gorm: "primaryKey;not null") + id: ID! @meta(gorm: "primaryKey;not null") createdAt: Time updatedAt: Time - name: String! @meta(gorm: "unique;not null") + name: String! @meta(gorm: "unique;not null") + userID: ID! @meta(gorm: "not null") } type Album { @@ -191,7 +171,7 @@ type Album { createdAt: Time updatedAt: Time name: String! @meta(gorm: "unique;not null") - # userID: ID! @meta(gorm: "not null") + userID: ID! @meta(gorm: "not null") } # ------------------------------------------------------------ @@ -208,8 +188,8 @@ input UserFilter { role: RoleFilter authType: AuthTypeFilter - and: UserFilter - or: UserFilter + # and: UserFilter + # or: UserFilter } input MediaItemFilter { @@ -224,8 +204,8 @@ input MediaItemFilter { tags: TagFilter albums: AlbumFilter - and: MediaItemFilter - or: MediaItemFilter + # and: MediaItemFilter + # or: MediaItemFilter } input DeviceFilter { @@ -235,8 +215,8 @@ input DeviceFilter { name: StringFilter type: DeviceTypeFilter - and: MediaItemFilter - or: MediaItemFilter + # and: MediaItemFilter + # or: MediaItemFilter } input TagFilter { @@ -245,8 +225,8 @@ input TagFilter { updatedAt: TimeFilter name: StringFilter - and: MediaItemFilter - or: MediaItemFilter + # and: MediaItemFilter + # or: MediaItemFilter } input AlbumFilter { @@ -255,8 +235,8 @@ input AlbumFilter { updatedAt: TimeFilter name: StringFilter - and: MediaItemFilter - or: MediaItemFilter + # and: MediaItemFilter + # or: MediaItemFilter } # ------------------------------------------------------------ diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index 1616c71..bdb69d9 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -102,13 +102,14 @@ func (r *mutationResolver) CreateAlbum(ctx context.Context, input model.NewAlbum // Get Context authContext := ctx.Value("auth").(*model.AuthContext) accessToken := *authContext.AccessToken - _, ok := accessToken.Get("sub") + userID, ok := accessToken.Get("sub") if !ok { return nil, errors.New("Upload Failed") } album := &model.Album{ - Name: input.Name, + Name: input.Name, + UserID: userID.(string), } err := r.DB.CreateAlbum(album) @@ -120,8 +121,17 @@ func (r *mutationResolver) CreateAlbum(ctx context.Context, input model.NewAlbum } func (r *mutationResolver) CreateTag(ctx context.Context, input model.NewTag) (*model.Tag, error) { + // Get Context + authContext := ctx.Value("auth").(*model.AuthContext) + accessToken := *authContext.AccessToken + userID, ok := accessToken.Get("sub") + if !ok { + return nil, errors.New("Upload Failed") + } + tag := &model.Tag{ - Name: input.Name, + Name: input.Name, + UserID: userID.(string), } err := r.DB.CreateTag(tag) @@ -223,13 +233,20 @@ func (r *queryResolver) Logout(ctx context.Context) (*model.AuthResponse, error) } func (r *queryResolver) MediaItem(ctx context.Context, id string, delete *bool) (*model.MediaItem, error) { - // TODO: User Specific - deviceID, err := uuid.Parse(id) + // Get Context + authContext := ctx.Value("auth").(*model.AuthContext) + accessToken := *authContext.AccessToken + userID, ok := accessToken.Get("sub") + if !ok { + return nil, errors.New("Context Error") + } + + mediaItemID, err := uuid.Parse(id) if err != nil { return nil, errors.New("Invalid ID Format") } - foundMediaItem := &model.MediaItem{ID: deviceID.String()} + foundMediaItem := &model.MediaItem{ID: mediaItemID.String(), UserID: userID.(string)} count, err := r.DB.MediaItem(foundMediaItem) if err != nil { return nil, errors.New("DB Error") @@ -240,13 +257,20 @@ func (r *queryResolver) MediaItem(ctx context.Context, id string, delete *bool) } func (r *queryResolver) Device(ctx context.Context, id string, delete *bool) (*model.Device, error) { - // TODO: User Specific + // Get Context + authContext := ctx.Value("auth").(*model.AuthContext) + accessToken := *authContext.AccessToken + userID, ok := accessToken.Get("sub") + if !ok { + return nil, errors.New("Context Error") + } + deviceID, err := uuid.Parse(id) if err != nil { return nil, errors.New("Invalid ID Format") } - foundDevice := &model.Device{ID: deviceID.String()} + foundDevice := &model.Device{ID: deviceID.String(), UserID: userID.(string)} count, err := r.DB.Device(foundDevice) if err != nil { return nil, errors.New("DB Error") @@ -257,13 +281,20 @@ func (r *queryResolver) Device(ctx context.Context, id string, delete *bool) (*m } func (r *queryResolver) Album(ctx context.Context, id string, delete *bool) (*model.Album, error) { - // TODO: User Specific + // Get Context + authContext := ctx.Value("auth").(*model.AuthContext) + accessToken := *authContext.AccessToken + userID, ok := accessToken.Get("sub") + if !ok { + return nil, errors.New("Context Error") + } + albumID, err := uuid.Parse(id) if err != nil { return nil, errors.New("Invalid ID Format") } - foundAlbum := &model.Album{ID: albumID.String()} + foundAlbum := &model.Album{ID: albumID.String(), UserID: userID.(string)} count, err := r.DB.Album(foundAlbum) if err != nil { return nil, errors.New("DB Error") @@ -323,7 +354,7 @@ func (r *queryResolver) Me(ctx context.Context, delete *bool) (*model.User, erro } func (r *queryResolver) MediaItems(ctx context.Context, delete *bool, filter *model.MediaItemFilter, count *int, page *int) (*model.MediaItemResponse, error) { - resp, totalCount, err := r.DB.MediaItems() + resp, totalCount, err := r.DB.MediaItems(filter) if err != nil { return nil, errors.New("Context Error") } @@ -338,10 +369,18 @@ func (r *queryResolver) MediaItems(ctx context.Context, delete *bool, filter *mo } func (r *queryResolver) Devices(ctx context.Context, delete *bool, filter *model.DeviceFilter, count *int, page *int) (*model.DeviceResponse, error) { - // TODO: User Specific + // Get Context + authContext := ctx.Value("auth").(*model.AuthContext) + accessToken := *authContext.AccessToken + userID, ok := accessToken.Get("sub") + if !ok { + return nil, errors.New("Context Error") + } + _ = userID + resp, totalCount, err := r.DB.Devices() if err != nil { - return nil, errors.New("Context Error") + return nil, errors.New("DB Error") } return &model.DeviceResponse{ Data: resp, diff --git a/internal/db/filters.go b/internal/db/filters.go new file mode 100644 index 0000000..a13731b --- /dev/null +++ b/internal/db/filters.go @@ -0,0 +1,193 @@ +package db + +import ( + "fmt" + "reflect" + + "github.com/iancoleman/strcase" + "gorm.io/gorm" + "reichard.io/imagini/graph/model" +) + +// Generic function used to generate filters for the DB +func (dbm *DBManager) generateFilters(filter interface{}) (*gorm.DB, error) { + tx := dbm.db.Session(&gorm.Session{}).Debug() + + v := reflect.ValueOf(filter) + + for i := 0; i < v.NumField(); i++ { + fieldName := strcase.ToSnake(v.Type().Field(i).Name) + fieldVal := v.Field(i) + + if fieldVal.IsNil() { + continue + } + + switch valType := fieldVal.Type(); valType { + case reflect.TypeOf(&model.StringFilter{}): + tx = generateStringFilter(tx, fieldName, fieldVal.Interface().(*model.StringFilter)) + case reflect.TypeOf(&model.BooleanFilter{}): + tx = generateBooleanFilter(tx, fieldName, fieldVal.Interface().(*model.BooleanFilter)) + case reflect.TypeOf(&model.FloatFilter{}): + tx = generateFloatFilter(tx, fieldName, fieldVal.Interface().(*model.FloatFilter)) + case reflect.TypeOf(&model.IntFilter{}): + tx = generateIntFilter(tx, fieldName, fieldVal.Interface().(*model.IntFilter)) + case reflect.TypeOf(&model.IDFilter{}): + tx = generateIDFilter(tx, fieldName, fieldVal.Interface().(*model.IDFilter)) + case reflect.TypeOf(&model.TimeFilter{}): + tx = generateTimeFilter(tx, fieldName, fieldVal.Interface().(*model.TimeFilter)) + case reflect.TypeOf(&model.RoleFilter{}): + tx = generateRoleFilter(tx, fieldName, fieldVal.Interface().(*model.RoleFilter)) + case reflect.TypeOf(&model.DeviceTypeFilter{}): + tx = generateDeviceTypeFilter(tx, fieldName, fieldVal.Interface().(*model.DeviceTypeFilter)) + case reflect.TypeOf(&model.AuthTypeFilter{}): + tx = generateAuthTypeFilter(tx, fieldName, fieldVal.Interface().(*model.AuthTypeFilter)) + } + } + + return tx, nil +} + +func generateStringFilter(tx *gorm.DB, fieldName string, filter *model.StringFilter) *gorm.DB { + if filter.EqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s == ?", fieldName), *filter.EqualTo) + } + if filter.NotEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s != ?", fieldName), *filter.NotEqualTo) + } + if filter.StartsWith != nil { + tx = tx.Where(fmt.Sprintf("%s LIKE ?", fieldName), fmt.Sprintf("%s%%", *filter.StartsWith)) + } + if filter.NotStartsWith != nil { + tx = tx.Where(fmt.Sprintf("%s NOT LIKE ?", fieldName), fmt.Sprintf("%s%%", *filter.NotStartsWith)) + } + if filter.EndsWith != nil { + tx = tx.Where(fmt.Sprintf("%s LIKE ?", fieldName), fmt.Sprintf("%%%s", *filter.EndsWith)) + } + if filter.NotEndsWith != nil { + tx = tx.Where(fmt.Sprintf("%s NOT LIKE ?", fieldName), fmt.Sprintf("%%%s", *filter.NotEndsWith)) + } + if filter.Contains != nil { + tx = tx.Where(fmt.Sprintf("%s LIKE ?", fieldName), fmt.Sprintf("%%%s%%", *filter.Contains)) + } + if filter.NotContains != nil { + tx = tx.Where(fmt.Sprintf("%s NOT LIKE ?", fieldName), fmt.Sprintf("%%%s%%", *filter.NotContains)) + } + return tx +} + +func generateBooleanFilter(tx *gorm.DB, fieldName string, filter *model.BooleanFilter) *gorm.DB { + if filter.EqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s == ?", fieldName), *filter.EqualTo) + } + if filter.NotEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s != ?", fieldName), *filter.NotEqualTo) + } + return tx +} + +func generateFloatFilter(tx *gorm.DB, fieldName string, filter *model.FloatFilter) *gorm.DB { + if filter.EqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s == ?", fieldName), *filter.EqualTo) + } + if filter.NotEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s != ?", fieldName), *filter.NotEqualTo) + } + if filter.GreaterThan != nil { + tx = tx.Where(fmt.Sprintf("%s > ?", fieldName), *filter.GreaterThan) + } + if filter.GreaterThanOrEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s >= ?", fieldName), *filter.GreaterThanOrEqualTo) + } + if filter.LessThan != nil { + tx = tx.Where(fmt.Sprintf("%s < ?", fieldName), *filter.LessThan) + } + if filter.LessThanOrEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s <= ?", fieldName), *filter.LessThanOrEqualTo) + } + return tx +} + +func generateIntFilter(tx *gorm.DB, fieldName string, filter *model.IntFilter) *gorm.DB { + if filter.EqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s == ?", fieldName), *filter.EqualTo) + } + if filter.NotEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s != ?", fieldName), *filter.NotEqualTo) + } + if filter.GreaterThan != nil { + tx = tx.Where(fmt.Sprintf("%s > ?", fieldName), *filter.GreaterThan) + } + if filter.GreaterThanOrEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s >= ?", fieldName), *filter.GreaterThanOrEqualTo) + } + if filter.LessThan != nil { + tx = tx.Where(fmt.Sprintf("%s < ?", fieldName), *filter.LessThan) + } + if filter.LessThanOrEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s <= ?", fieldName), *filter.LessThanOrEqualTo) + } + return tx +} + +func generateIDFilter(tx *gorm.DB, fieldName string, filter *model.IDFilter) *gorm.DB { + if filter.EqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s == ?", fieldName), *filter.EqualTo) + } + if filter.NotEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s != ?", fieldName), *filter.NotEqualTo) + } + return tx +} + +func generateTimeFilter(tx *gorm.DB, fieldName string, filter *model.TimeFilter) *gorm.DB { + if filter.EqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s == ?", fieldName), *filter.EqualTo) + } + if filter.NotEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s != ?", fieldName), *filter.NotEqualTo) + } + if filter.GreaterThan != nil { + tx = tx.Where(fmt.Sprintf("%s > ?", fieldName), *filter.GreaterThan) + } + if filter.GreaterThanOrEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s >= ?", fieldName), *filter.GreaterThanOrEqualTo) + } + if filter.LessThan != nil { + tx = tx.Where(fmt.Sprintf("%s < ?", fieldName), *filter.LessThan) + } + if filter.LessThanOrEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s <= ?", fieldName), *filter.LessThanOrEqualTo) + } + return tx +} + +func generateRoleFilter(tx *gorm.DB, fieldName string, filter *model.RoleFilter) *gorm.DB { + if filter.EqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s == ?", fieldName), *filter.EqualTo) + } + if filter.NotEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s != ?", fieldName), *filter.NotEqualTo) + } + return tx +} + +func generateDeviceTypeFilter(tx *gorm.DB, fieldName string, filter *model.DeviceTypeFilter) *gorm.DB { + if filter.EqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s == ?", fieldName), *filter.EqualTo) + } + if filter.NotEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s != ?", fieldName), *filter.NotEqualTo) + } + return tx +} + +func generateAuthTypeFilter(tx *gorm.DB, fieldName string, filter *model.AuthTypeFilter) *gorm.DB { + if filter.EqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s == ?", fieldName), *filter.EqualTo) + } + if filter.NotEqualTo != nil { + tx = tx.Where(fmt.Sprintf("%s != ?", fieldName), *filter.NotEqualTo) + } + return tx +} diff --git a/internal/db/media_items.go b/internal/db/media_items.go index 3dab426..11656c9 100644 --- a/internal/db/media_items.go +++ b/internal/db/media_items.go @@ -18,9 +18,14 @@ func (dbm *DBManager) MediaItem(mediaItem *model.MediaItem) (int64, error) { return count, err } -func (dbm *DBManager) MediaItems() ([]*model.MediaItem, int64, error) { +func (dbm *DBManager) MediaItems(filters *model.MediaItemFilter) ([]*model.MediaItem, int64, error) { + // Perform Filters + tx, err := dbm.generateFilters(*filters) + if err != nil { + return nil, 0, err + } var mediaItems []*model.MediaItem var count int64 - err := dbm.db.Find(&mediaItems).Count(&count).Error + err = tx.Find(&mediaItems).Count(&count).Error return mediaItems, count, err }