Upstream sync

This commit is contained in:
Senad Uka
2018-05-25 09:12:42 +02:00
parent 6e903b4d57
commit 94229831e0
38 changed files with 1281 additions and 156 deletions

View File

@@ -13,6 +13,7 @@ type repoManager interface {
Profile() ProfileRepo
Organization() OrganizationRepo
Zipcodes() ZipcodeRepo
Plans() PlanRepo
}
// UserRepo defines the data set for users
@@ -20,6 +21,7 @@ type UserRepo interface {
GetAll() (list []entity.User, err error)
GetByID(userID int64) (retVal entity.User, err error)
GetByUUID(uuid string, profile string) (entity.User, error)
GetByMemberID(memberID string) (entity.User, error)
Login(email string, pass string) (entity.User, error)
FullLogin(loginType string, key string, pass string, profile string) (entity.User, error)
Create(user entity.User) (entity.User, error)
@@ -30,6 +32,7 @@ type UserRepo interface {
RemoveAddress(addressUUID string) error
SaveContact(contact entity.ContactInfo) (entity.ContactInfo, error)
RemoveContact(contact entity.ContactInfo) (entity.ContactInfo, error)
UpdateLogin(user entity.User) error
}
// RideRepo defines the data set for Rides
@@ -59,6 +62,7 @@ type ProviderRepo interface {
GetByMukID(mukID string, user entity.User) (entity.Provider, error)
GetByUUID(providerUUID string, user entity.User) (entity.Provider, error)
GetByNPI(NPI string, user entity.User) (entity.Provider, error)
GetByID(providerID int64, user entity.User) (entity.Provider, error)
}
// NotificationRepo defines the data set for Notification
@@ -94,6 +98,13 @@ type OrganizationRepo interface {
GetTypeByKey(key string) (entity.OrganizationType, error)
}
type PlanRepo interface {
GetByAlphaPrefix(alphaPrefix string) (entity.Plan, error)
GetByUUID(planUUID string) ([]entity.Plan, error)
GetByID(planID int64) ([]entity.Plan, error)
GetByPrefixUUID(prefixUUID string) (entity.Plan, error)
}
// VisitRepo defines the data set for Rides
type VisitRepo interface {
Create(visit entity.Visit) (entity.Visit, error)

21
domain/entity/plan.go Normal file
View File

@@ -0,0 +1,21 @@
package entity
import "time"
type Plan struct {
ID int64 `json:"-"`
UUID string `json:"id"`
Name string `json:"name"`
InternalID string `json:"key"`
Status bool `json:"desc"`
PlanEntityID int64 `json:"plan_entity_id"`
EntityID int64 `json:"entity_id"`
PayerID int64 `json:"payer_id"`
PayerName string `json:"payer_name"`
PrefixID int64 `json:"prefix_id"`
PrefixUUID string `json:"prefix_uuid"`
AlphaPrefix string `json:"alpha_prefix"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Active bool `json:"active"`
}

31
domain/service/plan.go Normal file
View File

@@ -0,0 +1,31 @@
package service
import (
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
)
type planService struct {
svc *Service
}
func newPlanService(svc *Service) *planService {
return &planService{
svc: svc,
}
}
func (s *planService) GetByAlphaPrefix(alphaPrefix string) (entity.Plan, error) {
return s.svc.db.Plans().GetByAlphaPrefix(alphaPrefix)
}
func (s *planService) GetByUUID(planUUID string) ([]entity.Plan, error) {
return s.svc.db.Plans().GetByUUID(planUUID)
}
func (s *planService) GetByID(planID int64) ([]entity.Plan, error) {
return s.svc.db.Plans().GetByID(planID)
}
func (s *planService) GetByPrefixUUID(prefixUUID string) (entity.Plan, error) {
return s.svc.db.Plans().GetByPrefixUUID(prefixUUID)
}

View File

@@ -1,6 +1,8 @@
package service
import (
"errors"
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
)
@@ -85,3 +87,21 @@ func (s *providerService) GetByNPI(NPI string, user entity.User) (entity.Provide
provider.Organization = organization
return provider, nil
}
func (s *providerService) GetByOrganization(organizationUUID string, user entity.User) (entity.Provider, error) {
organization, err := s.svc.db.Organization().GetByUUID(organizationUUID, user)
if err != nil {
return entity.Provider{}, err
}
if organization.Type.Key != "provider" {
return entity.Provider{}, errors.New("invalid organization")
}
provider, err := s.svc.db.Provider().GetByID(organization.ReferenceID, user)
if err != nil {
return entity.Provider{}, err
}
return provider, nil
}

View File

@@ -56,7 +56,12 @@ func (s *rideService) GetByID(id int64, user entity.User) (entity.Ride, error) {
// GetByUUID return a specific ride
func (s *rideService) GetByUUID(uuid string, user entity.User) (entity.Ride, error) {
return s.svc.db.Rides().GetByUUID(uuid, user)
ride, err := s.svc.db.Rides().GetByUUID(uuid, user)
if err != nil {
return entity.Ride{}, err
}
return ride, nil
}
// GetByUUID return a specific ride

View File

@@ -25,7 +25,8 @@ type Service struct {
Notification *notificationService
Profile *profileService
Organization *organizationService
Zipcodes *zipcodeService
Zipcodes *zipcodeService
Plans *planService
}
// New returns a new domain Service instance
@@ -41,6 +42,7 @@ func New(db contract.DataManager, cache contract.CacheManager, cfg *config.Confi
instance.Profile = newProfileService(instance)
instance.Organization = newOrganizationService(instance)
instance.Zipcodes = newZipcodeService(instance)
instance.Plans = newPlanService(instance)
})
return instance, nil

View File

@@ -33,6 +33,10 @@ func (s *userService) GetByUUID(uuid string, profile string) (entity.User, error
return s.svc.db.Users().GetByUUID(uuid, profile)
}
func (s *userService) GetByMemberID(memberID string) (entity.User, error) {
return s.svc.db.Users().GetByMemberID(memberID)
}
// Login returns a specific user by email and pass
func (s *userService) Login(email string, pass string) (entity.User, error) {
return s.svc.db.Users().Login(email, pass)
@@ -68,6 +72,10 @@ func (s *userService) CreateBulk(users []entity.User) ([]entity.User, error) {
return users, nil
}
func (s *userService) UpdateLogin(user entity.User) error {
return s.svc.db.Users().UpdateLogin(user)
}
// GetUsersByProfile returns a list of users by profile
func (s *userService) GetUsersByProfile(profile string) ([]entity.User, error) {
return s.svc.db.Users().GetUsersByProfile(profile)

View File

@@ -29,10 +29,10 @@ func (s *visitService) GetAll(user entity.User) ([]entity.Visit, error) {
return nil, err
}
rides, err := s.svc.db.Rides().GetAll(user)
if err != nil {
return nil, err
}
rides, _ := s.svc.db.Rides().GetAll(user)
// if err != nil {
// return nil, err
// }
ridesByVisit := make(map[int64][]entity.Ride)
for _, r := range rides {
@@ -55,10 +55,10 @@ func (s *visitService) GetByUUID(visitUUID string, user entity.User) (entity.Vis
return entity.Visit{}, errors.Wrap(err)
}
rides, err := s.svc.db.Rides().GetByVisitUUID(visitUUID, user)
if err != nil {
return entity.Visit{}, errors.Wrap(err)
}
rides, _ := s.svc.db.Rides().GetByVisitUUID(visitUUID, user)
// if err != nil {
// return entity.Visit{}, errors.Wrap(err)
// }
visit.Rides = rides
return visit, nil
@@ -71,10 +71,10 @@ func (s *visitService) GetByID(visitID int64, user entity.User) (entity.Visit, e
return entity.Visit{}, errors.Wrap(err)
}
rides, err := s.svc.db.Rides().GetByVisitUUID(visit.UUID, user)
if err != nil {
return entity.Visit{}, errors.Wrap(err)
}
rides, _ := s.svc.db.Rides().GetByVisitUUID(visit.UUID, user)
// if err != nil {
// return entity.Visit{}, errors.Wrap(err)
// }
visit.Rides = rides
return visit, nil