department_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 DepartmentAdaptor struct {
}

func (adaptor *DepartmentAdaptor) ToDepartment(companyId int64, departmentId int64) (*domain.Department, error) {
	departmentServiceGateway := service_gateway.NewHttplibUserServiceGateway()
	response, err := departmentServiceGateway.GetDepartment(companyId, departmentId)
	if err != nil {
		return nil, err
	}
	if departmentTranslator, err := translator.NewDepartmentTranslator(); err != nil {
		return nil, err
	} else {
		department, err := departmentTranslator.ToDepartmentFromRepresentation(response)
		if err != nil {
			return nil, err
		}
		return department, nil
	}
}

func NewDepartmentAdaptor() (*DepartmentAdaptor, error) {
	return &DepartmentAdaptor{}, nil
}