initial commit 2
This commit is contained in:
113
domain/service/organization.go
Normal file
113
domain/service/organization.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// userService is the domain service for user operations
|
||||
type organizationService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
// newUserService returns an instance of userService
|
||||
func newOrganizationService(svc *Service) *organizationService {
|
||||
return &organizationService{
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *organizationService) GetAllTypes() ([]entity.OrganizationType, error) {
|
||||
return s.svc.db.Organization().GetAllTypes()
|
||||
}
|
||||
|
||||
func (s *organizationService) GetByType(organizationTypeKey string) ([]entity.Organization, error) {
|
||||
return s.svc.db.Organization().GetByType(organizationTypeKey)
|
||||
}
|
||||
|
||||
func (s *organizationService) GetByName(name string, searchType string) ([]entity.Organization, error) {
|
||||
return s.svc.db.Organization().GetByName(name, searchType)
|
||||
}
|
||||
|
||||
func (s *organizationService) GetByUUID(organizationUUID string) (entity.Organization, error) {
|
||||
organization, err := s.svc.db.Organization().GetByUUID(organizationUUID)
|
||||
if err != nil {
|
||||
return organization, err
|
||||
}
|
||||
|
||||
organization.Contacts, err = s.GetContactsByOrganizationID(organization.ID)
|
||||
if err != nil {
|
||||
return organization, err
|
||||
}
|
||||
|
||||
organization.Addresses, err = s.GetAddressByOrganizationID(organization.ID)
|
||||
if err != nil {
|
||||
return organization, err
|
||||
}
|
||||
|
||||
organization.ChildOrgs, err = s.svc.db.Organization().GetChildsByID(organization.ID)
|
||||
if err != nil {
|
||||
return organization, err
|
||||
}
|
||||
|
||||
if organization.ParentID > 0 {
|
||||
parent, err := s.svc.db.Organization().GetByID(organization.ParentID)
|
||||
if err != nil {
|
||||
return organization, err
|
||||
}
|
||||
organization.Parent = &parent
|
||||
}
|
||||
|
||||
return organization, nil
|
||||
}
|
||||
|
||||
func (s *organizationService) SetParentOrganization(organizationID int64, parentOrganizationID int64) error {
|
||||
return s.svc.db.Organization().SetParentOrganization(organizationID, parentOrganizationID)
|
||||
}
|
||||
|
||||
func (s *organizationService) GetContactsByOrganizationUUID(organizationUUID string) ([]entity.OrganizationContact, error) {
|
||||
return s.svc.db.Organization().GetContactsByOrganizationUUID(organizationUUID)
|
||||
}
|
||||
|
||||
func (s *organizationService) GetContactsByOrganizationID(organizationID int64) ([]entity.OrganizationContact, error) {
|
||||
return s.svc.db.Organization().GetContactsByOrganizationID(organizationID)
|
||||
}
|
||||
|
||||
func (s *organizationService) GetContactsByUUID(contactUUID string) (entity.OrganizationContact, error) {
|
||||
return s.svc.db.Organization().GetContactsByUUID(contactUUID)
|
||||
}
|
||||
|
||||
func (s *organizationService) GetAddressByOrganizationUUID(organizationUUID string) ([]entity.OrganizationAddress, error) {
|
||||
return s.svc.db.Organization().GetAddressByOrganizationUUID(organizationUUID)
|
||||
}
|
||||
|
||||
func (s *organizationService) GetAddressByOrganizationID(organizationID int64) ([]entity.OrganizationAddress, error) {
|
||||
return s.svc.db.Organization().GetAddressByOrganizationID(organizationID)
|
||||
}
|
||||
|
||||
func (s *organizationService) GetAddressByUUID(contactUUID string) (entity.OrganizationAddress, error) {
|
||||
return s.svc.db.Organization().GetAddressByUUID(contactUUID)
|
||||
}
|
||||
|
||||
func (s *organizationService) InactivateOrganizationAddress(address entity.OrganizationAddress) error {
|
||||
return s.svc.db.Organization().InactivateOrganizationAddress(address)
|
||||
}
|
||||
|
||||
func (s *organizationService) SetOrganizationAddress(address entity.OrganizationAddress) (entity.OrganizationAddress, error) {
|
||||
return s.svc.db.Organization().SetOrganizationAddress(address)
|
||||
}
|
||||
|
||||
func (s *organizationService) InactivateOrganizationContact(contact entity.OrganizationContact) error {
|
||||
return s.svc.db.Organization().InactivateOrganizationContact(contact)
|
||||
}
|
||||
|
||||
func (s *organizationService) SetOrganizationContact(contact entity.OrganizationContact) (entity.OrganizationContact, error) {
|
||||
return s.svc.db.Organization().SetOrganizationContact(contact)
|
||||
}
|
||||
|
||||
func (s *organizationService) AddOrganization(organization entity.Organization) (entity.Organization, error) {
|
||||
return s.svc.db.Organization().AddOrganization(organization)
|
||||
}
|
||||
|
||||
func (s *organizationService) GetTypeByKey(key string) (entity.OrganizationType, error) {
|
||||
return s.svc.db.Organization().GetTypeByKey(key)
|
||||
}
|
||||
Reference in New Issue
Block a user