Example #1
0
// NewUpdateBottleContext parses the incoming request URL and body, performs validations and creates the
// context used by the bottle controller update action.
func NewUpdateBottleContext(c *goa.Context) (*UpdateBottleContext, error) {
	var err error
	ctx := UpdateBottleContext{Context: c}
	rawAccountID, ok := c.Get("accountID")
	if ok {
		if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
			ctx.AccountID = int(accountID)
		} else {
			err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
		}
	}
	rawBottleID, ok := c.Get("bottleID")
	if ok {
		if bottleID, err2 := strconv.Atoi(rawBottleID); err2 == nil {
			ctx.BottleID = int(bottleID)
		} else {
			err = goa.InvalidParamTypeError("bottleID", rawBottleID, "integer", err)
		}
	}
	p, err := NewUpdateBottlePayload(c.Payload())
	if err != nil {
		return nil, err
	}
	ctx.Payload = p
	return &ctx, err
}
Example #2
0
// NewListBottleContext parses the incoming request URL and body, performs validations and creates the
// context used by the bottle controller list action.
func NewListBottleContext(c *goa.Context) (*ListBottleContext, error) {
	var err error
	ctx := ListBottleContext{Context: c}
	rawAccountID, ok := c.Get("accountID")
	if ok {
		if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
			ctx.AccountID = int(accountID)
		} else {
			err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
		}
	}
	rawYears, ok := c.Get("years")
	if ok {
		elemsYears := strings.Split(rawYears, ",")
		elemsYears2 := make([]int, len(elemsYears))
		for i, rawElem := range elemsYears {
			if elem, err2 := strconv.Atoi(rawElem); err2 == nil {
				elemsYears2[i] = int(elem)
			} else {
				err = goa.InvalidParamTypeError("elem", rawElem, "integer", err)
			}
		}
		ctx.Years = elemsYears2
		ctx.HasYears = true
	}
	return &ctx, err
}
Example #3
0
// NewShowBottleContext parses the incoming request URL and body, performs validations and creates the
// context used by the bottle controller show action.
func NewShowBottleContext(c *goa.Context) (*ShowBottleContext, error) {
	var err error
	ctx := ShowBottleContext{Context: c}
	rawAccountID := c.Get("accountID")
	if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
		ctx.AccountID = int(accountID)
	} else {
		err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
	}
	rawBottleID := c.Get("bottleID")
	if bottleID, err2 := strconv.Atoi(rawBottleID); err2 == nil {
		ctx.BottleID = int(bottleID)
	} else {
		err = goa.InvalidParamTypeError("bottleID", rawBottleID, "integer", err)
	}
	return &ctx, err
}
Example #4
0
// NewShowUserContext parses the incoming request URL and body, performs validations and creates the
// context used by the user controller show action.
func NewShowUserContext(c *goa.Context) (*ShowUserContext, error) {
	var err error
	ctx := ShowUserContext{Context: c}
	rawAccountID, ok := c.Get("accountID")
	if ok {
		if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
			ctx.AccountID = int(accountID)
		} else {
			err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
		}
	}
	rawUserID, ok := c.Get("userID")
	if ok {
		if userID, err2 := strconv.Atoi(rawUserID); err2 == nil {
			ctx.UserID = int(userID)
		} else {
			err = goa.InvalidParamTypeError("userID", rawUserID, "integer", err)
		}
	}
	return &ctx, err
}
Example #5
0
		Ω(badReq.Error()).Should(Equal(rawErr.Error()))
	})
})

var _ = Describe("InvalidParamTypeError", func() {
	var valErr, err error
	name := "param"
	val := 42
	expected := "43"

	BeforeEach(func() {
		err = nil
	})

	JustBeforeEach(func() {
		valErr = goa.InvalidParamTypeError(name, val, expected, err)
	})

	It("creates a multi error", func() {
		Ω(valErr).ShouldNot(BeNil())
		Ω(valErr).Should(BeAssignableToTypeOf(goa.MultiError{}))
		mErr := valErr.(goa.MultiError)
		Ω(mErr).Should(HaveLen(1))
		Ω(mErr[0]).Should(BeAssignableToTypeOf(&goa.TypedError{}))
		tErr := mErr[0].(*goa.TypedError)
		Ω(tErr.ID).Should(Equal(goa.ErrorID((goa.ErrInvalidParamType))))
		Ω(tErr.Mesg).Should(ContainSubstring(name))
		Ω(tErr.Mesg).Should(ContainSubstring("%d", val))
		Ω(tErr.Mesg).Should(ContainSubstring(expected))
	})