fix: cascade deleting of image properties
This commit is contained in:
@ -145,7 +145,7 @@ func (h *ImageHandler) uploadImage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h *ImageHandler) deleteImage(w http.ResponseWriter, r *http.Request) {
|
||||
stringImageID := chi.URLParam(r, "name")
|
||||
stringImageID := chi.URLParam(r, "image-id")
|
||||
imageID, err := uuid.Parse(stringImageID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -168,6 +168,7 @@ func (h *ImageHandler) deleteImage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = h.imageModel.Delete(ctx, imageID)
|
||||
if err != nil {
|
||||
h.logger.Warn("cannot delete image", "error", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -188,6 +189,7 @@ func (h *ImageHandler) CreateRoutes(r chi.Router) {
|
||||
|
||||
r.Get("/", h.listImages)
|
||||
r.Post("/{name}", middleware.WithLimit(h.logger, h.limitsManager.HasReachedImageLimit, h.uploadImage))
|
||||
r.Delete("/{image-id}", h.deleteImage)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ func (m ImageModel) IsUserAuthorized(ctx context.Context, imageId uuid.UUID, use
|
||||
userImage := model.UserImages{}
|
||||
err := getImageUserId.QueryContext(ctx, m.dbPool, &userImage)
|
||||
|
||||
return err != nil && userImage.UserID.String() == userId.String()
|
||||
return err == nil && userImage.UserID.String() == userId.String()
|
||||
}
|
||||
|
||||
func NewImageModel(db *sql.DB) ImageModel {
|
||||
|
@ -23,13 +23,13 @@ CREATE TABLE haystack.image (
|
||||
CREATE TABLE haystack.user_images_to_process (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
status haystack.progress NOT NULL DEFAULT 'not-started',
|
||||
image_id uuid NOT NULL UNIQUE REFERENCES haystack.image (id),
|
||||
image_id uuid NOT NULL UNIQUE REFERENCES haystack.image (id) ON DELETE CASCADE,
|
||||
user_id uuid NOT NULL REFERENCES haystack.users (id)
|
||||
);
|
||||
|
||||
CREATE TABLE haystack.user_images (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
image_id uuid NOT NULL UNIQUE REFERENCES haystack.image (id),
|
||||
image_id uuid NOT NULL UNIQUE REFERENCES haystack.image (id) ON DELETE CASCADE,
|
||||
user_id uuid NOT NULL REFERENCES haystack.users (id),
|
||||
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT now()
|
||||
@ -37,7 +37,7 @@ CREATE TABLE haystack.user_images (
|
||||
|
||||
CREATE TABLE haystack.logs (
|
||||
log TEXT NOT NULL,
|
||||
image_id UUID NOT NULL REFERENCES haystack.image (id),
|
||||
image_id UUID NOT NULL REFERENCES haystack.image (id) ON DELETE CASCADE,
|
||||
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT now()
|
||||
);
|
||||
@ -67,7 +67,7 @@ CREATE TABLE haystack.processing_lists (
|
||||
CREATE TABLE haystack.image_lists (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
|
||||
image_id UUID NOT NULL REFERENCES haystack.image (id),
|
||||
image_id UUID NOT NULL REFERENCES haystack.image (id) ON DELETE CASCADE,
|
||||
list_id UUID NOT NULL REFERENCES haystack.lists (id)
|
||||
);
|
||||
|
||||
@ -93,7 +93,7 @@ CREATE TABLE haystack.image_schema_items (
|
||||
value TEXT,
|
||||
|
||||
schema_item_id UUID NOT NULL REFERENCES haystack.schema_items (id),
|
||||
image_id UUID NOT NULL REFERENCES haystack.image (id)
|
||||
image_id UUID NOT NULL REFERENCES haystack.image (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
/* -----| Indexes |----- */
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { ImageComponentFullHeight } from "@components/image";
|
||||
import { useSearchImageContext } from "@contexts/SearchImageContext";
|
||||
import { useParams } from "@solidjs/router";
|
||||
import { useNavigate, useParams } from "@solidjs/router";
|
||||
import { For, type Component } from "solid-js";
|
||||
import SolidjsMarkdown from "solidjs-markdown";
|
||||
import { ListCard } from "@components/list-card";
|
||||
import { deleteImage } from "@network/index";
|
||||
|
||||
export const ImagePage: Component = () => {
|
||||
const { imageId } = useParams<{ imageId: string }>();
|
||||
const nav = useNavigate();
|
||||
|
||||
const { userImages, lists, onDeleteImage } = useSearchImageContext();
|
||||
|
||||
@ -16,7 +16,10 @@ export const ImagePage: Component = () => {
|
||||
return (
|
||||
<main class="flex flex-col items-center gap-4">
|
||||
<div class="w-full bg-white rounded-xl p-4">
|
||||
<ImageComponentFullHeight ID={imageId} onDelete={onDeleteImage()} />
|
||||
<ImageComponentFullHeight ID={imageId} onDelete={(id) => {
|
||||
onDeleteImage(id);
|
||||
nav("/");
|
||||
}} />
|
||||
</div>
|
||||
<div class="w-full bg-white rounded-xl p-4 flex flex-col gap-4">
|
||||
<h2 class="font-bold text-2xl">Description</h2>
|
||||
|
Reference in New Issue
Block a user