26 lines
573 B
Go
26 lines
573 B
Go
package handlers
|
|
|
|
import (
|
|
"go-server/internal/service"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type CategoryController struct {
|
|
categoryService *service.CategoryService
|
|
}
|
|
|
|
func NewCategoryController(categoryService *service.CategoryService) *CategoryController {
|
|
return &CategoryController{categoryService: categoryService}
|
|
}
|
|
|
|
func (h *CategoryController) GetAll(c *gin.Context) {
|
|
categories, err := h.categoryService.GetAll(c)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, categories)
|
|
}
|