schema.resolvers.go 6.0 KB
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 (
	"context"
	"fmt"
	query2 "github.com/tiptok/godevp/pkg/application/clientVersion/query"
	"unsafe"

	"github.com/tiptok/gocomm/common"
	clientVersionService "github.com/tiptok/godevp/pkg/application/clientVersion/service"
	"github.com/tiptok/godevp/pkg/application/factory"
	"github.com/tiptok/godevp/pkg/application/users/command"
	"github.com/tiptok/godevp/pkg/application/users/query"
	"github.com/tiptok/godevp/pkg/application/users/service"
	domain1 "github.com/tiptok/godevp/pkg/domain"
	"github.com/tiptok/godevp/pkg/domain/role"
	domain "github.com/tiptok/godevp/pkg/domain/users"
	"github.com/tiptok/godevp/pkg/port/graphql/graph/generated"
	"github.com/tiptok/godevp/pkg/port/graphql/graph/libs"
	"github.com/tiptok/godevp/pkg/port/graphql/graph/model"
)

func (r *clientVersionResolver) CreateTime(ctx context.Context, obj *domain1.ClientVersion) (*libs.Datetime, error) {
	return libs.NewDatetimeFromTime(obj.CreateTime), nil
}

func (r *mutationResolver) CreateUsers(ctx context.Context, input model.CreateUsersInput) (*model.Users, error) {
	usersService := service.NewUsersService(nil)
	createUsersCommand := &command.CreateUsersCommand{
		Name:  input.Name,
		Phone: input.Phone,
	}
	data, err := usersService.CreateUsers(createUsersCommand)
	if err != nil {
		return nil, err
	}
	if user, ok := data.(*domain.Users); ok {
		return &model.Users{
			Name:  &user.Name,
			Phone: &user.Phone,
		}, nil
	}
	return nil, fmt.Errorf("type error except: domain.Users")
}

func (r *mutationResolver) RemoveUsers(ctx context.Context, input model.RemoveUsersInput) (*model.Users, error) {
	panic(fmt.Errorf("not implemented"))
}

func (r *mutationResolver) UpdateUsers(ctx context.Context, input model.UpdateUsersInput) (*model.Users, error) {
	panic(fmt.Errorf("not implemented"))
}

func (r *queryResolver) User(ctx context.Context, input model.GetUsersInput) (*model.Users, error) {
	usersService := service.NewUsersService(nil)
	getUsersCommand := &query.GetUsersQuery{
		UsersId: int64(input.ID),
	}
	data, err := usersService.GetUsers(getUsersCommand)
	if err != nil {
		return nil, err
	}
	if user, ok := data.(*domain.Users); ok {
		return &model.Users{
			Name:   &user.Name,
			Phone:  &user.Phone,
			Status: &user.Status,
		}, nil
	}
	return nil, fmt.Errorf("type error except: domain.Users")
}

func (r *queryResolver) Users(ctx context.Context, input model.ListUsersInput) ([]*model.Users, error) {
	usersService := service.NewUsersService(nil)
	getUsersCommand := &query.ListUsersQuery{
		Limit:  input.Limit,
		Offset: input.Offset,
	}
	data, err := usersService.ListUsers(getUsersCommand)
	if err != nil {
		return nil, err
	}
	if userMap, ok := data.(map[string]interface{}); ok {
		users := userMap["users"].([]*domain.Users)
		var ret []*model.Users
		for _, user := range users {
			createTime := common.AssertString(user.CreateTime.Unix())
			updateTime := common.AssertString(user.UpdateTime.Unix())
			ret = append(ret, &model.Users{
				Name:       &user.Name,
				Phone:      &user.Phone,
				Status:     &user.Status,
				AdminType:  &user.AdminType,
				CreateTime: &createTime,
				UpdateTime: &updateTime,
			})
		}
		return ret, nil
	}
	return nil, fmt.Errorf("type error except: domain.Users")
}

func (r *queryResolver) Menus(ctx context.Context, input *model.MenuAccessInput) ([]*model.Access, error) {
	transactionContext, _ := factory.CreateDefaultTransactionContext(nil)
	var AccessRepository, _ = factory.CreateAccessRepository(map[string]interface{}{"transactionContext": transactionContext})
	_, access, _ := AccessRepository.Find(map[string]interface{}{})
	var rsp []*model.Access
	for _, item := range access {
		rsp = append(rsp, &model.Access{
			ID:         (*int)(unsafe.Pointer(&item.Id)),
			ParentID:   (*int)(unsafe.Pointer(&item.ParentId)),
			AccessName: &item.AccessName,
			AccessCode: &item.AccessCode,
			AccessType: &item.AccessType,
			Sort:       (*int)(unsafe.Pointer(&item.Sort)),
			Object:     &item.Object,
			Action:     &item.Action,
			Module:     &item.Module,
			Icon:       &item.Icon,
			Status:     (*int)(unsafe.Pointer(&item.Status)),
		})
	}
	return rsp, nil
}

func (r *queryResolver) ClientVersion(ctx context.Context, id *int) (*domain1.ClientVersion, error) {
	svr := clientVersionService.NewClientVersionService(nil)
	m, err := svr.GetClientVersion(&query2.GetClientVersionQuery{Id: int64(*id)})
	if err != nil || m == nil {
		return nil, err
	}
	return m.(*domain1.ClientVersion), nil
}

func (r *roleResolver) Access(ctx context.Context, obj *model.Role) ([]*model.Access, error) {
	return []*model.Access{
		&model.Access{},
	}, nil
}

func (r *usersResolver) Roles(ctx context.Context, obj *model.Users) ([]*model.Role, error) {
	var ro = &role.Role{
		Id:       1,
		RoleName: "ccc",
		ParentId: 1,
	}
	var id = int(ro.Id)
	return []*model.Role{
		&model.Role{
			ID:       &id,
			RoleName: &ro.RoleName,
		},
		&model.Role{
			ID:       &id,
			RoleName: &ro.RoleName,
		},
	}, nil
}

// ClientVersion returns generated.ClientVersionResolver implementation.
func (r *Resolver) ClientVersion() generated.ClientVersionResolver { return &clientVersionResolver{r} }

// 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} }

// Role returns generated.RoleResolver implementation.
func (r *Resolver) Role() generated.RoleResolver { return &roleResolver{r} }

// Users returns generated.UsersResolver implementation.
func (r *Resolver) Users() generated.UsersResolver { return &usersResolver{r} }

type clientVersionResolver struct{ *Resolver }
type mutationResolver struct{ *Resolver }
type queryResolver struct{ *Resolver }
type roleResolver struct{ *Resolver }
type usersResolver struct{ *Resolver }