Commit 4e0c3211 authored by Max Granzow's avatar Max Granzow

Apply 1 suggestion(s) to 1 file(s)

parent 592a9685
Pipeline #2287 passed with stages
in 5 minutes and 2 seconds
......@@ -378,24 +378,22 @@ func searchForUsers(repository UserQuery) gin.HandlerFunc {
func getRecommendedUsers(repository UserQuery) gin.HandlerFunc {
return func(ctx *gin.Context) {
DefaultCount := 3
MaxCount := 10
const DefaultCount = 3
const MaxCount = 10
countParam := ctx.DefaultQuery("c", strconv.Itoa(DefaultCount))
count64, err := strconv.ParseInt(countParam, 10, 32)
var req struct {
Count int32 `form:"c"`
}
// Only accept numbers as count
if err != nil {
ctx.String(http.StatusBadRequest, "Invalid user count. Specify a number in range 1 to "+strconv.Itoa(MaxCount)+".")
if err := ctx.BindQuery(&req); err != nil {
return
}
count := int(count64)
// Only accept numbers in range [0-10]
if count <= 0 {
count = DefaultCount
} else if count > MaxCount {
count = MaxCount
if req.Count <= 0 {
req.Count = DefaultCount
} else if req.Count > MaxCount {
req.Count = MaxCount
}
userID, err := endpoint.GetUserID(ctx)
......@@ -404,7 +402,7 @@ func getRecommendedUsers(repository UserQuery) gin.HandlerFunc {
}
// fetch matching users from database
users, err := repository.SelectUserRecommendations(userID, uint32(count))
users, err := repository.SelectUserRecommendations(userID, uint32(req.Count))
if err != nil {
eventID := raven.CaptureError(err, nil)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment