Backend ws publishes for CUD

This commit is contained in:
Brieuc Dubois 2024-01-20 20:08:47 +01:00
parent c271af9d93
commit 1991f26322
4 changed files with 291 additions and 15 deletions

View File

@ -67,7 +67,24 @@ func CreateCardTag(c *fiber.Ctx) error {
}) })
} }
return c.SendStatus(fiber.StatusCreated) err = c.SendStatus(fiber.StatusCreated)
if err != nil {
return err
}
source := c.Get("X-Request-Source");
if source == "" {
return nil;
}
publish(fiber.Map{
"object": "cardtag",
"action": "create",
"data": cardtag,
"X-Request-Source": source,
});
return nil
} }
func GetCardTags(c *fiber.Ctx) error { func GetCardTags(c *fiber.Ctx) error {
@ -143,7 +160,25 @@ func DeleteCardTag(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source");
if source == "" {
return nil
}
publish(fiber.Map{
"object": "cardtag",
"action": "delete",
"id": cardID,
"X-Request-Source": source,
});
return nil
} }
func DeleteCardTags(c *fiber.Ctx) error { func DeleteCardTags(c *fiber.Ctx) error {
@ -172,6 +207,8 @@ func DeleteCardTags(c *fiber.Ctx) error {
} }
return c.SendStatus(fiber.StatusNoContent) return c.SendStatus(fiber.StatusNoContent)
// TODO publish event
} }
func UpdateCardTag(c *fiber.Ctx) error { func UpdateCardTag(c *fiber.Ctx) error {
@ -224,5 +261,24 @@ func UpdateCardTag(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source");
if source == "" {
return nil
}
publish(fiber.Map{
"object": "cardtag",
"action": "update",
"card_id": cardID,
"tag_id": tagID,
"changes": cardtag,
"X-Request-Source": source,
})
return nil
} }

View File

@ -47,9 +47,28 @@ func CreateFilter(c *fiber.Ctx) error {
}) })
} }
return c.Status(fiber.StatusCreated).JSON(fiber.Map{ err = c.Status(fiber.StatusCreated).JSON(fiber.Map{
"id": id, "id": id,
}) })
if err != nil {
return err
}
filter.ID = id
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "filter",
"action": "create",
"data": filter,
"X-Request-Source": source,
})
return nil
} }
func GetFilter(c *fiber.Ctx) error { func GetFilter(c *fiber.Ctx) error {
@ -107,7 +126,25 @@ func UpdateFilter(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "filter",
"action": "update",
"id": id,
"changes": filter,
"X-Request-Source": source,
})
return nil
} }
func DeleteFilter(c *fiber.Ctx) error { func DeleteFilter(c *fiber.Ctx) error {
@ -127,5 +164,22 @@ func DeleteFilter(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "filter",
"action": "delete",
"id": id,
"X-Request-Source": source,
})
return nil
} }

View File

@ -35,7 +35,26 @@ func CreateTag(c *fiber.Ctx) error {
}) })
} }
return c.Status(fiber.StatusCreated).JSON(fiber.Map{"id": id}) err = c.Status(fiber.StatusCreated).JSON(fiber.Map{"id": id})
if err != nil {
return err
}
tag.ID = id
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "tag",
"action": "create",
"data": tag,
"X-Request-Source": source,
})
return nil
} }
func GetTag(c *fiber.Ctx) error { func GetTag(c *fiber.Ctx) error {
@ -76,7 +95,24 @@ func DeleteTag(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "tag",
"action": "delete",
"id": id,
"X-Request-Source": source,
})
return nil
} }
func UpdateTag(c *fiber.Ctx) error { func UpdateTag(c *fiber.Ctx) error {
@ -102,7 +138,25 @@ func UpdateTag(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "tag",
"action": "update",
"id": id,
"changes": tag,
"X-Request-Source": source,
})
return nil
} }
func CreateTagOption(c *fiber.Ctx) error { func CreateTagOption(c *fiber.Ctx) error {
@ -135,7 +189,26 @@ func CreateTagOption(c *fiber.Ctx) error {
}) })
} }
return c.Status(fiber.StatusCreated).JSON(fiber.Map{"id": id}) err = c.Status(fiber.StatusCreated).JSON(fiber.Map{"id": id})
if err != nil {
return err
}
option.ID = id
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "tagoption",
"action": "create",
"data": option,
"X-Request-Source": source,
})
return nil
} }
func GetTagOptions(c *fiber.Ctx) error { func GetTagOptions(c *fiber.Ctx) error {
@ -200,7 +273,25 @@ func DeleteTagOption(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "tagoption",
"action": "delete",
"tag_id": tagID,
"option_id": optionID,
"X-Request-Source": source,
})
return nil
} }
func UpdateTagOption(c *fiber.Ctx) error { func UpdateTagOption(c *fiber.Ctx) error {
@ -242,7 +333,26 @@ func UpdateTagOption(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "tagoption",
"action": "update",
"tag_id": tagID,
"option_id": optionID,
"changes": option,
"X-Request-Source": source,
})
return nil
} }
func DeleteTagOptions(c *fiber.Ctx) error { func DeleteTagOptions(c *fiber.Ctx) error {
@ -271,4 +381,6 @@ func DeleteTagOptions(c *fiber.Ctx) error {
} }
return c.SendStatus(fiber.StatusNoContent) return c.SendStatus(fiber.StatusNoContent)
// TODO: publish event
} }

View File

@ -35,9 +35,28 @@ func CreateView(c *fiber.Ctx) error {
}) })
} }
return c.Status(fiber.StatusCreated).JSON(fiber.Map{ err = c.Status(fiber.StatusCreated).JSON(fiber.Map{
"id": id, "id": id,
}) })
if err != nil {
return err
}
view.ID = id
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "view",
"action": "create",
"data": view,
"X-Request-Source": source,
})
return nil
} }
func GetView(c *fiber.Ctx) error { func GetView(c *fiber.Ctx) error {
@ -85,7 +104,25 @@ func UpdateView(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "view",
"action": "update",
"id": id,
"changes": view,
"X-Request-Source": source,
})
return nil
} }
func DeleteView(c *fiber.Ctx) error { func DeleteView(c *fiber.Ctx) error {
@ -106,7 +143,24 @@ func DeleteView(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNotFound) return c.SendStatus(fiber.StatusNotFound)
} }
return c.SendStatus(fiber.StatusNoContent) err = c.SendStatus(fiber.StatusNoContent)
if err != nil {
return err
}
source := c.Get("X-Request-Source")
if source == "" {
return nil
}
publish(fiber.Map{
"object": "view",
"action": "delete",
"id": id,
"X-Request-Source": source,
})
return nil
} }
func GetViewFilters(c *fiber.Ctx) error { func GetViewFilters(c *fiber.Ctx) error {