kanban dashboard refactor

This commit is contained in:
Mazyar
2026-05-27 22:06:23 +03:30
parent 42cd0452ce
commit ce2dc7a61b
12 changed files with 457 additions and 176 deletions
+23 -30
View File
@@ -20,32 +20,26 @@ func NewHandler(service Service) *Handler {
}
}
// RegisterRoutes registers kanban routes
// RegisterRoutes registers kanban routes on the provided group (e.g. /admin/v1/kanban).
func (h *Handler) RegisterRoutes(router *echo.Group) {
kanban := router.Group("/kanban")
{
// Board routes
kanban.POST("/boards", h.CreateBoard)
kanban.GET("/boards", h.GetBoardsByUser)
kanban.GET("/boards/default", h.GetDefaultBoard)
kanban.GET("/boards/:id", h.GetBoardByID)
kanban.PUT("/boards/:id", h.UpdateBoard)
kanban.DELETE("/boards/:id", h.DeleteBoard)
router.POST("/boards", h.CreateBoard)
router.GET("/boards", h.GetBoardsByUser)
router.GET("/boards/default", h.GetDefaultBoard)
router.GET("/boards/:id", h.GetBoardByID)
router.PUT("/boards/:id", h.UpdateBoard)
router.DELETE("/boards/:id", h.DeleteBoard)
// Column routes
kanban.POST("/columns", h.CreateColumn)
kanban.PUT("/columns/:id", h.UpdateColumn)
kanban.DELETE("/columns/:id", h.DeleteColumn)
kanban.PUT("/columns/reorder", h.ReorderColumns)
router.POST("/columns", h.CreateColumn)
router.PUT("/columns/:id", h.UpdateColumn)
router.DELETE("/columns/:id", h.DeleteColumn)
router.PUT("/columns/reorder", h.ReorderColumns)
// Card routes
kanban.POST("/cards", h.CreateCard)
kanban.GET("/cards/:id", h.GetCardByID)
kanban.PUT("/cards/:id", h.UpdateCard)
kanban.DELETE("/cards/:id", h.DeleteCard)
kanban.PUT("/cards/move", h.MoveCard)
kanban.PUT("/cards/reorder", h.ReorderCards)
}
router.POST("/cards", h.CreateCard)
router.GET("/cards/:id", h.GetCardByID)
router.PUT("/cards/:id", h.UpdateCard)
router.DELETE("/cards/:id", h.DeleteCard)
router.PUT("/cards/move", h.MoveCard)
router.PUT("/cards/reorder", h.ReorderCards)
}
// CreateBoard creates a new kanban board
@@ -65,12 +59,11 @@ func (h *Handler) CreateBoard(c echo.Context) error {
return response.ValidationError(c, "Invalid request data", err.Error())
}
// Get user ID from context (assuming auth middleware sets this)
userID, exists := c.Get("user_id").(string)
ownerID, exists := ownerIDFromContext(c)
if !exists {
return response.Unauthorized(c, "User not authenticated")
}
req.UserID = userID
req.UserID = ownerID
board, err := h.service.CreateBoard(c.Request().Context(), req)
if err != nil {
@@ -112,12 +105,12 @@ func (h *Handler) GetBoardByID(c echo.Context) error {
// @Failure 500 {object} response.Response
// @Router /kanban/boards [get]
func (h *Handler) GetBoardsByUser(c echo.Context) error {
userID, exists := c.Get("user_id").(string)
ownerID, exists := ownerIDFromContext(c)
if !exists {
return response.Unauthorized(c, "User not authenticated")
}
boards, err := h.service.GetBoardsByUserID(c.Request().Context(), userID)
boards, err := h.service.GetBoardsByUserID(c.Request().Context(), ownerID)
if err != nil {
return response.InternalServerError(c, "Failed to get boards")
}
@@ -136,12 +129,12 @@ func (h *Handler) GetBoardsByUser(c echo.Context) error {
// @Failure 500 {object} response.Response
// @Router /kanban/boards/default [get]
func (h *Handler) GetDefaultBoard(c echo.Context) error {
userID, exists := c.Get("user_id").(string)
ownerID, exists := ownerIDFromContext(c)
if !exists {
return response.Unauthorized(c, "User not authenticated")
}
board, err := h.service.GetDefaultBoard(c.Request().Context(), userID)
board, err := h.service.GetDefaultBoard(c.Request().Context(), ownerID)
if err != nil {
return response.InternalServerError(c, "Failed to get default board")
}