2024-03-15 21:27:45 +03:00
|
|
|
package endpoints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"relynolli-server/models"
|
|
|
|
"relynolli-server/services"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (h *handlers) GetCatalogItems(c *gin.Context) {
|
|
|
|
|
|
|
|
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
|
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
|
|
offset := (page - 1) * limit
|
2024-03-18 05:58:15 +03:00
|
|
|
if c.DefaultQuery("isFilter", "0") == "0" {
|
|
|
|
c.JSON(200, services.GetCatalogItems(limit, offset))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.JSON(200, services.FilterCatalogItems(c.Request.URL.Query()))
|
2024-03-15 21:27:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlers) GetCatalogItem(c *gin.Context) {
|
|
|
|
code := c.Param("code")
|
|
|
|
if code == "" {
|
|
|
|
c.JSON(400, models.Response{Status: 400, Info: "product \"Code\" should be provided"})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := services.GetCatalogItem(code)
|
|
|
|
if err != nil {
|
|
|
|
c.JSON(404, models.Response{Status: 404, Info: err.Error()})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(200, resp)
|
|
|
|
}
|