Compare commits

8 Commits

Author SHA1 Message Date
GotPPay
6d77f470ee No need to check on delete 2018-05-28 10:49:13 +02:00
GotPPay
8137447e7f apply regex match on user and locations UUID 2018-05-28 10:49:13 +02:00
GotPPay
1e2b7fcd4c move validation to external function and update rules 2018-05-28 10:49:13 +02:00
GotPPay
1ad4b8a38e update validation rules based on new instructions 2018-05-28 10:49:13 +02:00
GotPPay
f0e63f4166 implement ride validation 2018-05-28 10:49:13 +02:00
Senad Uka
1ed02e2e73 Upsteam sync 2018-05-28 10:49:13 +02:00
GotPPay
cbbbdc601b create structure for rules checking 2018-05-28 10:49:13 +02:00
Senad Uka
d1680d50bf Upstream sync 2018-05-28 10:49:13 +02:00
3 changed files with 144 additions and 148 deletions

View File

@@ -92,12 +92,11 @@ func ResponseAPINotFoundError(c echo.Context) error {
return ResponseAPIError(c, http.StatusNotFound, "Not Found", false)
}
//ResponseAPINotEligibleError returns a standard API not eligible to the response
//ResponseAPINotEligible returns a standard API not eligible to the response
func ResponseAPINotEligibleError(c echo.Context) error {
return ResponseAPIError(c, http.StatusForbidden, "Member does not have active insurance coverage", false)
return ResponseAPIError(c, http.StatusForbidden, "Eligibility Not Found or Error", false)
}
//ResponseAPINotEligibleWithMessageError returns a standard API not eligible to the response with custom message
func ResponseAPINotEligibleWithMessageError(c echo.Context, message string) error {
return ResponseAPIError(c, http.StatusForbidden, message, false)
}

View File

@@ -1,15 +1,15 @@
package usersroute
import (
"bytes"
b64 "encoding/base64"
"encoding/json"
"fmt"
"math/rand"
"net/http"
"strings"
"sync"
"time"
"net/http"
"encoding/json"
"bytes"
"strings"
"bitbucket.org/nemt/nemt-portal-api/application/applicationservice"
"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/config"
"bitbucket.org/nemt/nemt-portal-api/server/authorization"
"bitbucket.org/nemt/nemt-portal-api/server/router/routeutils"
"bitbucket.org/nemt/nemt-portal-api/server/validation"
"bitbucket.org/nemt/nemt-portal-api/server/router/routeutils"
"github.com/labstack/echo"
"golang.org/x/net/context"
"googlemaps.github.io/maps"
@@ -420,7 +420,7 @@ func (c *controller) handleMember(ctx echo.Context) error {
client := &http.Client{}
eligibilityJson, err := json.Marshal(eligibility)
if err != nil {
return routeutils.ResponseAPINotEligibleError(ctx)
return routeutils.HandleAPIError(ctx, err)
}
req, _ := http.NewRequest("POST", c.cfg.Eligibility.Url, bytes.NewBuffer(eligibilityJson))
req.Header.Add("App", c.cfg.HTTP.Auth.AppKey)
@@ -429,24 +429,24 @@ func (c *controller) handleMember(ctx echo.Context) error {
resp, err := client.Do(req)
if err != nil {
return routeutils.ResponseAPINotEligibleError(ctx)
return routeutils.HandleAPIError(ctx, err)
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 300 {
return routeutils.ResponseAPINotEligibleError(ctx)
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Cannot check eligibility")
}
eligibilityResponse := viewmodel.Interchange271{}
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&eligibilityResponse)
if err != nil {
return routeutils.ResponseAPINotEligibleError(ctx)
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Cannot check eligibility")
}
//================================================================
if len(eligibilityResponse.Division.HealthCareEligibilityResponse.LoopHL0030) < 1 {
return routeutils.ResponseAPINotEligibleError(ctx)
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Cannot check eligibility")
}
address := viewmodel.Address{}

View File

@@ -1,15 +1,13 @@
package validation
import (
"time"
"fmt"
"strconv"
"regexp"
"strconv"
"time"
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
"bitbucket.org/nemt/nemt-portal-api/infra/errors"
)
const (
@@ -38,7 +36,7 @@ func isMixedIDValid(id string) bool {
hasLowerCase := false
hasNumber := false
for _, character := range (id) {
for _, character := range id {
hasUpperCase = hasUpperCase || ((character >= 65) && (character <= 90))
hasLowerCase = hasLowerCase || ((character >= 97) && (character <= 122))
hasNumber = hasNumber || ((character >= 48) && (character <= 57))
@@ -210,6 +208,5 @@ func ValidateRide(requestRide *viewmodel.RideRequest, user *viewmodel.User) []er
result = append(result, errors.ValidationError{Field: "trip_type.key", Message: "Step #4 - Choose a Trip Type"})
}
return result
}