Skip to content

Commit

Permalink
Allow fetch multiple queues in a batch
Browse files Browse the repository at this point in the history
  • Loading branch information
websterzh committed May 24, 2023
1 parent 2b1565b commit 204d58f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions gin/handlers/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"github.com/gin-gonic/gin"
"net/http"
"strings"
"vatprc-queue/gin/errors"
"vatprc-queue/gin/services"
)
Expand Down Expand Up @@ -94,3 +95,29 @@ func GetQueueHandler(c *gin.Context) (interface{}, error) {
}
return services.GetQueueResult(airport, true), nil
}

func GetMultipleQueuesHandler(c *gin.Context) (interface{}, error) {
param, ok := c.Params.Get("airports")
if !ok {
return nil, errors.ApiError{
Status: http.StatusBadRequest,
Code: http.StatusBadRequest,
ShowInProduction: true,
Message: "airports parameter is required",
}
}
airports := strings.Split(param, ",")
if len(airports) < 1 || len(airports) > 10 {
return nil, errors.ApiError{
Status: http.StatusBadRequest,
Code: http.StatusBadRequest,
ShowInProduction: true,
Message: "enter 1 to 10 airports",
}
}
result := make(map[string][]services.QueueResult)
for _, airport := range airports {
result[airport] = services.GetQueueResult(airport, true)
}
return result, nil
}
1 change: 1 addition & 0 deletions gin/router/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func InitRouter() *gin.Engine {
v1 := router.Group("v1")
{
v1.GET("/hello", errors.ErrorWrapper(handlers.HelloWorld))
v1.GET("/queue", errors.ErrorWrapper(handlers.GetMultipleQueuesHandler))
airport := v1.Group("/:airport")
{
airport.PATCH("/status", errors.ErrorWrapper(handlers.UpdateStatus))
Expand Down

0 comments on commit 204d58f

Please sign in to comment.