http_partner01_service_gateway.go 2.3 KB
package gateway

import (
	"github.com/linmadan/egglib-go/core/application"
	"github.com/tiptok/gocomm/gs"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01-gateway/pkg/constant"
	"net/http"
)

const (
	AuthsLogin               = "AuthsLogin"
	AuthsLoginByCompany      = "loginByCompany"
	AuthsAccessToken         = "AuthsAccessToken"
	AuthsRefreshToken        = "AuthsRefreshToken"
	AuthsSendSmsCode         = "AuthsSendSmsCode"
	AuthsRevoke              = "AuthsRevoke"
	AuthsChangePhonePassword = "AuthsChangePhonePassword"
)

const (
	CompanyGet    = "CompanyGet"
	CompanyCreate = "CompanyCreate"
	CompanyRemove = "CompanyRemove"
	CompanyList   = "CompanyList"
	CompanyUpdate = "CompanyUpdate"
)

var Partner01Service *HttpPartner01ServiceGateway

func init() {
	Partner01Service = &HttpPartner01ServiceGateway{gs.NewManagerService(constant.PARTER01_GATEWAY_ADDRESS, Routers())}
	Partner01Service.WithDebugModel(true)
}

type HttpPartner01ServiceGateway struct {
	*gs.GatewayService
}

func Routers() []gs.Router {
	routers := []gs.Router{
		{AuthsLogin, "/auths/login", http.MethodPost},
		{AuthsLoginByCompany, "/auths/loginByCompany", http.MethodPost},
		{AuthsAccessToken, "/auths/accessToken", http.MethodPost},
		{AuthsRefreshToken, "/auths/refreshToken", http.MethodPost},
		{AuthsSendSmsCode, "/auths/sendSmsCode", http.MethodPost},
		{AuthsRevoke, "/auths/revoke", http.MethodPost},
		{AuthsChangePhonePassword, "/auths/changePhonePassword", http.MethodPost},

		{CompanyGet, "/companies/:companyId", http.MethodGet},
		{CompanyRemove, "/companies/:companyId", http.MethodDelete},
		{CompanyUpdate, "/companies/:companyId", http.MethodPut},
		{CompanyCreate, "/companies/", http.MethodPost},
		{CompanyList, "/companies/", http.MethodGet},
	}
	return routers
}

func (service *HttpPartner01ServiceGateway) CompanyCreate(jsonObject interface{}) (interface{}, error) {
	data, err := service.Invoke(CompanyCreate, gs.WithJsonObject(jsonObject))
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	return data.Data, nil
}

func (service *HttpPartner01ServiceGateway) CompanyGet(pathParam interface{}) (interface{}, error) {
	data, err := service.Invoke(CompanyGet, gs.WithPathParam(pathParam))
	if err != nil {
		return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
	}
	return data.Data, nil
}