Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Fabian Vitt
good2go
Commits
7f03058a
Commit
7f03058a
authored
Jun 04, 2020
by
Max Richter
Browse files
fix(restapi): router dont work without strictslash(true)
parent
ad5aae12
Changes
3
Hide whitespace changes
Inline
Side-by-side
api/rest/subrouters/appointment_router.go
View file @
7f03058a
...
...
@@ -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"
)
...
...
api/rest/subrouters/building_router.go
View file @
7f03058a
...
...
@@ -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"
)
...
...
api/rest/subrouters/room_router.go
View file @
7f03058a
...
...
@@ -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"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment