Commit 35c0d234 authored by Max Richter's avatar Max Richter
Browse files

fix(): restore missing appointment router

parent 71128434
Pipeline #1867 passed with stages
in 2 minutes and 45 seconds
......@@ -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
......
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")
}
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