ADD: first api route get bookings
This commit is contained in:
@@ -33,6 +33,8 @@ func timeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case "PUT":
|
||||
createBooking(w, r)
|
||||
case "GET":
|
||||
getBookings(w, r)
|
||||
default:
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
@@ -57,6 +59,21 @@ func createBooking(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func getBookings(w http.ResponseWriter, r *http.Request) {
|
||||
card_id := r.URL.Query().Get("cardID")
|
||||
bookings, err := GetBookingsByCardID(DB, card_id)
|
||||
if err != nil {
|
||||
log.Println("Error getting bookings: ", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(bookings)
|
||||
|
||||
}
|
||||
|
||||
// func getBooking(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user