Accept flexible loan payloads and nest related info on lending responses.
Widen loan_orders.region in the init migration and share common relation helpers across loan APIs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0098422798
commit
6683826662
13 files changed
+591
-346
No files matched your search
@@ -263,7 +263,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
Limit: defaultLimit,
|
||||
}
|
||||
|
||||
if raw := c.Query("branch_id"); raw != "" {
|
||||
if raw := queryValue(c, "branch_id", "branchId"); raw != "" {
|
||||
id, ok := parseID(raw)
|
||||
if !ok {
|
||||
return ListFilter{}, false
|
||||
@@ -271,7 +271,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
filter.BranchId = &id
|
||||
}
|
||||
|
||||
if raw := c.Query("user_id"); raw != "" {
|
||||
if raw := queryValue(c, "user_id", "userId"); raw != "" {
|
||||
id, ok := parseID(raw)
|
||||
if !ok {
|
||||
return ListFilter{}, false
|
||||
@@ -279,7 +279,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
filter.UserId = &id
|
||||
}
|
||||
|
||||
if raw := c.Query("page"); raw != "" {
|
||||
if raw := queryValue(c, "page"); raw != "" {
|
||||
page, err := strconv.Atoi(raw)
|
||||
if err != nil || page < 1 {
|
||||
return ListFilter{}, false
|
||||
@@ -287,19 +287,22 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
filter.Page = page
|
||||
}
|
||||
|
||||
if raw := c.Query("limit"); raw != "" {
|
||||
if raw := queryValue(c, "limit"); raw != "" {
|
||||
limit, err := strconv.Atoi(raw)
|
||||
if err != nil || limit < 1 || limit > maxLimit {
|
||||
if err != nil || limit < 1 {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
if limit > maxLimit {
|
||||
limit = maxLimit
|
||||
}
|
||||
filter.Limit = limit
|
||||
}
|
||||
|
||||
if raw := strings.TrimSpace(c.Query("status")); raw != "" {
|
||||
if raw := queryValue(c, "status"); raw != "" {
|
||||
filter.Status = &raw
|
||||
}
|
||||
|
||||
if raw := strings.TrimSpace(c.Query("region")); raw != "" {
|
||||
if raw := queryValue(c, "region"); raw != "" {
|
||||
filter.Region = raw
|
||||
}
|
||||
|
||||
@@ -307,6 +310,15 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
return filter, true
|
||||
}
|
||||
|
||||
func queryValue(c *gin.Context, keys ...string) string {
|
||||
for _, key := range keys {
|
||||
if raw := strings.TrimSpace(c.Query(key)); raw != "" && raw != "undefined" && raw != "null" {
|
||||
return raw
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (h *handler) guardBranchByID(c *gin.Context, id int64) bool {
|
||||
if !rbac.HasBranchScope(c) {
|
||||
return true
|
||||
|
||||
Reference in new issue
Block a user