custom elig. api error msg ; first check elig. then create user
This commit is contained in:
@@ -39,7 +39,7 @@ func ResponseAPIErrorWithData(c echo.Context, status int, message string, redire
|
|||||||
Error: true,
|
Error: true,
|
||||||
Message: message,
|
Message: message,
|
||||||
Redirect: redirect,
|
Redirect: redirect,
|
||||||
Data: data,
|
Data: data,
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(status, returnValue)
|
return c.JSON(status, returnValue)
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package usersroute
|
package usersroute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
b64 "encoding/base64"
|
b64 "encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"net/http"
|
|
||||||
"encoding/json"
|
|
||||||
"bytes"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"bitbucket.org/nemt/nemt-portal-api/application/applicationservice"
|
"bitbucket.org/nemt/nemt-portal-api/application/applicationservice"
|
||||||
"bitbucket.org/nemt/nemt-portal-api/application/third/eligibility/bcbsi"
|
"bitbucket.org/nemt/nemt-portal-api/application/third/eligibility/bcbsi"
|
||||||
@@ -19,8 +19,8 @@ import (
|
|||||||
"bitbucket.org/nemt/nemt-portal-api/infra/cache"
|
"bitbucket.org/nemt/nemt-portal-api/infra/cache"
|
||||||
"bitbucket.org/nemt/nemt-portal-api/infra/config"
|
"bitbucket.org/nemt/nemt-portal-api/infra/config"
|
||||||
"bitbucket.org/nemt/nemt-portal-api/server/authorization"
|
"bitbucket.org/nemt/nemt-portal-api/server/authorization"
|
||||||
"bitbucket.org/nemt/nemt-portal-api/server/validation"
|
|
||||||
"bitbucket.org/nemt/nemt-portal-api/server/router/routeutils"
|
"bitbucket.org/nemt/nemt-portal-api/server/router/routeutils"
|
||||||
|
"bitbucket.org/nemt/nemt-portal-api/server/validation"
|
||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"googlemaps.github.io/maps"
|
"googlemaps.github.io/maps"
|
||||||
@@ -340,13 +340,14 @@ func (c *controller) handleGetPortal(ctx echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) handleMember(ctx echo.Context) error {
|
func (c *controller) handleMember(ctx echo.Context) error {
|
||||||
|
fmt.Println("\n\nHandle member\n\n")
|
||||||
var user viewmodel.User
|
var user viewmodel.User
|
||||||
if err := ctx.Bind(&user); err != nil {
|
if err := ctx.Bind(&user); err != nil {
|
||||||
return routeutils.HandleAPIError(ctx, err)
|
return routeutils.HandleAPIError(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Validate member
|
//Validate member
|
||||||
if validationErrors := validation.ValidateEligibility(&user) ; len(validationErrors) > 0 {
|
if validationErrors := validation.ValidateEligibility(&user); len(validationErrors) > 0 {
|
||||||
return routeutils.ResponseAPICustomValidationError(ctx, "eligibility validation failed", validationErrors)
|
return routeutils.ResponseAPICustomValidationError(ctx, "eligibility validation failed", validationErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,11 +410,11 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
|||||||
eligibility.ServiceInfo.ServiceTypeCodes = []string{"30"}
|
eligibility.ServiceInfo.ServiceTypeCodes = []string{"30"}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
resp, err := c.bcbsi.BXE.Get271(eligibility)
|
resp, err := c.bcbsi.BXE.Get271(eligibility)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Eligibility Not Found or Error: ", err.Error())
|
fmt.Println("Eligibility Not Found or Error: ", err.Error())
|
||||||
return routeutils.ResponseAPINotEligibleError(ctx)
|
return routeutils.ResponseAPINotEligibleError(ctx)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//This part is emulating eligibility check for testing purposes
|
//This part is emulating eligibility check for testing purposes
|
||||||
@@ -426,7 +427,7 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
|||||||
req.Header.Add("App", c.cfg.HTTP.Auth.AppKey)
|
req.Header.Add("App", c.cfg.HTTP.Auth.AppKey)
|
||||||
req.Header.Add("Token", ctx.Request().Header.Get("Token"))
|
req.Header.Add("Token", ctx.Request().Header.Get("Token"))
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return routeutils.HandleAPIError(ctx, err)
|
return routeutils.HandleAPIError(ctx, err)
|
||||||
@@ -446,7 +447,7 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
|||||||
//================================================================
|
//================================================================
|
||||||
|
|
||||||
if len(eligibilityResponse.Division.HealthCareEligibilityResponse.LoopHL0030) < 1 {
|
if len(eligibilityResponse.Division.HealthCareEligibilityResponse.LoopHL0030) < 1 {
|
||||||
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Cannot check eligibility")
|
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Cannot check eligibility")
|
||||||
}
|
}
|
||||||
|
|
||||||
address := viewmodel.Address{}
|
address := viewmodel.Address{}
|
||||||
@@ -467,17 +468,17 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
|||||||
if len(cleanZipcode) > zipcodeTrimLength {
|
if len(cleanZipcode) > zipcodeTrimLength {
|
||||||
trimmedZipcode = cleanZipcode[:zipcodeTrimLength]
|
trimmedZipcode = cleanZipcode[:zipcodeTrimLength]
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = c.svc.Zipcodes.GetByParticipatingZipcode(trimmedZipcode)
|
_, err = c.svc.Zipcodes.GetByParticipatingZipcode(trimmedZipcode)
|
||||||
|
|
||||||
if err != nil{
|
if err != nil {
|
||||||
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Member's Home zipcode, " + trimmedZipcode + ", is not currently eligible for participation in this program")
|
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Member's Home zipcode, "+trimmedZipcode+", is not currently eligible for participation in this program")
|
||||||
}
|
}
|
||||||
|
|
||||||
googleMapsAPI, err := maps.NewClient(maps.WithClientIDAndSignature("gme-bluecrossandblue1", "msqgD-jdqCyR0M_1u5C1HION5iI="))
|
googleMapsAPI, err := maps.NewClient(maps.WithClientIDAndSignature("gme-bluecrossandblue1", "msqgD-jdqCyR0M_1u5C1HION5iI="))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error to instantiate googles api: ", err.Error())
|
fmt.Println("Error to instantiate googles api: ", err.Error())
|
||||||
return routeutils.HandleAPIError(ctx,err)
|
return routeutils.HandleAPIError(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r := &maps.GeocodingRequest{
|
r := &maps.GeocodingRequest{
|
||||||
@@ -487,7 +488,7 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
|||||||
result, err := googleMapsAPI.Geocode(context.Background(), r)
|
result, err := googleMapsAPI.Geocode(context.Background(), r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error to instantiate googles api: ", err.Error())
|
fmt.Println("Error to instantiate googles api: ", err.Error())
|
||||||
return routeutils.HandleAPIError(ctx,err)
|
return routeutils.HandleAPIError(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(result) > 0 {
|
if len(result) > 0 {
|
||||||
@@ -497,7 +498,7 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
|||||||
_, err := c.svc.Users.SaveAddress(address)
|
_, err := c.svc.Users.SaveAddress(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error to save address: ", err.Error())
|
fmt.Println("Error to save address: ", err.Error())
|
||||||
return routeutils.HandleAPIError(ctx,err)
|
return routeutils.HandleAPIError(ctx, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,7 +598,7 @@ func (c *controller) handlePortal(ctx echo.Context) error {
|
|||||||
}
|
}
|
||||||
user.Pass = string(pass)
|
user.Pass = string(pass)
|
||||||
|
|
||||||
if passwordValidationErrors := validation.ValidatePassword(&user) ; len(passwordValidationErrors) > 0 {
|
if passwordValidationErrors := validation.ValidatePassword(&user); len(passwordValidationErrors) > 0 {
|
||||||
return routeutils.ResponseAPICustomValidationError(ctx, "Password not strong enough", passwordValidationErrors)
|
return routeutils.ResponseAPICustomValidationError(ctx, "Password not strong enough", passwordValidationErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user