Add GET /loan-orders/mobile to list loan orders created from the mobile app.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-22 18:37:31 +05:00
parent 8795ae2195
commit 427d5b4e07
6 changed files with 240 additions and 0 deletions

View File

@@ -176,6 +176,11 @@ func buildListQuery(filter loanorders.ListFilter) (whereClause string, args []in
conditions = append(conditions, fmt.Sprintf("lo.region = $%d", len(args)))
}
if filter.Source != "" {
args = append(args, filter.Source)
conditions = append(conditions, fmt.Sprintf("lo.source = $%d", len(args)))
}
if len(conditions) == 0 {
return "", args
}

View File

@@ -230,6 +230,7 @@ type ListFilter struct {
Status *string
BranchId *int64
UserId *int64
Source string
Region string
Page int
Limit int

View File

@@ -28,6 +28,7 @@ func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler
func (h *handler) Register(router *gin.RouterGroup) {
group := router.Group(baseURL, appresult.JwtTokenCheck())
group.GET("", h.list)
group.GET("/mobile", h.listMobile)
group.GET("/:id", h.getByID)
group.POST("", h.create)
group.PUT("/:id", h.update)
@@ -56,7 +57,36 @@ func (h *handler) list(c *gin.Context) {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return
}
h.respondList(c, filter)
}
// listMobile godoc
// @Summary List mobile loan orders
// @Description Returns paginated loan orders created from the mobile app
// @Tags loan-orders
// @Produce json
// @Security BearerAuth
// @Param status query string false "Filter by status"
// @Param branch_id query int false "Filter by branch ID"
// @Param user_id query int false "Filter by user ID"
// @Param region query string false "Filter by region"
// @Param page query int false "Page number" default(1)
// @Param limit query int false "Items per page" default(10)
// @Success 200 {object} appresult.AppSuccess
// @Failure 400 {object} appresult.AppError
// @Failure 500 {object} appresult.AppError
// @Router /loan-orders/mobile [get]
func (h *handler) listMobile(c *gin.Context) {
filter, ok := parseListFilter(c)
if !ok {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return
}
filter.Source = "mobile"
h.respondList(c, filter)
}
func (h *handler) respondList(c *gin.Context, filter ListFilter) {
result, err := h.repository.List(c.Request.Context(), filter)
if err != nil {
h.logger.Errorf("list loan orders failed: %v", err)