forked from mtusi2026/mtusi2026lab2
refactor(app) AI refactoring before moving to Lab3 done
This commit is contained in:
@@ -16,12 +16,12 @@ func NewHandler(st *store.Store) *Handler {
|
||||
}
|
||||
|
||||
type CreateChatRequest struct {
|
||||
Title string `json:"title" validate:"required"`
|
||||
MemberIDs []uuid.UUID `json:"member_ids" validate:"required"`
|
||||
Title string `json:"title"`
|
||||
MemberIDs []uuid.UUID `json:"member_ids"`
|
||||
}
|
||||
|
||||
func (h *Handler) CreateChat(c fiber.Ctx) error {
|
||||
userID := c.Locals("userID").(uuid.UUID)
|
||||
userID := common.MustUserID(c)
|
||||
|
||||
var req CreateChatRequest
|
||||
if err := common.BindJSON(c, &req); err != nil {
|
||||
@@ -44,7 +44,7 @@ func (h *Handler) CreateChat(c fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func (h *Handler) ListChats(c fiber.Ctx) error {
|
||||
userID := c.Locals("userID").(uuid.UUID)
|
||||
userID := common.MustUserID(c)
|
||||
|
||||
limit, err := common.ParseLimit(c, 50)
|
||||
if err != nil {
|
||||
@@ -69,7 +69,7 @@ func (h *Handler) ListChats(c fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func (h *Handler) GetChat(c fiber.Ctx) error {
|
||||
userID := c.Locals("userID").(uuid.UUID)
|
||||
userID := common.MustUserID(c)
|
||||
|
||||
chatID, err := uuid.Parse(c.Params("chat_id"))
|
||||
if err != nil {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func RegisterRoutes(router fiber.Router, st *store.Store) {
|
||||
func RegisterProtectedRoutes(router fiber.Router, st *store.Store) {
|
||||
handler := NewHandler(st)
|
||||
router.Post("/chats", handler.CreateChat)
|
||||
router.Get("/chats", handler.ListChats)
|
||||
|
||||
Reference in New Issue
Block a user