From daee67d6c34f023425ceb1ef669cec34b17a3027 Mon Sep 17 00:00:00 2001 From: Bhasher Date: Sat, 30 Dec 2023 02:13:30 +0100 Subject: [PATCH] Create and delete card --- backend/handlers/cards.go | 10 ++--- frontend/src/components/card.svelte | 5 ++- frontend/src/components/modal_card.svelte | 21 ++++++++++ frontend/src/components/project.svelte | 51 +++++++++++++++++++++-- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/backend/handlers/cards.go b/backend/handlers/cards.go index 4479a6e..82c185e 100644 --- a/backend/handlers/cards.go +++ b/backend/handlers/cards.go @@ -12,15 +12,15 @@ import ( func CreateCard(c *fiber.Ctx) error { card := types.Card{} if err := c.BodyParser(&card); err != nil { - return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Cannot parse request"}) + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"status": "error", "error": "Cannot parse request", "trace": fmt.Sprint(err)}) } id, err := db.CreateCard(card) if err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot create card", "trace": fmt.Sprint(err)}) + return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"status": "error", "error": "Cannot create card", "trace": fmt.Sprint(err)}) } - return c.Status(fiber.StatusCreated).JSON(fiber.Map{"id": id}) + return c.Status(fiber.StatusCreated).JSON(fiber.Map{"status": "ok", "id": id}) } func GetAllCardsOf(c *fiber.Ctx) error { @@ -57,12 +57,12 @@ func GetCard(c *fiber.Ctx) error { func DeleteCard(c *fiber.Ctx) error { id, err := strconv.Atoi(c.Params("id")) if err != nil { - return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid card ID"}) + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"status": "error", "error": "Invalid card ID", "trace": fmt.Sprint(err)}) } err = db.DeleteCard(id) if err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot delete card"}) + return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"status": "error", "error": "Cannot delete card", "trace": fmt.Sprint(err)}) } return c.SendStatus(fiber.StatusNoContent) diff --git a/frontend/src/components/card.svelte b/frontend/src/components/card.svelte index ce7ed61..14b7702 100644 --- a/frontend/src/components/card.svelte +++ b/frontend/src/components/card.svelte @@ -12,7 +12,8 @@ tags: [] }; - let showModal = false; + export let showModal = false; + export let onDelete: () => void; function editCard() { showModal = true; @@ -49,4 +50,4 @@ {/if} - + diff --git a/frontend/src/components/modal_card.svelte b/frontend/src/components/modal_card.svelte index 73e4423..a82ced4 100644 --- a/frontend/src/components/modal_card.svelte +++ b/frontend/src/components/modal_card.svelte @@ -7,6 +7,7 @@ export let show: boolean; export let card: Card; export let onCancel: () => void; + export let onDelete: () => void; let tempCard: Card = { ...card }; @@ -32,6 +33,26 @@
save(false)} />
+ +
    {#if cards} {#each cards as card} - + await deleteCard(card.id)} + /> {/each} {/if}