initial commit 2
This commit is contained in:
15
domain/constants.go
Normal file
15
domain/constants.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package domain
|
||||
|
||||
type errorString string
|
||||
|
||||
func (err errorString) Error() string {
|
||||
return string(err)
|
||||
}
|
||||
|
||||
// ErrCacheMiss indicates a cache miss when fetching an item from CacheManager.
|
||||
const ErrCacheMiss = errorString("cache miss: key not found")
|
||||
|
||||
// Used to log errors with communication and operation of cache implementation
|
||||
const LogProblemGettingFromCache = "Getting from cache is not working correctly: %v"
|
||||
const LogProblemPuttingToCache = "Putting to cache is not working correctly: %v"
|
||||
const LogProblemExpiringCache = "Expiring cache key is not working correctly: %v"
|
||||
19
domain/contract/cache.go
Normal file
19
domain/contract/cache.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package contract
|
||||
|
||||
import "time"
|
||||
|
||||
// CacheManager defines the main caching interface
|
||||
// - Get methods can return domain.ErrCacheMiss
|
||||
type CacheManager interface {
|
||||
GetItem(key string) ([]byte, error)
|
||||
SetItem(key string, data []byte) error
|
||||
|
||||
GetString(key string) (string, error)
|
||||
SetString(key string, data string) error
|
||||
|
||||
GetStruct(key string, data interface{}) error
|
||||
SetStruct(key string, data interface{}) error
|
||||
|
||||
GetExpiration(key string) (time.Duration, error)
|
||||
SetExpiration(key string, expiration time.Duration) error
|
||||
}
|
||||
16
domain/contract/data.go
Normal file
16
domain/contract/data.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package contract
|
||||
|
||||
// DataManager holds the methods that manipulates the main data.
|
||||
type DataManager interface {
|
||||
repoManager
|
||||
Begin() (TransactionManager, error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
// TransactionManager holds the methods that manipulates the main
|
||||
// data, from within a transaction.
|
||||
type TransactionManager interface {
|
||||
repoManager
|
||||
Rollback() error
|
||||
Commit() error
|
||||
}
|
||||
104
domain/contract/repo.go
Normal file
104
domain/contract/repo.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package contract
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
type repoManager interface {
|
||||
Users() UserRepo
|
||||
Rides() RideRepo
|
||||
Visits() VisitRepo
|
||||
Provider() ProviderRepo
|
||||
Notification() NotificationRepo
|
||||
Profile() ProfileRepo
|
||||
Organization() OrganizationRepo
|
||||
}
|
||||
|
||||
// UserRepo defines the data set for users
|
||||
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)
|
||||
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)
|
||||
GetUsersByProfile(profile string) ([]entity.User, error)
|
||||
SaveAddress(address entity.Address) (entity.Address, error)
|
||||
GetAddressByUUID(addressUUID string) (entity.Address, error)
|
||||
GetContactType() (retVal []entity.ContactType, err error)
|
||||
RemoveAddress(addressUUID string) error
|
||||
}
|
||||
|
||||
// RideRepo defines the data set for Rides
|
||||
type RideRepo interface {
|
||||
Save(ride entity.Ride) (entity.Ride, error)
|
||||
GetAll(user entity.User) ([]entity.Ride, error)
|
||||
GetByID(id int64, user entity.User) (entity.Ride, error)
|
||||
GetByUUID(uuid string, user entity.User) (entity.Ride, error)
|
||||
GetByInternalID(internalID string) (entity.Ride, error)
|
||||
GetByUserID(userID int64, user entity.User) ([]entity.Ride, error)
|
||||
GetByUserUUID(userUUID string, user entity.User) ([]entity.Ride, error)
|
||||
GetByUUIDAndUserUUID(UUID string, userUUID string) (entity.Ride, error)
|
||||
UpdateStatus(rideUUID string, status string) error
|
||||
Update(hook entity.WebhookResponse, user entity.User) (entity.Ride, error)
|
||||
GetLastRideByPhoneNumber(phoneNumber string) (entity.Ride, error)
|
||||
GetLastRideByDriversNumber(phoneNumber string) (entity.Ride, error)
|
||||
GetByInternalPassengerID(internalPassengerID string) (entity.Ride, error)
|
||||
GetByVisitUUID(visitUUID string, user entity.User) ([]entity.Ride, error)
|
||||
GetByVisitUUIDAndTripType(visitUUID string, tripTypeKey string, user entity.User) (entity.Ride, error)
|
||||
}
|
||||
|
||||
// ProviderRepo defines the data set for Provider
|
||||
type ProviderRepo interface {
|
||||
Save(providers []entity.ProviderResponse, user entity.User) ([]entity.Provider, error)
|
||||
GetAll(user entity.User) ([]entity.Provider, error)
|
||||
Get(query string, lat float64, long float64, distance int64, planCode string, productID string, mukID string, internalID string, sort string, user entity.User) ([]entity.Provider, error)
|
||||
GetByMukID(mukID string, user entity.User) (entity.Provider, error)
|
||||
}
|
||||
|
||||
// NotificationRepo defines the data set for Notification
|
||||
type NotificationRepo interface {
|
||||
Create(notification entity.Notification) (entity.Notification, error)
|
||||
GetByUserUUIDAndReadStatus(userUUID string, status string, isRead bool) ([]entity.Notification, error)
|
||||
GetByUserUUID(userUUID string, status string) ([]entity.Notification, error)
|
||||
ReadStatus(notificationUUID string, readed bool) error
|
||||
GetLastNotificationFromPhoneNumber(notificationType string, phoneNumber string, status string) (entity.Notification, error)
|
||||
}
|
||||
|
||||
// ProviderRepo defines the data set for Rides
|
||||
type OrganizationRepo interface {
|
||||
GetAllTypes() ([]entity.OrganizationType, error)
|
||||
GetByType(organizationTypeKey string) ([]entity.Organization, error)
|
||||
GetByUUID(organizationUUID string) (entity.Organization, error)
|
||||
GetContactsByOrganizationUUID(organizationUUID string) ([]entity.OrganizationContact, error)
|
||||
GetContactsByOrganizationID(organizationID int64) ([]entity.OrganizationContact, error)
|
||||
GetContactsByUUID(contactUUID string) (entity.OrganizationContact, error)
|
||||
GetAddressByOrganizationUUID(organizationUUID string) ([]entity.OrganizationAddress, error)
|
||||
GetAddressByOrganizationID(organizationID int64) ([]entity.OrganizationAddress, error)
|
||||
GetAddressByUUID(contactUUID string) (entity.OrganizationAddress, error)
|
||||
GetByID(organizationID int64) (entity.Organization, error)
|
||||
GetChildsByID(organizationID int64) ([]entity.Organization, error)
|
||||
GetByName(name string, searchType string) ([]entity.Organization, error)
|
||||
SetParentOrganization(organizationID int64, parentOrganizationID int64) error
|
||||
InactivateOrganizationAddress(address entity.OrganizationAddress) error
|
||||
SetOrganizationAddress(address entity.OrganizationAddress) (entity.OrganizationAddress, error)
|
||||
InactivateOrganizationContact(contact entity.OrganizationContact) error
|
||||
SetOrganizationContact(contact entity.OrganizationContact) (entity.OrganizationContact, error)
|
||||
AddOrganization(organization entity.Organization) (entity.Organization, error)
|
||||
GetTypeByKey(key string) (entity.OrganizationType, error)
|
||||
}
|
||||
|
||||
// VisitRepo defines the data set for Rides
|
||||
type VisitRepo interface {
|
||||
Create(visit entity.Visit) (entity.Visit, error)
|
||||
GetAll(user entity.User) ([]entity.Visit, error)
|
||||
GetByUUID(visitUUID string, user entity.User) (entity.Visit, error)
|
||||
GetByID(visitID int64, user entity.User) (entity.Visit, error)
|
||||
}
|
||||
|
||||
type ProfileRepo interface {
|
||||
GetAll() ([]entity.Profile, error)
|
||||
GetByKey(key string) (entity.Profile, error)
|
||||
GetVisibles(visible bool) ([]entity.Profile, error)
|
||||
GetByOrganizationType(organizationTypeID int64) ([]entity.Profile, error)
|
||||
}
|
||||
12
domain/contract/tnc.go
Normal file
12
domain/contract/tnc.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package contract
|
||||
|
||||
type tncManager interface {
|
||||
TNC() TNCManager
|
||||
}
|
||||
|
||||
//TNCManager defines the integration with any TNC
|
||||
type TNCManager interface {
|
||||
GetETA(lag float64, log float64, params map[string]interface{}) (interface{}, error)
|
||||
GetDrivers(lag float64, log float64) (interface{}, error)
|
||||
GetTypes(lag float64, log float64, params map[string]interface{}) (interface{}, error)
|
||||
}
|
||||
21
domain/entity/address.go
Normal file
21
domain/entity/address.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package entity
|
||||
|
||||
type Address struct {
|
||||
ID int64
|
||||
UUID string
|
||||
InternalID string
|
||||
Name string
|
||||
Address string
|
||||
AddressType Params
|
||||
Latitude float64
|
||||
Longitude float64
|
||||
Origin Params
|
||||
User User
|
||||
CreatedUser User
|
||||
}
|
||||
|
||||
type Params struct {
|
||||
ID int64
|
||||
Key string
|
||||
Name string
|
||||
}
|
||||
252
domain/entity/eligibility.go
Normal file
252
domain/entity/eligibility.go
Normal file
@@ -0,0 +1,252 @@
|
||||
package entity
|
||||
|
||||
type Interchange struct {
|
||||
ISA ISA
|
||||
Division Division
|
||||
}
|
||||
|
||||
type ISA struct {
|
||||
ISA01 string
|
||||
ISA02 string
|
||||
ISA03 string
|
||||
ISA04 string
|
||||
ISA05 string
|
||||
ISA06 string
|
||||
ISA07 string
|
||||
ISA08 string
|
||||
ISA09 string
|
||||
ISA10 string
|
||||
ISA11 string
|
||||
ISA12 string
|
||||
ISA13 string
|
||||
ISA14 string
|
||||
ISA15 string
|
||||
ISA16 string
|
||||
}
|
||||
|
||||
type Division struct {
|
||||
GS GS
|
||||
HealthCareEligibilityBenefitResponse HealthCareEligibilityBenefitResponse
|
||||
}
|
||||
|
||||
type GS struct {
|
||||
GS01 string
|
||||
GS02 string
|
||||
GS03 string
|
||||
GS04 string
|
||||
GS05 string
|
||||
GS06 string
|
||||
GS07 string
|
||||
GS08 string
|
||||
}
|
||||
|
||||
type HealthCareEligibilityBenefitResponse struct {
|
||||
ST0010 ST0010
|
||||
BHT0020 BHT0020
|
||||
LoopHL0030 LoopHL0030
|
||||
}
|
||||
|
||||
type ST0010 struct {
|
||||
ST01 string
|
||||
ST02 string
|
||||
ST03 string
|
||||
}
|
||||
|
||||
type BHT0020 struct {
|
||||
BHT01 string
|
||||
BHT02 string
|
||||
BHT03 string
|
||||
BHT04 string
|
||||
BHT05 string
|
||||
}
|
||||
|
||||
type LoopHL0030 struct {
|
||||
HL0030 HL0030
|
||||
LoopNM10060 LoopNM10060
|
||||
LoopHL0460 LoopHL0460
|
||||
}
|
||||
|
||||
type HL0030 struct {
|
||||
HL01 string
|
||||
HL02 string
|
||||
HL03 string
|
||||
HL04 string
|
||||
}
|
||||
|
||||
type LoopNM10060 struct {
|
||||
NM10060 NM10060
|
||||
}
|
||||
|
||||
type NM10060 struct {
|
||||
NM101 string
|
||||
NM102 string
|
||||
NM103 string
|
||||
NM104 string
|
||||
NM105 string
|
||||
NM106 string
|
||||
NM107 string
|
||||
NM108 string
|
||||
NM109 string
|
||||
}
|
||||
|
||||
type LoopHL0460 struct {
|
||||
HL0460 HL0460
|
||||
LoopNM10490 LoopNM10490
|
||||
LoopHL0890 LoopHL0890
|
||||
}
|
||||
|
||||
type HL0460 struct {
|
||||
HL01 string
|
||||
HL02 string
|
||||
HL03 string
|
||||
HL04 string
|
||||
}
|
||||
|
||||
type LoopNM10490 struct {
|
||||
NM10490 NM10490
|
||||
}
|
||||
|
||||
type NM10490 struct {
|
||||
NM101 string
|
||||
NM102 string
|
||||
NM103 string
|
||||
NM104 string
|
||||
NM105 string
|
||||
NM106 string
|
||||
NM107 string
|
||||
NM108 string
|
||||
NM109 string
|
||||
}
|
||||
|
||||
type LoopHL0890 struct {
|
||||
HL0890 HL0890
|
||||
TRN0900 TRN0900
|
||||
LoopNM10920 LoopNM10920
|
||||
}
|
||||
|
||||
type HL0890 struct {
|
||||
HL01 string
|
||||
HL02 string
|
||||
HL03 string
|
||||
HL04 string
|
||||
}
|
||||
|
||||
type TRN0900 struct {
|
||||
TRN01 string
|
||||
TRN02 string
|
||||
TRN03 string
|
||||
}
|
||||
|
||||
type LoopNM10920 struct {
|
||||
NM10920 NM10920
|
||||
REF0930 REF0930
|
||||
N30950 N30950
|
||||
N40960 N40960
|
||||
DMG1000 DMG1000
|
||||
DTP1030 DTP1030
|
||||
LoopEB1050 []LoopEB1050
|
||||
}
|
||||
|
||||
type NM10920 struct {
|
||||
NM101 string
|
||||
NM102 string
|
||||
NM103 string
|
||||
NM104 string
|
||||
NM105 string
|
||||
NM106 string
|
||||
NM107 string
|
||||
NM108 string
|
||||
NM109 string
|
||||
}
|
||||
|
||||
type REF0930 struct {
|
||||
REF01 string
|
||||
REF02 string
|
||||
REF03 string
|
||||
}
|
||||
|
||||
type N30950 struct {
|
||||
N301 string
|
||||
}
|
||||
|
||||
type N40960 struct {
|
||||
N401 string
|
||||
N402 string
|
||||
N403 string
|
||||
}
|
||||
|
||||
type DMG1000 struct {
|
||||
DMG01 string
|
||||
DMG02 string
|
||||
DMG03 string
|
||||
}
|
||||
|
||||
type DTP1030 struct {
|
||||
DTP01 string
|
||||
DTP02 string
|
||||
DTP03 string
|
||||
}
|
||||
|
||||
type LoopEB1050 struct {
|
||||
EB1050 EB1050
|
||||
REF1070 REF1070
|
||||
MSG1180 MSG1180
|
||||
LoopIII1190 LoopIII1190
|
||||
LS1260 LS1260
|
||||
LoopNM11270 LoopNM11270
|
||||
}
|
||||
|
||||
type EB1050 struct {
|
||||
EB01 string
|
||||
EB02 string
|
||||
EB03 string
|
||||
EB04 string
|
||||
EB05 string
|
||||
EB06 string
|
||||
EB07 string
|
||||
EB08 string
|
||||
EB09 string
|
||||
EB10 string
|
||||
EB11 string
|
||||
EB12 string
|
||||
}
|
||||
|
||||
type REF1070 struct {
|
||||
REF01 string
|
||||
REF02 string
|
||||
REF03 string
|
||||
}
|
||||
|
||||
type MSG1180 struct {
|
||||
MSG01 string
|
||||
}
|
||||
|
||||
type LS1260 struct {
|
||||
LS01 string
|
||||
}
|
||||
|
||||
type LoopIII1190 struct {
|
||||
III1190 III1190
|
||||
}
|
||||
|
||||
type III1190 struct {
|
||||
III01 string
|
||||
III02 string
|
||||
}
|
||||
|
||||
type LoopNM11270 struct {
|
||||
NM11270 NM11270
|
||||
PER1310 PER1310
|
||||
}
|
||||
|
||||
type NM11270 struct {
|
||||
NM101 string
|
||||
NM102 string
|
||||
NM103 string
|
||||
}
|
||||
|
||||
type PER1310 struct {
|
||||
PER01 string
|
||||
PER02 string
|
||||
PER03 string
|
||||
}
|
||||
20
domain/entity/notification.go
Normal file
20
domain/entity/notification.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type Notification struct {
|
||||
ID int64 `json:"-"`
|
||||
UUID string `json:"uuid"`
|
||||
From string `json:"to"`
|
||||
To string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
TypeID int64 `json:"type_id"`
|
||||
Subject string `json:"subject"`
|
||||
Message string `json:"message"`
|
||||
MessageType string `json:"message_type"`
|
||||
Ride Ride `json:"ride"`
|
||||
User User `json:"user"`
|
||||
CreatedUser User `json:"created_user"`
|
||||
Created time.Time `json:"create_at"`
|
||||
Read bool `json:"read"`
|
||||
}
|
||||
68
domain/entity/organization.go
Normal file
68
domain/entity/organization.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type OrganizationType struct {
|
||||
ID int64 `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
Description string `json:"desc"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
}
|
||||
|
||||
type Organization struct {
|
||||
ID int64 `json:"-"`
|
||||
UUID string `json:"id"`
|
||||
Type OrganizationType `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"desc"`
|
||||
ReferenceID int64 `json:"-"`
|
||||
ParentID int64 `json:"-"`
|
||||
Main bool `json:"main"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
Active bool `json:"active"`
|
||||
Blocked bool `json:"blocked"`
|
||||
Suspended bool `json:"suspended"`
|
||||
Author User `json:"author"`
|
||||
LastEditor User `json:"last_editor"`
|
||||
Contacts []OrganizationContact `json:"contacts"`
|
||||
Addresses []OrganizationAddress `json:"addresses"`
|
||||
ChildOrgs []Organization `json:"childs"`
|
||||
Parent *Organization `json:"parent"`
|
||||
}
|
||||
|
||||
type OrganizationContact struct {
|
||||
ID int64 `json:"-"`
|
||||
UUID string `json:"id"`
|
||||
Organization *Organization `json:"organization"`
|
||||
Type ContactType `json:"type"`
|
||||
Contact string `json:"contact"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"desc"`
|
||||
Created time.Time `json:"created"`
|
||||
CreatedUser User `json:"author"`
|
||||
Updated time.Time `json:"updated"`
|
||||
UpdatedUser User `json:"last_editor"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
type OrganizationAddress struct {
|
||||
ID int64 `json:"-"`
|
||||
UUID string `json:"id"`
|
||||
Organization *Organization `json:"organization"`
|
||||
InternalID string `json:"internal_id"`
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Description string `json:"desc"`
|
||||
Latitude float64 `json:"lat"`
|
||||
Longitude float64 `json:"long"`
|
||||
Created time.Time `json:"created"`
|
||||
CreatedUser User `json:"author"`
|
||||
Updated time.Time `json:"updated"`
|
||||
UpdatedUser User `json:"last_editor"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
17
domain/entity/profile.go
Normal file
17
domain/entity/profile.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type Profile struct {
|
||||
ID int64 `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
Description string `json:"desc"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
Active bool `json:"active"`
|
||||
Blocked bool `json:"blocked"`
|
||||
Suspended bool `json:"suspended"`
|
||||
Visible bool `json:"visible"`
|
||||
Organization Organization `json:"organization"`
|
||||
}
|
||||
126
domain/entity/provider.go
Normal file
126
domain/entity/provider.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Provider struct {
|
||||
ProviderID int64 `json:"-"`
|
||||
ProviderUUID string `json:"provider_uuid"`
|
||||
InternalID string `json:"internal_id"`
|
||||
InternalSuffixID string `json:"internal_suffix_id"`
|
||||
MukID string `json:"muk_id"`
|
||||
OrganizatioName string `json:"org_name"`
|
||||
Gender string `json:"gender"`
|
||||
AcceptNewPatients string `json:"accept_new_patients"`
|
||||
Name string `json:"name"`
|
||||
FirstName string `json:"first"`
|
||||
MiddleName string `json:"middle"`
|
||||
LastName string `json:"last"`
|
||||
Title string `json:"title"`
|
||||
Active bool `json:"active"`
|
||||
Enabled bool `json:"enabled"`
|
||||
CreateDate time.Time `json:"create_at"`
|
||||
UpdateDate time.Time `json:"update_at"`
|
||||
CreatedUser User `json:"created_user"`
|
||||
Keys []ProviderKey `json:"keys"`
|
||||
Address ProviderAddress `json:"address"`
|
||||
Distance float64 `json:"distance"`
|
||||
}
|
||||
|
||||
type ProviderKey struct {
|
||||
ProviderKeyID int64 `json:"-"`
|
||||
Provider Provider `json:"provider"`
|
||||
InternalID string `json:"internal_id"`
|
||||
InternalSuffixID string `json:"internal_suffix_id"`
|
||||
LocationSeqNumber string `json:"location_seq_number"`
|
||||
PlanCode string `json:"plan_code"`
|
||||
ProductID string `json:"product_id"`
|
||||
TreatmentCategoryCode string `json:"treatment_category_code"`
|
||||
Active bool `json:"active"`
|
||||
Enabled bool `json:"enabled"`
|
||||
CreateDate time.Time `json:"create_at"`
|
||||
UpdateDate time.Time `json:"update_at"`
|
||||
CreatedUser User `json:"created_user"`
|
||||
}
|
||||
|
||||
type ProviderAddress struct {
|
||||
StreetAddress1 string `json:"street_address_1"`
|
||||
StreetAddress2 string `json:"street_address_2"`
|
||||
CityName string `json:"city"`
|
||||
State string `json:"state"`
|
||||
ZipCode string `json:"zipcode"`
|
||||
Country string `json:"country"`
|
||||
Latitude float64 `json:"lat"`
|
||||
Longitude float64 `json:"long"`
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
}
|
||||
|
||||
type ProviderResponse struct {
|
||||
MukID string `json:"mukId"`
|
||||
FivePartKeyGroups []PartKeyGroup `json:"fivePartKeyGroups"`
|
||||
OrgName string `json:"orgName"`
|
||||
Gender string `json:"gender"`
|
||||
AcceptNewPatients string `json:"acceptNewPatients"`
|
||||
ProviderName string `json:"providerName"`
|
||||
FirstName string `json:"firstName"`
|
||||
LastName string `json:"lastName"`
|
||||
MiddleName string `json:"middleName"`
|
||||
ProviderTitle string `json:"providerTitle"`
|
||||
StreetName1 string `json:"streetName_1"`
|
||||
StreetName2 string `json:"streetName_2"`
|
||||
CityName string `json:"cityName"`
|
||||
State string `json:"state"`
|
||||
ZipCode string `json:"zipCode"`
|
||||
Country string `json:"country"`
|
||||
Latitude string `json:"latitude"`
|
||||
Longitude string `json:"longitude"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
ProviderEntityName string `json:"providerEntityName"`
|
||||
ProviderEntityCode string `json:"providerEntityCode"`
|
||||
ProviderTypeCode []ProviderTypeCode `json:"providerTypeCode"`
|
||||
Distance string `json:"distance"`
|
||||
AvailabilityOfCost string `json:"availabilityOfCost"`
|
||||
TDDPhoneNumber string `json:"tddPhoneNumber"`
|
||||
ExtendedOfficeHours string `json:"extendedOfficeHours"`
|
||||
ProviderCountyCode string `json:"providerCountyCode"`
|
||||
ProviderCountyName string `json:"providerCountyName"`
|
||||
HospitalAffiliationNames []HospitalAffiliationNames `json:"hospitalAffiliationNames"`
|
||||
ProviderAffiliationNumber string `json:"providerAffiliationNumber"`
|
||||
ProviderAffiliationName string `json:"providerAffiliationName"`
|
||||
LanguagesSpoken []Languages `json:"languagesSpoken"`
|
||||
OfficeLanguagesSpoken []Languages `json:"officeLanguagesSpoken"`
|
||||
MedSchool string `json:"medSchool"`
|
||||
MedSchoolYear string `json:"medSchoolYear"`
|
||||
Internship string `json:"internship"`
|
||||
Residence string `json:"residency"`
|
||||
Specialty1 string `json:"specialty1"`
|
||||
Specialty2 string `json:"specialty2"`
|
||||
Specialty3 string `json:"specialty3"`
|
||||
Specialty4 string `json:"specialty4"`
|
||||
Certification1 string `json:"certification1"`
|
||||
Certification2 string `json:"certification2"`
|
||||
Certification3 string `json:"certification3"`
|
||||
Certification4 string `json:"certification4"`
|
||||
}
|
||||
|
||||
type HospitalAffiliationNames struct {
|
||||
HospAffProvOrgName string `json:"hospAffProvOrgName"`
|
||||
}
|
||||
|
||||
type Languages struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type ProviderTypeCode struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type PartKeyGroup struct {
|
||||
ProviderNum string `json:"providerNum"`
|
||||
ProviderNumSuffix string `json:"providerNumSuffix"`
|
||||
LocationSeqNum string `json:"locationSeqNum"`
|
||||
PlanCode string `json:"planCode"`
|
||||
ProductID string `json:"productId"`
|
||||
TreatmentCategoryCode string `json:"treatmentCategoryCode"`
|
||||
}
|
||||
116
domain/entity/ride.go
Normal file
116
domain/entity/ride.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
//WebhookResponse has the data and events from the webhook
|
||||
type WebhookResponse struct {
|
||||
EventID string `json:"event_id,omitempty"`
|
||||
HREF string `json:"href,omitempty"`
|
||||
OccurredAt time.Time `json:"occurred_at,omitempty"`
|
||||
EventType string `json:"event_type,omitempty"`
|
||||
Ride Ride `json:"event,omitempty"`
|
||||
}
|
||||
|
||||
// Ride entity data
|
||||
type Ride struct {
|
||||
ID int64 `db:"ride_id" json:"-"`
|
||||
UUID string `db:"ride_uuid" json:"ride_uuid"`
|
||||
User User `db:"user" json:"user"`
|
||||
Status RideStatus `db:"status" json:"status"`
|
||||
Type RideType `db:"type" json:"type"`
|
||||
InternalID string `db:"internal_id" json:"internal_id"`
|
||||
RequestDate *time.Time `db:"request_date" json:"request_date"`
|
||||
RequestMiliseconds *int64 `db:"request_ms" json:"request_ms"`
|
||||
GenerateDate *time.Time `db:"generate_date" json:"generate_date"`
|
||||
GenerateMiliseconds *int64 `db:"generate_ms" json:"generate_ms"`
|
||||
Note string `db:"notes" json:"notes"`
|
||||
PrimetimePercentage string `db:"primetime_percentage" json:"primetime_percentage"`
|
||||
Passenger RidePassenger `db:"passenger" json:"passenger"`
|
||||
Driver RideDriver `db:"driver" json:"driver"`
|
||||
Vehicle RideVehicle `db:"vehicle" json:"vehicle"`
|
||||
Route RideRoute `db:"route" json:"route"`
|
||||
VisitDate *time.Time `db:"visit_date" json:"visit_date"`
|
||||
VisitTime *time.Time `db:"visit_time" json:"visit_time"`
|
||||
PickupTime *time.Time `db:"pickup_time" json:"pickup_time"`
|
||||
Created time.Time `db:"create_at" json:"create_at"`
|
||||
Updated time.Time `db:"update_at" json:"update_at"`
|
||||
Visit Visit `db:"visit" json:"visit"`
|
||||
CreatedUser User `db:"created_user" json:"created_user"`
|
||||
TripType TripType `db:"trip_type" json:"trip_type"`
|
||||
}
|
||||
|
||||
// RidePassenger entity data
|
||||
type RidePassenger struct {
|
||||
ID int64 `db:"ride_passenger_id" json:"-"`
|
||||
FirstName string `db:"first_name" json:"first_name"`
|
||||
LastName string `db:"last_name" json:"last_name"`
|
||||
ImageURL *string `db:"image_url" json:"image_url"`
|
||||
PhoneNumber string `db:"phone_number" json:"phone_number"`
|
||||
InternalID *string `db:"internal_id" json:"internal_id"`
|
||||
}
|
||||
|
||||
// RideStatus entity data
|
||||
type RideStatus struct {
|
||||
ID int64 `db:"ride_status_id" json:"-"`
|
||||
Key string `db:"key" json:"key"`
|
||||
Value string `db:"value" json:"value"`
|
||||
}
|
||||
|
||||
// RideStatus entity data
|
||||
type TripType struct {
|
||||
ID int64 `db:"trip_type_id" json:"-"`
|
||||
Key string `db:"trip_type_key" json:"key"`
|
||||
Value string `db:"trip_type" json:"value"`
|
||||
}
|
||||
|
||||
// RideType entity data
|
||||
type RideType struct {
|
||||
ID int64 `db:"ride_type_id" json:"-"`
|
||||
Key string `db:"key" json:"key"`
|
||||
Value string `db:"value" json:"value"`
|
||||
}
|
||||
|
||||
// RideRoute entity data
|
||||
type RideRoute struct {
|
||||
ID int64 `db:"ride_route_id" json:"-"`
|
||||
Origin Location `db:"origin" json:"origin"`
|
||||
Destination Location `db:"destination" json:"destination"`
|
||||
RouteKML *string `db:"route_kml" json:"route_kml"`
|
||||
Distance float64 `db:"distance" json:"distance"`
|
||||
Duration int64 `db:"duration" json:"duration"`
|
||||
ETA int64 `db:"eta" json:"eta"`
|
||||
Created time.Time `db:"create_at" json:"create_at"`
|
||||
Updated time.Time `db:"update_at" json:"update_at"`
|
||||
}
|
||||
|
||||
// Location entity data
|
||||
type Location struct {
|
||||
ID string `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Address string `db:"address" json:"address"`
|
||||
Latitude float64 `db:"lat" json:"lat"`
|
||||
Longitude float64 `db:"lng" json:"lng"`
|
||||
}
|
||||
|
||||
// RideDriver entity data
|
||||
type RideDriver struct {
|
||||
ID int64 `db:"ride_driver_id" json:"-"`
|
||||
Name string `db:"name" json:"name"`
|
||||
ImageURL *string `db:"image_url" json:"image_url"`
|
||||
PhoneNumber string `db:"phone_number" json:"phone_number"`
|
||||
Rating *string `db:"rating" json:"rating"`
|
||||
}
|
||||
|
||||
// RideVehicle entity data
|
||||
type RideVehicle struct {
|
||||
ID int64 `db:"ride_vehicle_id" json:"-"`
|
||||
Color string `db:"color" json:"color"`
|
||||
ImageURL string `db:"image_url" json:"image_url"`
|
||||
LicensePlate string `db:"license_plate" json:"license_plate"`
|
||||
LicensePlateState string `db:"license_plate_state" json:"license_plate_state"`
|
||||
Make string `db:"make" json:"make"`
|
||||
Model string `db:"model" json:"model"`
|
||||
Year int64 `db:"year" json:"year"`
|
||||
}
|
||||
55
domain/entity/user.go
Normal file
55
domain/entity/user.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/errors"
|
||||
)
|
||||
|
||||
// User entity data
|
||||
type User struct {
|
||||
ID int64 `db:"user_id" json:"-"`
|
||||
UUID string `db:"user_uuid" json:"uuid"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Member string `db:"member" json:"member"`
|
||||
BirthDate time.Time `db:"birth_date" json:"birthdate"`
|
||||
LoginID int64 `db:"login_id" json:"-"`
|
||||
LoginUUID string `db:"login_uuid" json:"loginuuid"`
|
||||
Email string `db:"email" json:"email"`
|
||||
PhoneNumber string `db:"phone_number" json:"phonenumber"`
|
||||
Pass string `db:"password" json:"pass"`
|
||||
LoginKey string `db:"login_key" json:"loginkey"`
|
||||
Gender string `db:"gender" json:"gender"`
|
||||
Active bool `db:"active" json:"active"`
|
||||
Created time.Time `db:"createat" json:"createat"`
|
||||
Updated time.Time `db:"updateat" json:"updateat"`
|
||||
Contacts []ContactInfo `db:"contacts" json:"contacts"`
|
||||
Rides []Ride `db:"rides" json:"rides"`
|
||||
Addresses []Address `db:"addresses" json:"addresses"`
|
||||
Profiles []Profile `json:"profiles,omitempty"`
|
||||
Types []OrganizationType `json:"types,omitempty"`
|
||||
Organizations []Organization `json:"organizations,omitempty"`
|
||||
}
|
||||
|
||||
type ContactInfo struct {
|
||||
ID int64 `db:"contact_id" json:"contact_id"`
|
||||
Type ContactType `db:"contact_type" json:"contact_type"`
|
||||
UserID int64 `db:"user_id" json:"-"`
|
||||
Value string `db:"value" json:"value"`
|
||||
}
|
||||
|
||||
type ContactType struct {
|
||||
ID int64 `db:"contact_type_id" json:"contact_type_id"`
|
||||
Key string `db:"contact_type_key" json:"contact_type_key"`
|
||||
Value string `db:"contact_type_value" json:"contact_type_value"`
|
||||
}
|
||||
|
||||
// Validate validates the user entity state
|
||||
func (entity *User) Validate() error {
|
||||
if strings.TrimSpace(entity.Name) == "" {
|
||||
return errors.NewValidationError("name", "Nome do usuário é obrigatório")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
35
domain/entity/visit.go
Normal file
35
domain/entity/visit.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// VisitStatus entity data
|
||||
type VisitStatus struct {
|
||||
ID int64 `db:"visit_status_id" json:"-"`
|
||||
Key string `db:"key" json:"key"`
|
||||
Value string `db:"value" json:"value"`
|
||||
}
|
||||
|
||||
// Visit entity data
|
||||
type Visit struct {
|
||||
ID int64 `db:"visit_id" json:"-"`
|
||||
UUID string `db:"visit_uuid" json:"-"`
|
||||
Status VisitStatus `db:"visit_status" json:"-"`
|
||||
User User `db:"user" json:"-"`
|
||||
VisitDuration int64 `db:"visit_duration" json:"-"`
|
||||
VisitDatetime time.Time `db:"visit_datetime" json:"-"`
|
||||
PickupDatetime time.Time `db:"pickup_datetime" json:"-"`
|
||||
Notes *string `db:"notes" json:"-"`
|
||||
PickupAddressID int64 `db:"pickup_address_id" json:"-"`
|
||||
DestinationAddressID int64 `db:"destination_address_id" json:"-"`
|
||||
Pickup Location `db:"pickup" json:"-"`
|
||||
Provider Provider `db:"provider" json:"-"`
|
||||
CreatedUser User `db:"created_user" json:"-"`
|
||||
Created time.Time `db:"created_date" json:"-"`
|
||||
Updated time.Time `db:"updated_date" json:"-"`
|
||||
ReturnDate *time.Time `db:"return_date" json:"-"`
|
||||
TripType TripType `db:"trip_type" json:"-"`
|
||||
ExternalID string `db:"visit_external_id" json:"-"`
|
||||
Rides []Ride `db:"rides" json:"-"`
|
||||
}
|
||||
36
domain/service/notification.go
Normal file
36
domain/service/notification.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package service
|
||||
|
||||
import "bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
|
||||
// userService is the domain service for user operations
|
||||
type notificationService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
// newUserService returns an instance of userService
|
||||
func newNotificationService(svc *Service) *notificationService {
|
||||
return ¬ificationService{
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
// Save the ride for a expected user
|
||||
func (s *notificationService) Create(notification entity.Notification) (entity.Notification, error) {
|
||||
return s.svc.db.Notification().Create(notification)
|
||||
}
|
||||
|
||||
func (c *notificationService) GetByUserUUIDAndReadStatus(userUUID string, status string, isRead bool) ([]entity.Notification, error) {
|
||||
return c.svc.db.Notification().GetByUserUUIDAndReadStatus(userUUID, status, isRead)
|
||||
}
|
||||
|
||||
func (c *notificationService) GetByUserUUID(userUUID string, status string) ([]entity.Notification, error) {
|
||||
return c.svc.db.Notification().GetByUserUUID(userUUID, status)
|
||||
}
|
||||
|
||||
func (c *notificationService) ReadStatus(notificationUUID string, isRead bool) error {
|
||||
return c.svc.db.Notification().ReadStatus(notificationUUID, isRead)
|
||||
}
|
||||
|
||||
func (c *notificationService) GetLastNotificationFromPhoneNumber(notificationType string, phoneNumber string, status string) (entity.Notification, error) {
|
||||
return c.svc.db.Notification().GetLastNotificationFromPhoneNumber(notificationType, phoneNumber, status)
|
||||
}
|
||||
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)
|
||||
}
|
||||
33
domain/service/profile.go
Normal file
33
domain/service/profile.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// userService is the domain service for user operations
|
||||
type profileService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
// newUserService returns an instance of userService
|
||||
func newProfileService(svc *Service) *profileService {
|
||||
return &profileService{
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *profileService) GetAll() ([]entity.Profile, error) {
|
||||
return s.svc.db.Profile().GetAll()
|
||||
}
|
||||
|
||||
func (s *profileService) GetByKey(key string) (entity.Profile, error) {
|
||||
return s.svc.db.Profile().GetByKey(key)
|
||||
}
|
||||
|
||||
func (s *profileService) GetVisibles(visible bool) ([]entity.Profile, error) {
|
||||
return s.svc.db.Profile().GetVisibles(visible)
|
||||
}
|
||||
|
||||
func (s *profileService) GetByOrganizationType(organizationTypeID int64) ([]entity.Profile, error) {
|
||||
return s.svc.db.Profile().GetByOrganizationType(organizationTypeID)
|
||||
}
|
||||
46
domain/service/provider.go
Normal file
46
domain/service/provider.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// userService is the domain service for user operations
|
||||
type providerService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
// newUserService returns an instance of userService
|
||||
func newProviderService(svc *Service) *providerService {
|
||||
return &providerService{
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
// Save the ride for a expected user
|
||||
func (s *providerService) Save(providers []entity.ProviderResponse, user entity.User) ([]entity.Provider, error) {
|
||||
tx, err := s.svc.db.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newProviders, err := tx.Provider().Save(providers, user)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
tx.Commit()
|
||||
|
||||
return newProviders, nil
|
||||
}
|
||||
|
||||
func (s *providerService) GetAll(user entity.User) ([]entity.Provider, error) {
|
||||
return s.svc.db.Provider().GetAll(user)
|
||||
}
|
||||
|
||||
func (s *providerService) Get(query string, lat float64, long float64, distance int64, planCode string, productID string, mukID string, internalID string, sort string, user entity.User) ([]entity.Provider, error) {
|
||||
return s.svc.db.Provider().Get(query, lat, long, distance, planCode, productID, mukID, internalID, sort, user)
|
||||
}
|
||||
|
||||
func (s *providerService) GetByMukID(mukID string, user entity.User) (entity.Provider, error) {
|
||||
return s.svc.db.Provider().GetByMukID(mukID, user)
|
||||
}
|
||||
103
domain/service/ride.go
Normal file
103
domain/service/ride.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// userService is the domain service for user operations
|
||||
type rideService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
// newUserService returns an instance of userService
|
||||
func newRideService(svc *Service) *rideService {
|
||||
return &rideService{
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
// Save the ride for a expected user
|
||||
func (s *rideService) Save(ride entity.Ride) (entity.Ride, error) {
|
||||
ride, err := s.svc.db.Rides().Save(ride)
|
||||
if err != nil {
|
||||
return ride, err
|
||||
}
|
||||
|
||||
user, err := s.svc.db.Users().GetByID(ride.CreatedUser.ID)
|
||||
if err != nil {
|
||||
return ride, err
|
||||
}
|
||||
|
||||
return s.GetByUUID(ride.UUID, user)
|
||||
}
|
||||
|
||||
func (s *rideService) Update(hook entity.WebhookResponse) (entity.Ride, error) {
|
||||
user, err := s.svc.db.Users().GetByID(hook.Ride.CreatedUser.ID)
|
||||
if err != nil {
|
||||
return entity.Ride{}, err
|
||||
}
|
||||
|
||||
ride, err := s.svc.db.Rides().Update(hook, user)
|
||||
if err != nil {
|
||||
return ride, err
|
||||
}
|
||||
|
||||
return s.GetByUUID(ride.UUID, user)
|
||||
}
|
||||
|
||||
// GetAll return all rides
|
||||
func (s *rideService) GetAll(user entity.User) ([]entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetAll(user)
|
||||
}
|
||||
|
||||
func (s *rideService) GetByID(id int64, user entity.User) (entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetByID(id, user)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// GetByUUID return a specific ride
|
||||
func (s *rideService) GetByUUIDAndUserUUID(UUID string, userUUID string) (entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetByUUIDAndUserUUID(UUID, userUUID)
|
||||
}
|
||||
|
||||
// GetByUUID return a specific ride
|
||||
func (s *rideService) GetByInternalID(internalID string) (entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetByInternalID(internalID)
|
||||
}
|
||||
|
||||
// GetByUserID return a list of rides
|
||||
func (s *rideService) GetByUserID(userID int64, user entity.User) ([]entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetByUserID(userID, user)
|
||||
}
|
||||
|
||||
func (s *rideService) GetByUserUUID(userUUID string, user entity.User) ([]entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetByUserUUID(userUUID, user)
|
||||
}
|
||||
|
||||
func (s *rideService) UpdateStatus(rideUUID string, status string) error {
|
||||
return s.svc.db.Rides().UpdateStatus(rideUUID, status)
|
||||
}
|
||||
|
||||
func (s *rideService) GetLastRideByPhoneNumber(phoneNumber string) (entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetLastRideByPhoneNumber(phoneNumber)
|
||||
}
|
||||
|
||||
func (s *rideService) GetLastRideByDriversNumber(phoneNumber string) (entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetLastRideByDriversNumber(phoneNumber)
|
||||
}
|
||||
|
||||
func (s *rideService) GetByInternalPassengerID(internalPassengerID string) (entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetByInternalPassengerID(internalPassengerID)
|
||||
}
|
||||
|
||||
func (s *rideService) GetByVisitUUID(visitUUID string, user entity.User) ([]entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetByVisitUUID(visitUUID, user)
|
||||
}
|
||||
|
||||
func (s *rideService) GetByVisitUUIDAndTripType(visitUUID string, tripTypeKey string, user entity.User) (entity.Ride, error) {
|
||||
return s.svc.db.Rides().GetByVisitUUIDAndTripType(visitUUID, tripTypeKey, user)
|
||||
}
|
||||
45
domain/service/service.go
Normal file
45
domain/service/service.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/contract"
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/config"
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
instance *Service
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
// Service holds the domain service repositories
|
||||
type Service struct {
|
||||
db contract.DataManager
|
||||
cache contract.CacheManager
|
||||
tnc contract.TNCManager
|
||||
Users *userService
|
||||
Rides *rideService
|
||||
Visits *visitService
|
||||
Provider *providerService
|
||||
Notification *notificationService
|
||||
Profile *profileService
|
||||
Organization *organizationService
|
||||
}
|
||||
|
||||
// New returns a new domain Service instance
|
||||
func New(db contract.DataManager, cache contract.CacheManager, cfg *config.Config, log *logger.Logger) (*Service, error) {
|
||||
once.Do(func() {
|
||||
instance = &Service{db: db, cache: cache}
|
||||
|
||||
instance.Users = newUserService(instance)
|
||||
instance.Rides = newRideService(instance)
|
||||
instance.Visits = newVisitService(instance)
|
||||
instance.Provider = newProviderService(instance)
|
||||
instance.Notification = newNotificationService(instance)
|
||||
instance.Profile = newProfileService(instance)
|
||||
instance.Organization = newOrganizationService(instance)
|
||||
})
|
||||
|
||||
return instance, nil
|
||||
}
|
||||
28
domain/service/tnc.go
Normal file
28
domain/service/tnc.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package service
|
||||
|
||||
// tncService is the domain service for transportation network operations
|
||||
type tncService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
// newTncService returns an instance of tncService
|
||||
func newTncService(svc *Service) *tncService {
|
||||
return &tncService{
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
//GetETA will return the list of ETA's for the current location
|
||||
func (s *tncService) GetETA(lag float64, log float64, params map[string]interface{}) (interface{}, error) {
|
||||
return s.svc.tnc.GetETA(lag, log, params)
|
||||
}
|
||||
|
||||
//GetDrivers return the drivers for the current location
|
||||
func (s *tncService) GetDrivers(lag float64, log float64) (interface{}, error) {
|
||||
return s.svc.tnc.GetDrivers(lag, log)
|
||||
}
|
||||
|
||||
//GetTypes will return the available types of ride for the current location
|
||||
func (s *tncService) GetTypes(lag float64, log float64, params map[string]interface{}) (interface{}, error) {
|
||||
return s.svc.tnc.GetTypes(lag, log, params)
|
||||
}
|
||||
92
domain/service/user.go
Normal file
92
domain/service/user.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// userService is the domain service for user operations
|
||||
type userService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
// newUserService returns an instance of userService
|
||||
func newUserService(svc *Service) *userService {
|
||||
return &userService{
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
// GetAll returns a list of users
|
||||
func (s *userService) GetAll() (list []entity.User, err error) {
|
||||
return s.svc.db.Users().GetAll()
|
||||
}
|
||||
|
||||
// GetByID returns a specific user by its ID
|
||||
func (s *userService) GetByID(userID int64) (entity.User, error) {
|
||||
return s.svc.db.Users().GetByID(userID)
|
||||
}
|
||||
|
||||
// GetByID returns a specific user by its ID
|
||||
func (s *userService) GetByUUID(uuid string, profile string) (entity.User, error) {
|
||||
return s.svc.db.Users().GetByUUID(uuid, profile)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// Login returns a specific user by email and pass
|
||||
func (s *userService) FullLogin(loginType string, key string, pass string, profile string) (entity.User, error) {
|
||||
return s.svc.db.Users().FullLogin(loginType, key, pass, profile)
|
||||
}
|
||||
|
||||
// Login returns a specific user by email and pass
|
||||
func (s *userService) Create(user entity.User) (entity.User, error) {
|
||||
return s.svc.db.Users().Create(user)
|
||||
}
|
||||
|
||||
func (s *userService) CreateBulk(users []entity.User) ([]entity.User, error) {
|
||||
tx, err := s.svc.db.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i, _ := range users {
|
||||
users[i], err = tx.Users().Create(users[i])
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprintf("Email %s got error: %s", users[i].Email, err.Error()))
|
||||
tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(fmt.Sprintf("Email %s created", users[i].Email))
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return users, nil
|
||||
}
|
||||
|
||||
// GetUsersByProfile returns a list of users by profile
|
||||
func (s *userService) GetUsersByProfile(profile string) ([]entity.User, error) {
|
||||
return s.svc.db.Users().GetUsersByProfile(profile)
|
||||
}
|
||||
|
||||
func (s *userService) RemoveAddress(addressUUID string) error {
|
||||
return s.svc.db.Users().RemoveAddress(addressUUID)
|
||||
}
|
||||
|
||||
// SaveAddress returns a list of users by profile
|
||||
func (s *userService) SaveAddress(address entity.Address) (entity.Address, error) {
|
||||
return s.svc.db.Users().SaveAddress(address)
|
||||
}
|
||||
|
||||
// GetAddressByUUID returns a list of users by profile
|
||||
func (s *userService) GetAddressByUUID(addressUUID string) (entity.Address, error) {
|
||||
return s.svc.db.Users().GetAddressByUUID(addressUUID)
|
||||
}
|
||||
|
||||
func (s *userService) GetContactType() (retVal []entity.ContactType, err error) {
|
||||
return s.svc.db.Users().GetContactType()
|
||||
}
|
||||
81
domain/service/visit.go
Normal file
81
domain/service/visit.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/errors"
|
||||
)
|
||||
|
||||
// userService is the domain service for user operations
|
||||
type visitService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
// newUserService returns an instance of userService
|
||||
func newVisitService(svc *Service) *visitService {
|
||||
return &visitService{
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
// Save the ride for a expected user
|
||||
func (s *visitService) Create(visit entity.Visit) (entity.Visit, error) {
|
||||
return s.svc.db.Visits().Create(visit)
|
||||
}
|
||||
|
||||
// Save the ride for a expected user
|
||||
func (s *visitService) GetAll(user entity.User) ([]entity.Visit, error) {
|
||||
visit, err := s.svc.db.Visits().GetAll(user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rides, err := s.svc.db.Rides().GetAll(user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ridesByVisit := make(map[int64][]entity.Ride)
|
||||
for _, r := range rides {
|
||||
rides := ridesByVisit[r.Visit.ID]
|
||||
rides = append(rides, r)
|
||||
ridesByVisit[r.Visit.ID] = rides
|
||||
}
|
||||
|
||||
for i, v := range visit {
|
||||
visit[i].Rides = ridesByVisit[v.ID]
|
||||
}
|
||||
|
||||
return visit, nil
|
||||
}
|
||||
|
||||
// Save the ride for a expected user
|
||||
func (s *visitService) GetByUUID(visitUUID string, user entity.User) (entity.Visit, error) {
|
||||
visit, err := s.svc.db.Visits().GetByUUID(visitUUID, user)
|
||||
if err != nil {
|
||||
return entity.Visit{}, errors.Wrap(err)
|
||||
}
|
||||
|
||||
rides, err := s.svc.db.Rides().GetByVisitUUID(visitUUID, user)
|
||||
if err != nil {
|
||||
return entity.Visit{}, errors.Wrap(err)
|
||||
}
|
||||
visit.Rides = rides
|
||||
|
||||
return visit, nil
|
||||
}
|
||||
|
||||
// Save the ride for a expected user
|
||||
func (s *visitService) GetByID(visitID int64, user entity.User) (entity.Visit, error) {
|
||||
visit, err := s.svc.db.Visits().GetByID(visitID, user)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
visit.Rides = rides
|
||||
|
||||
return visit, nil
|
||||
}
|
||||
Reference in New Issue
Block a user