ch some
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

This commit is contained in:
guwandyk committed 2026-09-04 19:33:26 +05:00
1 parent 28509eb4ca
commit d1a6fcaadc
102 files changed
+2089 -1957

No files matched your search

+10 -23
View File
@@ -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"
@@ -83,7 +84,7 @@ func (h *handler) list(c *gin.Context) {
// @Failure 500 {object} appresult.AppError
// @Router /loan-paid-off-letters/branches [get]
func (h *handler) listBranchesByProvince(c *gin.Context) {
provinceID, ok := parseID(c.Query("province_id"))
provinceID, ok := shared.ParseID(c.Query("province_id"))
if !ok {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return
@@ -122,7 +123,7 @@ func (h *handler) listBranchesByProvince(c *gin.Context) {
// @Failure 500 {object} appresult.AppError
// @Router /loan-paid-off-letters/{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
@@ -189,7 +190,7 @@ func (h *handler) create(c *gin.Context) {
// @Failure 500 {object} appresult.AppError
// @Router /loan-paid-off-letters/{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
@@ -232,7 +233,7 @@ func (h *handler) update(c *gin.Context) {
// @Failure 500 {object} appresult.AppError
// @Router /loan-paid-off-letters/{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
@@ -254,24 +255,10 @@ func (h *handler) delete(c *gin.Context) {
c.JSON(http.StatusOK, appresult.SuccessWithData("loan paid off letter 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 := c.Query("page"); raw != "" {
@@ -284,7 +271,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
if raw := c.Query("limit"); raw != "" {
limit, err := strconv.Atoi(raw)
if err != nil || limit < 1 || limit > maxLimit {
if err != nil || limit < 1 || limit > shared.MaxLimit {
return ListFilter{}, false
}
filter.Limit = limit
@@ -307,7 +294,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
}
if raw := c.Query("branch_id"); raw != "" {
id, ok := parseID(raw)
id, ok := shared.ParseID(raw)
if !ok {
return ListFilter{}, false
}
@@ -319,7 +306,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
raw = strings.TrimSpace(c.Query("userId"))
}
if raw != "" {
id, ok := parseID(raw)
id, ok := shared.ParseID(raw)
if !ok {
return ListFilter{}, false
}