api_auth_lib.go 1.5 KB
package authlib

import (
	"context"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway"
	"net/http"
)

type ApiAuthService struct {
	gateway.Service
}

func (svc *ApiAuthService) MeInfo(ctx context.Context, request RequestUserMeQuery) (*DataUserMe, error) {
	var result DataUserMe
	if err := svc.Do(ctx, "/v1/user/me", http.MethodGet, request, &result); err != nil {
		return nil, err
	}
	return &result, nil
}

func (svc *ApiAuthService) MeAppInfo(ctx context.Context, request RequestUserMeQuery) (*DataUserAppInfo, error) {
	var result DataUserAppInfo
	if err := svc.Do(ctx, "/v1/user/me-app-info", http.MethodGet, request, &result); err != nil {
		return nil, err
	}
	return &result, nil
}

func (svc *ApiAuthService) LoginCheck(ctx context.Context, request RequestLoginCheck) (*DataLoginCheck, error) {
	var (
		result DataLoginCheck
		err    error
	)
	if err = svc.Do(ctx, "/v1/login/check?token="+request.Token, http.MethodGet, request, &result); err != nil {
		return nil, err
	}
	if errCodeMsg, ok := err.(gateway.HttpError); ok {
		return &DataLoginCheck{
			Code: errCodeMsg.Base.Code,
			Msg:  errCodeMsg.Base.Msg,
		}, nil
	}
	return &result, nil
}

func (svc *ApiAuthService) AppLogin(ctx context.Context, request RequestAppLogin) (*DataAppLogin, error) {
	var result DataAppLogin
	if err := svc.Do(ctx, "/v1/login/check?token="+request.Token, http.MethodGet, request, &result); err != nil {
		return nil, err
	}
	return &result, nil
}