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
8a575bd3
Commit
8a575bd3
authored
Jun 05, 2020
by
Max Richter
Browse files
Merge branch 'dev' into 'master'
fix(): restore missing appointment router See merge request
!37
parents
76da79e0
35c0d234
Pipeline
#1868
passed with stages
in 3 minutes and 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
api/rest/main.go
View file @
8a575bd3
...
...
@@ -32,6 +32,7 @@ func Init() {
// Register all the Routers
h
.
RoomRouter
.
AttachRouter
(
r
)
h
.
AppointmentRouter
.
AttachRouter
(
r
)
h
.
HomeRouter
.
AttachRouter
(
r
)
// Create a new server
...
...
api/rest/routes/appointment_router.go
0 → 100644
View file @
8a575bd3
package
restapi
import
(
"encoding/json"
"fmt"
"net/http"
u
"git.coco.study/fvitt/good2go/api/rest/utils"
"git.coco.study/fvitt/good2go/internal/model"
s
"git.coco.study/fvitt/good2go/internal/services"
"github.com/gorilla/mux"
)
type
appointmentRouter
struct
{}
var
(
// AppointmentRouter handles appointment requests
AppointmentRouter
=
&
appointmentRouter
{}
)
func
createAppointment
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
type
AppointmentDTO
struct
{
StartTime
string
Duration
string
}
var
r
AppointmentDTO
err
:=
json
.
NewDecoder
(
req
.
Body
)
.
Decode
(
&
r
)
if
err
!=
nil
{
http
.
Error
(
res
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
}
app
,
err
:=
model
.
Appointment
{}
.
New
(
r
.
StartTime
,
r
.
Duration
)
if
err
!=
nil
{
http
.
Error
(
res
,
err
.
Error
(),
http
.
StatusBadRequest
)
}
room
,
err
:=
s
.
AppointmentService
.
AddAppointment
(
app
)
if
err
!=
nil
{
http
.
Error
(
res
,
err
.
Error
(),
http
.
StatusBadRequest
)
}
err
=
u
.
SendJSON
(
res
)
.
Encode
(
room
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
func
getAppointment
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
}
func
getAllAppointments
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
apps
:=
s
.
AppointmentService
.
GetAppointments
()
err
:=
u
.
SendJSON
(
res
)
.
Encode
(
apps
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
func
updateAppointment
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
}
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
)
{
singular
:=
router
.
PathPrefix
(
"/appointment"
)
.
Subrouter
()
.
StrictSlash
(
true
)
plural
:=
router
.
PathPrefix
(
"/appointments"
)
.
Subrouter
()
.
StrictSlash
(
true
)
// CREATE
singular
.
HandleFunc
(
"/"
,
createAppointment
)
.
Methods
(
"POST"
)
// READ
singular
.
HandleFunc
(
"/{id}"
,
getAppointment
)
.
Methods
(
"GET"
)
plural
.
HandleFunc
(
"/"
,
getAllAppointments
)
.
Methods
(
"GET"
)
// UPDATE
singular
.
HandleFunc
(
"/{id}"
,
updateAppointment
)
.
Methods
(
"PUT"
)
// DELETE
singular
.
HandleFunc
(
"/{id}"
,
deleteAppointment
)
.
Methods
(
"DELETE"
)
}
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