feat(app) lab 3 implemented

This commit is contained in:
imadev
2026-10-30 18:11:30 +03:00
parent f731f9b460
commit 48a616e910
57 changed files with 1390 additions and 303 deletions
+10 -3
View File
@@ -1,8 +1,10 @@
// Package messages implements message creation with idempotency and message
// history pagination.
package messages
import (
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/common"
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/store"
"gitflic.ru/project/bulla-max/mtusi2026lab/internal/common"
"gitflic.ru/project/bulla-max/mtusi2026lab/internal/store"
"github.com/gofiber/fiber/v3"
"github.com/google/uuid"
)
@@ -28,6 +30,11 @@ func (h *Handler) CreateMessage(c fiber.Ctx) error {
common.ErrorCodeInvalidRequest, "invalid chat_id format")
}
idempotencyKey := c.Get("Idempotency-Key")
if msg := common.ValidateIdempotencyKey(idempotencyKey); msg != "" {
return common.SendError(c, fiber.StatusBadRequest, common.ErrorCodeInvalidRequest, msg)
}
var req CreateMessageRequest
if err := common.BindJSON(c, &req); err != nil {
return common.SendAppError(c, err)
@@ -36,7 +43,7 @@ func (h *Handler) CreateMessage(c fiber.Ctx) error {
return common.SendError(c, fiber.StatusBadRequest, common.ErrorCodeInvalidRequest, msg)
}
message, err := h.store.CreateMessage(c.Context(), chatID, userID, req.Text)
message, err := h.store.CreateMessage(c.Context(), chatID, userID, req.Text, idempotencyKey)
if err != nil {
return common.SendAppError(c, err)
}
+1 -1
View File
@@ -1,7 +1,7 @@
package messages
import (
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/store"
"gitflic.ru/project/bulla-max/mtusi2026lab/internal/store"
"github.com/gofiber/fiber/v3"
)