Upstream sync
This commit is contained in:
@@ -23,6 +23,7 @@ type Service struct {
|
||||
Notification *notificationService
|
||||
Profile *profileService
|
||||
Organization *organizationService
|
||||
Zipcodes *zipcodeService
|
||||
}
|
||||
|
||||
// New returns a new domain Service instance
|
||||
@@ -36,6 +37,7 @@ func New(svc *service.Service, mapper *entitymapping.Mapper, notification *notif
|
||||
Notification: newNotificationService(svc, mapper, notification, cfg),
|
||||
Profile: newProfileService(svc, mapper),
|
||||
Organization: newOrganizationService(svc, mapper),
|
||||
Zipcodes: newZipcodeService(svc, mapper),
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
37
application/applicationservice/zipcode.go
Normal file
37
application/applicationservice/zipcode.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package applicationservice
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/entitymapping"
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/service"
|
||||
)
|
||||
|
||||
// zipcodeService holds methods to participating zipcode application service
|
||||
type zipcodeService struct {
|
||||
svc *service.Service
|
||||
mapEntity *entitymapping.Mapper
|
||||
}
|
||||
|
||||
// newZipcodeService returns a zipcodeService instance
|
||||
func newZipcodeService(svc *service.Service, mapper *entitymapping.Mapper) *zipcodeService {
|
||||
return &zipcodeService{
|
||||
svc: svc,
|
||||
mapEntity: mapper,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *zipcodeService) GetAll() ([]viewmodel.Zipcode, error) {
|
||||
result, err := s.svc.Zipcodes.GetAll()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.mapEntity.Zipcode.ToZipcodeModelSlice(result), nil
|
||||
}
|
||||
|
||||
func (s *zipcodeService) GetByParticipatingZipcode(zipcode string) (viewmodel.Zipcode, error) {
|
||||
result, err := s.svc.Zipcodes.GetByParticipatingZipcode(zipcode)
|
||||
if err != nil {
|
||||
return viewmodel.Zipcode{}, err
|
||||
}
|
||||
return s.mapEntity.Zipcode.ToZipcodeModel(result), nil
|
||||
}
|
||||
@@ -21,6 +21,7 @@ type Mapper struct {
|
||||
Notification *notificationMapping
|
||||
Profile *profileMapping
|
||||
Organization *organizationMapping
|
||||
Zipcode *zipcodeMapping
|
||||
}
|
||||
|
||||
// New returns an EntityMapper for fluent mapping
|
||||
@@ -36,6 +37,7 @@ func New() *Mapper {
|
||||
instance.Notification = ¬ificationMapping{instance}
|
||||
instance.Profile = &profileMapping{instance}
|
||||
instance.Organization = &organizationMapping{instance}
|
||||
instance.Zipcode = &zipcodeMapping{instance}
|
||||
})
|
||||
|
||||
return instance
|
||||
|
||||
51
application/entitymapping/zipcode.go
Normal file
51
application/entitymapping/zipcode.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// zipcodeMapping has method to map zipcode entities to view models
|
||||
type zipcodeMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *zipcodeMapping) ToZipcodeEntitySlice(list []viewmodel.Zipcode) (retVal []entity.Zipcode) {
|
||||
retVal = make([]entity.Zipcode, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToZipcodeEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *zipcodeMapping) ToZipcodeEntity(model viewmodel.Zipcode) entity.Zipcode {
|
||||
return entity.Zipcode{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
Zipcode: model.Zipcode,
|
||||
Participating: model.Participating,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *zipcodeMapping) ToZipcodeModelSlice(list []entity.Zipcode) (retVal []viewmodel.Zipcode) {
|
||||
retVal = make([]viewmodel.Zipcode, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToZipcodeModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *zipcodeMapping) ToZipcodeModel(model entity.Zipcode) viewmodel.Zipcode {
|
||||
return viewmodel.Zipcode{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
Zipcode: model.Zipcode,
|
||||
Participating: model.Participating,
|
||||
}
|
||||
}
|
||||
8
application/viewmodel/zipcode.go
Normal file
8
application/viewmodel/zipcode.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package viewmodel
|
||||
|
||||
type Zipcode struct {
|
||||
ID int64 `json:"-"`
|
||||
UUID string `json:"uuid"`
|
||||
Zipcode string `json:"zipcode"`
|
||||
Participating bool `json:"participating"`
|
||||
}
|
||||
Reference in New Issue
Block a user