2021-02-02 20:34:10 +00:00
|
|
|
package graph
|
|
|
|
|
|
|
|
// This file will be automatically regenerated based on the schema, any resolver implementations
|
|
|
|
// will be copied through when generating and any unknown code will be moved to the end.
|
|
|
|
|
|
|
|
import (
|
2021-02-03 03:55:35 +00:00
|
|
|
"net/http"
|
2021-02-02 20:34:10 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"reichard.io/imagini/graph/generated"
|
|
|
|
"reichard.io/imagini/graph/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (r *mutationResolver) CreateMediaItem(ctx context.Context, input model.NewMediaItem) (*model.MediaItem, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *mutationResolver) CreateDevice(ctx context.Context, input model.NewDevice) (*model.Device, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *mutationResolver) CreateAlbum(ctx context.Context, input model.NewAlbum) (*model.Album, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *mutationResolver) CreateTag(ctx context.Context, input model.NewTag) (*model.Tag, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *mutationResolver) CreateUser(ctx context.Context, input model.NewUser) (*model.User, error) {
|
2021-02-03 03:55:35 +00:00
|
|
|
user := &model.User{
|
|
|
|
Email: input.Email,
|
|
|
|
Username: input.Username,
|
|
|
|
FirstName: input.FirstName,
|
|
|
|
LastName: input.LastName,
|
|
|
|
Role: input.Role,
|
|
|
|
AuthType: input.AuthType,
|
|
|
|
Password: input.Password,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := r.DB.CreateUser(user)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("DB Error"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return user, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *queryResolver) Login(ctx context.Context, user string, password string) (model.AuthResult, 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)
|
|
|
|
|
|
|
|
return model.AuthResultSuccess, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *queryResolver) Logout(ctx context.Context) (model.AuthResult, error) {
|
|
|
|
// panic(fmt.Errorf("not implemented"))
|
|
|
|
return model.AuthResultSuccess, nil
|
2021-02-02 20:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *queryResolver) MediaItem(ctx context.Context, id string) (*model.MediaItem, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *queryResolver) Device(ctx context.Context, id string) (*model.Device, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *queryResolver) Album(ctx context.Context, id string) (*model.Album, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
2021-02-03 03:55:35 +00:00
|
|
|
func (r *queryResolver) User(ctx context.Context, id string) (*model.User, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
2021-02-02 20:34:10 +00:00
|
|
|
func (r *queryResolver) Tag(ctx context.Context, id string) (*model.Tag, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
2021-02-03 03:55:35 +00:00
|
|
|
func (r *queryResolver) Me(ctx context.Context) (*model.User, error) {
|
2021-02-02 20:34:10 +00:00
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
|
|
|
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) Devices(ctx context.Context, filter *model.DeviceFilter, count *int, page *int) (*model.DeviceResponse, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
|
|
|
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) Tags(ctx context.Context, filter *model.TagFilter, count *int, page *int) (*model.TagResponse, error) {
|
|
|
|
panic(fmt.Errorf("not implemented"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *queryResolver) Users(ctx context.Context, filter *model.UserFilter, count *int, page *int) (*model.UserResponse, error) {
|
2021-02-03 03:55:35 +00:00
|
|
|
resp, totalCount, err := r.DB.Users()
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("DB Error"))
|
|
|
|
}
|
|
|
|
return &model.UserResponse{
|
|
|
|
Data: resp,
|
|
|
|
PageInfo: &model.PageInfo{
|
|
|
|
Count: int(totalCount),
|
|
|
|
Page: 0,
|
|
|
|
Total: int(totalCount),
|
|
|
|
},
|
|
|
|
}, nil
|
2021-02-02 20:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns generated.MutationResolver implementation.
|
|
|
|
func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} }
|
|
|
|
|
|
|
|
// Query returns generated.QueryResolver implementation.
|
|
|
|
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
|
|
|
|
|
|
|
|
type mutationResolver struct{ *Resolver }
|
|
|
|
type queryResolver struct{ *Resolver }
|