ch some
Some checks failed
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:
2026-09-04 19:33:26 +05:00
parent 28509eb4ca
commit d1a6fcaadc
102 changed files with 2089 additions and 1957 deletions

View File

@@ -10,6 +10,7 @@ import (
"online-back/internal/handlers"
"online-back/internal/identity/rbac"
"online-back/internal/org/province"
"online-back/internal/shared"
"online-back/pkg/logging"
"github.com/gin-gonic/gin"
@@ -68,6 +69,11 @@ func (h *handler) list(c *gin.Context) {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
}
if !rbac.IsAdminGuard(c) {
for i := range result.Branches {
clearBranchSecrets(&result.Branches[i])
}
}
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
}
@@ -148,7 +154,7 @@ func (h *handler) listEtraps(c *gin.Context) {
// @Failure 500 {object} appresult.AppError
// @Router /branches/{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
@@ -167,6 +173,9 @@ func (h *handler) getByID(c *gin.Context) {
if !rbac.GuardBranch(c, item.Id) {
return
}
if !rbac.IsAdminGuard(c) {
clearBranchSecrets(&item)
}
c.JSON(http.StatusOK, appresult.SuccessWithData(item))
}
@@ -219,7 +228,7 @@ func (h *handler) create(c *gin.Context) {
// @Failure 500 {object} appresult.AppError
// @Router /branches/{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
@@ -262,7 +271,7 @@ func (h *handler) update(c *gin.Context) {
// @Failure 500 {object} appresult.AppError
// @Router /branches/{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
@@ -285,14 +294,6 @@ func isClientError(err error) bool {
return msg == "province not found" || msg == "unique code already exists"
}
func parseID(raw string) (int64, bool) {
id, err := strconv.ParseInt(raw, 10, 64)
if err != nil || id <= 0 {
return 0, false
}
return id, true
}
func parseActiveOnly(c *gin.Context, defaultValue bool) (bool, bool) {
raw := c.Query("active")
if raw == "" {
@@ -305,20 +306,14 @@ func parseActiveOnly(c *gin.Context, defaultValue bool) (bool, bool) {
return active, 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("province_id"); raw != "" {
id, ok := parseID(raw)
id, ok := shared.ParseID(raw)
if !ok {
return ListFilter{}, false
}
@@ -335,7 +330,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
@@ -356,3 +351,17 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
rbac.BindBranchIDs(c, &filter.BranchIds)
return filter, true
}
func clearBranchSecrets(item *BranchDTO) {
if item == nil {
return
}
item.BillingUsername = ""
item.BillingPassword = ""
item.BillingSberUsername = ""
item.BillingSberPassword = ""
item.BillingVisaMasterUsername = ""
item.BillingVisaMasterPassword = ""
item.BillingSwiftUsername = ""
item.BillingSwiftPassword = ""
}