Skip to content

Commit

Permalink
fix: throw bad request for negative count value
Browse files Browse the repository at this point in the history
  • Loading branch information
D3vd committed Jun 14, 2021
1 parent 214900c commit f523369
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions api/gimme/n_random_memes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ func GetNRandomMemes(c *gin.Context) {

count, _ := strconv.Atoi(c.Param("interface"))

if count <= 0 {
c.JSON(http.StatusBadRequest, response.Error{
Code: http.StatusBadRequest,
Message: "Invalid Count Value",
})
return
}

// Check if the count is less than 50
if count > 50 {
count = 50
Expand Down
2 changes: 1 addition & 1 deletion api/gimme/n_random_posts_from_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GetNPostsFromSub(c *gin.Context) {
sub := strings.ToLower(c.Param("interface"))
count, err := strconv.Atoi(c.Param("count"))

if err != nil {
if err != nil || count <= 0 {
res := response.Error{
Code: http.StatusBadRequest,
Message: "Invalid Count Value",
Expand Down

0 comments on commit f523369

Please sign in to comment.