This commit is contained in:
Héctor Hurtado
2019-10-24 10:44:48 +02:00
parent d2c3138036
commit 84a71815e4
3 changed files with 66 additions and 6 deletions
+10
View File
@@ -21,6 +21,7 @@ import (
"log"
"net/http"
"github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/BBVA/kapow/internal/server/model"
@@ -67,6 +68,7 @@ func listRoutes(res http.ResponseWriter, req *http.Request) {
}
var funcAdd func(model.Route) model.Route = user.Routes.Append
var idGenerator = uuid.NewUUID
func addRoute(res http.ResponseWriter, req *http.Request) {
var route model.Route
@@ -85,6 +87,14 @@ func addRoute(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusUnprocessableEntity)
return
}
id, err := idGenerator()
if err != nil {
res.WriteHeader(http.StatusInternalServerError)
return
}
route.ID = id.String()
created := funcAdd(route)
createdBytes, _ := json.Marshal(created)