Enable GraphQL! #1

Merged
evan merged 8 commits from graphql into master 2021-02-09 00:44:20 +00:00
7 changed files with 538 additions and 165 deletions
Showing only changes of commit 5fede6d6da - Show all commits

View File

@ -115,19 +115,19 @@ type ComplexityRoot struct {
}
Query struct {
Album func(childComplexity int, id string) int
Albums func(childComplexity int, filter *model.AlbumFilter, count *int, page *int) int
Device func(childComplexity int, id string) int
Devices func(childComplexity int, filter *model.DeviceFilter, count *int, page *int) int
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
Login func(childComplexity int, user string, password string, deviceID *string) int
Logout func(childComplexity int) int
Me func(childComplexity int) int
MediaItem func(childComplexity int, id string) int
MediaItems func(childComplexity int, filter *model.MediaItemFilter, count *int, page *int) int
Tag func(childComplexity int, id string) int
Tags func(childComplexity int, filter *model.TagFilter, count *int, page *int) int
User func(childComplexity int, id string) int
Users func(childComplexity int, filter *model.UserFilter, count *int, page *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
}
Tag struct {
@ -172,17 +172,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) (*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, count *int, page *int) (*model.MediaItemResponse, error)
Devices(ctx context.Context, filter *model.DeviceFilter, count *int, page *int) (*model.DeviceResponse, error)
Albums(ctx context.Context, filter *model.AlbumFilter, count *int, page *int) (*model.AlbumResponse, error)
Tags(ctx context.Context, filter *model.TagFilter, count *int, page *int) (*model.TagResponse, error)
Users(ctx context.Context, filter *model.UserFilter, count *int, page *int) (*model.UserResponse, 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)
}
type executableSchema struct {
@ -503,7 +503,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.Album(childComplexity, args["id"].(string)), true
return e.complexity.Query.Album(childComplexity, args["id"].(string), args["delete"].(*bool)), true
case "Query.albums":
if e.complexity.Query.Albums == nil {
@ -515,7 +515,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.Albums(childComplexity, args["filter"].(*model.AlbumFilter), args["count"].(*int), args["page"].(*int)), true
return e.complexity.Query.Albums(childComplexity, args["delete"].(*bool), args["filter"].(*model.AlbumFilter), args["count"].(*int), args["page"].(*int)), true
case "Query.device":
if e.complexity.Query.Device == nil {
@ -527,7 +527,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.Device(childComplexity, args["id"].(string)), true
return e.complexity.Query.Device(childComplexity, args["id"].(string), args["delete"].(*bool)), true
case "Query.devices":
if e.complexity.Query.Devices == nil {
@ -539,7 +539,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.Devices(childComplexity, args["filter"].(*model.DeviceFilter), args["count"].(*int), args["page"].(*int)), true
return e.complexity.Query.Devices(childComplexity, args["delete"].(*bool), args["filter"].(*model.DeviceFilter), args["count"].(*int), args["page"].(*int)), true
case "Query.login":
if e.complexity.Query.Login == nil {
@ -565,7 +565,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
break
}
return e.complexity.Query.Me(childComplexity), true
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
case "Query.mediaItem":
if e.complexity.Query.MediaItem == nil {
@ -577,7 +582,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.MediaItem(childComplexity, args["id"].(string)), true
return e.complexity.Query.MediaItem(childComplexity, args["id"].(string), args["delete"].(*bool)), true
case "Query.mediaItems":
if e.complexity.Query.MediaItems == nil {
@ -589,7 +594,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.MediaItems(childComplexity, args["filter"].(*model.MediaItemFilter), args["count"].(*int), args["page"].(*int)), true
return e.complexity.Query.MediaItems(childComplexity, args["delete"].(*bool), args["filter"].(*model.MediaItemFilter), args["count"].(*int), args["page"].(*int)), true
case "Query.tag":
if e.complexity.Query.Tag == nil {
@ -601,7 +606,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.Tag(childComplexity, args["id"].(string)), true
return e.complexity.Query.Tag(childComplexity, args["id"].(string), args["delete"].(*bool)), true
case "Query.tags":
if e.complexity.Query.Tags == nil {
@ -613,7 +618,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.Tags(childComplexity, args["filter"].(*model.TagFilter), args["count"].(*int), args["page"].(*int)), true
return e.complexity.Query.Tags(childComplexity, args["delete"].(*bool), args["filter"].(*model.TagFilter), args["count"].(*int), args["page"].(*int)), true
case "Query.user":
if e.complexity.Query.User == nil {
@ -625,7 +630,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.User(childComplexity, args["id"].(string)), true
return e.complexity.Query.User(childComplexity, args["id"].(string), args["delete"].(*bool)), true
case "Query.users":
if e.complexity.Query.Users == nil {
@ -637,7 +642,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.Query.Users(childComplexity, args["filter"].(*model.UserFilter), args["count"].(*int), args["page"].(*int)), true
return e.complexity.Query.Users(childComplexity, args["delete"].(*bool), args["filter"].(*model.UserFilter), args["count"].(*int), args["page"].(*int)), true
case "Tag.createdAt":
if e.complexity.Tag.CreatedAt == nil {
@ -1036,6 +1041,7 @@ type Album {
createdAt: Time
updatedAt: Time
name: String! @meta(gorm: "unique;not null")
# userID: ID! @meta(gorm: "not null")
}
# ------------------------------------------------------------
@ -1171,7 +1177,6 @@ type AlbumResponse {
# ------------------------------------------------------------
type Query {
# Authentication
login(
user: String!
@ -1181,39 +1186,59 @@ type Query {
logout: AuthResponse! @hasMinRole(role: User)
# Single Item
mediaItem(id: ID!): MediaItem! @hasMinRole(role: User)
device(id: ID!): Device! @hasMinRole(role: User)
album(id: ID!): Album! @hasMinRole(role: User)
user(id: ID!): User! @hasMinRole(role: Admin)
tag(id: ID!): Tag! @hasMinRole(role: User)
me: User! @hasMinRole(role: User)
mediaItem(
id: ID!
delete: Boolean
): MediaItem! @hasMinRole(role: User)
device(
id: ID!
delete: Boolean
): Device! @hasMinRole(role: User)
album(
id: ID!
delete: Boolean
): Album! @hasMinRole(role: User)
user(
id: ID!
delete: Boolean
): User! @hasMinRole(role: Admin) # TODO: Delete All User Content
tag(
id: ID!
delete: Boolean
): Tag! @hasMinRole(role: User)
me(delete: Boolean): User! @hasMinRole(role: User)
# All
mediaItems(
delete: Boolean
filter: MediaItemFilter
count: Int
page: Int
): MediaItemResponse! @hasMinRole(role: User)
devices(
delete: Boolean
filter: DeviceFilter
count: Int
page: Int
): DeviceResponse! @hasMinRole(role: User)
albums(
delete: Boolean
filter: AlbumFilter
count: Int
page: Int
): AlbumResponse! @hasMinRole(role: User)
tags(
delete: Boolean
filter: TagFilter
count: Int
page: Int
): TagResponse! @hasMinRole(role: User)
users(
delete: Boolean
filter: UserFilter
count: Int
page: Int
): UserResponse! @hasMinRole(role: Admin)
): UserResponse! @hasMinRole(role: Admin) # TODO: Delete All User Content
}
type Mutation {
@ -1347,39 +1372,57 @@ 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 *model.AlbumFilter
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
if tmp, ok := rawArgs["filter"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter"))
arg0, err = ec.unmarshalOAlbumFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAlbumFilter(ctx, tmp)
arg1, err = ec.unmarshalOAlbumFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAlbumFilter(ctx, tmp)
if err != nil {
return nil, err
}
}
args["filter"] = arg0
var arg1 *int
args["filter"] = arg1
var arg2 *int
if tmp, ok := rawArgs["count"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count"))
arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["count"] = arg1
var arg2 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg2
args["count"] = arg2
var arg3 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg3
return args, nil
}
@ -1395,39 +1438,57 @@ 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 *model.DeviceFilter
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
if tmp, ok := rawArgs["filter"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter"))
arg0, err = ec.unmarshalODeviceFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceFilter(ctx, tmp)
arg1, err = ec.unmarshalODeviceFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceFilter(ctx, tmp)
if err != nil {
return nil, err
}
}
args["filter"] = arg0
var arg1 *int
args["filter"] = arg1
var arg2 *int
if tmp, ok := rawArgs["count"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count"))
arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["count"] = arg1
var arg2 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg2
args["count"] = arg2
var arg3 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg3
return args, nil
}
@ -1464,6 +1525,21 @@ 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{}{}
@ -1476,39 +1552,57 @@ 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 *model.MediaItemFilter
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
if tmp, ok := rawArgs["filter"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter"))
arg0, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, tmp)
arg1, err = ec.unmarshalOMediaItemFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐMediaItemFilter(ctx, tmp)
if err != nil {
return nil, err
}
}
args["filter"] = arg0
var arg1 *int
args["filter"] = arg1
var arg2 *int
if tmp, ok := rawArgs["count"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count"))
arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["count"] = arg1
var arg2 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg2
args["count"] = arg2
var arg3 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg3
return args, nil
}
@ -1524,39 +1618,57 @@ 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 *model.TagFilter
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
if tmp, ok := rawArgs["filter"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter"))
arg0, err = ec.unmarshalOTagFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐTagFilter(ctx, tmp)
arg1, err = ec.unmarshalOTagFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐTagFilter(ctx, tmp)
if err != nil {
return nil, err
}
}
args["filter"] = arg0
var arg1 *int
args["filter"] = arg1
var arg2 *int
if tmp, ok := rawArgs["count"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count"))
arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["count"] = arg1
var arg2 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg2
args["count"] = arg2
var arg3 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg3
return args, nil
}
@ -1572,39 +1684,57 @@ 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 *model.UserFilter
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
if tmp, ok := rawArgs["filter"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter"))
arg0, err = ec.unmarshalOUserFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUserFilter(ctx, tmp)
arg1, err = ec.unmarshalOUserFilter2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUserFilter(ctx, tmp)
if err != nil {
return nil, err
}
}
args["filter"] = arg0
var arg1 *int
args["filter"] = arg1
var arg2 *int
if tmp, ok := rawArgs["count"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("count"))
arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["count"] = arg1
var arg2 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg2
args["count"] = arg2
var arg3 *int
if tmp, ok := rawArgs["page"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page"))
arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["page"] = arg3
return args, nil
}
@ -3543,7 +3673,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))
return ec.resolvers.Query().MediaItem(rctx, args["id"].(string), args["delete"].(*bool))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User")
@ -3609,7 +3739,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))
return ec.resolvers.Query().Device(rctx, args["id"].(string), args["delete"].(*bool))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User")
@ -3675,7 +3805,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))
return ec.resolvers.Query().Album(rctx, args["id"].(string), args["delete"].(*bool))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User")
@ -3741,7 +3871,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))
return ec.resolvers.Query().User(rctx, args["id"].(string), args["delete"].(*bool))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "Admin")
@ -3807,7 +3937,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))
return ec.resolvers.Query().Tag(rctx, args["id"].(string), args["delete"].(*bool))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User")
@ -3863,10 +3993,17 @@ 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)
return ec.resolvers.Query().Me(rctx, args["delete"].(*bool))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User")
@ -3932,7 +4069,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["filter"].(*model.MediaItemFilter), args["count"].(*int), args["page"].(*int))
return ec.resolvers.Query().MediaItems(rctx, args["delete"].(*bool), args["filter"].(*model.MediaItemFilter), args["count"].(*int), args["page"].(*int))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User")
@ -3998,7 +4135,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["filter"].(*model.DeviceFilter), args["count"].(*int), args["page"].(*int))
return ec.resolvers.Query().Devices(rctx, args["delete"].(*bool), args["filter"].(*model.DeviceFilter), args["count"].(*int), args["page"].(*int))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User")
@ -4064,7 +4201,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["filter"].(*model.AlbumFilter), args["count"].(*int), args["page"].(*int))
return ec.resolvers.Query().Albums(rctx, args["delete"].(*bool), args["filter"].(*model.AlbumFilter), args["count"].(*int), args["page"].(*int))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User")
@ -4130,7 +4267,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["filter"].(*model.TagFilter), args["count"].(*int), args["page"].(*int))
return ec.resolvers.Query().Tags(rctx, args["delete"].(*bool), args["filter"].(*model.TagFilter), args["count"].(*int), args["page"].(*int))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "User")
@ -4196,7 +4333,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["filter"].(*model.UserFilter), args["count"].(*int), args["page"].(*int))
return ec.resolvers.Query().Users(rctx, args["delete"].(*bool), args["filter"].(*model.UserFilter), args["count"].(*int), args["page"].(*int))
}
directive1 := func(ctx context.Context) (interface{}, error) {
role, err := ec.unmarshalNRole2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐRole(ctx, "Admin")

View File

@ -191,6 +191,7 @@ type Album {
createdAt: Time
updatedAt: Time
name: String! @meta(gorm: "unique;not null")
# userID: ID! @meta(gorm: "not null")
}
# ------------------------------------------------------------
@ -326,7 +327,6 @@ type AlbumResponse {
# ------------------------------------------------------------
type Query {
# Authentication
login(
user: String!
@ -336,39 +336,59 @@ type Query {
logout: AuthResponse! @hasMinRole(role: User)
# Single Item
mediaItem(id: ID!): MediaItem! @hasMinRole(role: User)
device(id: ID!): Device! @hasMinRole(role: User)
album(id: ID!): Album! @hasMinRole(role: User)
user(id: ID!): User! @hasMinRole(role: Admin)
tag(id: ID!): Tag! @hasMinRole(role: User)
me: User! @hasMinRole(role: User)
mediaItem(
id: ID!
delete: Boolean
): MediaItem! @hasMinRole(role: User)
device(
id: ID!
delete: Boolean
): Device! @hasMinRole(role: User)
album(
id: ID!
delete: Boolean
): Album! @hasMinRole(role: User)
user(
id: ID!
delete: Boolean
): User! @hasMinRole(role: Admin) # TODO: Delete All User Content
tag(
id: ID!
delete: Boolean
): Tag! @hasMinRole(role: User)
me(delete: Boolean): User! @hasMinRole(role: User)
# All
mediaItems(
delete: Boolean
filter: MediaItemFilter
count: Int
page: Int
): MediaItemResponse! @hasMinRole(role: User)
devices(
delete: Boolean
filter: DeviceFilter
count: Int
page: Int
): DeviceResponse! @hasMinRole(role: User)
albums(
delete: Boolean
filter: AlbumFilter
count: Int
page: Int
): AlbumResponse! @hasMinRole(role: User)
tags(
delete: Boolean
filter: TagFilter
count: Int
page: Int
): TagResponse! @hasMinRole(role: User)
users(
delete: Boolean
filter: UserFilter
count: Int
page: Int
): UserResponse! @hasMinRole(role: Admin)
): UserResponse! @hasMinRole(role: Admin) # TODO: Delete All User Content
}
type Mutation {

View File

@ -7,7 +7,6 @@ import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
"os"
@ -21,7 +20,6 @@ import (
"reichard.io/imagini/graph/model"
)
// Done
func (r *mutationResolver) CreateMediaItem(ctx context.Context, input model.NewMediaItem) (*model.MediaItem, error) {
// Get Context
authContext := ctx.Value("auth").(*model.AuthContext)
@ -101,11 +99,37 @@ func (r *mutationResolver) CreateMediaItem(ctx context.Context, input model.NewM
}
func (r *mutationResolver) CreateAlbum(ctx context.Context, input model.NewAlbum) (*model.Album, error) {
panic(fmt.Errorf("not implemented"))
// Get Context
authContext := ctx.Value("auth").(*model.AuthContext)
accessToken := *authContext.AccessToken
_, ok := accessToken.Get("sub")
if !ok {
return nil, errors.New("Upload Failed")
}
album := &model.Album{
Name: input.Name,
}
err := r.DB.CreateAlbum(album)
if err != nil {
return nil, err
}
return album, nil
}
func (r *mutationResolver) CreateTag(ctx context.Context, input model.NewTag) (*model.Tag, error) {
panic(fmt.Errorf("not implemented"))
tag := &model.Tag{
Name: input.Name,
}
err := r.DB.CreateTag(tag)
if err != nil {
return nil, err
}
return tag, nil
}
func (r *mutationResolver) CreateUser(ctx context.Context, input model.NewUser) (*model.User, error) {
@ -198,50 +222,172 @@ 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) (*model.MediaItem, error) {
panic(fmt.Errorf("not implemented"))
func (r *queryResolver) MediaItem(ctx context.Context, id string, delete *bool) (*model.MediaItem, error) {
// TODO: User Specific
deviceID, err := uuid.Parse(id)
if err != nil {
return nil, errors.New("Invalid ID Format")
}
foundMediaItem := &model.MediaItem{ID: deviceID.String()}
count, err := r.DB.MediaItem(foundMediaItem)
if err != nil {
return nil, errors.New("DB Error")
} else if count != 1 {
return nil, errors.New("MediaItem Not Found")
}
return foundMediaItem, nil
}
func (r *queryResolver) Device(ctx context.Context, id string) (*model.Device, error) {
panic(fmt.Errorf("not implemented"))
func (r *queryResolver) Device(ctx context.Context, id string, delete *bool) (*model.Device, error) {
// TODO: User Specific
deviceID, err := uuid.Parse(id)
if err != nil {
return nil, errors.New("Invalid ID Format")
}
foundDevice := &model.Device{ID: deviceID.String()}
count, err := r.DB.Device(foundDevice)
if err != nil {
return nil, errors.New("DB Error")
} else if count != 1 {
return nil, errors.New("Device Not Found")
}
return foundDevice, nil
}
func (r *queryResolver) Album(ctx context.Context, id string) (*model.Album, error) {
panic(fmt.Errorf("not implemented"))
func (r *queryResolver) Album(ctx context.Context, id string, delete *bool) (*model.Album, error) {
// TODO: User Specific
albumID, err := uuid.Parse(id)
if err != nil {
return nil, errors.New("Invalid ID Format")
}
foundAlbum := &model.Album{ID: albumID.String()}
count, err := r.DB.Album(foundAlbum)
if err != nil {
return nil, errors.New("DB Error")
} else if count != 1 {
return nil, errors.New("Album Not Found")
}
return foundAlbum, nil
}
func (r *queryResolver) User(ctx context.Context, id string) (*model.User, error) {
panic(fmt.Errorf("not implemented"))
func (r *queryResolver) User(ctx context.Context, id string, delete *bool) (*model.User, error) {
userID, err := uuid.Parse(id)
if err != nil {
return nil, errors.New("Invalid ID Format")
}
foundUser := &model.User{ID: userID.String()}
count, err := r.DB.User(foundUser)
if err != nil {
return nil, errors.New("DB Error")
} else if count != 1 {
return nil, errors.New("User Not Found")
}
return foundUser, nil
}
func (r *queryResolver) Tag(ctx context.Context, id string) (*model.Tag, error) {
panic(fmt.Errorf("not implemented"))
func (r *queryResolver) Tag(ctx context.Context, id string, delete *bool) (*model.Tag, error) {
tagID, err := uuid.Parse(id)
if err != nil {
return nil, errors.New("Invalid ID Format")
}
foundTag := &model.Tag{ID: tagID.String()}
count, err := r.DB.Tag(foundTag)
if err != nil {
return nil, errors.New("DB Error")
} else if count != 1 {
return nil, errors.New("Tag Not Found")
}
return foundTag, nil
}
func (r *queryResolver) Me(ctx context.Context) (*model.User, error) {
panic(fmt.Errorf("not implemented"))
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")
}
foundUser := &model.User{ID: userID.(string)}
count, err := r.DB.User(foundUser)
if err != nil || count != 1 {
return nil, errors.New("DB Error")
}
return foundUser, nil
}
func (r *queryResolver) MediaItems(ctx context.Context, filter *model.MediaItemFilter, count *int, page *int) (*model.MediaItemResponse, error) {
panic(fmt.Errorf("not implemented"))
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()
if err != nil {
return nil, errors.New("Context Error")
}
return &model.MediaItemResponse{
Data: resp,
PageInfo: &model.PageInfo{
Count: int(totalCount),
Page: 0,
Total: int(totalCount),
},
}, nil
}
func (r *queryResolver) Devices(ctx context.Context, filter *model.DeviceFilter, count *int, page *int) (*model.DeviceResponse, error) {
panic(fmt.Errorf("not implemented"))
func (r *queryResolver) Devices(ctx context.Context, delete *bool, filter *model.DeviceFilter, count *int, page *int) (*model.DeviceResponse, error) {
// TODO: User Specific
resp, totalCount, err := r.DB.Devices()
if err != nil {
return nil, errors.New("Context Error")
}
return &model.DeviceResponse{
Data: resp,
PageInfo: &model.PageInfo{
Count: int(totalCount),
Page: 0,
Total: int(totalCount),
},
}, nil
}
func (r *queryResolver) Albums(ctx context.Context, filter *model.AlbumFilter, count *int, page *int) (*model.AlbumResponse, error) {
panic(fmt.Errorf("not implemented"))
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()
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),
},
}, nil
}
func (r *queryResolver) Tags(ctx context.Context, filter *model.TagFilter, count *int, page *int) (*model.TagResponse, error) {
panic(fmt.Errorf("not implemented"))
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()
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),
},
}, nil
}
func (r *queryResolver) Users(ctx context.Context, filter *model.UserFilter, count *int, page *int) (*model.UserResponse, error) {
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()
if err != nil {
panic(fmt.Errorf("DB Error"))
return nil, errors.New("Context Error")
}
return &model.UserResponse{
Data: resp,

View File

@ -1 +1,30 @@
package db
import (
log "github.com/sirupsen/logrus"
"reichard.io/imagini/graph/model"
)
func (dbm *DBManager) CreateAlbum(album *model.Album) error {
log.Debug("[db] Creating album: ", album.Name)
err := dbm.db.Create(album).Error
return err
}
func (dbm *DBManager) Album(album *model.Album) (int64, error) {
var count int64
err := dbm.db.Where(album).First(album).Count(&count).Error
return count, err
}
func (dbm *DBManager) Albums() ([]*model.Album, int64, error) {
var foundAlbums []*model.Album
var count int64
err := dbm.db.Find(&foundAlbums).Count(&count).Error
return foundAlbums, count, err
}
func (dbm *DBManager) DeleteAlbum(album *model.Album) error {
return nil
}

View File

@ -21,6 +21,13 @@ func (dbm *DBManager) Device(device *model.Device) (int64, error) {
return count, err
}
func (dbm *DBManager) Devices() ([]*model.Device, int64, error) {
var foundDevices []*model.Device
var count int64
err := dbm.db.Find(&foundDevices).Count(&count).Error
return foundDevices, count, err
}
func (dbm *DBManager) DeleteDevice(user *model.Device) error {
return nil
}

View File

@ -12,10 +12,15 @@ func (dbm *DBManager) CreateMediaItem(mediaItem *model.MediaItem) error {
return err
}
func (dbm *DBManager) MediaItems(mediaItemFilter *model.MediaItem) ([]model.MediaItem, int64, error) {
var mediaItems []model.MediaItem
func (dbm *DBManager) MediaItem(mediaItem *model.MediaItem) (int64, error) {
var count int64
err := dbm.db.Where(mediaItem).First(mediaItem).Count(&count).Error
return count, err
}
err := dbm.db.Where(mediaItemFilter).Find(&mediaItems).Count(&count).Error
func (dbm *DBManager) MediaItems() ([]*model.MediaItem, int64, error) {
var mediaItems []*model.MediaItem
var count int64
err := dbm.db.Find(&mediaItems).Count(&count).Error
return mediaItems, count, err
}

View File

@ -1 +1,30 @@
package db
import (
log "github.com/sirupsen/logrus"
"reichard.io/imagini/graph/model"
)
func (dbm *DBManager) CreateTag(tag *model.Tag) error {
log.Debug("[db] Creating tag: ", tag.Name)
err := dbm.db.Create(tag).Error
return err
}
func (dbm *DBManager) Tag(tag *model.Tag) (int64, error) {
var count int64
err := dbm.db.Where(tag).First(tag).Count(&count).Error
return count, err
}
func (dbm *DBManager) Tags() ([]*model.Tag, int64, error) {
var foundTags []*model.Tag
var count int64
err := dbm.db.Find(&foundTags).Count(&count).Error
return foundTags, count, err
}
func (dbm *DBManager) DeleteTag(tag *model.Tag) error {
return nil
}