forked from mtusi2026/mtusi2026lab3
feat(app) lab 3 implemented
This commit is contained in:
@@ -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,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"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user