organization_adaptor.go 1.0 KB
package adaptor

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
	"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 OrganizationAdaptor struct {
}

func (adaptor *OrganizationAdaptor) ToOrganization(companyId int64, orgId int64) (*domain.Org, error) {
	organizationServiceGateway := service_gateway.NewHttplibUserServiceGateway()
	response, err := organizationServiceGateway.GetOrganization(companyId, orgId)
	if err != nil {
		return nil, err
	}
	if organizationTranslator, err := translator.NewOrganizationTranslator(); err != nil {
		return nil, err
	} else {
		organization, err := organizationTranslator.ToOrganizationFromRepresentation(response)
		if err != nil {
			return nil, err
		}
		return organization, nil
	}
}

func NewOrganizationAdaptor() (*OrganizationAdaptor, error) {
	return &OrganizationAdaptor{}, nil
}