From 9ae7fe30772a8caa9ae413266631183bbb81ef73 Mon Sep 17 00:00:00 2001 From: John Costa Date: Tue, 13 May 2025 17:05:46 +0100 Subject: [PATCH] feat: end point for getting image similarity --- backend/main.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/backend/main.go b/backend/main.go index 8df4f71..555212e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -186,6 +186,36 @@ func main() { w.Write(jsonImages) }) + r.Get("/image-similar/{id}", func(w http.ResponseWriter, r *http.Request) { + // TODO: authentication + stringImageId := r.PathValue("id") + + imageId, err := uuid.Parse(stringImageId) + if err != nil { + w.WriteHeader(http.StatusForbidden) + fmt.Fprintf(w, "You cannot read this") + return + } + + similarImages, err := imageModel.GetSimilar(r.Context(), imageId) + if err != nil { + log.Println(err) + w.WriteHeader(http.StatusNotFound) + fmt.Fprintf(w, "Something went wrong") + return + } + + jsonImages, err := json.Marshal(similarImages) + if err != nil { + log.Println(err) + w.WriteHeader(http.StatusBadRequest) + fmt.Fprintf(w, "Could not create JSON response for this image") + return + } + + w.Write(jsonImages) + }) + r.Post("/image/{name}", func(w http.ResponseWriter, r *http.Request) { imageName := r.PathValue("name") userId := r.Context().Value(USER_ID).(uuid.UUID)