Wooo API!
This commit is contained in:
@@ -60,6 +60,7 @@ type ComplexityRoot struct {
|
||||
}
|
||||
|
||||
AuthResponse struct {
|
||||
Device func(childComplexity int) int
|
||||
Error func(childComplexity int) int
|
||||
Result func(childComplexity int) int
|
||||
}
|
||||
@@ -72,6 +73,7 @@ type ComplexityRoot struct {
|
||||
Type func(childComplexity int) int
|
||||
UpdatedAt func(childComplexity int) int
|
||||
User func(childComplexity int) int
|
||||
UserID func(childComplexity int) int
|
||||
}
|
||||
|
||||
DeviceResponse struct {
|
||||
@@ -92,6 +94,7 @@ type ComplexityRoot struct {
|
||||
Tags func(childComplexity int) int
|
||||
UpdatedAt func(childComplexity int) int
|
||||
User func(childComplexity int) int
|
||||
UserID func(childComplexity int) int
|
||||
}
|
||||
|
||||
MediaItemResponse struct {
|
||||
@@ -118,7 +121,7 @@ type ComplexityRoot struct {
|
||||
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
|
||||
Login func(childComplexity int, user string, password string) 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
|
||||
@@ -168,8 +171,8 @@ type MutationResolver interface {
|
||||
CreateUser(ctx context.Context, input model.NewUser) (*model.User, error)
|
||||
}
|
||||
type QueryResolver interface {
|
||||
Login(ctx context.Context, user string, password string) (model.AuthResult, error)
|
||||
Logout(ctx context.Context) (model.AuthResult, error)
|
||||
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)
|
||||
@@ -240,6 +243,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.AlbumResponse.PageInfo(childComplexity), true
|
||||
|
||||
case "AuthResponse.Device":
|
||||
if e.complexity.AuthResponse.Device == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.AuthResponse.Device(childComplexity), true
|
||||
|
||||
case "AuthResponse.Error":
|
||||
if e.complexity.AuthResponse.Error == nil {
|
||||
break
|
||||
@@ -303,6 +313,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.Device.User(childComplexity), true
|
||||
|
||||
case "Device.userID":
|
||||
if e.complexity.Device.UserID == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.Device.UserID(childComplexity), true
|
||||
|
||||
case "DeviceResponse.data":
|
||||
if e.complexity.DeviceResponse.Data == nil {
|
||||
break
|
||||
@@ -401,6 +418,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.MediaItem.User(childComplexity), true
|
||||
|
||||
case "MediaItem.userID":
|
||||
if e.complexity.MediaItem.UserID == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.MediaItem.UserID(childComplexity), true
|
||||
|
||||
case "MediaItemResponse.data":
|
||||
if e.complexity.MediaItemResponse.Data == nil {
|
||||
break
|
||||
@@ -554,7 +578,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Query.Login(childComplexity, args["user"].(string), args["password"].(string)), true
|
||||
return e.complexity.Query.Login(childComplexity, args["user"].(string), args["password"].(string), args["deviceID"].(*string)), true
|
||||
|
||||
case "Query.logout":
|
||||
if e.complexity.Query.Logout == nil {
|
||||
@@ -876,6 +900,7 @@ enum AuthResult {
|
||||
|
||||
type AuthResponse {
|
||||
Result: AuthResult!
|
||||
Device: Device
|
||||
Error: String
|
||||
}
|
||||
|
||||
@@ -972,17 +997,18 @@ input AuthTypeFilter {
|
||||
# ------------------------------------------------------------
|
||||
|
||||
type Device {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
name: String! @meta(gorm: "not null")
|
||||
type: DeviceType! @meta(gorm: "default:Unknown;not null")
|
||||
user: User @meta(gorm: "ForeignKey:ID;not null")
|
||||
userID: ID! @meta(gorm: "not null")
|
||||
user: User! @meta(gorm: "foreignKey:ID;references:UserID;not null")
|
||||
refreshKey: String
|
||||
}
|
||||
|
||||
type User {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
email: String! @meta(gorm: "not null;unique")
|
||||
@@ -995,7 +1021,7 @@ type User {
|
||||
}
|
||||
|
||||
type MediaItem {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
exifDate: Time
|
||||
@@ -1006,18 +1032,19 @@ type MediaItem {
|
||||
origName: String! @meta(gorm: "not null")
|
||||
tags: [Tag] @meta(gorm: "many2many:media_tags")
|
||||
albums: [Album] @meta(gorm: "many2many:media_albums")
|
||||
user: User @meta(gorm: "ForeignKey:ID;not null")
|
||||
userID: ID! @meta(gorm: "not null")
|
||||
user: User! @meta(gorm: "foreignKey:ID;references:UserID;not null")
|
||||
}
|
||||
|
||||
type Tag {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
name: String! @meta(gorm: "unique;not null")
|
||||
}
|
||||
|
||||
type Album {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
name: String! @meta(gorm: "unique;not null")
|
||||
@@ -1165,8 +1192,9 @@ type Query {
|
||||
login(
|
||||
user: String!
|
||||
password: String!
|
||||
): AuthResult!
|
||||
logout: AuthResult! @hasMinRole(role: User)
|
||||
deviceID: ID
|
||||
): AuthResponse!
|
||||
logout: AuthResponse! @hasMinRole(role: User)
|
||||
|
||||
# Single Item
|
||||
mediaItem(id: ID!): MediaItem! @hasMinRole(role: User)
|
||||
@@ -1456,6 +1484,15 @@ func (ec *executionContext) field_Query_login_args(ctx context.Context, rawArgs
|
||||
}
|
||||
}
|
||||
args["password"] = arg1
|
||||
var arg2 *string
|
||||
if tmp, ok := rawArgs["deviceID"]; ok {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("deviceID"))
|
||||
arg2, err = ec.unmarshalOID2ᚖstring(ctx, tmp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
args["deviceID"] = arg2
|
||||
return args, nil
|
||||
}
|
||||
|
||||
@@ -1663,7 +1700,7 @@ func (ec *executionContext) _Album_id(ctx context.Context, field graphql.Collect
|
||||
return obj.ID, nil
|
||||
}
|
||||
directive1 := func(ctx context.Context) (interface{}, error) {
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primarykey;not null")
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primaryKey;not null")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1680,21 +1717,24 @@ func (ec *executionContext) _Album_id(ctx context.Context, field graphql.Collect
|
||||
if tmp == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if data, ok := tmp.(*string); ok {
|
||||
if data, ok := tmp.(string); ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp)
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*string)
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalOID2ᚖstring(ctx, field.Selections, res)
|
||||
return ec.marshalNID2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Album_createdAt(ctx context.Context, field graphql.CollectedField, obj *model.Album) (ret graphql.Marshaler) {
|
||||
@@ -1922,6 +1962,38 @@ func (ec *executionContext) _AuthResponse_Result(ctx context.Context, field grap
|
||||
return ec.marshalNAuthResult2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthResult(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _AuthResponse_Device(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "AuthResponse",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
}
|
||||
|
||||
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.Device, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*model.Device)
|
||||
fc.Result = res
|
||||
return ec.marshalODevice2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDevice(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _AuthResponse_Error(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -1976,7 +2048,7 @@ func (ec *executionContext) _Device_id(ctx context.Context, field graphql.Collec
|
||||
return obj.ID, nil
|
||||
}
|
||||
directive1 := func(ctx context.Context) (interface{}, error) {
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primarykey;not null")
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primaryKey;not null")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1993,21 +2065,24 @@ func (ec *executionContext) _Device_id(ctx context.Context, field graphql.Collec
|
||||
if tmp == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if data, ok := tmp.(*string); ok {
|
||||
if data, ok := tmp.(string); ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp)
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*string)
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalOID2ᚖstring(ctx, field.Selections, res)
|
||||
return ec.marshalNID2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Device_createdAt(ctx context.Context, field graphql.CollectedField, obj *model.Device) (ret graphql.Marshaler) {
|
||||
@@ -2192,6 +2267,65 @@ func (ec *executionContext) _Device_type(ctx context.Context, field graphql.Coll
|
||||
return ec.marshalNDeviceType2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐDeviceType(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Device_userID(ctx context.Context, field graphql.CollectedField, obj *model.Device) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "Device",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
directive0 := func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.UserID, nil
|
||||
}
|
||||
directive1 := func(ctx context.Context) (interface{}, error) {
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "not null")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ec.directives.Meta == nil {
|
||||
return nil, errors.New("directive meta is not implemented")
|
||||
}
|
||||
return ec.directives.Meta(ctx, obj, directive0, gorm)
|
||||
}
|
||||
|
||||
tmp, err := directive1(rctx)
|
||||
if err != nil {
|
||||
return nil, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
if tmp == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if data, ok := tmp.(string); ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNID2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Device_user(ctx context.Context, field graphql.CollectedField, obj *model.Device) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -2214,7 +2348,7 @@ func (ec *executionContext) _Device_user(ctx context.Context, field graphql.Coll
|
||||
return obj.User, nil
|
||||
}
|
||||
directive1 := func(ctx context.Context) (interface{}, error) {
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "ForeignKey:ID;not null")
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "foreignKey:ID;references:UserID;not null")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2241,11 +2375,14 @@ func (ec *executionContext) _Device_user(ctx context.Context, field graphql.Coll
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*model.User)
|
||||
fc.Result = res
|
||||
return ec.marshalOUser2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUser(ctx, field.Selections, res)
|
||||
return ec.marshalNUser2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUser(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Device_refreshKey(ctx context.Context, field graphql.CollectedField, obj *model.Device) (ret graphql.Marshaler) {
|
||||
@@ -2369,7 +2506,7 @@ func (ec *executionContext) _MediaItem_id(ctx context.Context, field graphql.Col
|
||||
return obj.ID, nil
|
||||
}
|
||||
directive1 := func(ctx context.Context) (interface{}, error) {
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primarykey;not null")
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primaryKey;not null")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2386,21 +2523,24 @@ func (ec *executionContext) _MediaItem_id(ctx context.Context, field graphql.Col
|
||||
if tmp == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if data, ok := tmp.(*string); ok {
|
||||
if data, ok := tmp.(string); ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp)
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*string)
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalOID2ᚖstring(ctx, field.Selections, res)
|
||||
return ec.marshalNID2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _MediaItem_createdAt(ctx context.Context, field graphql.CollectedField, obj *model.MediaItem) (ret graphql.Marshaler) {
|
||||
@@ -2852,6 +2992,65 @@ func (ec *executionContext) _MediaItem_albums(ctx context.Context, field graphql
|
||||
return ec.marshalOAlbum2ᚕᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAlbum(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _MediaItem_userID(ctx context.Context, field graphql.CollectedField, obj *model.MediaItem) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "MediaItem",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
directive0 := func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.UserID, nil
|
||||
}
|
||||
directive1 := func(ctx context.Context) (interface{}, error) {
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "not null")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ec.directives.Meta == nil {
|
||||
return nil, errors.New("directive meta is not implemented")
|
||||
}
|
||||
return ec.directives.Meta(ctx, obj, directive0, gorm)
|
||||
}
|
||||
|
||||
tmp, err := directive1(rctx)
|
||||
if err != nil {
|
||||
return nil, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
if tmp == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if data, ok := tmp.(string); ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNID2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _MediaItem_user(ctx context.Context, field graphql.CollectedField, obj *model.MediaItem) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -2874,7 +3073,7 @@ func (ec *executionContext) _MediaItem_user(ctx context.Context, field graphql.C
|
||||
return obj.User, nil
|
||||
}
|
||||
directive1 := func(ctx context.Context) (interface{}, error) {
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "ForeignKey:ID;not null")
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "foreignKey:ID;references:UserID;not null")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2901,11 +3100,14 @@ func (ec *executionContext) _MediaItem_user(ctx context.Context, field graphql.C
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*model.User)
|
||||
fc.Result = res
|
||||
return ec.marshalOUser2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUser(ctx, field.Selections, res)
|
||||
return ec.marshalNUser2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐUser(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _MediaItemResponse_data(ctx context.Context, field graphql.CollectedField, obj *model.MediaItemResponse) (ret graphql.Marshaler) {
|
||||
@@ -3435,7 +3637,7 @@ func (ec *executionContext) _Query_login(ctx context.Context, field graphql.Coll
|
||||
fc.Args = args
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Query().Login(rctx, args["user"].(string), args["password"].(string))
|
||||
return ec.resolvers.Query().Login(rctx, args["user"].(string), args["password"].(string), args["deviceID"].(*string))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
@@ -3447,9 +3649,9 @@ func (ec *executionContext) _Query_login(ctx context.Context, field graphql.Coll
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(model.AuthResult)
|
||||
res := resTmp.(*model.AuthResponse)
|
||||
fc.Result = res
|
||||
return ec.marshalNAuthResult2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthResult(ctx, field.Selections, res)
|
||||
return ec.marshalNAuthResponse2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthResponse(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Query_logout(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
@@ -3491,10 +3693,10 @@ func (ec *executionContext) _Query_logout(ctx context.Context, field graphql.Col
|
||||
if tmp == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if data, ok := tmp.(model.AuthResult); ok {
|
||||
if data, ok := tmp.(*model.AuthResponse); ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be reichard.io/imagini/graph/model.AuthResult`, tmp)
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be *reichard.io/imagini/graph/model.AuthResponse`, tmp)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
@@ -3506,9 +3708,9 @@ func (ec *executionContext) _Query_logout(ctx context.Context, field graphql.Col
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(model.AuthResult)
|
||||
res := resTmp.(*model.AuthResponse)
|
||||
fc.Result = res
|
||||
return ec.marshalNAuthResult2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthResult(ctx, field.Selections, res)
|
||||
return ec.marshalNAuthResponse2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthResponse(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Query_mediaItem(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
@@ -4323,7 +4525,7 @@ func (ec *executionContext) _Tag_id(ctx context.Context, field graphql.Collected
|
||||
return obj.ID, nil
|
||||
}
|
||||
directive1 := func(ctx context.Context) (interface{}, error) {
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primarykey;not null")
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primaryKey;not null")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -4340,21 +4542,24 @@ func (ec *executionContext) _Tag_id(ctx context.Context, field graphql.Collected
|
||||
if tmp == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if data, ok := tmp.(*string); ok {
|
||||
if data, ok := tmp.(string); ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp)
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*string)
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalOID2ᚖstring(ctx, field.Selections, res)
|
||||
return ec.marshalNID2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Tag_createdAt(ctx context.Context, field graphql.CollectedField, obj *model.Tag) (ret graphql.Marshaler) {
|
||||
@@ -4569,7 +4774,7 @@ func (ec *executionContext) _User_id(ctx context.Context, field graphql.Collecte
|
||||
return obj.ID, nil
|
||||
}
|
||||
directive1 := func(ctx context.Context) (interface{}, error) {
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primarykey;not null")
|
||||
gorm, err := ec.unmarshalOString2ᚖstring(ctx, "primaryKey;not null")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -4586,21 +4791,24 @@ func (ec *executionContext) _User_id(ctx context.Context, field graphql.Collecte
|
||||
if tmp == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if data, ok := tmp.(*string); ok {
|
||||
if data, ok := tmp.(string); ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp)
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*string)
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalOID2ᚖstring(ctx, field.Selections, res)
|
||||
return ec.marshalNID2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _User_createdAt(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) {
|
||||
@@ -7282,6 +7490,9 @@ func (ec *executionContext) _Album(ctx context.Context, sel ast.SelectionSet, ob
|
||||
out.Values[i] = graphql.MarshalString("Album")
|
||||
case "id":
|
||||
out.Values[i] = ec._Album_id(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "createdAt":
|
||||
out.Values[i] = ec._Album_createdAt(ctx, field, obj)
|
||||
case "updatedAt":
|
||||
@@ -7347,6 +7558,8 @@ func (ec *executionContext) _AuthResponse(ctx context.Context, sel ast.Selection
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "Device":
|
||||
out.Values[i] = ec._AuthResponse_Device(ctx, field, obj)
|
||||
case "Error":
|
||||
out.Values[i] = ec._AuthResponse_Error(ctx, field, obj)
|
||||
default:
|
||||
@@ -7373,6 +7586,9 @@ func (ec *executionContext) _Device(ctx context.Context, sel ast.SelectionSet, o
|
||||
out.Values[i] = graphql.MarshalString("Device")
|
||||
case "id":
|
||||
out.Values[i] = ec._Device_id(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "createdAt":
|
||||
out.Values[i] = ec._Device_createdAt(ctx, field, obj)
|
||||
case "updatedAt":
|
||||
@@ -7387,8 +7603,16 @@ func (ec *executionContext) _Device(ctx context.Context, sel ast.SelectionSet, o
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "userID":
|
||||
out.Values[i] = ec._Device_userID(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "user":
|
||||
out.Values[i] = ec._Device_user(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "refreshKey":
|
||||
out.Values[i] = ec._Device_refreshKey(ctx, field, obj)
|
||||
default:
|
||||
@@ -7444,6 +7668,9 @@ func (ec *executionContext) _MediaItem(ctx context.Context, sel ast.SelectionSet
|
||||
out.Values[i] = graphql.MarshalString("MediaItem")
|
||||
case "id":
|
||||
out.Values[i] = ec._MediaItem_id(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "createdAt":
|
||||
out.Values[i] = ec._MediaItem_createdAt(ctx, field, obj)
|
||||
case "updatedAt":
|
||||
@@ -7473,8 +7700,16 @@ func (ec *executionContext) _MediaItem(ctx context.Context, sel ast.SelectionSet
|
||||
out.Values[i] = ec._MediaItem_tags(ctx, field, obj)
|
||||
case "albums":
|
||||
out.Values[i] = ec._MediaItem_albums(ctx, field, obj)
|
||||
case "userID":
|
||||
out.Values[i] = ec._MediaItem_userID(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "user":
|
||||
out.Values[i] = ec._MediaItem_user(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
@@ -7828,6 +8063,9 @@ func (ec *executionContext) _Tag(ctx context.Context, sel ast.SelectionSet, obj
|
||||
out.Values[i] = graphql.MarshalString("Tag")
|
||||
case "id":
|
||||
out.Values[i] = ec._Tag_id(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "createdAt":
|
||||
out.Values[i] = ec._Tag_createdAt(ctx, field, obj)
|
||||
case "updatedAt":
|
||||
@@ -7890,6 +8128,9 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj
|
||||
out.Values[i] = graphql.MarshalString("User")
|
||||
case "id":
|
||||
out.Values[i] = ec._User_id(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "createdAt":
|
||||
out.Values[i] = ec._User_createdAt(ctx, field, obj)
|
||||
case "updatedAt":
|
||||
@@ -8233,6 +8474,20 @@ func (ec *executionContext) marshalNAlbumResponse2ᚖreichardᚗioᚋimaginiᚋg
|
||||
return ec._AlbumResponse(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNAuthResponse2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthResponse(ctx context.Context, sel ast.SelectionSet, v model.AuthResponse) graphql.Marshaler {
|
||||
return ec._AuthResponse(ctx, sel, &v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNAuthResponse2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthResponse(ctx context.Context, sel ast.SelectionSet, v *model.AuthResponse) graphql.Marshaler {
|
||||
if v == nil {
|
||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
return ec._AuthResponse(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNAuthResult2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthResult(ctx context.Context, v interface{}) (model.AuthResult, error) {
|
||||
var res model.AuthResult
|
||||
err := res.UnmarshalGQL(v)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http"
|
||||
|
||||
"github.com/lestrrat-go/jwx/jwt"
|
||||
)
|
||||
|
||||
type AuthContext struct {
|
||||
AccessToken string
|
||||
RefreshToken string
|
||||
AuthResponse *http.ResponseWriter
|
||||
AuthRequest *http.Request
|
||||
AccessToken *jwt.Token
|
||||
AuthResponse *http.ResponseWriter
|
||||
AuthRequest *http.Request
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"github.com/google/uuid"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (u *User) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
newID := uuid.New().String()
|
||||
u.ID = &newID
|
||||
return
|
||||
newID := uuid.New().String()
|
||||
u.ID = newID
|
||||
return
|
||||
}
|
||||
|
||||
func (a *Album) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
newID := uuid.New().String()
|
||||
a.ID = &newID
|
||||
return
|
||||
newID := uuid.New().String()
|
||||
a.ID = newID
|
||||
return
|
||||
}
|
||||
|
||||
func (m *MediaItem) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
newID := uuid.New().String()
|
||||
m.ID = &newID
|
||||
return
|
||||
newID := uuid.New().String()
|
||||
m.ID = newID
|
||||
return
|
||||
}
|
||||
|
||||
func (t *Tag) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
newID := uuid.New().String()
|
||||
t.ID = &newID
|
||||
return
|
||||
newID := uuid.New().String()
|
||||
t.ID = newID
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Device) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
newID := uuid.New().String()
|
||||
d.ID = &newID
|
||||
return
|
||||
newID := uuid.New().String()
|
||||
d.ID = newID
|
||||
return
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
type Album struct {
|
||||
ID *string `json:"id" gorm:"primarykey;not null"`
|
||||
ID string `json:"id" gorm:"primaryKey;not null"`
|
||||
CreatedAt *time.Time `json:"createdAt" `
|
||||
UpdatedAt *time.Time `json:"updatedAt" `
|
||||
Name string `json:"name" gorm:"unique;not null"`
|
||||
@@ -34,6 +34,7 @@ type AlbumResponse struct {
|
||||
|
||||
type AuthResponse struct {
|
||||
Result AuthResult `json:"Result" `
|
||||
Device *Device `json:"Device" `
|
||||
Error *string `json:"Error" `
|
||||
}
|
||||
|
||||
@@ -50,12 +51,13 @@ type BooleanFilter struct {
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
ID *string `json:"id" gorm:"primarykey;not null"`
|
||||
ID string `json:"id" gorm:"primaryKey;not null"`
|
||||
CreatedAt *time.Time `json:"createdAt" `
|
||||
UpdatedAt *time.Time `json:"updatedAt" `
|
||||
Name string `json:"name" gorm:"not null"`
|
||||
Type DeviceType `json:"type" gorm:"default:Unknown;not null"`
|
||||
User *User `json:"user" gorm:"ForeignKey:ID;not null"`
|
||||
UserID string `json:"userID" gorm:"not null"`
|
||||
User *User `json:"user" gorm:"foreignKey:ID;references:UserID;not null"`
|
||||
RefreshKey *string `json:"refreshKey" `
|
||||
}
|
||||
|
||||
@@ -111,7 +113,7 @@ type IntFilter struct {
|
||||
}
|
||||
|
||||
type MediaItem struct {
|
||||
ID *string `json:"id" gorm:"primarykey;not null"`
|
||||
ID string `json:"id" gorm:"primaryKey;not null"`
|
||||
CreatedAt *time.Time `json:"createdAt" `
|
||||
UpdatedAt *time.Time `json:"updatedAt" `
|
||||
ExifDate *time.Time `json:"exifDate" `
|
||||
@@ -122,7 +124,8 @@ type MediaItem struct {
|
||||
OrigName string `json:"origName" gorm:"not null"`
|
||||
Tags []*Tag `json:"tags" gorm:"many2many:media_tags"`
|
||||
Albums []*Album `json:"albums" gorm:"many2many:media_albums"`
|
||||
User *User `json:"user" gorm:"ForeignKey:ID;not null"`
|
||||
UserID string `json:"userID" gorm:"not null"`
|
||||
User *User `json:"user" gorm:"foreignKey:ID;references:UserID;not null"`
|
||||
}
|
||||
|
||||
type MediaItemFilter struct {
|
||||
@@ -206,7 +209,7 @@ type StringFilter struct {
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
ID *string `json:"id" gorm:"primarykey;not null"`
|
||||
ID string `json:"id" gorm:"primaryKey;not null"`
|
||||
CreatedAt *time.Time `json:"createdAt" `
|
||||
UpdatedAt *time.Time `json:"updatedAt" `
|
||||
Name string `json:"name" gorm:"unique;not null"`
|
||||
@@ -236,7 +239,7 @@ type TimeFilter struct {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID *string `json:"id" gorm:"primarykey;not null"`
|
||||
ID string `json:"id" gorm:"primaryKey;not null"`
|
||||
CreatedAt *time.Time `json:"createdAt" `
|
||||
UpdatedAt *time.Time `json:"updatedAt" `
|
||||
Email string `json:"email" gorm:"not null;unique"`
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"reichard.io/imagini/internal/db"
|
||||
"reichard.io/imagini/internal/auth"
|
||||
"reichard.io/imagini/internal/db"
|
||||
)
|
||||
|
||||
// This file will not be regenerated automatically.
|
||||
//
|
||||
// It serves as dependency injection for your app, add any dependencies you require here.
|
||||
|
||||
type Resolver struct{
|
||||
DB *db.DBManager
|
||||
type Resolver struct {
|
||||
Auth *auth.AuthManager
|
||||
DB *db.DBManager
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ enum AuthResult {
|
||||
|
||||
type AuthResponse {
|
||||
Result: AuthResult!
|
||||
Device: Device
|
||||
Error: String
|
||||
}
|
||||
|
||||
@@ -138,17 +139,18 @@ input AuthTypeFilter {
|
||||
# ------------------------------------------------------------
|
||||
|
||||
type Device {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
name: String! @meta(gorm: "not null")
|
||||
type: DeviceType! @meta(gorm: "default:Unknown;not null")
|
||||
user: User @meta(gorm: "ForeignKey:ID;not null")
|
||||
userID: ID! @meta(gorm: "not null")
|
||||
user: User! @meta(gorm: "foreignKey:ID;references:UserID;not null")
|
||||
refreshKey: String
|
||||
}
|
||||
|
||||
type User {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
email: String! @meta(gorm: "not null;unique")
|
||||
@@ -161,7 +163,7 @@ type User {
|
||||
}
|
||||
|
||||
type MediaItem {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
exifDate: Time
|
||||
@@ -172,18 +174,19 @@ type MediaItem {
|
||||
origName: String! @meta(gorm: "not null")
|
||||
tags: [Tag] @meta(gorm: "many2many:media_tags")
|
||||
albums: [Album] @meta(gorm: "many2many:media_albums")
|
||||
user: User @meta(gorm: "ForeignKey:ID;not null")
|
||||
userID: ID! @meta(gorm: "not null")
|
||||
user: User! @meta(gorm: "foreignKey:ID;references:UserID;not null")
|
||||
}
|
||||
|
||||
type Tag {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
name: String! @meta(gorm: "unique;not null")
|
||||
}
|
||||
|
||||
type Album {
|
||||
id: ID @meta(gorm: "primarykey;not null")
|
||||
id: ID! @meta(gorm: "primaryKey;not null")
|
||||
createdAt: Time
|
||||
updatedAt: Time
|
||||
name: String! @meta(gorm: "unique;not null")
|
||||
@@ -331,8 +334,9 @@ type Query {
|
||||
login(
|
||||
user: String!
|
||||
password: String!
|
||||
): AuthResult!
|
||||
logout: AuthResult! @hasMinRole(role: User)
|
||||
deviceID: ID
|
||||
): AuthResponse!
|
||||
logout: AuthResponse! @hasMinRole(role: User)
|
||||
|
||||
# Single Item
|
||||
mediaItem(id: ID!): MediaItem! @hasMinRole(role: User)
|
||||
|
||||
@@ -4,10 +4,12 @@ package graph
|
||||
// will be copied through when generating and any unknown code will be moved to the end.
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"reichard.io/imagini/graph/generated"
|
||||
"reichard.io/imagini/graph/model"
|
||||
)
|
||||
@@ -41,26 +43,66 @@ func (r *mutationResolver) CreateUser(ctx context.Context, input model.NewUser)
|
||||
|
||||
err := r.DB.CreateUser(user)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("DB Error"))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) Login(ctx context.Context, user string, password string) (model.AuthResult, error) {
|
||||
|
||||
// Set Cookie From Context
|
||||
func (r *queryResolver) Login(ctx context.Context, user string, password string, deviceID *string) (*model.AuthResponse, error) {
|
||||
// Set Cookie From Context
|
||||
authContext := ctx.Value("auth").(*model.AuthContext)
|
||||
resp := *authContext.AuthResponse
|
||||
testCookie := http.Cookie{Name: "TestCookie", Value: "Test123", Path: "/", HttpOnly: true}
|
||||
http.SetCookie(resp, &testCookie)
|
||||
resp := authContext.AuthResponse
|
||||
req := authContext.AuthRequest
|
||||
|
||||
return model.AuthResultSuccess, nil
|
||||
// Do Login
|
||||
foundUser, success := r.Auth.AuthenticateUser(user, password)
|
||||
if !success {
|
||||
return &model.AuthResponse{Result: model.AuthResultFailure}, nil
|
||||
}
|
||||
|
||||
// Upsert Device
|
||||
foundDevice := model.Device{}
|
||||
if deviceID != nil {
|
||||
parsedDeviceID, err := uuid.Parse(*deviceID)
|
||||
if err != nil {
|
||||
return &model.AuthResponse{Result: model.AuthResultFailure}, nil
|
||||
}
|
||||
foundDevice.ID = parsedDeviceID.String()
|
||||
count, err := r.DB.Device(&foundDevice)
|
||||
if count != 1 || err != nil {
|
||||
return &model.AuthResponse{Result: model.AuthResultFailure}, nil
|
||||
}
|
||||
} else {
|
||||
foundDevice.Type = deriveDeviceType(req)
|
||||
err := r.DB.CreateDevice(&foundDevice)
|
||||
if err != nil {
|
||||
return &model.AuthResponse{Result: model.AuthResultFailure}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Create Tokens
|
||||
accessToken, err := r.Auth.CreateJWTAccessToken(foundUser, foundDevice)
|
||||
if err != nil {
|
||||
return &model.AuthResponse{Result: model.AuthResultFailure}, nil
|
||||
}
|
||||
refreshToken, err := r.Auth.CreateJWTRefreshToken(foundUser, foundDevice)
|
||||
if err != nil {
|
||||
return &model.AuthResponse{Result: model.AuthResultFailure}, nil
|
||||
}
|
||||
|
||||
// Set appropriate cookies
|
||||
accessCookie := http.Cookie{Name: "AccessToken", Value: accessToken, Path: "/", HttpOnly: true}
|
||||
refreshCookie := http.Cookie{Name: "RefreshToken", Value: refreshToken, Path: "/", HttpOnly: true}
|
||||
http.SetCookie(*resp, &accessCookie)
|
||||
http.SetCookie(*resp, &refreshCookie)
|
||||
|
||||
return &model.AuthResponse{Result: model.AuthResultSuccess, Device: &foundDevice}, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) Logout(ctx context.Context) (model.AuthResult, error) {
|
||||
func (r *queryResolver) Logout(ctx context.Context) (*model.AuthResponse, error) {
|
||||
// panic(fmt.Errorf("not implemented"))
|
||||
return model.AuthResultSuccess, nil
|
||||
return &model.AuthResponse{Result: model.AuthResultSuccess}, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) MediaItem(ctx context.Context, id string) (*model.MediaItem, error) {
|
||||
@@ -126,3 +168,29 @@ func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
|
||||
|
||||
type mutationResolver struct{ *Resolver }
|
||||
type queryResolver struct{ *Resolver }
|
||||
|
||||
// !!! WARNING !!!
|
||||
// The code below was going to be deleted when updating resolvers. It has been copied here so you have
|
||||
// one last chance to move it out of harms way if you want. There are two reasons this happens:
|
||||
// - When renaming or deleting a resolver the old code will be put in here. You can safely delete
|
||||
// it when you're done.
|
||||
// - You have helper methods in this file. Move them out to keep these resolver files clean.
|
||||
func deriveDeviceType(r *http.Request) model.DeviceType {
|
||||
userAgent := strings.ToLower(r.Header.Get("User-Agent"))
|
||||
if strings.Contains(userAgent, "ios-imagini") {
|
||||
return model.DeviceTypeIOs
|
||||
} else if strings.Contains(userAgent, "android-imagini") {
|
||||
return model.DeviceTypeAndroid
|
||||
} else if strings.Contains(userAgent, "chrome") {
|
||||
return model.DeviceTypeChrome
|
||||
} else if strings.Contains(userAgent, "firefox") {
|
||||
return model.DeviceTypeFirefox
|
||||
} else if strings.Contains(userAgent, "msie") {
|
||||
return model.DeviceTypeInternetExplorer
|
||||
} else if strings.Contains(userAgent, "edge") {
|
||||
return model.DeviceTypeEdge
|
||||
} else if strings.Contains(userAgent, "safari") {
|
||||
return model.DeviceTypeSafari
|
||||
}
|
||||
return model.DeviceTypeUnknown
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user