Add backups, currencies and dashboard APIs, and scope access by guard_name.
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

Web users may only CRUD their own records, operators stay in assigned branches, and admin/manager/superadmin keep full access.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
guwandykandCursor committed 2026-08-31 18:14:47 +05:00
1 parent 0d000f9af6
commit 28509eb4ca
65 files changed
+9132 -296

No files matched your search

@@ -1,64 +0,0 @@
package loanorders_test
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"online-back/internal/lending/loanorders"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
func mobileCreateBody() []byte {
body, _ := json.Marshal(map[string]any{
"source": "mobile", "loanType": "1", "region": "Ahal", "branchId": "1",
"customerName": "Kerim", "customerSurname": "Atayew",
"passportAddress": "Ashgabat", "realAddress": "Ashgabat",
"passportSerie": "I-AG", "passportId": "101010",
"passportGivenAt": "2017-01-15", "passportGivenBy": "Police",
"bornPlace": "Ashgabat", "bornAt": "1989-03-21",
"phone": "+993 61 92 92 48", "education": "higher", "marriageStatus": "married",
"passportOne": "a.jpg", "passportTwo": "b.jpg", "passportThree": "c.jpg", "passportFour": "d.jpg",
"satisfiable": "yes", "guarantorNote": "Brother", "loanAmount": "20000",
})
return body
}
func TestCreateLoanOrderDTOBindMobilePayload(t *testing.T) {
var dto loanorders.CreateLoanOrderDTO
if err := json.Unmarshal(mobileCreateBody(), &dto); err != nil {
t.Fatalf("unmarshal: %v", err)
}
if dto.LoanType.Int64() != 1 || dto.BranchId.Int64() != 1 {
t.Fatalf("ids: loanType=%d branchId=%d", dto.LoanType.Int64(), dto.BranchId.Int64())
}
if dto.Region != "Ahal" {
t.Fatalf("region=%q", dto.Region)
}
if dto.BornAt.Time().Format("2006-01-02") != "1989-03-21" {
t.Fatalf("bornAt=%v", dto.BornAt.Time())
}
if dto.PassportGivenAt.Time().Format("2006-01-02") != "2017-01-15" {
t.Fatalf("passportGivenAt=%v", dto.PassportGivenAt.Time())
}
}
func TestCreateLoanOrderGinBindRequired(t *testing.T) {
gin.SetMode(gin.TestMode)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(mobileCreateBody()))
c.Request.Header.Set("Content-Type", "application/json")
var dto loanorders.CreateLoanOrderDTO
if err := c.ShouldBindBodyWith(&dto, binding.JSON); err != nil {
t.Fatalf("ShouldBindJSON: %v", err)
}
if dto.LoanType.Int64() != 1 || dto.Region != "Ahal" {
t.Fatalf("unexpected dto loanType=%d region=%q", dto.LoanType.Int64(), dto.Region)
}
}
+5 -4
View File
@@ -38,7 +38,7 @@ func (h *handler) Register(router *gin.RouterGroup) {
// list godoc
// @Summary List loan orders
// @Description Returns paginated loan orders with optional filters
// @Description Returns paginated loan orders created from the web with optional filters
// @Tags loan-orders
// @Produce json
// @Security BearerAuth
@@ -58,6 +58,7 @@ func (h *handler) list(c *gin.Context) {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return
}
filter.Source = "web"
h.respondList(c, filter)
}
@@ -127,7 +128,7 @@ func (h *handler) getByID(c *gin.Context) {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
}
if !rbac.GuardBranch(c, item.BranchId) {
if !rbac.GuardOrder(c, item.UserId, item.BranchId) {
return
}
@@ -324,7 +325,7 @@ func queryValue(c *gin.Context, keys ...string) string {
}
func (h *handler) guardBranchByID(c *gin.Context, id int64) bool {
if !rbac.HasBranchScope(c) {
if rbac.SkipRecordGuard(c) {
return true
}
item, err := h.repository.GetByID(c.Request.Context(), id)
@@ -336,5 +337,5 @@ func (h *handler) guardBranchByID(c *gin.Context, id int64) bool {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return false
}
return rbac.GuardBranch(c, item.BranchId)
return rbac.GuardOrder(c, item.UserId, item.BranchId)
}