19 lines
467 B
Go
19 lines
467 B
Go
|
package Controllers
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"net/http"
|
||
|
"tel-commerce/ent"
|
||
|
"tel-commerce/ent/product"
|
||
|
)
|
||
|
|
||
|
func (Controller Controller) GetProducts() gin.HandlerFunc {
|
||
|
return func(ctx *gin.Context) {
|
||
|
if products, err := Controller.Client.Product.Query().Order(ent.Asc(product.FieldID)).All(Controller.Ctx); err != nil {
|
||
|
ctx.IndentedJSON(http.StatusInternalServerError, err.Error())
|
||
|
} else {
|
||
|
ctx.IndentedJSON(http.StatusOK, products)
|
||
|
}
|
||
|
}
|
||
|
}
|