initial commit 2
This commit is contained in:
74
application/entitymapping/address.go
Normal file
74
application/entitymapping/address.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// rideMapping has method to map ride entities to view models
|
||||
type addressMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
// ToVisitEntity maps a User entity to User view model
|
||||
func (mapping *addressMapping) ToAddressEntity(item viewmodel.Address) entity.Address {
|
||||
return entity.Address{
|
||||
UUID: item.UUID,
|
||||
InternalID: item.InternalID,
|
||||
Name: item.Name,
|
||||
Address: item.Address,
|
||||
AddressType: mapping.ToParamEntity(item.AddressType),
|
||||
Latitude: item.Latitude,
|
||||
Longitude: item.Longitude,
|
||||
Origin: mapping.ToParamEntity(item.Type),
|
||||
User: mapping.mapper.User.ToUserEntity(item.User),
|
||||
CreatedUser: entity.User{
|
||||
UUID: item.CreatedUserUUID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *addressMapping) ToParamEntity(item string) entity.Params {
|
||||
return entity.Params{
|
||||
Key: item,
|
||||
}
|
||||
}
|
||||
|
||||
// ToVisitEntity maps a User entity to User view model
|
||||
func (mapping *addressMapping) ToAddressModel(item entity.Address) viewmodel.Address {
|
||||
return viewmodel.Address{
|
||||
UUID: item.UUID,
|
||||
InternalID: item.InternalID,
|
||||
Name: item.Name,
|
||||
Address: item.Address,
|
||||
AddressType: item.AddressType.Key,
|
||||
AddressTypeName: item.AddressType.Name,
|
||||
Latitude: item.Latitude,
|
||||
Longitude: item.Longitude,
|
||||
Type: item.Origin.Key,
|
||||
User: mapping.mapper.User.ToUserModel(item.User),
|
||||
CreatedUserUUID: item.CreatedUser.UUID,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *addressMapping) ToAddressEntitySlice(list []viewmodel.Address) (retVal []entity.Address) {
|
||||
retVal = make([]entity.Address, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToAddressEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToRideModelSlice maps a Ride entity slice to Ride view model slice
|
||||
func (mapping *addressMapping) ToAddressModelSlice(list []entity.Address) (retVal []viewmodel.Address) {
|
||||
retVal = make([]viewmodel.Address, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToAddressModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
51
application/entitymapping/entitymapping.go
Normal file
51
application/entitymapping/entitymapping.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
instance *Mapper
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
// Mapper has mapping methods to map entities to view models
|
||||
type Mapper struct {
|
||||
User *userMapping
|
||||
Ride *rideMapping
|
||||
Visit *visitMapping
|
||||
Address *addressMapping
|
||||
Provider *providerMapping
|
||||
Notification *notificationMapping
|
||||
Profile *profileMapping
|
||||
Organization *organizationMapping
|
||||
}
|
||||
|
||||
// New returns an EntityMapper for fluent mapping
|
||||
func New() *Mapper {
|
||||
once.Do(func() {
|
||||
instance = &Mapper{}
|
||||
|
||||
instance.User = &userMapping{instance}
|
||||
instance.Ride = &rideMapping{instance}
|
||||
instance.Visit = &visitMapping{instance}
|
||||
instance.Address = &addressMapping{instance}
|
||||
instance.Provider = &providerMapping{instance}
|
||||
instance.Notification = ¬ificationMapping{instance}
|
||||
instance.Profile = &profileMapping{instance}
|
||||
instance.Organization = &organizationMapping{instance}
|
||||
})
|
||||
|
||||
return instance
|
||||
}
|
||||
|
||||
// isEmpty returns the alternative option in case the first is empty
|
||||
func ifEmpty(firstOption string, alternativeOption string) string {
|
||||
if strings.TrimSpace(firstOption) == "" {
|
||||
return alternativeOption
|
||||
}
|
||||
|
||||
return firstOption
|
||||
}
|
||||
69
application/entitymapping/notification.go
Normal file
69
application/entitymapping/notification.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// providerMapping has method to map provider entities to view models
|
||||
type notificationMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *notificationMapping) ToNotificationEntitySlice(list []viewmodel.Notification) (retVal []entity.Notification) {
|
||||
retVal = make([]entity.Notification, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToNotificationEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *notificationMapping) ToNotificationEntity(model viewmodel.Notification) entity.Notification {
|
||||
return entity.Notification{
|
||||
UUID: model.UUID,
|
||||
To: model.To,
|
||||
From: model.From,
|
||||
Type: model.Type,
|
||||
Subject: model.Subject,
|
||||
Message: model.Message,
|
||||
Created: model.Created,
|
||||
Ride: entity.Ride{
|
||||
UUID: model.Ride.UUID,
|
||||
},
|
||||
User: mapping.mapper.User.ToUserEntity(model.User),
|
||||
CreatedUser: mapping.mapper.User.ToUserEntity(model.CreatedUser),
|
||||
Read: model.Read,
|
||||
MessageType: model.MessageType,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *notificationMapping) ToNotificationModelSlice(list []entity.Notification) (retVal []viewmodel.Notification) {
|
||||
retVal = make([]viewmodel.Notification, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToNotificationModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *notificationMapping) ToNotificationModel(model entity.Notification) viewmodel.Notification {
|
||||
return viewmodel.Notification{
|
||||
UUID: model.UUID,
|
||||
To: model.To,
|
||||
From: model.From,
|
||||
Type: model.Type,
|
||||
Subject: model.Subject,
|
||||
Message: model.Message,
|
||||
Created: model.Created,
|
||||
Ride: mapping.mapper.Ride.ToRideModel(model.Ride),
|
||||
User: mapping.mapper.User.ToUserModel(model.User),
|
||||
CreatedUser: mapping.mapper.User.ToUserModel(model.CreatedUser),
|
||||
Read: model.Read,
|
||||
MessageType: model.MessageType,
|
||||
}
|
||||
}
|
||||
256
application/entitymapping/organization.go
Normal file
256
application/entitymapping/organization.go
Normal file
@@ -0,0 +1,256 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// providerMapping has method to map provider entities to view models
|
||||
type organizationMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *organizationMapping) ToOrganizationTypeEntitySlice(list []viewmodel.OrganizationType) (retVal []entity.OrganizationType) {
|
||||
retVal = make([]entity.OrganizationType, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToOrganizationTypeEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *organizationMapping) ToOrganizationEntitySlice(list []viewmodel.Organization) (retVal []entity.Organization) {
|
||||
retVal = make([]entity.Organization, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToOrganizationEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationEntity(model viewmodel.Organization) entity.Organization {
|
||||
return entity.Organization{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
Type: mapping.ToOrganizationTypeEntity(model.Type),
|
||||
Name: model.Name,
|
||||
Description: model.Description,
|
||||
ReferenceID: model.ReferenceID,
|
||||
ParentID: model.ParentID,
|
||||
Main: model.Main,
|
||||
Created: model.Created,
|
||||
Updated: model.Updated,
|
||||
Active: model.Active,
|
||||
Blocked: model.Blocked,
|
||||
Suspended: model.Suspended,
|
||||
Author: mapping.mapper.User.ToUserEntity(model.Author),
|
||||
LastEditor: mapping.mapper.User.ToUserEntity(model.LastEditor),
|
||||
Contacts: mapping.ToOrganizationContactEntitySlice(model.Contacts),
|
||||
Addresses: mapping.ToOrganizationAddressEntitySlice(model.Addresses),
|
||||
ChildOrgs: mapping.ToOrganizationEntitySlice(model.ChildOrgs),
|
||||
Parent: mapping.ToOrganizationEntityPointer(model.Parent),
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationEntityPointer(model *viewmodel.Organization) *entity.Organization {
|
||||
if model != nil {
|
||||
convertibleModel := *model
|
||||
convertibleEntity := mapping.ToOrganizationEntity(convertibleModel)
|
||||
return &convertibleEntity
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationModelPointer(model *entity.Organization) *viewmodel.Organization {
|
||||
if model != nil {
|
||||
convertibleModel := *model
|
||||
convertibleEntity := mapping.ToOrganizationModel(convertibleModel)
|
||||
return &convertibleEntity
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationTypeEntity(model viewmodel.OrganizationType) entity.OrganizationType {
|
||||
return entity.OrganizationType{
|
||||
ID: model.ID,
|
||||
Name: model.Name,
|
||||
Key: model.Key,
|
||||
Description: model.Description,
|
||||
Created: model.Created,
|
||||
Updated: model.Updated,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationTypeModelSlice(list []entity.OrganizationType) (retVal []viewmodel.OrganizationType) {
|
||||
retVal = make([]viewmodel.OrganizationType, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToOrganizationTypeModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *organizationMapping) ToOrganizationModelSlice(list []entity.Organization) (retVal []viewmodel.Organization) {
|
||||
retVal = make([]viewmodel.Organization, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToOrganizationModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationModel(model entity.Organization) viewmodel.Organization {
|
||||
return viewmodel.Organization{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
Type: mapping.ToOrganizationTypeModel(model.Type),
|
||||
Name: model.Name,
|
||||
Description: model.Description,
|
||||
ReferenceID: model.ReferenceID,
|
||||
ParentID: model.ParentID,
|
||||
Main: model.Main,
|
||||
Created: model.Created,
|
||||
Updated: model.Updated,
|
||||
Active: model.Active,
|
||||
Blocked: model.Blocked,
|
||||
Suspended: model.Suspended,
|
||||
Author: mapping.mapper.User.ToUserModel(model.Author),
|
||||
LastEditor: mapping.mapper.User.ToUserModel(model.LastEditor),
|
||||
Contacts: mapping.ToOrganizationContactModelSlice(model.Contacts),
|
||||
Addresses: mapping.ToOrganizationAddressModelSlice(model.Addresses),
|
||||
ChildOrgs: mapping.ToOrganizationModelSlice(model.ChildOrgs),
|
||||
Parent: mapping.ToOrganizationModelPointer(model.Parent),
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationTypeModel(model entity.OrganizationType) viewmodel.OrganizationType {
|
||||
return viewmodel.OrganizationType{
|
||||
ID: model.ID,
|
||||
Name: model.Name,
|
||||
Key: model.Key,
|
||||
Description: model.Description,
|
||||
Created: model.Created,
|
||||
Updated: model.Updated,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationContactModel(model entity.OrganizationContact) viewmodel.OrganizationContact {
|
||||
return viewmodel.OrganizationContact{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
Type: mapping.mapper.User.ToContactTypeModel(model.Type),
|
||||
Contact: model.Contact,
|
||||
Name: model.Name,
|
||||
Description: model.Description,
|
||||
Created: model.Created,
|
||||
CreatedUser: mapping.mapper.User.ToUserModel(model.CreatedUser),
|
||||
Updated: model.Updated,
|
||||
UpdatedUser: mapping.mapper.User.ToUserModel(model.UpdatedUser),
|
||||
Active: model.Active,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationContactEntity(model viewmodel.OrganizationContact) entity.OrganizationContact {
|
||||
return entity.OrganizationContact{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
Type: mapping.mapper.User.ToContactTypeEntity(model.Type),
|
||||
Contact: model.Contact,
|
||||
Name: model.Name,
|
||||
Description: model.Description,
|
||||
Created: model.Created,
|
||||
CreatedUser: mapping.mapper.User.ToUserEntity(model.CreatedUser),
|
||||
Updated: model.Updated,
|
||||
UpdatedUser: mapping.mapper.User.ToUserEntity(model.UpdatedUser),
|
||||
Active: model.Active,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *organizationMapping) ToOrganizationContactModelSlice(list []entity.OrganizationContact) (retVal []viewmodel.OrganizationContact) {
|
||||
retVal = make([]viewmodel.OrganizationContact, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToOrganizationContactModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *organizationMapping) ToOrganizationContactEntitySlice(list []viewmodel.OrganizationContact) (retVal []entity.OrganizationContact) {
|
||||
retVal = make([]entity.OrganizationContact, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToOrganizationContactEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationAddressModel(model entity.OrganizationAddress) viewmodel.OrganizationAddress {
|
||||
return viewmodel.OrganizationAddress{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
InternalID: model.InternalID,
|
||||
Address: model.Address,
|
||||
Name: model.Name,
|
||||
Description: model.Description,
|
||||
Latitude: model.Latitude,
|
||||
Longitude: model.Longitude,
|
||||
Created: model.Created,
|
||||
CreatedUser: mapping.mapper.User.ToUserModel(model.CreatedUser),
|
||||
Updated: model.Updated,
|
||||
UpdatedUser: mapping.mapper.User.ToUserModel(model.UpdatedUser),
|
||||
Active: model.Active,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *organizationMapping) ToOrganizationAddressEntity(model viewmodel.OrganizationAddress) entity.OrganizationAddress {
|
||||
return entity.OrganizationAddress{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
InternalID: model.InternalID,
|
||||
Address: model.Address,
|
||||
Name: model.Name,
|
||||
Description: model.Description,
|
||||
Latitude: model.Latitude,
|
||||
Longitude: model.Longitude,
|
||||
Created: model.Created,
|
||||
CreatedUser: mapping.mapper.User.ToUserEntity(model.CreatedUser),
|
||||
Updated: model.Updated,
|
||||
UpdatedUser: mapping.mapper.User.ToUserEntity(model.UpdatedUser),
|
||||
Active: model.Active,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *organizationMapping) ToOrganizationAddressModelSlice(list []entity.OrganizationAddress) (retVal []viewmodel.OrganizationAddress) {
|
||||
retVal = make([]viewmodel.OrganizationAddress, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToOrganizationAddressModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *organizationMapping) ToOrganizationAddressEntitySlice(list []viewmodel.OrganizationAddress) (retVal []entity.OrganizationAddress) {
|
||||
retVal = make([]entity.OrganizationAddress, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToOrganizationAddressEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
65
application/entitymapping/profile.go
Normal file
65
application/entitymapping/profile.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// providerMapping has method to map provider entities to view models
|
||||
type profileMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *profileMapping) ToProfileEntitySlice(list []viewmodel.Profile) (retVal []entity.Profile) {
|
||||
retVal = make([]entity.Profile, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToProfileEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *profileMapping) ToProfileEntity(model viewmodel.Profile) entity.Profile {
|
||||
return entity.Profile{
|
||||
ID: model.ID,
|
||||
Key: model.Key,
|
||||
Name: model.Name,
|
||||
Description: model.Description,
|
||||
Created: model.Created,
|
||||
Updated: model.Updated,
|
||||
Active: model.Active,
|
||||
Visible: model.Visible,
|
||||
Blocked: model.Blocked,
|
||||
Suspended: model.Suspended,
|
||||
Organization: mapping.mapper.Organization.ToOrganizationEntity(model.Organization),
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *profileMapping) ToProfileModelSlice(list []entity.Profile) (retVal []viewmodel.Profile) {
|
||||
retVal = make([]viewmodel.Profile, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToProfileModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *profileMapping) ToProfileModel(model entity.Profile) viewmodel.Profile {
|
||||
return viewmodel.Profile{
|
||||
ID: model.ID,
|
||||
Key: model.Key,
|
||||
Name: model.Name,
|
||||
Description: model.Description,
|
||||
Created: model.Created,
|
||||
Updated: model.Updated,
|
||||
Active: model.Active,
|
||||
Visible: model.Visible,
|
||||
Blocked: model.Blocked,
|
||||
Suspended: model.Suspended,
|
||||
Organization: mapping.mapper.Organization.ToOrganizationModel(model.Organization),
|
||||
}
|
||||
}
|
||||
375
application/entitymapping/provider.go
Normal file
375
application/entitymapping/provider.go
Normal file
@@ -0,0 +1,375 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/third/npd/npdmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// providerMapping has method to map provider entities to view models
|
||||
type providerMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToProviderRespEntitySlice(list []viewmodel.ProviderResp) (retVal []entity.Provider) {
|
||||
retVal = make([]entity.Provider, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToProviderRespEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToProviderRespEntity(item viewmodel.ProviderResp) entity.Provider {
|
||||
return entity.Provider{
|
||||
ProviderUUID: item.ProviderUUID,
|
||||
InternalID: item.InternalID,
|
||||
InternalSuffixID: item.InternalSuffixID,
|
||||
MukID: item.MukID,
|
||||
OrganizatioName: item.OrganizatioName,
|
||||
Gender: item.Gender,
|
||||
AcceptNewPatients: item.AcceptNewPatients,
|
||||
Name: item.Name,
|
||||
FirstName: item.FirstName,
|
||||
MiddleName: item.MiddleName,
|
||||
LastName: item.LastName,
|
||||
Title: item.Title,
|
||||
Distance: item.Distance,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToProviderRespModelSlice(list []entity.Provider) (retVal []viewmodel.ProviderResp) {
|
||||
retVal = make([]viewmodel.ProviderResp, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToProviderRespModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToProviderRespModel(item entity.Provider) viewmodel.ProviderResp {
|
||||
return viewmodel.ProviderResp{
|
||||
ProviderUUID: item.ProviderUUID,
|
||||
InternalID: item.InternalID,
|
||||
InternalSuffixID: item.InternalSuffixID,
|
||||
MukID: item.MukID,
|
||||
OrganizatioName: item.OrganizatioName,
|
||||
Gender: item.Gender,
|
||||
AcceptNewPatients: item.AcceptNewPatients,
|
||||
Name: item.Name,
|
||||
FirstName: item.FirstName,
|
||||
MiddleName: item.MiddleName,
|
||||
LastName: item.LastName,
|
||||
Title: item.Title,
|
||||
Keys: mapping.ToProviderKeyModelSlice(item.Keys),
|
||||
Address: mapping.ToProviderRespAddressModel(item.Address),
|
||||
Distance: item.Distance,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToProviderKeyModelSlice(list []entity.ProviderKey) (retVal []viewmodel.ProviderKey) {
|
||||
retVal = make([]viewmodel.ProviderKey, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToProviderKeyModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToProviderKeyModel(item entity.ProviderKey) viewmodel.ProviderKey {
|
||||
return viewmodel.ProviderKey{
|
||||
InternalID: item.InternalID,
|
||||
InternalSuffixID: item.InternalSuffixID,
|
||||
LocationSeqNumber: item.LocationSeqNumber,
|
||||
PlanCode: item.PlanCode,
|
||||
ProductID: item.ProductID,
|
||||
TreatmentCategoryCode: item.TreatmentCategoryCode,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToProviderRespAddressModel(item entity.ProviderAddress) viewmodel.ProviderAddress {
|
||||
return viewmodel.ProviderAddress{
|
||||
StreetAddress1: item.StreetAddress1,
|
||||
StreetAddress2: item.StreetAddress2,
|
||||
CityName: item.CityName,
|
||||
State: item.State,
|
||||
ZipCode: item.ZipCode,
|
||||
Country: item.Country,
|
||||
Latitude: item.Latitude,
|
||||
Longitude: item.Longitude,
|
||||
PhoneNumber: item.PhoneNumber,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToProviderEntity(item npdmodel.ProviderResponse) entity.ProviderResponse {
|
||||
return entity.ProviderResponse{
|
||||
MukID: item.MukID,
|
||||
FivePartKeyGroups: mapping.ToPartKeyGroupEntitySlice(item.FivePartKeyGroups),
|
||||
OrgName: item.OrgName,
|
||||
Gender: item.Gender,
|
||||
AcceptNewPatients: item.AcceptNewPatients,
|
||||
ProviderName: item.ProviderName,
|
||||
FirstName: item.FirstName,
|
||||
LastName: item.LastName,
|
||||
MiddleName: item.MiddleName,
|
||||
ProviderTitle: item.ProviderTitle,
|
||||
StreetName1: item.StreetName1,
|
||||
StreetName2: item.StreetName2,
|
||||
CityName: item.CityName,
|
||||
State: item.State,
|
||||
ZipCode: item.ZipCode,
|
||||
Country: item.Country,
|
||||
Latitude: item.Latitude,
|
||||
Longitude: item.Longitude,
|
||||
PhoneNumber: item.PhoneNumber,
|
||||
ProviderEntityName: item.ProviderEntityName,
|
||||
ProviderEntityCode: item.ProviderEntityCode,
|
||||
ProviderTypeCode: mapping.ToProviderTypeCodeEntitySlice(item.ProviderTypeCode),
|
||||
Distance: item.Distance,
|
||||
AvailabilityOfCost: item.AvailabilityOfCost,
|
||||
TDDPhoneNumber: item.TDDPhoneNumber,
|
||||
ExtendedOfficeHours: item.ExtendedOfficeHours,
|
||||
ProviderCountyCode: item.ProviderCountyCode,
|
||||
ProviderCountyName: item.ProviderCountyName,
|
||||
HospitalAffiliationNames: mapping.ToHospitalAffiliationNamesEntitySlice(item.HospitalAffiliationNames),
|
||||
ProviderAffiliationNumber: item.ProviderAffiliationNumber,
|
||||
ProviderAffiliationName: item.ProviderAffiliationName,
|
||||
LanguagesSpoken: mapping.ToLanguagesEntitySlice(item.LanguagesSpoken),
|
||||
OfficeLanguagesSpoken: mapping.ToLanguagesEntitySlice(item.OfficeLanguagesSpoken),
|
||||
MedSchool: item.MedSchool,
|
||||
MedSchoolYear: item.MedSchoolYear,
|
||||
Internship: item.Internship,
|
||||
Residence: item.Residence,
|
||||
Specialty1: item.Specialty1,
|
||||
Specialty2: item.Specialty2,
|
||||
Specialty3: item.Specialty3,
|
||||
Specialty4: item.Specialty4,
|
||||
Certification1: item.Certification1,
|
||||
Certification2: item.Certification2,
|
||||
Certification3: item.Certification3,
|
||||
Certification4: item.Certification4,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToProviderModel(item entity.ProviderResponse) npdmodel.ProviderResponse {
|
||||
return npdmodel.ProviderResponse{
|
||||
MukID: item.MukID,
|
||||
FivePartKeyGroups: mapping.ToPartKeyGroupModelSlice(item.FivePartKeyGroups),
|
||||
OrgName: item.OrgName,
|
||||
Gender: item.Gender,
|
||||
AcceptNewPatients: item.AcceptNewPatients,
|
||||
ProviderName: item.ProviderName,
|
||||
FirstName: item.FirstName,
|
||||
LastName: item.LastName,
|
||||
MiddleName: item.MiddleName,
|
||||
ProviderTitle: item.ProviderTitle,
|
||||
StreetName1: item.StreetName1,
|
||||
StreetName2: item.StreetName2,
|
||||
CityName: item.CityName,
|
||||
State: item.State,
|
||||
ZipCode: item.ZipCode,
|
||||
Country: item.Country,
|
||||
Latitude: item.Latitude,
|
||||
Longitude: item.Longitude,
|
||||
PhoneNumber: item.PhoneNumber,
|
||||
ProviderEntityName: item.ProviderEntityName,
|
||||
ProviderEntityCode: item.ProviderEntityCode,
|
||||
ProviderTypeCode: mapping.ToProviderTypeCodeModelSlice(item.ProviderTypeCode),
|
||||
Distance: item.Distance,
|
||||
AvailabilityOfCost: item.AvailabilityOfCost,
|
||||
TDDPhoneNumber: item.TDDPhoneNumber,
|
||||
ExtendedOfficeHours: item.ExtendedOfficeHours,
|
||||
ProviderCountyCode: item.ProviderCountyCode,
|
||||
ProviderCountyName: item.ProviderCountyName,
|
||||
HospitalAffiliationNames: mapping.ToHospitalAffiliationNamesModelSlice(item.HospitalAffiliationNames),
|
||||
ProviderAffiliationNumber: item.ProviderAffiliationNumber,
|
||||
ProviderAffiliationName: item.ProviderAffiliationName,
|
||||
LanguagesSpoken: mapping.ToLanguagesModelSlice(item.LanguagesSpoken),
|
||||
OfficeLanguagesSpoken: mapping.ToLanguagesModelSlice(item.OfficeLanguagesSpoken),
|
||||
MedSchool: item.MedSchool,
|
||||
MedSchoolYear: item.MedSchoolYear,
|
||||
Internship: item.Internship,
|
||||
Residence: item.Residence,
|
||||
Specialty1: item.Specialty1,
|
||||
Specialty2: item.Specialty2,
|
||||
Specialty3: item.Specialty3,
|
||||
Specialty4: item.Specialty4,
|
||||
Certification1: item.Certification1,
|
||||
Certification2: item.Certification2,
|
||||
Certification3: item.Certification3,
|
||||
Certification4: item.Certification4}
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToHospitalAffiliationNamesEntity(item npdmodel.HospitalAffiliationNames) entity.HospitalAffiliationNames {
|
||||
return entity.HospitalAffiliationNames{
|
||||
HospAffProvOrgName: item.HospAffProvOrgName,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToHospitalAffiliationNamesModel(item entity.HospitalAffiliationNames) npdmodel.HospitalAffiliationNames {
|
||||
return npdmodel.HospitalAffiliationNames{
|
||||
HospAffProvOrgName: item.HospAffProvOrgName,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToHospitalAffiliationNamesEntitySlice(list []npdmodel.HospitalAffiliationNames) (retVal []entity.HospitalAffiliationNames) {
|
||||
retVal = make([]entity.HospitalAffiliationNames, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToHospitalAffiliationNamesEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToHospitalAffiliationNamesModelSlice(list []entity.HospitalAffiliationNames) (retVal []npdmodel.HospitalAffiliationNames) {
|
||||
retVal = make([]npdmodel.HospitalAffiliationNames, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToHospitalAffiliationNamesModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToLanguagesEntity(item npdmodel.Languages) entity.Languages {
|
||||
return entity.Languages{
|
||||
Code: item.Code,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToLanguagesModel(item entity.Languages) npdmodel.Languages {
|
||||
return npdmodel.Languages{
|
||||
Code: item.Code,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToLanguagesEntitySlice(list []npdmodel.Languages) (retVal []entity.Languages) {
|
||||
retVal = make([]entity.Languages, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToLanguagesEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToLanguagesModelSlice(list []entity.Languages) (retVal []npdmodel.Languages) {
|
||||
retVal = make([]npdmodel.Languages, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToLanguagesModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToProviderTypeCodeEntity(item npdmodel.ProviderTypeCode) entity.ProviderTypeCode {
|
||||
return entity.ProviderTypeCode{
|
||||
Code: item.Code,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToProviderTypeCodeModel(item entity.ProviderTypeCode) npdmodel.ProviderTypeCode {
|
||||
return npdmodel.ProviderTypeCode{
|
||||
Code: item.Code,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToProviderTypeCodeEntitySlice(list []npdmodel.ProviderTypeCode) (retVal []entity.ProviderTypeCode) {
|
||||
retVal = make([]entity.ProviderTypeCode, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToProviderTypeCodeEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToProviderTypeCodeModelSlice(list []entity.ProviderTypeCode) (retVal []npdmodel.ProviderTypeCode) {
|
||||
retVal = make([]npdmodel.ProviderTypeCode, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToProviderTypeCodeModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToPartKeyGroupEntity(item npdmodel.PartKeyGroup) entity.PartKeyGroup {
|
||||
return entity.PartKeyGroup{
|
||||
ProviderNum: item.ProviderNum,
|
||||
ProviderNumSuffix: item.ProviderNumSuffix,
|
||||
LocationSeqNum: item.LocationSeqNum,
|
||||
PlanCode: item.PlanCode,
|
||||
ProductID: item.ProductID,
|
||||
TreatmentCategoryCode: item.TreatmentCategoryCode,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *providerMapping) ToPartKeyGroupModel(item entity.PartKeyGroup) npdmodel.PartKeyGroup {
|
||||
return npdmodel.PartKeyGroup{
|
||||
ProviderNum: item.ProviderNum,
|
||||
ProviderNumSuffix: item.ProviderNumSuffix,
|
||||
LocationSeqNum: item.LocationSeqNum,
|
||||
PlanCode: item.PlanCode,
|
||||
ProductID: item.ProductID,
|
||||
TreatmentCategoryCode: item.TreatmentCategoryCode,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToPartKeyGroupEntitySlice(list []npdmodel.PartKeyGroup) (retVal []entity.PartKeyGroup) {
|
||||
retVal = make([]entity.PartKeyGroup, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToPartKeyGroupEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToPartKeyGroupModelSlice(list []entity.PartKeyGroup) (retVal []npdmodel.PartKeyGroup) {
|
||||
retVal = make([]npdmodel.PartKeyGroup, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToPartKeyGroupModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToProviderEntitySlice(list []npdmodel.ProviderResponse) (retVal []entity.ProviderResponse) {
|
||||
retVal = make([]entity.ProviderResponse, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToProviderEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *providerMapping) ToProviderModelSlice(list []entity.ProviderResponse) (retVal []npdmodel.ProviderResponse) {
|
||||
retVal = make([]npdmodel.ProviderResponse, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToProviderModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
254
application/entitymapping/ride.go
Normal file
254
application/entitymapping/ride.go
Normal file
@@ -0,0 +1,254 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// rideMapping has method to map ride entities to view models
|
||||
type rideMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRideModel(item entity.Ride) viewmodel.Ride {
|
||||
return viewmodel.Ride{
|
||||
User: mapping.mapper.User.ToUserModel(item.User),
|
||||
Status: mapping.ToRideStatusModel(item.Status),
|
||||
Type: mapping.ToRideTypeModel(item.Type),
|
||||
UUID: item.UUID,
|
||||
Note: item.Note,
|
||||
Driver: mapping.ToDriverUserModel(item.Driver),
|
||||
Passenger: mapping.ToPassengerUserModel(item.Passenger),
|
||||
Vehicle: mapping.ToVehicleModel(item.Vehicle),
|
||||
Route: mapping.ToRouteModel(item.Route),
|
||||
PickupTime: item.PickupTime,
|
||||
VisitDate: item.VisitDate,
|
||||
VisitTime: item.VisitTime,
|
||||
InternalID: item.InternalID,
|
||||
Visit: mapping.mapper.Visit.ToVisitModel(item.Visit),
|
||||
CreatedUser: mapping.mapper.User.ToUserModel(item.CreatedUser),
|
||||
CreateAt: item.Created,
|
||||
UpdateAt: item.Updated,
|
||||
TripType: mapping.mapper.Visit.ToTripTypeModel(item.TripType),
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRideInternalEntity(item viewmodel.Ride) entity.Ride {
|
||||
return entity.Ride{
|
||||
User: mapping.mapper.User.ToUserEntity(item.User),
|
||||
UUID: item.UUID,
|
||||
Note: item.Note,
|
||||
PickupTime: item.PickupTime,
|
||||
VisitDate: item.VisitDate,
|
||||
VisitTime: item.VisitTime,
|
||||
InternalID: item.InternalID,
|
||||
TripType: mapping.mapper.Visit.ToTripTypeEntity(item.TripType),
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRouteModel(item entity.RideRoute) viewmodel.RideRoute {
|
||||
return viewmodel.RideRoute{
|
||||
Origin: mapping.ToLocationModel(item.Origin),
|
||||
Destination: mapping.ToLocationModel(item.Destination),
|
||||
RouteKML: item.RouteKML,
|
||||
ETA: item.ETA,
|
||||
Distance: item.Distance,
|
||||
Duration: item.Duration,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToLocationModel(item entity.Location) viewmodel.Location {
|
||||
return viewmodel.Location{
|
||||
ID: item.ID,
|
||||
Name: item.Name,
|
||||
Address: item.Address,
|
||||
Latitude: item.Latitude,
|
||||
Longitude: item.Longitude,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToVehicleModel(item entity.RideVehicle) viewmodel.Vehicle {
|
||||
return viewmodel.Vehicle{
|
||||
Color: item.Color,
|
||||
Make: item.Make,
|
||||
LicensePlate: item.LicensePlate,
|
||||
ImageURL: item.ImageURL,
|
||||
Year: item.Year,
|
||||
LicensePlateState: item.LicensePlateState,
|
||||
Model: item.Model,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToDriverUserModel(item entity.RideDriver) viewmodel.UserLyft {
|
||||
return viewmodel.UserLyft{
|
||||
FirstName: item.Name,
|
||||
ImageURL: item.ImageURL,
|
||||
PhoneNumber: item.PhoneNumber,
|
||||
Rating: item.Rating,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToPassengerUserModel(item entity.RidePassenger) viewmodel.UserLyft {
|
||||
return viewmodel.UserLyft{
|
||||
FirstName: item.FirstName,
|
||||
LastName: item.LastName,
|
||||
ImageURL: item.ImageURL,
|
||||
PhoneNumber: item.PhoneNumber,
|
||||
UserID: item.InternalID,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRideStatusModel(item entity.RideStatus) viewmodel.RideStatus {
|
||||
return viewmodel.RideStatus{
|
||||
Value: item.Value,
|
||||
Key: item.Key,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRideTypeModel(item entity.RideType) viewmodel.RideType {
|
||||
return viewmodel.RideType{
|
||||
Value: item.Value,
|
||||
Key: item.Key,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToWebhookEntity(item viewmodel.WebhookResponse) entity.WebhookResponse {
|
||||
occurredAt, _ := time.Parse(time.RFC3339Nano, item.OccurredAt)
|
||||
|
||||
return entity.WebhookResponse{
|
||||
EventID: item.EventID,
|
||||
HREF: item.HREF,
|
||||
OccurredAt: occurredAt,
|
||||
EventType: item.EventType,
|
||||
Ride: mapping.ToRideEntity(item.Event),
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserModel maps a User entity to User view model
|
||||
func (mapping *rideMapping) ToRideEntity(item viewmodel.RideRequest) entity.Ride {
|
||||
return entity.Ride{
|
||||
User: entity.User{
|
||||
UUID: item.UserUUID,
|
||||
},
|
||||
Status: mapping.ToRideStatusEntity(item),
|
||||
Type: mapping.ToRideTypeEntity(item),
|
||||
InternalID: item.RideID,
|
||||
RequestDate: item.RequestAt,
|
||||
RequestMiliseconds: item.RequestAtMS,
|
||||
GenerateDate: item.GeneratedAt,
|
||||
GenerateMiliseconds: item.GeneratedAtMS,
|
||||
Note: item.Notes,
|
||||
PrimetimePercentage: item.PrimetimePercentage,
|
||||
Passenger: mapping.ToRidePassengerEntity(item),
|
||||
Driver: mapping.ToRideDriverEntity(item),
|
||||
Vehicle: mapping.ToRideVehicleEntity(item),
|
||||
Route: mapping.ToRideRouteEntity(item),
|
||||
PickupTime: item.PickupTime,
|
||||
VisitDate: item.VisitDate,
|
||||
VisitTime: item.VisitTime,
|
||||
Visit: mapping.mapper.Visit.ToVisitEntity(item.Visit),
|
||||
TripType: mapping.mapper.Visit.ToTripTypeEntity(item.TripType),
|
||||
CreatedUser: entity.User{
|
||||
UUID: item.CreateUserUUID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRideRouteEntity(item viewmodel.RideRequest) entity.RideRoute {
|
||||
return entity.RideRoute{
|
||||
Origin: mapping.ToLocationEntity(item.Origin),
|
||||
Destination: mapping.ToLocationEntity(item.Destination),
|
||||
RouteKML: &item.RouteURL,
|
||||
ETA: item.ETA,
|
||||
Distance: item.Distance,
|
||||
Duration: item.Duration,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToLocationEntity(item viewmodel.Location) entity.Location {
|
||||
return entity.Location{
|
||||
ID: item.ID,
|
||||
Name: item.Name,
|
||||
Address: item.Address,
|
||||
Latitude: item.Latitude,
|
||||
Longitude: item.Longitude,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRideVehicleEntity(item viewmodel.RideRequest) entity.RideVehicle {
|
||||
return entity.RideVehicle{
|
||||
Color: item.Vehicle.Color,
|
||||
Make: item.Vehicle.Make,
|
||||
LicensePlate: item.Vehicle.LicensePlate,
|
||||
LicensePlateState: item.Vehicle.LicensePlateState,
|
||||
ImageURL: item.Vehicle.ImageURL,
|
||||
Model: item.Vehicle.Model,
|
||||
Year: item.Vehicle.Year,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRideDriverEntity(item viewmodel.RideRequest) entity.RideDriver {
|
||||
return entity.RideDriver{
|
||||
Name: item.Driver.FirstName,
|
||||
ImageURL: item.Driver.ImageURL,
|
||||
PhoneNumber: item.Driver.PhoneNumber,
|
||||
Rating: item.Driver.Rating,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRidePassengerEntity(item viewmodel.RideRequest) entity.RidePassenger {
|
||||
return entity.RidePassenger{
|
||||
FirstName: item.Passenger.FirstName,
|
||||
LastName: item.Passenger.LastName,
|
||||
ImageURL: item.Passenger.ImageURL,
|
||||
PhoneNumber: item.Passenger.PhoneNumber,
|
||||
InternalID: item.Passenger.UserID,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRideStatusEntity(item viewmodel.RideRequest) entity.RideStatus {
|
||||
return entity.RideStatus{
|
||||
Key: item.Status,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *rideMapping) ToRideTypeEntity(item viewmodel.RideRequest) entity.RideType {
|
||||
return entity.RideType{
|
||||
Key: item.RideType,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *rideMapping) ToRideEntitySlice(list []viewmodel.RideRequest) (retVal []entity.Ride) {
|
||||
retVal = make([]entity.Ride, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToRideEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *rideMapping) ToRideInternalEntitySlice(list []viewmodel.Ride) (retVal []entity.Ride) {
|
||||
retVal = make([]entity.Ride, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToRideInternalEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToRideModelSlice maps a Ride entity slice to Ride view model slice
|
||||
func (mapping *rideMapping) ToRideModelSlice(list []entity.Ride) (retVal []viewmodel.Ride) {
|
||||
retVal = make([]viewmodel.Ride, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToRideModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
194
application/entitymapping/user.go
Normal file
194
application/entitymapping/user.go
Normal file
@@ -0,0 +1,194 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// userMapping has method to map User entities to view models
|
||||
type userMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
// ToUserModel maps a User entity to User view model
|
||||
func (mapping *userMapping) ToUserModel(item entity.User) viewmodel.User {
|
||||
var birthDate *time.Time
|
||||
if !item.BirthDate.IsZero() {
|
||||
birthDate = &item.BirthDate
|
||||
}
|
||||
|
||||
first := ""
|
||||
last := ""
|
||||
fullName := strings.Split(item.Name, " ")
|
||||
if len(fullName) > 0 {
|
||||
first = fullName[0]
|
||||
if len(fullName) > 1 {
|
||||
last = fullName[len(fullName)-1]
|
||||
}
|
||||
}
|
||||
|
||||
return viewmodel.User{
|
||||
ID: item.UUID,
|
||||
Name: item.Name,
|
||||
First: first,
|
||||
Last: last,
|
||||
Email: &item.Email,
|
||||
PhoneNumber: &item.PhoneNumber,
|
||||
Gender: &item.Gender,
|
||||
Member: &item.Member,
|
||||
BirthDate: birthDate,
|
||||
Active: item.Active,
|
||||
Created: item.Created,
|
||||
Updated: item.Updated,
|
||||
Contacts: mapping.ToContactModelSlice(item.Contacts),
|
||||
Rides: mapping.mapper.Ride.ToRideModelSlice(item.Rides),
|
||||
Addresses: mapping.mapper.Address.ToAddressModelSlice(item.Addresses),
|
||||
Profiles: mapping.mapper.Profile.ToProfileModelSlice(item.Profiles),
|
||||
Organizations: mapping.mapper.Organization.ToOrganizationModelSlice(item.Organizations),
|
||||
Types: mapping.mapper.Organization.ToOrganizationTypeModelSlice(item.Types),
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserModelSlice maps a User entity slice to User view model slice
|
||||
func (mapping *userMapping) ToUserModelSlice(list []entity.User) (retVal []viewmodel.User) {
|
||||
retVal = make([]viewmodel.User, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToUserModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToUserModel maps a User entity to User view model
|
||||
func (mapping *userMapping) ToUserEntity(item viewmodel.User) entity.User {
|
||||
user := entity.User{
|
||||
UUID: item.ID,
|
||||
Name: item.Name,
|
||||
Pass: item.Pass,
|
||||
Active: item.Active,
|
||||
Created: item.Created,
|
||||
Updated: item.Updated,
|
||||
Contacts: mapping.ToContactEntitySlice(item.Contacts),
|
||||
Profiles: mapping.mapper.Profile.ToProfileEntitySlice(item.Profiles),
|
||||
Organizations: mapping.mapper.Organization.ToOrganizationEntitySlice(item.Organizations),
|
||||
Types: mapping.mapper.Organization.ToOrganizationTypeEntitySlice(item.Types),
|
||||
}
|
||||
|
||||
if user.Name == "" {
|
||||
user.Name = fmt.Sprintf("%s %s", item.First, item.Last)
|
||||
}
|
||||
|
||||
if item.Email != nil {
|
||||
user.Email = *item.Email
|
||||
}
|
||||
|
||||
if item.PhoneNumber != nil {
|
||||
user.PhoneNumber = *item.PhoneNumber
|
||||
}
|
||||
|
||||
if item.Gender != nil {
|
||||
user.Gender = *item.Gender
|
||||
}
|
||||
|
||||
if item.Member != nil {
|
||||
user.Member = *item.Member
|
||||
}
|
||||
|
||||
if item.BirthDate != nil {
|
||||
user.BirthDate = *item.BirthDate
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *userMapping) ToUserEntitySlice(list []viewmodel.User) (retVal []entity.User) {
|
||||
retVal = make([]entity.User, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToUserEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToContactTypeEntity maps a Contact type entity to Contact Type view model
|
||||
func (mapping *userMapping) ToContactTypeEntity(item viewmodel.ContactType) entity.ContactType {
|
||||
return entity.ContactType{
|
||||
Key: item.Key,
|
||||
Value: item.Value,
|
||||
}
|
||||
}
|
||||
|
||||
// ToContactTypeEntitySlice maps a User entity slice to Contact Type view model slice
|
||||
func (mapping *userMapping) ToContactTypeEntitySlice(list []viewmodel.ContactType) (retVal []entity.ContactType) {
|
||||
retVal = make([]entity.ContactType, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToContactTypeEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToContactTypeModel maps a Contact type entity to Contact Type view model
|
||||
func (mapping *userMapping) ToContactTypeModel(item entity.ContactType) viewmodel.ContactType {
|
||||
return viewmodel.ContactType{
|
||||
Key: item.Key,
|
||||
Value: item.Value,
|
||||
}
|
||||
}
|
||||
|
||||
// ToContactTypeModelSlice maps a User entity slice to Contact Type view model slice
|
||||
func (mapping *userMapping) ToContactTypeModelSlice(list []entity.ContactType) (retVal []viewmodel.ContactType) {
|
||||
retVal = make([]viewmodel.ContactType, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToContactTypeModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToContactModel maps a Contact entity to Contact view model
|
||||
func (mapping *userMapping) ToContactModel(item entity.ContactInfo) viewmodel.Contact {
|
||||
return viewmodel.Contact{
|
||||
Type: mapping.ToContactTypeModel(item.Type),
|
||||
Value: item.Value,
|
||||
}
|
||||
}
|
||||
|
||||
// ToContactModelSlice maps a Contact entity slice to Contact view model slice
|
||||
func (mapping *userMapping) ToContactModelSlice(list []entity.ContactInfo) (retVal []viewmodel.Contact) {
|
||||
retVal = make([]viewmodel.Contact, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToContactModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToContactEntity maps a Contact entity to Contact view model
|
||||
func (mapping *userMapping) ToContactEntity(item viewmodel.Contact) entity.ContactInfo {
|
||||
return entity.ContactInfo{
|
||||
Type: mapping.ToContactTypeEntity(item.Type),
|
||||
Value: item.Value,
|
||||
}
|
||||
}
|
||||
|
||||
// ToContactEntitySlice maps a Contact entity slice to Contact view model slice
|
||||
func (mapping *userMapping) ToContactEntitySlice(list []viewmodel.Contact) (retVal []entity.ContactInfo) {
|
||||
retVal = make([]entity.ContactInfo, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToContactEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
131
application/entitymapping/visit.go
Normal file
131
application/entitymapping/visit.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// rideMapping has method to map ride entities to view models
|
||||
type visitMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
// ToVisitEntity maps a User entity to User view model
|
||||
func (mapping *visitMapping) ToVisitEntity(item viewmodel.Visit) entity.Visit {
|
||||
return entity.Visit{
|
||||
UUID: item.UUID,
|
||||
Status: mapping.ToVisitStatusEntity(item.Status),
|
||||
User: mapping.mapper.User.ToUserEntity(item.User),
|
||||
VisitDuration: item.VisitDuration,
|
||||
VisitDatetime: item.VisitDatetime,
|
||||
PickupDatetime: item.PickupDatetime,
|
||||
Notes: item.Notes,
|
||||
PickupAddressID: item.PickupAddressID,
|
||||
DestinationAddressID: item.DestinationAddressID,
|
||||
Pickup: mapping.mapper.Ride.ToLocationEntity(item.Pickup),
|
||||
Provider: mapping.mapper.Provider.ToProviderRespEntity(item.Provider),
|
||||
CreatedUser: mapping.mapper.User.ToUserEntity(item.CreatedUser),
|
||||
Created: item.CreatedDate,
|
||||
Updated: item.UpdatedDate,
|
||||
ReturnDate: item.ReturnDate,
|
||||
ExternalID: item.ExternalID,
|
||||
TripType: mapping.ToTripTypeEntity(item.TripType),
|
||||
Rides: mapping.mapper.Ride.ToRideInternalEntitySlice(item.Rides),
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *visitMapping) ToVisitStatusEntity(item viewmodel.VisitStatus) entity.VisitStatus {
|
||||
return entity.VisitStatus{
|
||||
Value: item.Value,
|
||||
Key: item.Key,
|
||||
}
|
||||
}
|
||||
|
||||
// ToVisitEntity maps a User entity to User view model
|
||||
func (mapping *visitMapping) ToVisitModel(item entity.Visit) viewmodel.Visit {
|
||||
return viewmodel.Visit{
|
||||
UUID: item.UUID,
|
||||
Status: mapping.ToVisitStatusModel(item.Status),
|
||||
User: mapping.mapper.User.ToUserModel(item.User),
|
||||
VisitDuration: item.VisitDuration,
|
||||
VisitDatetime: item.VisitDatetime,
|
||||
PickupDatetime: item.PickupDatetime,
|
||||
Notes: item.Notes,
|
||||
PickupAddressID: item.PickupAddressID,
|
||||
DestinationAddressID: item.DestinationAddressID,
|
||||
Pickup: mapping.mapper.Ride.ToLocationModel(item.Pickup),
|
||||
Provider: mapping.mapper.Provider.ToProviderRespModel(item.Provider),
|
||||
CreatedUser: mapping.mapper.User.ToUserModel(item.CreatedUser),
|
||||
CreatedDate: item.Created,
|
||||
UpdatedDate: item.Updated,
|
||||
ReturnDate: item.ReturnDate,
|
||||
ExternalID: item.ExternalID,
|
||||
TripType: mapping.ToTripTypeModel(item.TripType),
|
||||
Rides: mapping.mapper.Ride.ToRideModelSlice(item.Rides),
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *visitMapping) ToVisitStatusModel(item entity.VisitStatus) viewmodel.VisitStatus {
|
||||
return viewmodel.VisitStatus{
|
||||
Value: item.Value,
|
||||
Key: item.Key,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *visitMapping) ToVisitEntitySlice(list []viewmodel.Visit) (retVal []entity.Visit) {
|
||||
retVal = make([]entity.Visit, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToVisitEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToRideModelSlice maps a Ride entity slice to Ride view model slice
|
||||
func (mapping *visitMapping) ToVisitModelSlice(list []entity.Visit) (retVal []viewmodel.Visit) {
|
||||
retVal = make([]viewmodel.Visit, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToVisitModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *visitMapping) ToTripTypeModel(item entity.TripType) viewmodel.TripType {
|
||||
return viewmodel.TripType{
|
||||
Value: item.Value,
|
||||
Key: item.Key,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapping *visitMapping) ToTripTypeEntity(item viewmodel.TripType) entity.TripType {
|
||||
return entity.TripType{
|
||||
Value: item.Value,
|
||||
Key: item.Key,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *visitMapping) ToTripTypeEntitySlice(list []viewmodel.TripType) (retVal []entity.TripType) {
|
||||
retVal = make([]entity.TripType, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToTripTypeEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
// ToRideModelSlice maps a Ride entity slice to Ride view model slice
|
||||
func (mapping *visitMapping) ToTripTypeModelSlice(list []entity.TripType) (retVal []viewmodel.TripType) {
|
||||
retVal = make([]viewmodel.TripType, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToTripTypeModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
Reference in New Issue
Block a user