ch some
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/handlers"
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -112,7 +113,7 @@ func (h *handler) respondList(c *gin.Context, filter ListFilter) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-orders/{id} [get]
|
||||
func (h *handler) getByID(c *gin.Context) {
|
||||
id, ok := parseID(c.Param("id"))
|
||||
id, ok := shared.ParseID(c.Param("id"))
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
@@ -183,7 +184,7 @@ func (h *handler) create(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-orders/{id} [put]
|
||||
func (h *handler) update(c *gin.Context) {
|
||||
id, ok := parseID(c.Param("id"))
|
||||
id, ok := shared.ParseID(c.Param("id"))
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
@@ -226,7 +227,7 @@ func (h *handler) update(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-orders/{id} [delete]
|
||||
func (h *handler) delete(c *gin.Context) {
|
||||
id, ok := parseID(c.Param("id"))
|
||||
id, ok := shared.ParseID(c.Param("id"))
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
@@ -248,28 +249,14 @@ func (h *handler) delete(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData("loan order removed"))
|
||||
}
|
||||
|
||||
func parseID(raw string) (int64, bool) {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return id, true
|
||||
}
|
||||
|
||||
const (
|
||||
defaultPage = 1
|
||||
defaultLimit = 10
|
||||
maxLimit = 100
|
||||
)
|
||||
|
||||
func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
filter := ListFilter{
|
||||
Page: defaultPage,
|
||||
Limit: defaultLimit,
|
||||
Page: shared.DefaultPage,
|
||||
Limit: shared.DefaultLimit,
|
||||
}
|
||||
|
||||
if raw := queryValue(c, "branch_id", "branchId"); raw != "" {
|
||||
id, ok := parseID(raw)
|
||||
id, ok := shared.ParseID(raw)
|
||||
if !ok {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
@@ -277,7 +264,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
}
|
||||
|
||||
if raw := queryValue(c, "user_id", "userId"); raw != "" {
|
||||
id, ok := parseID(raw)
|
||||
id, ok := shared.ParseID(raw)
|
||||
if !ok {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
@@ -297,8 +284,8 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
if err != nil || limit < 1 {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
if limit > maxLimit {
|
||||
limit = maxLimit
|
||||
if limit > shared.MaxLimit {
|
||||
limit = shared.MaxLimit
|
||||
}
|
||||
filter.Limit = limit
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user