From 25caf06545d1d5048978ba35ba720d20168f35c9 Mon Sep 17 00:00:00 2001 From: darmiel <71837281+darmiel@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:45:07 +0200 Subject: [PATCH] feat[backend]: auto subscribe to topics on create --- backend/api/handlers/topic_handler.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/api/handlers/topic_handler.go b/backend/api/handlers/topic_handler.go index 49102ab..cd7bae2 100644 --- a/backend/api/handlers/topic_handler.go +++ b/backend/api/handlers/topic_handler.go @@ -93,6 +93,12 @@ func (h *TopicHandler) AddTopic(ctx *fiber.Ctx) error { if err != nil { return ctx.Status(fiber.StatusInternalServerError).JSON(presenter.ErrorResponse(err)) } + + // subscribe to topic + if err = h.srv.SubscribeUser(topic.ID, u.UserID); err != nil { + h.logger.Warnf("cannot subscribe user %s (creator) to topic %d: %v", u.UserID, topic.ID, err) + } + return ctx.Status(fiber.StatusCreated).JSON(presenter.SuccessResponse("topic created", topic)) }