Upstream sync
This commit is contained in:
@@ -28,7 +28,8 @@ type Conn struct {
|
||||
notification *notificationRepo
|
||||
profile *profileRepo
|
||||
organization *organizationRepo
|
||||
zipcodes *zipcodeRepo
|
||||
zipcodes *zipcodeRepo
|
||||
plan *planRepo
|
||||
}
|
||||
|
||||
// Begin starts a transaction
|
||||
@@ -81,10 +82,14 @@ func (c *Conn) Organization() contract.OrganizationRepo {
|
||||
return c.organization
|
||||
}
|
||||
|
||||
func (c *Conn) Zipcodes() contract.ZipcodeRepo{
|
||||
func (c *Conn) Zipcodes() contract.ZipcodeRepo {
|
||||
return c.zipcodes
|
||||
}
|
||||
|
||||
func (c *Conn) Plans() contract.PlanRepo {
|
||||
return c.plan
|
||||
}
|
||||
|
||||
// Instance returns an instance of a DataManager
|
||||
func Instance(cfg *config.Config) (contract.DataManager, error) {
|
||||
once.Do(func() {
|
||||
@@ -117,6 +122,7 @@ func Instance(cfg *config.Config) (contract.DataManager, error) {
|
||||
instance.profile = newProfileRepo(db)
|
||||
instance.organization = newOrganizationRepo(db)
|
||||
instance.zipcodes = newZipcodeRepo(db)
|
||||
instance.plan = newPlanRepo(db)
|
||||
})
|
||||
|
||||
return instance, connErr
|
||||
|
||||
@@ -44,7 +44,7 @@ func (c *organizationRepo) getProfileQuery(user entity.User) (query string, wher
|
||||
where = fmt.Sprintf(` AND (a.organization_uuid = '%s' OR f.organization_uuid = '%s') `, p.Organization.UUID, p.Organization.UUID)
|
||||
return
|
||||
}
|
||||
case "SP", "SPT":
|
||||
case "SP", "SPT", "VIRPT":
|
||||
switch p.Organization.Type.Key {
|
||||
case "techsupport", "bcbsi", "bcbsa":
|
||||
return
|
||||
|
||||
82
data/datamysql/plan.go
Normal file
82
data/datamysql/plan.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package datamysql
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/errors"
|
||||
)
|
||||
|
||||
type planRepo struct {
|
||||
conn executor
|
||||
}
|
||||
|
||||
func newPlanRepo(conn executor) *planRepo {
|
||||
return &planRepo{
|
||||
conn: conn,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *planRepo) getQuery() string {
|
||||
const query = `SELECT
|
||||
a.plan_id,
|
||||
a.plan_uuid,
|
||||
a.plan_name,
|
||||
a.plan_internal_id,
|
||||
a.plan_internal_status,
|
||||
a.plan_entity_id,
|
||||
a.entity_id,
|
||||
a.payer_id,
|
||||
a.payer_name,
|
||||
a.active,
|
||||
a.created,
|
||||
a.updated,
|
||||
b.plan_prefix_id,
|
||||
b.plan_prefix_uuid,
|
||||
b.alpha_prefix
|
||||
FROM
|
||||
tab_plan a
|
||||
INNER JOIN
|
||||
tab_plan_alpha_prefix b ON a.plan_id = b.plan_id `
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
func (c *planRepo) parseSet(rows *sql.Rows, err error) ([]entity.Plan, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
result := make([]entity.Plan, 0)
|
||||
for rows.Next() {
|
||||
entity, err := c.parseEntity(rows)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
result = append(result, entity)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *planRepo) parseEntity(row scanner) (retVal entity.Plan, err error) {
|
||||
err = row.Scan(
|
||||
&retVal.ID, &retVal.UUID, &retVal.Name, &retVal.InternalID, &retVal.Status, &retVal.PlanEntityID, &retVal.EntityID, &retVal.PayerID, &retVal.PayerName,
|
||||
&retVal.Active, &retVal.Created, &retVal.Updated, &retVal.PrefixID, &retVal.PrefixUUID, &retVal.AlphaPrefix)
|
||||
|
||||
return retVal, errors.Wrap(err)
|
||||
}
|
||||
|
||||
func (c *planRepo) GetByAlphaPrefix(alphaPrefix string) (entity.Plan, error) {
|
||||
return c.parseEntity(c.conn.QueryRow(c.getQuery()+" WHERE b.alpha_prefix = ? ", alphaPrefix))
|
||||
}
|
||||
|
||||
func (c *planRepo) GetByUUID(planUUID string) ([]entity.Plan, error) {
|
||||
return c.parseSet(c.conn.Query(c.getQuery()+" WHERE a.plan_uuid = ? ", planUUID))
|
||||
}
|
||||
|
||||
func (c *planRepo) GetByID(planID int64) ([]entity.Plan, error) {
|
||||
return c.parseSet(c.conn.Query(c.getQuery()+" WHERE a.plan_id = ? ", planID))
|
||||
}
|
||||
|
||||
func (c *planRepo) GetByPrefixUUID(prefixUUID string) (entity.Plan, error) {
|
||||
return c.parseEntity(c.conn.QueryRow(c.getQuery()+" WHERE b.plan_prefix_uuid = ? ", prefixUUID))
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func (c *providerRepo) getProfileQuery(user entity.User) (query string, where st
|
||||
if len(user.Profiles) > 0 {
|
||||
for _, p := range user.Profiles {
|
||||
switch p.Key {
|
||||
case "AD", "BCBSIAD", "BDCAD", "PLANAD":
|
||||
case "AD", "BCBSIAD", "BDCAD", "PLANAD", "VIRPT":
|
||||
return
|
||||
case "SP", "SPT":
|
||||
switch p.Organization.Type.Key {
|
||||
@@ -145,6 +145,20 @@ func (c *providerRepo) GetByUUID(providerUUID string, user entity.User) (entity.
|
||||
return c.parseEntity(c.conn.QueryRow(query, lat, long, lat, providerUUID))
|
||||
}
|
||||
|
||||
func (c *providerRepo) GetByID(providerID int64, user entity.User) (entity.Provider, error) {
|
||||
lat := 41.886406
|
||||
long := -87.624225
|
||||
|
||||
query, where, err := c.getProfileQuery(user)
|
||||
if err != nil {
|
||||
return entity.Provider{}, err
|
||||
}
|
||||
|
||||
query = c.getSelectQueryBase() + query + " WHERE a.provider_id = ? " + where
|
||||
|
||||
return c.parseEntity(c.conn.QueryRow(query, lat, long, lat, providerID))
|
||||
}
|
||||
|
||||
func (c *providerRepo) GetByMukID(mukID string, user entity.User) (entity.Provider, error) {
|
||||
lat := 41.886406
|
||||
long := -87.624225
|
||||
|
||||
@@ -144,13 +144,13 @@ func (c *rideRepo) getProfileQuery(user entity.User) (query string, where string
|
||||
switch p.Key {
|
||||
case "AD", "BCBSIAD", "BDCAD", "PLANAD":
|
||||
return
|
||||
case "SP", "SPT":
|
||||
case "SP", "SPT", "VIRPT":
|
||||
switch p.Organization.Type.Key {
|
||||
case "techsupport", "bcbsi", "bcbsa", "plan":
|
||||
return
|
||||
case "provider":
|
||||
query = `INNER JOIN viw_visit_provider o ON a.ride_id = o.ride_id`
|
||||
where = fmt.Sprintf(` AND (o.organization_uuid = '%s' OR o.parent_organization_uuid = '%s') `, p.Organization.UUID, p.Organization.UUID)
|
||||
query = `INNER JOIN viw_visit_provider z ON a.ride_id = z.ride_id`
|
||||
where = fmt.Sprintf(` AND (z.organization_uuid = '%s' OR z.parent_organization_uuid = '%s') `, p.Organization.UUID, p.Organization.UUID)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -676,6 +676,7 @@ func (c *rideRepo) GetByUUID(uuid string, user entity.User) (entity.Ride, error)
|
||||
}
|
||||
|
||||
query = c.getQuery() + query + " WHERE a.ride_uuid = ? " + where
|
||||
|
||||
return c.parseEntity(c.conn.QueryRow(query, uuid))
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ type transaction struct {
|
||||
notification *notificationRepo
|
||||
profile *profileRepo
|
||||
organization *organizationRepo
|
||||
zipcodes *zipcodeRepo
|
||||
zipcodes *zipcodeRepo
|
||||
plan *planRepo
|
||||
}
|
||||
|
||||
func newTransaction(tx *sql.Tx) *transaction {
|
||||
@@ -28,6 +29,11 @@ func newTransaction(tx *sql.Tx) *transaction {
|
||||
t.rides = newRideRepo(tx)
|
||||
t.visits = newVisitRepo(tx)
|
||||
t.provider = newProviderRepo(tx)
|
||||
t.notification = newNotificationRepo(tx)
|
||||
t.profile = newProfileRepo(tx)
|
||||
t.organization = newOrganizationRepo(tx)
|
||||
t.zipcodes = newZipcodeRepo(tx)
|
||||
t.plan = newPlanRepo(tx)
|
||||
|
||||
return t
|
||||
}
|
||||
@@ -67,10 +73,14 @@ func (t transaction) Organization() contract.OrganizationRepo {
|
||||
return t.organization
|
||||
}
|
||||
|
||||
func (t transaction) Zipcodes() contract.ZipcodeRepo{
|
||||
func (t transaction) Zipcodes() contract.ZipcodeRepo {
|
||||
return t.zipcodes
|
||||
}
|
||||
|
||||
func (t transaction) Plans() contract.PlanRepo {
|
||||
return t.plan
|
||||
}
|
||||
|
||||
func (t *transaction) Commit() error {
|
||||
|
||||
err := t.tx.Commit()
|
||||
|
||||
@@ -22,6 +22,32 @@ func newUserRepo(conn executor) *userRepo {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *userRepo) GetByMemberID(memberID string) (entity.User, error) {
|
||||
finalQuery := c.getQuery() + " AND a.member = ? AND e.key = 'US'"
|
||||
|
||||
user, err := c.parseSet(c.conn.Query(finalQuery, memberID))
|
||||
if err != nil {
|
||||
return entity.User{}, err
|
||||
}
|
||||
|
||||
if len(user) > 0 {
|
||||
retVal := user[0]
|
||||
retVal.Contacts, err = c.GetContacts(retVal.ID)
|
||||
if err != nil {
|
||||
return entity.User{}, err
|
||||
}
|
||||
|
||||
retVal.Addresses = nil
|
||||
retVal.Addresses, err = c.getAddressByUserID(retVal.ID)
|
||||
if err != nil {
|
||||
return entity.User{}, err
|
||||
}
|
||||
return retVal, nil
|
||||
} else {
|
||||
return entity.User{}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *userRepo) GetByUUID(uuid string, profile string) (entity.User, error) {
|
||||
params := make([]interface{}, 0)
|
||||
params = append(params, uuid)
|
||||
@@ -390,6 +416,24 @@ func (c *userRepo) SaveContact(contact entity.ContactInfo) (entity.ContactInfo,
|
||||
return c.addContactInfo(contact)
|
||||
}
|
||||
|
||||
func (c *userRepo) UpdateLogin(user entity.User) error {
|
||||
const (
|
||||
query = `UPDATE tab_login a
|
||||
INNER JOIN tab_user b
|
||||
ON a.user_id = b.user_id
|
||||
SET a.email = ?,
|
||||
a.phone_number = ?
|
||||
WHERE
|
||||
b.user_uuid = ?`
|
||||
)
|
||||
|
||||
if _, err := c.conn.Exec(query, user.Email, user.PhoneNumber, user.UUID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *userRepo) RemoveContact(contact entity.ContactInfo) (entity.ContactInfo, error) {
|
||||
const (
|
||||
query = `DELETE FROM tab_contact WHERE contact_uuid = ?;`
|
||||
@@ -561,7 +605,7 @@ func (c *userRepo) createUser(user entity.User) (int64, string, error) {
|
||||
|
||||
func (c *userRepo) RemoveAddress(addressUUID string) error {
|
||||
const (
|
||||
query = "UPDATE tab_address SET active = 0 WHERE address_uuid = ?"
|
||||
query = "DELETE FROM tab_address WHERE address_uuid = ?;"
|
||||
)
|
||||
|
||||
_, err := c.conn.Exec(query, addressUUID)
|
||||
|
||||
@@ -27,14 +27,13 @@ func (c *visitRepo) getProfileQuery(user entity.User) (query string, where strin
|
||||
switch p.Key {
|
||||
case "AD", "BCBSIAD", "BDCAD", "PLANAD":
|
||||
return
|
||||
case "SP", "SPT":
|
||||
case "SP", "SPT", "VIRPT":
|
||||
switch p.Organization.Type.Key {
|
||||
case "techsupport", "bcbsi", "bcbsa", "plan":
|
||||
return
|
||||
case "provider":
|
||||
query = ` INNER JOIN viw_visit_provider f
|
||||
ON f.visit_id = a.visit_id `
|
||||
where = fmt.Sprintf(` AND (f.organization_uuid = '%s' OR f.parent_organization_uuid = '%s') `, p.Organization.UUID, p.Organization.UUID)
|
||||
query = ` INNER JOIN viw_visit_provider AS o ON o.visit_id = a.visit_id `
|
||||
where = fmt.Sprintf(` AND ( o.organization_uuid = '%s' OR o.parent_organization_uuid = '%s' ) `, p.Organization.UUID, p.Organization.UUID)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -85,17 +84,17 @@ func (c *visitRepo) getQuery() string {
|
||||
IFNULL(f.provider_muk_id, '') provider_muk_id,
|
||||
IFNULL(f.provider_name, '') provider_name
|
||||
FROM
|
||||
tab_visit a
|
||||
INNER JOIN tab_visit_status b
|
||||
tab_visit AS a
|
||||
INNER JOIN tab_visit_status AS b
|
||||
ON a.visit_status_id = b.visit_status_id
|
||||
INNER JOIN tab_user c
|
||||
INNER JOIN tab_user AS c
|
||||
ON c.user_id = a.user_id
|
||||
INNER JOIN tab_user d
|
||||
INNER JOIN tab_user AS d
|
||||
ON d.user_id = a.created_user_id
|
||||
INNER JOIN tab_trip_type e
|
||||
INNER JOIN tab_trip_type AS e
|
||||
ON e.trip_type_id = a.trip_type_id
|
||||
INNER JOIN tab_provider f
|
||||
ON f.provider_id = a.provider_id `
|
||||
INNER JOIN tab_provider AS f
|
||||
ON f.provider_id = a.provider_id `
|
||||
}
|
||||
|
||||
func (c *visitRepo) GetAll(user entity.User) ([]entity.Visit, error) {
|
||||
@@ -205,6 +204,5 @@ func (c *visitRepo) Create(visit entity.Visit) (entity.Visit, error) {
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
fmt.Println("Visit ID: ", retVal.ID)
|
||||
return retVal, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user