CHANGE: adde OpenAPI Docs + swagger UI
This commit is contained in:
@@ -25,7 +25,7 @@ func main() {
|
||||
http.HandleFunc("/time", timeHandler)
|
||||
|
||||
fmt.Printf("Server is running at http://localhost:8080 exposed to port %s\n", getEnv("EXPOSED_PORT", "8000"))
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||
}
|
||||
|
||||
func timeCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -38,6 +38,9 @@ func timeCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func timeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if os.Getenv("DEBUG") == "true" {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
}
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
getBookings(w, r)
|
||||
@@ -46,6 +49,7 @@ func timeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func createBooking(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -69,6 +73,10 @@ func createBooking(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func getBookings(w http.ResponseWriter, r *http.Request) {
|
||||
card_id := r.URL.Query().Get("cardID")
|
||||
if card_id == "" {
|
||||
http.Error(w, "Missing cardID query parameter", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
bookings, err := (*models.Booking).GetBookingsByCardID(nil, card_id)
|
||||
if err != nil {
|
||||
log.Println("Error getting bookings: ", err)
|
||||
|
||||
Reference in New Issue
Block a user