Commit 7f03058a authored by Max Richter's avatar Max Richter
Browse files

fix(restapi): router dont work without strictslash(true)

parent ad5aae12
......@@ -35,7 +35,7 @@ func deleteAppointment(res http.ResponseWriter, req *http.Request) {
// AttachRouter Creates and attaches a sub-router to the given routers
func (a appointmentRouter) AttachRouter(router *mux.Router) {
r := router.PathPrefix("/appointments").Subrouter()
r := router.PathPrefix("/appointments").Subrouter().StrictSlash(true)
// CREATE
r.HandleFunc("/", createAppointment).Methods("POST")
......
......@@ -21,6 +21,9 @@ var (
func createBuilding(res http.ResponseWriter, req *http.Request) {
panic("Eyyyyyy")
// Parse incoming body
var buildingDTO model.Building
err := json.NewDecoder(req.Body).Decode(&model.Building{})
if err != nil {
......@@ -28,12 +31,18 @@ func createBuilding(res http.ResponseWriter, req *http.Request) {
return
}
fmt.Print("2")
// Create a new building instance/save it to db
building, err := s.BuildingService.CreateBuilding(&buildingDTO)
if err != nil {
http.Error(res, err.Error(), http.StatusBadRequest)
return
}
fmt.Print(building)
// Return new building
err = u.SendJSON(res).Encode(building)
if err != nil {
fmt.Println(err)
......@@ -82,7 +91,7 @@ func deleteBuilding(res http.ResponseWriter, req *http.Request) {
// AttachRouter initialize Router
func (a buildingRouter) AttachRouter(router *mux.Router) {
r := router.PathPrefix("/buildings/").Subrouter()
r := router.PathPrefix("/buildings").Subrouter().StrictSlash(true)
// CREATE
r.HandleFunc("/", createBuilding).Methods("POST")
......
......@@ -101,7 +101,7 @@ func deleteRoom(res http.ResponseWriter, req *http.Request) {
// AttachRouter initialize Router
func (a roomRouter) AttachRouter(router *mux.Router) {
r := router.PathPrefix("/rooms").Subrouter()
r := router.PathPrefix("/rooms").Subrouter().StrictSlash(true)
// CREATE
r.HandleFunc("/", createRoom).Methods("POST")
......
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