From a079fbf9db848f5977b1555972a4bdee28263384 Mon Sep 17 00:00:00 2001 From: daru Date: Sat, 28 May 2022 12:30:21 +0200 Subject: [PATCH] GET appointments --- ober.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ober.go b/ober.go index c05eb86..c4f4b7e 100644 --- a/ober.go +++ b/ober.go @@ -153,7 +153,30 @@ func AnimeSearchGet(ctx *fasthttp.RequestCtx) { } func AppointmentGet(ctx *fasthttp.RequestCtx) { - ctx.SetStatusCode(fasthttp.StatusNotImplemented) + appoints, err := ReadAppointments() + // check if no appointments exists + if err != nil { + if strings.Contains(err.Error(), "not found") || err == nutsdb.ErrBucketEmpty { + appoints = make([]Appointment, 0) + } else { + addErrorToCtx(ctx, err) + return + } + } + + bytes, err := json.Marshal(appoints) + if err != nil { + addErrorToCtx(ctx, err) + return + } + _, err = ctx.Write(bytes) + if err != nil { + addErrorToCtx(ctx, err) + return + } + + ctx.SetContentType("application/json; charset=utf-8") + ctx.SetStatusCode(fasthttp.StatusOK) } func ChatGet(ctx *fasthttp.RequestCtx) {