diff --git a/Screenshot 2026-09-30 at 13.46.37.png b/Screenshot 2026-09-30 at 13.46.37.png new file mode 100644 index 0000000..eab8da7 Binary files /dev/null and b/Screenshot 2026-09-30 at 13.46.37.png differ diff --git a/internal/org/branches/db/postgresql.go b/internal/org/branches/db/postgresql.go index f4d151f..ea3f46f 100644 --- a/internal/org/branches/db/postgresql.go +++ b/internal/org/branches/db/postgresql.go @@ -67,6 +67,8 @@ const branchSelectColumns = `b.id, b.unique_code, b.name, b.address, b.region, b b.billing_visa_master_username, b.billing_visa_master_password, b.billing_swift_username, b.billing_swift_password, b.active` +const branchListColumns = `b.id, b.unique_code, b.name, p.name, b.phone_numbers, b.active` + const branchReturningColumns = `id, unique_code, name, address, region, province_id, phone_numbers, billing_username, billing_password, billing_sber_username, billing_sber_password, billing_visa_master_username, billing_visa_master_password, @@ -98,7 +100,7 @@ func (r *repository) List(ctx context.Context, filter branches.ListFilter) (bran offsetPlaceholder := len(args) + 2 listQuery := fmt.Sprintf( `SELECT %s%s%s ORDER BY b.id LIMIT $%d OFFSET $%d`, - branchSelectColumns, branchFromClause, whereClause, limitPlaceholder, offsetPlaceholder, + branchListColumns, branchFromClause, whereClause, limitPlaceholder, offsetPlaceholder, ) listArgs := append(args, filter.Limit, offset) @@ -108,9 +110,9 @@ func (r *repository) List(ctx context.Context, filter branches.ListFilter) (bran } defer rows.Close() - var items []branches.BranchDTO + items := []branches.BranchListItemDTO{} for rows.Next() { - item, err := scanBranch(rows) + item, err := scanBranchListItem(rows) if err != nil { return branches.ListBranchDTO{}, err } @@ -288,6 +290,28 @@ func isUniqueViolation(err error) bool { return errors.As(err, &pgErr) && pgErr.Code == "23505" } +func scanBranchListItem(row genericrepo.Scanner) (branches.BranchListItemDTO, error) { + var item branches.BranchListItemDTO + var nameJSON, provinceNameJSON []byte + var uniqueCode *string + + if err := row.Scan(&item.Id, &uniqueCode, &nameJSON, &provinceNameJSON, &item.PhoneNumbers, &item.Active); err != nil { + return branches.BranchListItemDTO{}, err + } + if uniqueCode != nil { + item.UniqueCode = *uniqueCode + } + if err := json.Unmarshal(nameJSON, &item.Name); err != nil { + return branches.BranchListItemDTO{}, err + } + if provinceNameJSON != nil { + if err := json.Unmarshal(provinceNameJSON, &item.ProvinceName); err != nil { + return branches.BranchListItemDTO{}, err + } + } + return item, nil +} + func scanBranch(row genericrepo.Scanner) (branches.BranchDTO, error) { var item branches.BranchDTO var nameJSON, addressJSON, provinceNameJSON []byte diff --git a/internal/org/branches/dto.go b/internal/org/branches/dto.go index 7014100..7bbf5d4 100644 --- a/internal/org/branches/dto.go +++ b/internal/org/branches/dto.go @@ -71,7 +71,18 @@ type ListFilter struct { Limit int } -type ListBranchDTO struct { - Count int64 `json:"count"` - Branches []BranchDTO `json:"branches"` +// BranchListItemDTO is the list row; address, region and billing credentials +// come from GET /branches/:id. +type BranchListItemDTO struct { + Id int64 `json:"id"` + UniqueCode string `json:"uniqueCode"` + Name LocalizedText `json:"name"` + ProvinceName LocalizedText `json:"provinceName"` + PhoneNumbers string `json:"phoneNumbers"` + Active bool `json:"active"` +} + +type ListBranchDTO struct { + Count int64 `json:"count"` + Branches []BranchListItemDTO `json:"branches"` } diff --git a/internal/org/branches/handler.go b/internal/org/branches/handler.go index 7bf2edc..ab39ae2 100644 --- a/internal/org/branches/handler.go +++ b/internal/org/branches/handler.go @@ -70,11 +70,6 @@ func (h *handler) list(c *gin.Context) { c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer) return } - if !rbac.HasAllScope(c) { - for i := range result.Branches { - clearBranchSecrets(&result.Branches[i]) - } - } c.JSON(http.StatusOK, appresult.SuccessWithData(result)) }