diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 2b29157..19bb14d 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -57,8 +57,8 @@ type ComplexityRoot struct { } AlbumResponse struct { - Data func(childComplexity int) int - PageInfo func(childComplexity int) int + Data func(childComplexity int) int + Page func(childComplexity int) int } AuthResponse struct { @@ -78,8 +78,8 @@ type ComplexityRoot struct { } DeviceResponse struct { - Data func(childComplexity int) int - PageInfo func(childComplexity int) int + Data func(childComplexity int) int + Page func(childComplexity int) int } MediaItem struct { @@ -98,8 +98,8 @@ type ComplexityRoot struct { } MediaItemResponse struct { - Data func(childComplexity int) int - PageInfo func(childComplexity int) int + Data func(childComplexity int) int + Page func(childComplexity int) int } Mutation struct { @@ -109,26 +109,26 @@ type ComplexityRoot struct { CreateUser func(childComplexity int, input model.NewUser) int } - PageInfo struct { - Count func(childComplexity int) int + PageResponse struct { Page func(childComplexity int) int + Size func(childComplexity int) int Total func(childComplexity int) int } Query struct { - Album func(childComplexity int, id string, delete *bool) int - Albums func(childComplexity int, delete *bool, filter *model.AlbumFilter, count *int, page *int) int - Device func(childComplexity int, id string, delete *bool) int - Devices func(childComplexity int, delete *bool, filter *model.DeviceFilter, count *int, page *int) int + Album func(childComplexity int, id string) int + Albums func(childComplexity int, filter *model.AlbumFilter, page *model.Page, order *model.Order) int + Device func(childComplexity int, id string) int + Devices func(childComplexity int, filter *model.DeviceFilter, page *model.Page, order *model.Order) int Login func(childComplexity int, user string, password string, deviceID *string) int Logout func(childComplexity int) int - Me func(childComplexity int, delete *bool) int - MediaItem func(childComplexity int, id string, delete *bool) int - MediaItems func(childComplexity int, delete *bool, filter *model.MediaItemFilter, count *int, page *int) int - Tag func(childComplexity int, id string, delete *bool) int - Tags func(childComplexity int, delete *bool, filter *model.TagFilter, count *int, page *int) int - User func(childComplexity int, id string, delete *bool) int - Users func(childComplexity int, delete *bool, filter *model.UserFilter, count *int, page *int) int + Me func(childComplexity int) int + MediaItem func(childComplexity int, id string) int + MediaItems func(childComplexity int, filter *model.MediaItemFilter, page *model.Page, order *model.Order) int + Tag func(childComplexity int, id string) int + Tags func(childComplexity int, filter *model.TagFilter, page *model.Page, order *model.Order) int + User func(childComplexity int, id string) int + Users func(childComplexity int, filter *model.UserFilter, page *model.Page, order *model.Order) int } Tag struct { @@ -140,8 +140,8 @@ type ComplexityRoot struct { } TagResponse struct { - Data func(childComplexity int) int - PageInfo func(childComplexity int) int + Data func(childComplexity int) int + Page func(childComplexity int) int } User struct { @@ -160,8 +160,8 @@ type ComplexityRoot struct { } UserResponse struct { - Data func(childComplexity int) int - PageInfo func(childComplexity int) int + Data func(childComplexity int) int + Page func(childComplexity int) int } } @@ -174,17 +174,17 @@ type MutationResolver interface { type QueryResolver interface { Login(ctx context.Context, user string, password string, deviceID *string) (*model.AuthResponse, error) Logout(ctx context.Context) (*model.AuthResponse, error) - MediaItem(ctx context.Context, id string, delete *bool) (*model.MediaItem, error) - Device(ctx context.Context, id string, delete *bool) (*model.Device, error) - Album(ctx context.Context, id string, delete *bool) (*model.Album, error) - User(ctx context.Context, id string, delete *bool) (*model.User, error) - Tag(ctx context.Context, id string, delete *bool) (*model.Tag, error) - Me(ctx context.Context, delete *bool) (*model.User, error) - MediaItems(ctx context.Context, delete *bool, filter *model.MediaItemFilter, count *int, page *int) (*model.MediaItemResponse, error) - Devices(ctx context.Context, delete *bool, filter *model.DeviceFilter, count *int, page *int) (*model.DeviceResponse, error) - Albums(ctx context.Context, delete *bool, filter *model.AlbumFilter, count *int, page *int) (*model.AlbumResponse, error) - Tags(ctx context.Context, delete *bool, filter *model.TagFilter, count *int, page *int) (*model.TagResponse, error) - Users(ctx context.Context, delete *bool, filter *model.UserFilter, count *int, page *int) (*model.UserResponse, error) + MediaItem(ctx context.Context, id string) (*model.MediaItem, error) + Device(ctx context.Context, id string) (*model.Device, error) + Album(ctx context.Context, id string) (*model.Album, error) + User(ctx context.Context, id string) (*model.User, error) + Tag(ctx context.Context, id string) (*model.Tag, error) + Me(ctx context.Context) (*model.User, error) + MediaItems(ctx context.Context, filter *model.MediaItemFilter, page *model.Page, order *model.Order) (*model.MediaItemResponse, error) + Devices(ctx context.Context, filter *model.DeviceFilter, page *model.Page, order *model.Order) (*model.DeviceResponse, error) + Albums(ctx context.Context, filter *model.AlbumFilter, page *model.Page, order *model.Order) (*model.AlbumResponse, error) + Tags(ctx context.Context, filter *model.TagFilter, page *model.Page, order *model.Order) (*model.TagResponse, error) + Users(ctx context.Context, filter *model.UserFilter, page *model.Page, order *model.Order) (*model.UserResponse, error) } type executableSchema struct { @@ -244,12 +244,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.AlbumResponse.Data(childComplexity), true - case "AlbumResponse.pageInfo": - if e.complexity.AlbumResponse.PageInfo == nil { + case "AlbumResponse.page": + if e.complexity.AlbumResponse.Page == nil { break } - return e.complexity.AlbumResponse.PageInfo(childComplexity), true + return e.complexity.AlbumResponse.Page(childComplexity), true case "AuthResponse.device": if e.complexity.AuthResponse.Device == nil { @@ -328,12 +328,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.DeviceResponse.Data(childComplexity), true - case "DeviceResponse.pageInfo": - if e.complexity.DeviceResponse.PageInfo == nil { + case "DeviceResponse.page": + if e.complexity.DeviceResponse.Page == nil { break } - return e.complexity.DeviceResponse.PageInfo(childComplexity), true + return e.complexity.DeviceResponse.Page(childComplexity), true case "MediaItem.albums": if e.complexity.MediaItem.Albums == nil { @@ -426,12 +426,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MediaItemResponse.Data(childComplexity), true - case "MediaItemResponse.pageInfo": - if e.complexity.MediaItemResponse.PageInfo == nil { + case "MediaItemResponse.page": + if e.complexity.MediaItemResponse.Page == nil { break } - return e.complexity.MediaItemResponse.PageInfo(childComplexity), true + return e.complexity.MediaItemResponse.Page(childComplexity), true case "Mutation.createAlbum": if e.complexity.Mutation.CreateAlbum == nil { @@ -481,26 +481,26 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.CreateUser(childComplexity, args["input"].(model.NewUser)), true - case "PageInfo.count": - if e.complexity.PageInfo.Count == nil { + case "PageResponse.page": + if e.complexity.PageResponse.Page == nil { break } - return e.complexity.PageInfo.Count(childComplexity), true + return e.complexity.PageResponse.Page(childComplexity), true - case "PageInfo.page": - if e.complexity.PageInfo.Page == nil { + case "PageResponse.size": + if e.complexity.PageResponse.Size == nil { break } - return e.complexity.PageInfo.Page(childComplexity), true + return e.complexity.PageResponse.Size(childComplexity), true - case "PageInfo.total": - if e.complexity.PageInfo.Total == nil { + case "PageResponse.total": + if e.complexity.PageResponse.Total == nil { break } - return e.complexity.PageInfo.Total(childComplexity), true + return e.complexity.PageResponse.Total(childComplexity), true case "Query.album": if e.complexity.Query.Album == nil { @@ -512,7 +512,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.Album(childComplexity, args["id"].(string), args["delete"].(*bool)), true + return e.complexity.Query.Album(childComplexity, args["id"].(string)), true case "Query.albums": if e.complexity.Query.Albums == nil { @@ -524,7 +524,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.Albums(childComplexity, args["delete"].(*bool), args["filter"].(*model.AlbumFilter), args["count"].(*int), args["page"].(*int)), true + return e.complexity.Query.Albums(childComplexity, args["filter"].(*model.AlbumFilter), args["page"].(*model.Page), args["order"].(*model.Order)), true case "Query.device": if e.complexity.Query.Device == nil { @@ -536,7 +536,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.Device(childComplexity, args["id"].(string), args["delete"].(*bool)), true + return e.complexity.Query.Device(childComplexity, args["id"].(string)), true case "Query.devices": if e.complexity.Query.Devices == nil { @@ -548,7 +548,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.Devices(childComplexity, args["delete"].(*bool), args["filter"].(*model.DeviceFilter), args["count"].(*int), args["page"].(*int)), true + return e.complexity.Query.Devices(childComplexity, args["filter"].(*model.DeviceFilter), args["page"].(*model.Page), args["order"].(*model.Order)), true case "Query.login": if e.complexity.Query.Login == nil { @@ -574,12 +574,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in break } - args, err := ec.field_Query_me_args(context.TODO(), rawArgs) - if err != nil { - return 0, false - } - - return e.complexity.Query.Me(childComplexity, args["delete"].(*bool)), true + return e.complexity.Query.Me(childComplexity), true case "Query.mediaItem": if e.complexity.Query.MediaItem == nil { @@ -591,7 +586,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.MediaItem(childComplexity, args["id"].(string), args["delete"].(*bool)), true + return e.complexity.Query.MediaItem(childComplexity, args["id"].(string)), true case "Query.mediaItems": if e.complexity.Query.MediaItems == nil { @@ -603,7 +598,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.MediaItems(childComplexity, args["delete"].(*bool), args["filter"].(*model.MediaItemFilter), args["count"].(*int), args["page"].(*int)), true + return e.complexity.Query.MediaItems(childComplexity, args["filter"].(*model.MediaItemFilter), args["page"].(*model.Page), args["order"].(*model.Order)), true case "Query.tag": if e.complexity.Query.Tag == nil { @@ -615,7 +610,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.Tag(childComplexity, args["id"].(string), args["delete"].(*bool)), true + return e.complexity.Query.Tag(childComplexity, args["id"].(string)), true case "Query.tags": if e.complexity.Query.Tags == nil { @@ -627,7 +622,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.Tags(childComplexity, args["delete"].(*bool), args["filter"].(*model.TagFilter), args["count"].(*int), args["page"].(*int)), true + return e.complexity.Query.Tags(childComplexity, args["filter"].(*model.TagFilter), args["page"].(*model.Page), args["order"].(*model.Order)), true case "Query.user": if e.complexity.Query.User == nil { @@ -639,7 +634,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.User(childComplexity, args["id"].(string), args["delete"].(*bool)), true + return e.complexity.Query.User(childComplexity, args["id"].(string)), true case "Query.users": if e.complexity.Query.Users == nil { @@ -651,7 +646,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.Users(childComplexity, args["delete"].(*bool), args["filter"].(*model.UserFilter), args["count"].(*int), args["page"].(*int)), true + return e.complexity.Query.Users(childComplexity, args["filter"].(*model.UserFilter), args["page"].(*model.Page), args["order"].(*model.Order)), true case "Tag.createdAt": if e.complexity.Tag.CreatedAt == nil { @@ -695,12 +690,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.TagResponse.Data(childComplexity), true - case "TagResponse.pageInfo": - if e.complexity.TagResponse.PageInfo == nil { + case "TagResponse.page": + if e.complexity.TagResponse.Page == nil { break } - return e.complexity.TagResponse.PageInfo(childComplexity), true + return e.complexity.TagResponse.Page(childComplexity), true case "User.authType": if e.complexity.User.AuthType == nil { @@ -793,12 +788,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.UserResponse.Data(childComplexity), true - case "UserResponse.pageInfo": - if e.complexity.UserResponse.PageInfo == nil { + case "UserResponse.page": + if e.complexity.UserResponse.Page == nil { break } - return e.complexity.UserResponse.PageInfo(childComplexity), true + return e.complexity.UserResponse.Page(childComplexity), true } return 0, false @@ -898,6 +893,11 @@ enum AuthType { LDAP } +enum OrderDirection { + ASC + DESC +} + # ------------------------------------------------------------ # ---------------------- Authentication ---------------------- # ------------------------------------------------------------ @@ -1133,39 +1133,49 @@ input NewAlbum { name: String! } +input Page { + size: Int + page: Int +} + +input Order { + by: String + direction: OrderDirection +} + # ------------------------------------------------------------ # ------------------------ Responses ------------------------- # ------------------------------------------------------------ -type PageInfo { - count: Int! +type PageResponse { + size: Int! page: Int! total: Int! } type MediaItemResponse { data: [MediaItem] - pageInfo: PageInfo! + page: PageResponse! } type UserResponse { data: [User] - pageInfo: PageInfo! + page: PageResponse! } type DeviceResponse { data: [Device] - pageInfo: PageInfo! + page: PageResponse! } type TagResponse { data: [Tag] - pageInfo: PageInfo! + page: PageResponse! } type AlbumResponse { data: [Album] - pageInfo: PageInfo! + page: PageResponse! } # ------------------------------------------------------------ @@ -1179,62 +1189,52 @@ type Query { password: String! deviceID: ID ): AuthResponse! - logout: AuthResponse! @hasMinRole(role: User) + logout: AuthResponse! @hasMinRole(role: User) # Single Item mediaItem( id: ID! - delete: Boolean - ): MediaItem! @hasMinRole(role: User) + ): MediaItem! @hasMinRole(role: User) device( id: ID! - delete: Boolean - ): Device! @hasMinRole(role: User) + ): Device! @hasMinRole(role: User) album( id: ID! - delete: Boolean - ): Album! @hasMinRole(role: User) + ): Album! @hasMinRole(role: User) user( id: ID! - delete: Boolean - ): User! @hasMinRole(role: Admin) # TODO: Delete All User Content + ): User! @hasMinRole(role: Admin) tag( id: ID! - delete: Boolean - ): Tag! @hasMinRole(role: User) - me(delete: Boolean): User! @hasMinRole(role: User) + ): Tag! @hasMinRole(role: User) + me: User! @hasMinRole(role: User) # All mediaItems( - delete: Boolean filter: MediaItemFilter - count: Int - page: Int - ): MediaItemResponse! @hasMinRole(role: User) + page: Page + order: Order + ): MediaItemResponse! @hasMinRole(role: User) devices( - delete: Boolean filter: DeviceFilter - count: Int - page: Int - ): DeviceResponse! @hasMinRole(role: User) + page: Page + order: Order + ): DeviceResponse! @hasMinRole(role: User) albums( - delete: Boolean filter: AlbumFilter - count: Int - page: Int - ): AlbumResponse! @hasMinRole(role: User) + page: Page + order: Order + ): AlbumResponse! @hasMinRole(role: User) tags( - delete: Boolean filter: TagFilter - count: Int - page: Int - ): TagResponse! @hasMinRole(role: User) + page: Page + order: Order + ): TagResponse! @hasMinRole(role: User) users( - delete: Boolean filter: UserFilter - count: Int - page: Int - ): UserResponse! @hasMinRole(role: Admin) # TODO: Delete All User Content + page: Page + order: Order + ): UserResponse! @hasMinRole(role: Admin) } type Mutation { @@ -1368,57 +1368,39 @@ func (ec *executionContext) field_Query_album_args(ctx context.Context, rawArgs } } args["id"] = arg0 - var arg1 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg1, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg1 return args, nil } func (ec *executionContext) field_Query_albums_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg0, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg0 - var arg1 *model.AlbumFilter + var arg0 *model.AlbumFilter if tmp, ok := rawArgs["filter"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter")) - arg1, err = ec.unmarshalOAlbumFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAlbumFilter(ctx, tmp) + arg0, err = ec.unmarshalOAlbumFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAlbumFilter(ctx, tmp) if err != nil { return nil, err } } - args["filter"] = arg1 - var arg2 *int - if tmp, ok := rawArgs["count"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count")) - arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp) - if err != nil { - return nil, err - } - } - args["count"] = arg2 - var arg3 *int + args["filter"] = arg0 + var arg1 *model.Page if tmp, ok := rawArgs["page"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page")) - arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + arg1, err = ec.unmarshalOPage2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPage(ctx, tmp) if err != nil { return nil, err } } - args["page"] = arg3 + args["page"] = arg1 + var arg2 *model.Order + if tmp, ok := rawArgs["order"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("order")) + arg2, err = ec.unmarshalOOrder2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐOrder(ctx, tmp) + if err != nil { + return nil, err + } + } + args["order"] = arg2 return args, nil } @@ -1434,57 +1416,39 @@ func (ec *executionContext) field_Query_device_args(ctx context.Context, rawArgs } } args["id"] = arg0 - var arg1 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg1, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg1 return args, nil } func (ec *executionContext) field_Query_devices_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg0, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg0 - var arg1 *model.DeviceFilter + var arg0 *model.DeviceFilter if tmp, ok := rawArgs["filter"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter")) - arg1, err = ec.unmarshalODeviceFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceFilter(ctx, tmp) + arg0, err = ec.unmarshalODeviceFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceFilter(ctx, tmp) if err != nil { return nil, err } } - args["filter"] = arg1 - var arg2 *int - if tmp, ok := rawArgs["count"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count")) - arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp) - if err != nil { - return nil, err - } - } - args["count"] = arg2 - var arg3 *int + args["filter"] = arg0 + var arg1 *model.Page if tmp, ok := rawArgs["page"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page")) - arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + arg1, err = ec.unmarshalOPage2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPage(ctx, tmp) if err != nil { return nil, err } } - args["page"] = arg3 + args["page"] = arg1 + var arg2 *model.Order + if tmp, ok := rawArgs["order"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("order")) + arg2, err = ec.unmarshalOOrder2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐOrder(ctx, tmp) + if err != nil { + return nil, err + } + } + args["order"] = arg2 return args, nil } @@ -1521,21 +1485,6 @@ func (ec *executionContext) field_Query_login_args(ctx context.Context, rawArgs return args, nil } -func (ec *executionContext) field_Query_me_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { - var err error - args := map[string]interface{}{} - var arg0 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg0, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg0 - return args, nil -} - func (ec *executionContext) field_Query_mediaItem_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1548,57 +1497,39 @@ func (ec *executionContext) field_Query_mediaItem_args(ctx context.Context, rawA } } args["id"] = arg0 - var arg1 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg1, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg1 return args, nil } func (ec *executionContext) field_Query_mediaItems_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg0, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg0 - var arg1 *model.MediaItemFilter + var arg0 *model.MediaItemFilter if tmp, ok := rawArgs["filter"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter")) - arg1, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, tmp) + arg0, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, tmp) if err != nil { return nil, err } } - args["filter"] = arg1 - var arg2 *int - if tmp, ok := rawArgs["count"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count")) - arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp) - if err != nil { - return nil, err - } - } - args["count"] = arg2 - var arg3 *int + args["filter"] = arg0 + var arg1 *model.Page if tmp, ok := rawArgs["page"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page")) - arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + arg1, err = ec.unmarshalOPage2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPage(ctx, tmp) if err != nil { return nil, err } } - args["page"] = arg3 + args["page"] = arg1 + var arg2 *model.Order + if tmp, ok := rawArgs["order"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("order")) + arg2, err = ec.unmarshalOOrder2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐOrder(ctx, tmp) + if err != nil { + return nil, err + } + } + args["order"] = arg2 return args, nil } @@ -1614,57 +1545,39 @@ func (ec *executionContext) field_Query_tag_args(ctx context.Context, rawArgs ma } } args["id"] = arg0 - var arg1 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg1, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg1 return args, nil } func (ec *executionContext) field_Query_tags_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg0, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg0 - var arg1 *model.TagFilter + var arg0 *model.TagFilter if tmp, ok := rawArgs["filter"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter")) - arg1, err = ec.unmarshalOTagFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐTagFilter(ctx, tmp) + arg0, err = ec.unmarshalOTagFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐTagFilter(ctx, tmp) if err != nil { return nil, err } } - args["filter"] = arg1 - var arg2 *int - if tmp, ok := rawArgs["count"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count")) - arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp) - if err != nil { - return nil, err - } - } - args["count"] = arg2 - var arg3 *int + args["filter"] = arg0 + var arg1 *model.Page if tmp, ok := rawArgs["page"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page")) - arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + arg1, err = ec.unmarshalOPage2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPage(ctx, tmp) if err != nil { return nil, err } } - args["page"] = arg3 + args["page"] = arg1 + var arg2 *model.Order + if tmp, ok := rawArgs["order"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("order")) + arg2, err = ec.unmarshalOOrder2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐOrder(ctx, tmp) + if err != nil { + return nil, err + } + } + args["order"] = arg2 return args, nil } @@ -1680,57 +1593,39 @@ func (ec *executionContext) field_Query_user_args(ctx context.Context, rawArgs m } } args["id"] = arg0 - var arg1 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg1, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg1 return args, nil } func (ec *executionContext) field_Query_users_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 *bool - if tmp, ok := rawArgs["delete"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("delete")) - arg0, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["delete"] = arg0 - var arg1 *model.UserFilter + var arg0 *model.UserFilter if tmp, ok := rawArgs["filter"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter")) - arg1, err = ec.unmarshalOUserFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUserFilter(ctx, tmp) + arg0, err = ec.unmarshalOUserFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUserFilter(ctx, tmp) if err != nil { return nil, err } } - args["filter"] = arg1 - var arg2 *int - if tmp, ok := rawArgs["count"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count")) - arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp) - if err != nil { - return nil, err - } - } - args["count"] = arg2 - var arg3 *int + args["filter"] = arg0 + var arg1 *model.Page if tmp, ok := rawArgs["page"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page")) - arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + arg1, err = ec.unmarshalOPage2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPage(ctx, tmp) if err != nil { return nil, err } } - args["page"] = arg3 + args["page"] = arg1 + var arg2 *model.Order + if tmp, ok := rawArgs["order"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("order")) + arg2, err = ec.unmarshalOOrder2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐOrder(ctx, tmp) + if err != nil { + return nil, err + } + } + args["order"] = arg2 return args, nil } @@ -2045,7 +1940,7 @@ func (ec *executionContext) _AlbumResponse_data(ctx context.Context, field graph return ec.marshalOAlbum2ᚕᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAlbum(ctx, field.Selections, res) } -func (ec *executionContext) _AlbumResponse_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.AlbumResponse) (ret graphql.Marshaler) { +func (ec *executionContext) _AlbumResponse_page(ctx context.Context, field graphql.CollectedField, obj *model.AlbumResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2063,7 +1958,7 @@ func (ec *executionContext) _AlbumResponse_pageInfo(ctx context.Context, field g 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.PageInfo, nil + return obj.Page, nil }) if err != nil { ec.Error(ctx, err) @@ -2075,9 +1970,9 @@ func (ec *executionContext) _AlbumResponse_pageInfo(ctx context.Context, field g } return graphql.Null } - res := resTmp.(*model.PageInfo) + res := resTmp.(*model.PageResponse) fc.Result = res - return ec.marshalNPageInfo2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res) + return ec.marshalNPageResponse2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageResponse(ctx, field.Selections, res) } func (ec *executionContext) _AuthResponse_result(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) { @@ -2563,7 +2458,7 @@ func (ec *executionContext) _DeviceResponse_data(ctx context.Context, field grap return ec.marshalODevice2ᚕᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDevice(ctx, field.Selections, res) } -func (ec *executionContext) _DeviceResponse_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.DeviceResponse) (ret graphql.Marshaler) { +func (ec *executionContext) _DeviceResponse_page(ctx context.Context, field graphql.CollectedField, obj *model.DeviceResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2581,7 +2476,7 @@ func (ec *executionContext) _DeviceResponse_pageInfo(ctx context.Context, field 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.PageInfo, nil + return obj.Page, nil }) if err != nil { ec.Error(ctx, err) @@ -2593,9 +2488,9 @@ func (ec *executionContext) _DeviceResponse_pageInfo(ctx context.Context, field } return graphql.Null } - res := resTmp.(*model.PageInfo) + res := resTmp.(*model.PageResponse) fc.Result = res - return ec.marshalNPageInfo2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res) + return ec.marshalNPageResponse2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageResponse(ctx, field.Selections, res) } func (ec *executionContext) _MediaItem_id(ctx context.Context, field graphql.CollectedField, obj *model.MediaItem) (ret graphql.Marshaler) { @@ -3245,7 +3140,7 @@ func (ec *executionContext) _MediaItemResponse_data(ctx context.Context, field g return ec.marshalOMediaItem2ᚕᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItem(ctx, field.Selections, res) } -func (ec *executionContext) _MediaItemResponse_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.MediaItemResponse) (ret graphql.Marshaler) { +func (ec *executionContext) _MediaItemResponse_page(ctx context.Context, field graphql.CollectedField, obj *model.MediaItemResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3263,7 +3158,7 @@ func (ec *executionContext) _MediaItemResponse_pageInfo(ctx context.Context, fie 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.PageInfo, nil + return obj.Page, nil }) if err != nil { ec.Error(ctx, err) @@ -3275,9 +3170,9 @@ func (ec *executionContext) _MediaItemResponse_pageInfo(ctx context.Context, fie } return graphql.Null } - res := resTmp.(*model.PageInfo) + res := resTmp.(*model.PageResponse) fc.Result = res - return ec.marshalNPageInfo2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res) + return ec.marshalNPageResponse2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageResponse(ctx, field.Selections, res) } func (ec *executionContext) _Mutation_createMediaItem(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { @@ -3544,7 +3439,7 @@ func (ec *executionContext) _Mutation_createUser(ctx context.Context, field grap return ec.marshalNUser2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUser(ctx, field.Selections, res) } -func (ec *executionContext) _PageInfo_count(ctx context.Context, field graphql.CollectedField, obj *model.PageInfo) (ret graphql.Marshaler) { +func (ec *executionContext) _PageResponse_size(ctx context.Context, field graphql.CollectedField, obj *model.PageResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3552,7 +3447,7 @@ func (ec *executionContext) _PageInfo_count(ctx context.Context, field graphql.C } }() fc := &graphql.FieldContext{ - Object: "PageInfo", + Object: "PageResponse", Field: field, Args: nil, IsMethod: false, @@ -3562,7 +3457,7 @@ func (ec *executionContext) _PageInfo_count(ctx context.Context, field graphql.C 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.Count, nil + return obj.Size, nil }) if err != nil { ec.Error(ctx, err) @@ -3579,7 +3474,7 @@ func (ec *executionContext) _PageInfo_count(ctx context.Context, field graphql.C return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) _PageInfo_page(ctx context.Context, field graphql.CollectedField, obj *model.PageInfo) (ret graphql.Marshaler) { +func (ec *executionContext) _PageResponse_page(ctx context.Context, field graphql.CollectedField, obj *model.PageResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3587,7 +3482,7 @@ func (ec *executionContext) _PageInfo_page(ctx context.Context, field graphql.Co } }() fc := &graphql.FieldContext{ - Object: "PageInfo", + Object: "PageResponse", Field: field, Args: nil, IsMethod: false, @@ -3614,7 +3509,7 @@ func (ec *executionContext) _PageInfo_page(ctx context.Context, field graphql.Co return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) _PageInfo_total(ctx context.Context, field graphql.CollectedField, obj *model.PageInfo) (ret graphql.Marshaler) { +func (ec *executionContext) _PageResponse_total(ctx context.Context, field graphql.CollectedField, obj *model.PageResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3622,7 +3517,7 @@ func (ec *executionContext) _PageInfo_total(ctx context.Context, field graphql.C } }() fc := &graphql.FieldContext{ - Object: "PageInfo", + Object: "PageResponse", Field: field, Args: nil, IsMethod: false, @@ -3776,7 +3671,7 @@ func (ec *executionContext) _Query_mediaItem(ctx context.Context, field graphql. 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 ec.resolvers.Query().MediaItem(rctx, args["id"].(string), args["delete"].(*bool)) + return ec.resolvers.Query().MediaItem(rctx, args["id"].(string)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User") @@ -3842,7 +3737,7 @@ func (ec *executionContext) _Query_device(ctx context.Context, field graphql.Col 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 ec.resolvers.Query().Device(rctx, args["id"].(string), args["delete"].(*bool)) + return ec.resolvers.Query().Device(rctx, args["id"].(string)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User") @@ -3908,7 +3803,7 @@ func (ec *executionContext) _Query_album(ctx context.Context, field graphql.Coll 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 ec.resolvers.Query().Album(rctx, args["id"].(string), args["delete"].(*bool)) + return ec.resolvers.Query().Album(rctx, args["id"].(string)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User") @@ -3974,7 +3869,7 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle 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 ec.resolvers.Query().User(rctx, args["id"].(string), args["delete"].(*bool)) + return ec.resolvers.Query().User(rctx, args["id"].(string)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "Admin") @@ -4040,7 +3935,7 @@ func (ec *executionContext) _Query_tag(ctx context.Context, field graphql.Collec 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 ec.resolvers.Query().Tag(rctx, args["id"].(string), args["delete"].(*bool)) + return ec.resolvers.Query().Tag(rctx, args["id"].(string)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User") @@ -4096,17 +3991,10 @@ func (ec *executionContext) _Query_me(ctx context.Context, field graphql.Collect } ctx = graphql.WithFieldContext(ctx, fc) - rawArgs := field.ArgumentMap(ec.Variables) - args, err := ec.field_Query_me_args(ctx, rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - fc.Args = args 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 ec.resolvers.Query().Me(rctx, args["delete"].(*bool)) + return ec.resolvers.Query().Me(rctx) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User") @@ -4172,7 +4060,7 @@ func (ec *executionContext) _Query_mediaItems(ctx context.Context, field graphql 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 ec.resolvers.Query().MediaItems(rctx, args["delete"].(*bool), args["filter"].(*model.MediaItemFilter), args["count"].(*int), args["page"].(*int)) + return ec.resolvers.Query().MediaItems(rctx, args["filter"].(*model.MediaItemFilter), args["page"].(*model.Page), args["order"].(*model.Order)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User") @@ -4238,7 +4126,7 @@ func (ec *executionContext) _Query_devices(ctx context.Context, field graphql.Co 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 ec.resolvers.Query().Devices(rctx, args["delete"].(*bool), args["filter"].(*model.DeviceFilter), args["count"].(*int), args["page"].(*int)) + return ec.resolvers.Query().Devices(rctx, args["filter"].(*model.DeviceFilter), args["page"].(*model.Page), args["order"].(*model.Order)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User") @@ -4304,7 +4192,7 @@ func (ec *executionContext) _Query_albums(ctx context.Context, field graphql.Col 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 ec.resolvers.Query().Albums(rctx, args["delete"].(*bool), args["filter"].(*model.AlbumFilter), args["count"].(*int), args["page"].(*int)) + return ec.resolvers.Query().Albums(rctx, args["filter"].(*model.AlbumFilter), args["page"].(*model.Page), args["order"].(*model.Order)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User") @@ -4370,7 +4258,7 @@ func (ec *executionContext) _Query_tags(ctx context.Context, field graphql.Colle 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 ec.resolvers.Query().Tags(rctx, args["delete"].(*bool), args["filter"].(*model.TagFilter), args["count"].(*int), args["page"].(*int)) + return ec.resolvers.Query().Tags(rctx, args["filter"].(*model.TagFilter), args["page"].(*model.Page), args["order"].(*model.Order)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User") @@ -4436,7 +4324,7 @@ func (ec *executionContext) _Query_users(ctx context.Context, field graphql.Coll 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 ec.resolvers.Query().Users(rctx, args["delete"].(*bool), args["filter"].(*model.UserFilter), args["count"].(*int), args["page"].(*int)) + return ec.resolvers.Query().Users(rctx, args["filter"].(*model.UserFilter), args["page"].(*model.Page), args["order"].(*model.Order)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "Admin") @@ -4820,7 +4708,7 @@ func (ec *executionContext) _TagResponse_data(ctx context.Context, field graphql return ec.marshalOTag2ᚕᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐTag(ctx, field.Selections, res) } -func (ec *executionContext) _TagResponse_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.TagResponse) (ret graphql.Marshaler) { +func (ec *executionContext) _TagResponse_page(ctx context.Context, field graphql.CollectedField, obj *model.TagResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -4838,7 +4726,7 @@ func (ec *executionContext) _TagResponse_pageInfo(ctx context.Context, field gra 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.PageInfo, nil + return obj.Page, nil }) if err != nil { ec.Error(ctx, err) @@ -4850,9 +4738,9 @@ func (ec *executionContext) _TagResponse_pageInfo(ctx context.Context, field gra } return graphql.Null } - res := resTmp.(*model.PageInfo) + res := resTmp.(*model.PageResponse) fc.Result = res - return ec.marshalNPageInfo2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res) + return ec.marshalNPageResponse2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageResponse(ctx, field.Selections, res) } func (ec *executionContext) _User_id(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) { @@ -5474,7 +5362,7 @@ func (ec *executionContext) _UserResponse_data(ctx context.Context, field graphq return ec.marshalOUser2ᚕᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUser(ctx, field.Selections, res) } -func (ec *executionContext) _UserResponse_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.UserResponse) (ret graphql.Marshaler) { +func (ec *executionContext) _UserResponse_page(ctx context.Context, field graphql.CollectedField, obj *model.UserResponse) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -5492,7 +5380,7 @@ func (ec *executionContext) _UserResponse_pageInfo(ctx context.Context, field gr 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.PageInfo, nil + return obj.Page, nil }) if err != nil { ec.Error(ctx, err) @@ -5504,9 +5392,9 @@ func (ec *executionContext) _UserResponse_pageInfo(ctx context.Context, field gr } return graphql.Null } - res := resTmp.(*model.PageInfo) + res := resTmp.(*model.PageResponse) fc.Result = res - return ec.marshalNPageInfo2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res) + return ec.marshalNPageResponse2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageResponse(ctx, field.Selections, res) } func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { @@ -7160,6 +7048,62 @@ func (ec *executionContext) unmarshalInputNewUser(ctx context.Context, obj inter return it, nil } +func (ec *executionContext) unmarshalInputOrder(ctx context.Context, obj interface{}) (model.Order, error) { + var it model.Order + var asMap = obj.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "by": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("by")) + it.By, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "direction": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("direction")) + it.Direction, err = ec.unmarshalOOrderDirection2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐOrderDirection(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputPage(ctx context.Context, obj interface{}) (model.Page, error) { + var it model.Page + var asMap = obj.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "size": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("size")) + it.Size, err = ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + case "page": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page")) + it.Page, err = ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + func (ec *executionContext) unmarshalInputRoleFilter(ctx context.Context, obj interface{}) (model.RoleFilter, error) { var it model.RoleFilter var asMap = obj.(map[string]interface{}) @@ -7506,8 +7450,8 @@ func (ec *executionContext) _AlbumResponse(ctx context.Context, sel ast.Selectio out.Values[i] = graphql.MarshalString("AlbumResponse") case "data": out.Values[i] = ec._AlbumResponse_data(ctx, field, obj) - case "pageInfo": - out.Values[i] = ec._AlbumResponse_pageInfo(ctx, field, obj) + case "page": + out.Values[i] = ec._AlbumResponse_page(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } @@ -7614,8 +7558,8 @@ func (ec *executionContext) _DeviceResponse(ctx context.Context, sel ast.Selecti out.Values[i] = graphql.MarshalString("DeviceResponse") case "data": out.Values[i] = ec._DeviceResponse_data(ctx, field, obj) - case "pageInfo": - out.Values[i] = ec._DeviceResponse_pageInfo(ctx, field, obj) + case "page": + out.Values[i] = ec._DeviceResponse_page(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } @@ -7704,8 +7648,8 @@ func (ec *executionContext) _MediaItemResponse(ctx context.Context, sel ast.Sele out.Values[i] = graphql.MarshalString("MediaItemResponse") case "data": out.Values[i] = ec._MediaItemResponse_data(ctx, field, obj) - case "pageInfo": - out.Values[i] = ec._MediaItemResponse_pageInfo(ctx, field, obj) + case "page": + out.Values[i] = ec._MediaItemResponse_page(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } @@ -7766,29 +7710,29 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) return out } -var pageInfoImplementors = []string{"PageInfo"} +var pageResponseImplementors = []string{"PageResponse"} -func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, obj *model.PageInfo) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, pageInfoImplementors) +func (ec *executionContext) _PageResponse(ctx context.Context, sel ast.SelectionSet, obj *model.PageResponse) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, pageResponseImplementors) out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString("PageInfo") - case "count": - out.Values[i] = ec._PageInfo_count(ctx, field, obj) + out.Values[i] = graphql.MarshalString("PageResponse") + case "size": + out.Values[i] = ec._PageResponse_size(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } case "page": - out.Values[i] = ec._PageInfo_page(ctx, field, obj) + out.Values[i] = ec._PageResponse_page(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } case "total": - out.Values[i] = ec._PageInfo_total(ctx, field, obj) + out.Values[i] = ec._PageResponse_total(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } @@ -8069,8 +8013,8 @@ func (ec *executionContext) _TagResponse(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("TagResponse") case "data": out.Values[i] = ec._TagResponse_data(ctx, field, obj) - case "pageInfo": - out.Values[i] = ec._TagResponse_pageInfo(ctx, field, obj) + case "page": + out.Values[i] = ec._TagResponse_page(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } @@ -8159,8 +8103,8 @@ func (ec *executionContext) _UserResponse(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("UserResponse") case "data": out.Values[i] = ec._UserResponse_data(ctx, field, obj) - case "pageInfo": - out.Values[i] = ec._UserResponse_pageInfo(ctx, field, obj) + case "page": + out.Values[i] = ec._UserResponse_page(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } @@ -8613,14 +8557,14 @@ func (ec *executionContext) unmarshalNNewUser2reichardᚗioᚋimaginiᚋgraphᚋ return res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) marshalNPageInfo2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageInfo(ctx context.Context, sel ast.SelectionSet, v *model.PageInfo) graphql.Marshaler { +func (ec *executionContext) marshalNPageResponse2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageResponse(ctx context.Context, sel ast.SelectionSet, v *model.PageResponse) graphql.Marshaler { if v == nil { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { ec.Errorf(ctx, "must not be null") } return graphql.Null } - return ec._PageInfo(ctx, sel, v) + return ec._PageResponse(ctx, sel, v) } func (ec *executionContext) unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx context.Context, v interface{}) (model.Role, error) { @@ -9370,6 +9314,38 @@ func (ec *executionContext) unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimagini return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalOOrder2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐOrder(ctx context.Context, v interface{}) (*model.Order, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalInputOrder(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalOOrderDirection2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐOrderDirection(ctx context.Context, v interface{}) (*model.OrderDirection, error) { + if v == nil { + return nil, nil + } + var res = new(model.OrderDirection) + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOOrderDirection2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐOrderDirection(ctx context.Context, sel ast.SelectionSet, v *model.OrderDirection) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return v +} + +func (ec *executionContext) unmarshalOPage2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPage(ctx context.Context, v interface{}) (*model.Page, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalInputPage(ctx, v) + 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 diff --git a/graph/helpers.go b/graph/helpers.go index e2b2c07..409842c 100644 --- a/graph/helpers.go +++ b/graph/helpers.go @@ -1,15 +1,61 @@ package graph import ( + "context" + "errors" "net/http" "strings" "time" "github.com/dsoprea/go-exif/v3" exifcommon "github.com/dsoprea/go-exif/v3/common" + "github.com/google/uuid" "reichard.io/imagini/graph/model" ) +func getContextHTTP(ctx context.Context) (*http.ResponseWriter, *http.Request, error) { + authContext := ctx.Value("auth").(*model.AuthContext) + + resp := authContext.AuthResponse + if resp == nil { + return nil, nil, errors.New("Context Error") + } + + req := authContext.AuthRequest + if resp == nil { + return nil, nil, errors.New("Context Error") + } + + return resp, req, nil +} + +func getContextIDs(ctx context.Context) (string, string, error) { + authContext := ctx.Value("auth").(*model.AuthContext) + accessToken := *authContext.AccessToken + + uid, ok := accessToken.Get("sub") + if !ok { + return "", "", errors.New("Context Error") + } + + did, ok := accessToken.Get("sub") + if !ok { + return "", "", errors.New("Context Error") + } + + userID, err := uuid.Parse(uid.(string)) + if err != nil { + return "", "", errors.New("Context Error") + } + + deviceID, err := uuid.Parse(did.(string)) + if err != nil { + return "", "", errors.New("Context Error") + } + + return userID.String(), deviceID.String(), nil +} + func deriveDeviceType(r *http.Request) model.DeviceType { userAgent := strings.ToLower(r.Header.Get("User-Agent")) if strings.Contains(userAgent, "ios-imagini") { diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index a2cdbbc..66d036a 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -27,8 +27,8 @@ type AlbumFilter struct { } type AlbumResponse struct { - Data []*Album `json:"data" ` - PageInfo *PageInfo `json:"pageInfo" ` + Data []*Album `json:"data" ` + Page *PageResponse `json:"page" ` } type AuthResponse struct { @@ -66,8 +66,8 @@ type DeviceFilter struct { } type DeviceResponse struct { - Data []*Device `json:"data" ` - PageInfo *PageInfo `json:"pageInfo" ` + Data []*Device `json:"data" ` + Page *PageResponse `json:"page" ` } type DeviceTypeFilter struct { @@ -127,8 +127,8 @@ type MediaItemFilter struct { } type MediaItemResponse struct { - Data []*MediaItem `json:"data" ` - PageInfo *PageInfo `json:"pageInfo" ` + Data []*MediaItem `json:"data" ` + Page *PageResponse `json:"page" ` } type NewAlbum struct { @@ -155,8 +155,18 @@ type NewUser struct { Password *string `json:"password" ` } -type PageInfo struct { - Count int `json:"count" ` +type Order struct { + By *string `json:"by" ` + Direction *OrderDirection `json:"direction" ` +} + +type Page struct { + Size *int `json:"size" ` + Page *int `json:"page" ` +} + +type PageResponse struct { + Size int `json:"size" ` Page int `json:"page" ` Total int `json:"total" ` } @@ -193,8 +203,8 @@ type TagFilter struct { } type TagResponse struct { - Data []*Tag `json:"data" ` - PageInfo *PageInfo `json:"pageInfo" ` + Data []*Tag `json:"data" ` + Page *PageResponse `json:"page" ` } type TimeFilter struct { @@ -233,8 +243,8 @@ type UserFilter struct { } type UserResponse struct { - Data []*User `json:"data" ` - PageInfo *PageInfo `json:"pageInfo" ` + Data []*User `json:"data" ` + Page *PageResponse `json:"page" ` } type AuthResult string @@ -372,6 +382,47 @@ func (e DeviceType) MarshalGQL(w io.Writer) { fmt.Fprint(w, strconv.Quote(e.String())) } +type OrderDirection string + +const ( + OrderDirectionAsc OrderDirection = "ASC" + OrderDirectionDesc OrderDirection = "DESC" +) + +var AllOrderDirection = []OrderDirection{ + OrderDirectionAsc, + OrderDirectionDesc, +} + +func (e OrderDirection) IsValid() bool { + switch e { + case OrderDirectionAsc, OrderDirectionDesc: + return true + } + return false +} + +func (e OrderDirection) String() string { + return string(e) +} + +func (e *OrderDirection) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = OrderDirection(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid OrderDirection", str) + } + return nil +} + +func (e OrderDirection) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) +} + type Role string const ( diff --git a/graph/schema.graphqls b/graph/schema.graphqls index c3448f0..8e7bfdb 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -32,6 +32,11 @@ enum AuthType { LDAP } +enum OrderDirection { + ASC + DESC +} + # ------------------------------------------------------------ # ---------------------- Authentication ---------------------- # ------------------------------------------------------------ @@ -267,39 +272,49 @@ input NewAlbum { name: String! } +input Page { + size: Int + page: Int +} + +input Order { + by: String + direction: OrderDirection +} + # ------------------------------------------------------------ # ------------------------ Responses ------------------------- # ------------------------------------------------------------ -type PageInfo { - count: Int! +type PageResponse { + size: Int! page: Int! total: Int! } type MediaItemResponse { data: [MediaItem] - pageInfo: PageInfo! + page: PageResponse! } type UserResponse { data: [User] - pageInfo: PageInfo! + page: PageResponse! } type DeviceResponse { data: [Device] - pageInfo: PageInfo! + page: PageResponse! } type TagResponse { data: [Tag] - pageInfo: PageInfo! + page: PageResponse! } type AlbumResponse { data: [Album] - pageInfo: PageInfo! + page: PageResponse! } # ------------------------------------------------------------ @@ -313,62 +328,52 @@ type Query { password: String! deviceID: ID ): AuthResponse! - logout: AuthResponse! @hasMinRole(role: User) + logout: AuthResponse! @hasMinRole(role: User) # Single Item mediaItem( id: ID! - delete: Boolean - ): MediaItem! @hasMinRole(role: User) + ): MediaItem! @hasMinRole(role: User) device( id: ID! - delete: Boolean - ): Device! @hasMinRole(role: User) + ): Device! @hasMinRole(role: User) album( id: ID! - delete: Boolean - ): Album! @hasMinRole(role: User) + ): Album! @hasMinRole(role: User) user( id: ID! - delete: Boolean - ): User! @hasMinRole(role: Admin) # TODO: Delete All User Content + ): User! @hasMinRole(role: Admin) tag( id: ID! - delete: Boolean - ): Tag! @hasMinRole(role: User) - me(delete: Boolean): User! @hasMinRole(role: User) + ): Tag! @hasMinRole(role: User) + me: User! @hasMinRole(role: User) # All mediaItems( - delete: Boolean filter: MediaItemFilter - count: Int - page: Int - ): MediaItemResponse! @hasMinRole(role: User) + page: Page + order: Order + ): MediaItemResponse! @hasMinRole(role: User) devices( - delete: Boolean filter: DeviceFilter - count: Int - page: Int - ): DeviceResponse! @hasMinRole(role: User) + page: Page + order: Order + ): DeviceResponse! @hasMinRole(role: User) albums( - delete: Boolean filter: AlbumFilter - count: Int - page: Int - ): AlbumResponse! @hasMinRole(role: User) + page: Page + order: Order + ): AlbumResponse! @hasMinRole(role: User) tags( - delete: Boolean filter: TagFilter - count: Int - page: Int - ): TagResponse! @hasMinRole(role: User) + page: Page + order: Order + ): TagResponse! @hasMinRole(role: User) users( - delete: Boolean filter: UserFilter - count: Int - page: Int - ): UserResponse! @hasMinRole(role: Admin) # TODO: Delete All User Content + page: Page + order: Order + ): UserResponse! @hasMinRole(role: Admin) } type Mutation { diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index bdb69d9..08ce5fa 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -21,12 +21,10 @@ import ( ) func (r *mutationResolver) CreateMediaItem(ctx context.Context, input model.NewMediaItem) (*model.MediaItem, 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") + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err } // File header placeholder @@ -52,7 +50,7 @@ func (r *mutationResolver) CreateMediaItem(ctx context.Context, input model.NewM // Derive Folder & File Path mediaItemID := uuid.New().String() fileName := mediaItemID + fileMime.Extension() - folderPath := path.Join("/" + r.Config.DataPath + "/media/" + userID.(string)) + folderPath := path.Join("/" + r.Config.DataPath + "/media/" + userID) os.MkdirAll(folderPath, 0700) filePath := path.Join(folderPath + "/" + fileName) @@ -83,7 +81,7 @@ func (r *mutationResolver) CreateMediaItem(ctx context.Context, input model.NewM // Add Additional MediaItem Fields mediaItem.ID = mediaItemID - mediaItem.UserID = userID.(string) + mediaItem.UserID = userID mediaItem.IsVideo = isVideo mediaItem.FileName = fileName mediaItem.OrigName = input.File.Filename @@ -99,20 +97,18 @@ func (r *mutationResolver) CreateMediaItem(ctx context.Context, input model.NewM } func (r *mutationResolver) CreateAlbum(ctx context.Context, input model.NewAlbum) (*model.Album, 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") + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err } album := &model.Album{ Name: input.Name, - UserID: userID.(string), + UserID: userID, } - err := r.DB.CreateAlbum(album) + err = r.DB.CreateAlbum(album) if err != nil { return nil, err } @@ -121,20 +117,18 @@ 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") + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err } tag := &model.Tag{ Name: input.Name, - UserID: userID.(string), + UserID: userID, } - err := r.DB.CreateTag(tag) + err = r.DB.CreateTag(tag) if err != nil { return nil, err } @@ -162,10 +156,11 @@ func (r *mutationResolver) CreateUser(ctx context.Context, input model.NewUser) } func (r *queryResolver) Login(ctx context.Context, user string, password string, deviceID *string) (*model.AuthResponse, error) { - // Get Context - authContext := ctx.Value("auth").(*model.AuthContext) - resp := authContext.AuthResponse - req := authContext.AuthRequest + // Acquire Context + resp, req, err := getContextHTTP(ctx) + if err != nil { + return nil, err + } // Clear All Cookies By Default accessCookie := http.Cookie{Name: "AccessToken", Path: "/", HttpOnly: true, MaxAge: -1, Expires: time.Now().Add(-100 * time.Hour)} @@ -219,9 +214,11 @@ func (r *queryResolver) Login(ctx context.Context, user string, password string, } func (r *queryResolver) Logout(ctx context.Context) (*model.AuthResponse, error) { - // Set Cookie From Context - authContext := ctx.Value("auth").(*model.AuthContext) - resp := authContext.AuthResponse + // Acquire Context + resp, _, err := getContextHTTP(ctx) + if err != nil { + return nil, err + } // Clear All Cookies accessCookie := http.Cookie{Name: "AccessToken", Path: "/", HttpOnly: true, MaxAge: -1, Expires: time.Now().Add(-100 * time.Hour)} @@ -232,13 +229,11 @@ func (r *queryResolver) Logout(ctx context.Context) (*model.AuthResponse, error) return &model.AuthResponse{Result: model.AuthResultSuccess}, nil } -func (r *queryResolver) MediaItem(ctx context.Context, id string, delete *bool) (*model.MediaItem, error) { - // Get Context - authContext := ctx.Value("auth").(*model.AuthContext) - accessToken := *authContext.AccessToken - userID, ok := accessToken.Get("sub") - if !ok { - return nil, errors.New("Context Error") +func (r *queryResolver) MediaItem(ctx context.Context, id string) (*model.MediaItem, error) { + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err } mediaItemID, err := uuid.Parse(id) @@ -246,7 +241,7 @@ func (r *queryResolver) MediaItem(ctx context.Context, id string, delete *bool) return nil, errors.New("Invalid ID Format") } - foundMediaItem := &model.MediaItem{ID: mediaItemID.String(), UserID: userID.(string)} + foundMediaItem := &model.MediaItem{ID: mediaItemID.String(), UserID: userID} count, err := r.DB.MediaItem(foundMediaItem) if err != nil { return nil, errors.New("DB Error") @@ -256,13 +251,11 @@ func (r *queryResolver) MediaItem(ctx context.Context, id string, delete *bool) return foundMediaItem, nil } -func (r *queryResolver) Device(ctx context.Context, id string, delete *bool) (*model.Device, error) { - // Get Context - authContext := ctx.Value("auth").(*model.AuthContext) - accessToken := *authContext.AccessToken - userID, ok := accessToken.Get("sub") - if !ok { - return nil, errors.New("Context Error") +func (r *queryResolver) Device(ctx context.Context, id string) (*model.Device, error) { + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err } deviceID, err := uuid.Parse(id) @@ -270,7 +263,7 @@ func (r *queryResolver) Device(ctx context.Context, id string, delete *bool) (*m return nil, errors.New("Invalid ID Format") } - foundDevice := &model.Device{ID: deviceID.String(), UserID: userID.(string)} + foundDevice := &model.Device{ID: deviceID.String(), UserID: userID} count, err := r.DB.Device(foundDevice) if err != nil { return nil, errors.New("DB Error") @@ -280,13 +273,11 @@ func (r *queryResolver) Device(ctx context.Context, id string, delete *bool) (*m return foundDevice, nil } -func (r *queryResolver) Album(ctx context.Context, id string, delete *bool) (*model.Album, error) { - // Get Context - authContext := ctx.Value("auth").(*model.AuthContext) - accessToken := *authContext.AccessToken - userID, ok := accessToken.Get("sub") - if !ok { - return nil, errors.New("Context Error") +func (r *queryResolver) Album(ctx context.Context, id string) (*model.Album, error) { + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err } albumID, err := uuid.Parse(id) @@ -294,7 +285,7 @@ func (r *queryResolver) Album(ctx context.Context, id string, delete *bool) (*mo return nil, errors.New("Invalid ID Format") } - foundAlbum := &model.Album{ID: albumID.String(), UserID: userID.(string)} + foundAlbum := &model.Album{ID: albumID.String(), UserID: userID} count, err := r.DB.Album(foundAlbum) if err != nil { return nil, errors.New("DB Error") @@ -304,7 +295,7 @@ func (r *queryResolver) Album(ctx context.Context, id string, delete *bool) (*mo return foundAlbum, nil } -func (r *queryResolver) User(ctx context.Context, id string, delete *bool) (*model.User, error) { +func (r *queryResolver) User(ctx context.Context, id string) (*model.User, error) { userID, err := uuid.Parse(id) if err != nil { return nil, errors.New("Invalid ID Format") @@ -320,13 +311,19 @@ func (r *queryResolver) User(ctx context.Context, id string, delete *bool) (*mod return foundUser, nil } -func (r *queryResolver) Tag(ctx context.Context, id string, delete *bool) (*model.Tag, error) { +func (r *queryResolver) Tag(ctx context.Context, id string) (*model.Tag, error) { + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err + } + tagID, err := uuid.Parse(id) if err != nil { return nil, errors.New("Invalid ID Format") } - foundTag := &model.Tag{ID: tagID.String()} + foundTag := &model.Tag{ID: tagID.String(), UserID: userID} count, err := r.DB.Tag(foundTag) if err != nil { return nil, errors.New("DB Error") @@ -336,16 +333,14 @@ func (r *queryResolver) Tag(ctx context.Context, id string, delete *bool) (*mode return foundTag, nil } -func (r *queryResolver) Me(ctx context.Context, delete *bool) (*model.User, error) { - // Get Context - authContext := ctx.Value("auth").(*model.AuthContext) - accessToken := *authContext.AccessToken - userID, ok := accessToken.Get("sub") - if !ok { - return nil, errors.New("Context Error") +func (r *queryResolver) Me(ctx context.Context) (*model.User, error) { + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err } - foundUser := &model.User{ID: userID.(string)} + foundUser := &model.User{ID: userID} count, err := r.DB.User(foundUser) if err != nil || count != 1 { return nil, errors.New("DB Error") @@ -353,88 +348,82 @@ func (r *queryResolver) Me(ctx context.Context, delete *bool) (*model.User, erro return foundUser, nil } -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(filter) +func (r *queryResolver) MediaItems(ctx context.Context, filter *model.MediaItemFilter, page *model.Page, order *model.Order) (*model.MediaItemResponse, error) { + // Acquire Context + userID, _, err := getContextIDs(ctx) if err != nil { - return nil, errors.New("Context Error") + return nil, err + } + + resp, pageResponse, err := r.DB.MediaItems(userID, filter, page, order) + if err != nil { + return nil, errors.New("DB Error") } return &model.MediaItemResponse{ Data: resp, - PageInfo: &model.PageInfo{ - Count: int(totalCount), - Page: 0, - Total: int(totalCount), - }, + Page: &pageResponse, }, nil } -func (r *queryResolver) Devices(ctx context.Context, delete *bool, filter *model.DeviceFilter, count *int, page *int) (*model.DeviceResponse, error) { - // Get Context - authContext := ctx.Value("auth").(*model.AuthContext) - accessToken := *authContext.AccessToken - userID, ok := accessToken.Get("sub") - if !ok { - return nil, errors.New("Context Error") +func (r *queryResolver) Devices(ctx context.Context, filter *model.DeviceFilter, page *model.Page, order *model.Order) (*model.DeviceResponse, error) { + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err } - _ = userID - resp, totalCount, err := r.DB.Devices() + resp, pageResponse, err := r.DB.Devices(userID, filter, page, order) if err != nil { return nil, errors.New("DB Error") } return &model.DeviceResponse{ Data: resp, - PageInfo: &model.PageInfo{ - Count: int(totalCount), - Page: 0, - Total: int(totalCount), - }, + Page: &pageResponse, }, nil } -func (r *queryResolver) Albums(ctx context.Context, delete *bool, filter *model.AlbumFilter, count *int, page *int) (*model.AlbumResponse, error) { - // TODO: User Specific - resp, totalCount, err := r.DB.Albums() +func (r *queryResolver) Albums(ctx context.Context, filter *model.AlbumFilter, page *model.Page, order *model.Order) (*model.AlbumResponse, error) { + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err + } + + resp, pageResponse, err := r.DB.Albums(userID, filter, page, order) if err != nil { return nil, errors.New("Context Error") } return &model.AlbumResponse{ Data: resp, - PageInfo: &model.PageInfo{ - Count: int(totalCount), - Page: 0, - Total: int(totalCount), - }, + Page: &pageResponse, }, nil } -func (r *queryResolver) Tags(ctx context.Context, delete *bool, filter *model.TagFilter, count *int, page *int) (*model.TagResponse, error) { - resp, totalCount, err := r.DB.Tags() +func (r *queryResolver) Tags(ctx context.Context, filter *model.TagFilter, page *model.Page, order *model.Order) (*model.TagResponse, error) { + // Acquire Context + userID, _, err := getContextIDs(ctx) + if err != nil { + return nil, err + } + + resp, pageResponse, err := r.DB.Tags(userID, filter, page, order) if err != nil { return nil, errors.New("Context Error") } return &model.TagResponse{ Data: resp, - PageInfo: &model.PageInfo{ - Count: int(totalCount), - Page: 0, - Total: int(totalCount), - }, + Page: &pageResponse, }, nil } -func (r *queryResolver) Users(ctx context.Context, delete *bool, filter *model.UserFilter, count *int, page *int) (*model.UserResponse, error) { - resp, totalCount, err := r.DB.Users() +func (r *queryResolver) Users(ctx context.Context, filter *model.UserFilter, page *model.Page, order *model.Order) (*model.UserResponse, error) { + resp, pageResponse, err := r.DB.Users(filter, page, order) if err != nil { return nil, errors.New("Context Error") } return &model.UserResponse{ Data: resp, - PageInfo: &model.PageInfo{ - Count: int(totalCount), - Page: 0, - Total: int(totalCount), - }, + Page: &pageResponse, }, nil } diff --git a/internal/db/albums.go b/internal/db/albums.go index c2def31..2ffae04 100644 --- a/internal/db/albums.go +++ b/internal/db/albums.go @@ -2,6 +2,7 @@ package db import ( log "github.com/sirupsen/logrus" + "gorm.io/gorm" "reichard.io/imagini/graph/model" ) @@ -18,11 +19,17 @@ func (dbm *DBManager) Album(album *model.Album) (int64, error) { return count, err } -func (dbm *DBManager) Albums() ([]*model.Album, int64, error) { +func (dbm *DBManager) Albums(userID string, filters *model.AlbumFilter, page *model.Page, order *model.Order) ([]*model.Album, model.PageResponse, error) { + // Initial User Filter + tx := dbm.db.Session(&gorm.Session{}).Model(&model.Album{}).Where("user_id == ?", userID) + + // Dynamically Generate Base Query + tx, pageResponse := dbm.generateBaseQuery(tx, filters, page, order) + + // Acquire Results var foundAlbums []*model.Album - var count int64 - err := dbm.db.Find(&foundAlbums).Count(&count).Error - return foundAlbums, count, err + err := tx.Find(&foundAlbums).Error + return foundAlbums, pageResponse, err } func (dbm *DBManager) DeleteAlbum(album *model.Album) error { diff --git a/internal/db/db.go b/internal/db/db.go index 4121c42..a1f32a8 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -1,11 +1,13 @@ package db import ( - "errors" "fmt" "path" + "reflect" + "github.com/iancoleman/strcase" log "github.com/sirupsen/logrus" + // "gorm.io/gorm/logger" "gorm.io/driver/sqlite" "gorm.io/gorm" @@ -30,6 +32,7 @@ func NewMgr(c *config.Config) *DBManager { if c.DBType == "SQLite" { dbLocation := path.Join(c.ConfigPath, "imagini.db") dbm.db, _ = gorm.Open(sqlite.Open(dbLocation), gormConfig) + dbm.db = dbm.db.Debug() } else { log.Fatal("Unsupported Database") } @@ -48,28 +51,9 @@ func NewMgr(c *config.Config) *DBManager { dbm.bootstrapDatabase() } - dbm.testFeatures() - return dbm } -func (dbm *DBManager) testFeatures() { - - // Get Devices By UserID - // var myDevices []model.Device - // dbm.db.Debug().Where(&model.Device{UserID: "97589354-cd42-40e2-bc5e-7ba6badf89fa"}).Find(&myDevices) - // fmt.Printf("Devices: %+v\n", myDevices) - - // Get User by DeviceID - // var myUser []model.User - // dbm.db.Debug().Model(&model.User{}). - // Select("users.*"). - // Joins("left join devices on users.id = devices.user_id"). - // Where("devices.id = ?", "4e9aa851-f25b-4330-91dc-c0f975e56fa1"). - // Find(&myUser) - // fmt.Printf("User: %+v\n", myUser) -} - func (dbm *DBManager) bootstrapDatabase() { log.Info("[query] Bootstrapping database.") @@ -88,46 +72,84 @@ func (dbm *DBManager) bootstrapDatabase() { } } -// TODO -func (dbm *DBManager) QueryBuilder(dest interface{}, params []byte) (int64, error) { - // TODO: - // - Where Filters - // - Sort Filters - // - Paging Filters +func (dbm *DBManager) generateBaseQuery(tx *gorm.DB, filter interface{}, page *model.Page, order *model.Order) (*gorm.DB, model.PageResponse) { + tx = dbm.generateFilter(tx, filter) + tx = dbm.generateOrder(tx, order, filter) + tx, pageResponse := dbm.generatePage(tx, page) + return tx, pageResponse +} - objType := fmt.Sprintf("%T", dest) - if objType == "*[]model.MediaItem" { - // TODO: Validate MediaItem Type - } else { - // Return Error - return 0, errors.New("Invalid type") +func (dbm *DBManager) generateOrder(tx *gorm.DB, order *model.Order, filter interface{}) *gorm.DB { + // Set Defaults + orderBy := "created_at" + orderDirection := model.OrderDirectionDesc + + if order == nil { + order = &model.Order{ + By: &orderBy, + Direction: &orderDirection, + } } - var count int64 - err := dbm.db.Find(dest).Count(&count).Error - return count, err + if order.By == nil { + order.By = &orderBy + } - // Paging: - // - Regular Pagination: - // - /api/v1/MediaItems?page[limit]=50&page=2 - // - Meta Count Only - // - /api/v1/MediaItems?page[limit]=0 + if order.Direction == nil { + order.Direction = &orderDirection + } - // Sorting: - // - Ascending Sort: - // - /api/v1/MediaItems?sort=created_at - // - Descending Sort: - // - /api/v1/MediaItems?sort=-created_at + // Get Possible Values + ptr := reflect.New(reflect.TypeOf(filter).Elem()) + v := reflect.Indirect(ptr) - // Filters: - // - Greater Than / Less Than (created_at, updated_at, exif_date) - // - /api/v1/MediaItems?filter[created_at]>=2020-01-01&filter[created_at]<=2021-01-01 - // - Long / Lat Range (latitude, longitude) - // - /api/v1/MediaItems?filter[latitude]>=71.1827&filter[latitude]<=72.0000&filter[longitude]>=100.000&filter[longitude]<=101.0000 - // - Image / Video (media_type) - // - /api/v1/MediaItems?filter[media_type]=Image - // - Tags (tags) - // - /api/v1/MediaItems?filter[tags]=id1,id2,id3 - // - Albums (albums) - // - /api/v1/MediaItems?filter[albums]=id1 + isValid := false + for i := 0; i < v.NumField(); i++ { + fieldName := v.Type().Field(i).Name + if strcase.ToSnake(*order.By) == strcase.ToSnake(fieldName) { + isValid = true + break + } + } + + if isValid { + tx = tx.Order(fmt.Sprintf("%s %s", strcase.ToSnake(*order.By), order.Direction.String())) + } + + return tx +} + +func (dbm *DBManager) generatePage(tx *gorm.DB, page *model.Page) (*gorm.DB, model.PageResponse) { + // Set Defaults + var count int64 + pageSize := 50 + pageNum := 1 + + if page == nil { + page = &model.Page{ + Size: &pageSize, + Page: &pageNum, + } + } + + if page.Size == nil { + page.Size = &pageSize + } + + if page.Page == nil { + page.Page = &pageNum + } + + // Acquire Counts Before Pagination + tx.Count(&count) + + // Calculate Offset + calculatedOffset := (*page.Page - 1) * *page.Size + tx = tx.Limit(*page.Size).Offset(calculatedOffset) + + return tx, model.PageResponse{ + Page: *page.Page, + Size: *page.Size, + Total: int(count), + } } diff --git a/internal/db/devices.go b/internal/db/devices.go index 27bce06..393218b 100644 --- a/internal/db/devices.go +++ b/internal/db/devices.go @@ -3,6 +3,7 @@ package db import ( "github.com/google/uuid" log "github.com/sirupsen/logrus" + "gorm.io/gorm" "reichard.io/imagini/graph/model" ) @@ -21,11 +22,17 @@ func (dbm *DBManager) Device(device *model.Device) (int64, error) { return count, err } -func (dbm *DBManager) Devices() ([]*model.Device, int64, error) { +func (dbm *DBManager) Devices(userID string, filters *model.DeviceFilter, page *model.Page, order *model.Order) ([]*model.Device, model.PageResponse, error) { + // Initial User Filter + tx := dbm.db.Session(&gorm.Session{}).Model(&model.Device{}).Where("user_id == ?", userID) + + // Dynamically Generate Base Query + tx, pageResponse := dbm.generateBaseQuery(tx, filters, page, order) + + // Acquire Results var foundDevices []*model.Device - var count int64 - err := dbm.db.Find(&foundDevices).Count(&count).Error - return foundDevices, count, err + err := tx.Find(&foundDevices).Error + return foundDevices, pageResponse, err } func (dbm *DBManager) DeleteDevice(user *model.Device) error { diff --git a/internal/db/filters.go b/internal/db/filters.go index a13731b..7c0eaa7 100644 --- a/internal/db/filters.go +++ b/internal/db/filters.go @@ -10,10 +10,13 @@ import ( ) // 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() +func (dbm *DBManager) generateFilter(tx *gorm.DB, filter interface{}) *gorm.DB { + ptr := reflect.ValueOf(filter) + v := reflect.Indirect(ptr) - v := reflect.ValueOf(filter) + if v == reflect.ValueOf(nil) { + return tx + } for i := 0; i < v.NumField(); i++ { fieldName := strcase.ToSnake(v.Type().Field(i).Name) @@ -45,7 +48,7 @@ func (dbm *DBManager) generateFilters(filter interface{}) (*gorm.DB, error) { } } - return tx, nil + return tx } func generateStringFilter(tx *gorm.DB, fieldName string, filter *model.StringFilter) *gorm.DB { diff --git a/internal/db/media_items.go b/internal/db/media_items.go index 11656c9..d914cd7 100644 --- a/internal/db/media_items.go +++ b/internal/db/media_items.go @@ -2,6 +2,7 @@ package db import ( log "github.com/sirupsen/logrus" + "gorm.io/gorm" "reichard.io/imagini/graph/model" ) @@ -18,14 +19,16 @@ func (dbm *DBManager) MediaItem(mediaItem *model.MediaItem) (int64, error) { return count, err } -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 - } +// UserID, Filters, Sort, Page, Delete +func (dbm *DBManager) MediaItems(userID string, filters *model.MediaItemFilter, page *model.Page, order *model.Order) ([]*model.MediaItem, model.PageResponse, error) { + // Initial User Filter + tx := dbm.db.Session(&gorm.Session{}).Model(&model.MediaItem{}).Where("user_id == ?", userID) + + // Dynamically Generate Base Query + tx, pageResponse := dbm.generateBaseQuery(tx, filters, page, order) + + // Acquire Results var mediaItems []*model.MediaItem - var count int64 - err = tx.Find(&mediaItems).Count(&count).Error - return mediaItems, count, err + err := tx.Find(&mediaItems).Error + return mediaItems, pageResponse, err } diff --git a/internal/db/tags.go b/internal/db/tags.go index 8a017ca..0018469 100644 --- a/internal/db/tags.go +++ b/internal/db/tags.go @@ -2,6 +2,7 @@ package db import ( log "github.com/sirupsen/logrus" + "gorm.io/gorm" "reichard.io/imagini/graph/model" ) @@ -18,11 +19,17 @@ func (dbm *DBManager) Tag(tag *model.Tag) (int64, error) { return count, err } -func (dbm *DBManager) Tags() ([]*model.Tag, int64, error) { +func (dbm *DBManager) Tags(userID string, filters *model.TagFilter, page *model.Page, order *model.Order) ([]*model.Tag, model.PageResponse, error) { + // Initial User Filter + tx := dbm.db.Session(&gorm.Session{}).Model(&model.Tag{}).Where("user_id == ?", userID) + + // Dynamically Generate Base Query + tx, pageResponse := dbm.generateBaseQuery(tx, filters, page, order) + + // Acquire Results var foundTags []*model.Tag - var count int64 - err := dbm.db.Find(&foundTags).Count(&count).Error - return foundTags, count, err + err := tx.Find(&foundTags).Error + return foundTags, pageResponse, err } func (dbm *DBManager) DeleteTag(tag *model.Tag) error { diff --git a/internal/db/users.go b/internal/db/users.go index e69fa6b..31ffdbd 100644 --- a/internal/db/users.go +++ b/internal/db/users.go @@ -3,6 +3,7 @@ package db import ( log "github.com/sirupsen/logrus" "golang.org/x/crypto/bcrypt" + "gorm.io/gorm" "reichard.io/imagini/graph/model" ) @@ -25,11 +26,17 @@ func (dbm *DBManager) User(user *model.User) (int64, error) { return count, err } -func (dbm *DBManager) Users() ([]*model.User, int64, error) { +func (dbm *DBManager) Users(filters *model.UserFilter, page *model.Page, order *model.Order) ([]*model.User, model.PageResponse, error) { + // Initial User Filter + tx := dbm.db.Session(&gorm.Session{}).Model(&model.Tag{}) + + // Dynamically Generate Base Query + tx, pageResponse := dbm.generateBaseQuery(tx, filters, page, order) + + // Acquire Results var foundUsers []*model.User - var count int64 - err := dbm.db.Find(&foundUsers).Count(&count).Error - return foundUsers, count, err + err := tx.Find(&foundUsers).Error + return foundUsers, pageResponse, err } func (dbm *DBManager) DeleteUser(user model.User) error {