2018-07-05 08:52:05 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/labstack/echo"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2018-07-10 14:02:23 +02:00
|
|
|
// GetIntURLParam is a helper method which returns an int from an url param
|
2018-07-05 08:52:05 +02:00
|
|
|
func GetIntURLParam(param string, c echo.Context) (intParam int64, err error) {
|
|
|
|
|
|
|
|
id := c.Param(param)
|
|
|
|
if id != "" {
|
|
|
|
intParam, err = strconv.ParseInt(id, 10, 64)
|
|
|
|
}
|
|
|
|
|
|
|
|
return intParam, err
|
|
|
|
}
|
2018-07-07 14:19:34 +02:00
|
|
|
|
2018-07-10 14:02:23 +02:00
|
|
|
// GetByID gets an object by its ID
|
2018-07-07 14:19:34 +02:00
|
|
|
func GetByID(id int64, result interface{}) (err error) {
|
|
|
|
exists, err := x.ID(id).Get(result)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !exists {
|
|
|
|
return ErrListDoesNotExist{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2018-07-08 22:50:01 +02:00
|
|
|
}
|