user_adaptor.go 1.9 KB
package adaptor

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/translator"
)

type UserAdaptor struct {
}

func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId int64, aRoleName string) (interface{}, error) {
	userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
	response, err := userServiceGateway.GetUser(companyId, orgId, userId)
	if err != nil {
		return map[string]interface{}{}, err
	}
	if userTranslator, err := translator.NewUserTranslator(); err != nil {
		return map[string]interface{}{}, err
	} else {
		switch aRoleName {
		case "Relevant":
			relevant, err := userTranslator.ToRelevantFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, err
			}
			return relevant, nil
		case "Referrer":
			referrer, err := userTranslator.ToReferrerFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, err
			}
			return referrer, nil
		case "Salesman":
			salesman, err := userTranslator.ToSalesmanFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, nil
			}
			return salesman, nil
		case "Undertaker":
			undertaker, err := userTranslator.ToUndertakerFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, nil
			}
			return undertaker, nil
		case "Operator":
			operator, err := userTranslator.ToOperatorFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, nil
			}
			return operator, nil
		case "User":
			user, err := userTranslator.ToUserFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, nil
			}
			return user, nil
		}
	}
	return map[string]interface{}{}, nil
}

func NewUserAdaptor() (*UserAdaptor, error) {
	return &UserAdaptor{}, nil
}