refactor(app) AI refactoring before moving to Lab3 done

This commit is contained in:
imadev
2026-10-26 19:39:45 +03:00
parent d14fed291e
commit 71174f844c
30 changed files with 895 additions and 560 deletions
+5 -7
View File
@@ -5,7 +5,6 @@ import (
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/common"
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/store"
"github.com/gofiber/fiber/v3"
"github.com/google/uuid"
)
type Handler struct {
@@ -17,9 +16,9 @@ func NewHandler(st *store.Store) *Handler {
}
type CreateUserRequest struct {
Username string `json:"username" validate:"required"`
DisplayName string `json:"display_name" validate:"required"`
Password string `json:"password" validate:"required"`
Username string `json:"username"`
DisplayName string `json:"display_name"`
Password string `json:"password"`
}
func (h *Handler) CreateUser(c fiber.Ctx) error {
@@ -37,8 +36,7 @@ func (h *Handler) CreateUser(c fiber.Ctx) error {
hash, err := auth.HashPassword(req.Password)
if err != nil {
return common.SendError(c, fiber.StatusInternalServerError,
common.ErrorCodeInternal, "Internal server error")
return common.SendAppError(c, common.Internal())
}
user, err := h.store.CreateUser(c.Context(), req.Username, req.DisplayName, hash)
@@ -50,7 +48,7 @@ func (h *Handler) CreateUser(c fiber.Ctx) error {
}
func (h *Handler) GetCurrentUser(c fiber.Ctx) error {
userID, ok := c.Locals("userID").(uuid.UUID)
userID, ok := common.UserID(c)
if !ok {
return common.SendChallenge(c, `Bearer realm="messenger"`, "authentication required")
}