ch data
This commit is contained in:
1 parent
4f3631c70d
commit
68ead82827
4 files changed
+53
-6
No files matched your search
Binary file not shown.
|
Before Width: | Height: | Size: 286 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
@@ -34,6 +34,13 @@ LEFT JOIN users u ON u.id = lo.user_id
|
|||||||
LEFT JOIN provinces p ON p.id = lo.work_province_id
|
LEFT JOIN provinces p ON p.id = lo.work_province_id
|
||||||
LEFT JOIN loan_order_required_docs d ON d.id = lo.loan_order_required_doc_id`
|
LEFT JOIN loan_order_required_docs d ON d.id = lo.loan_order_required_doc_id`
|
||||||
|
|
||||||
|
const loanOrderListFromClause = ` FROM loan_orders lo
|
||||||
|
LEFT JOIN loan_types lt ON lt.id = lo.loan_type
|
||||||
|
LEFT JOIN branches b ON b.id = lo.branch_id`
|
||||||
|
|
||||||
|
const loanOrderListColumns = `lo.id, lo.loan_type, lt.name, lo.created_at, lo.region,
|
||||||
|
lo.branch_id, b.name, lo.customer_name, lo.customer_surname, lo.phone, lo.status`
|
||||||
|
|
||||||
// loanOrderWritableColumns lists every loan_orders column except id, created_at and
|
// loanOrderWritableColumns lists every loan_orders column except id, created_at and
|
||||||
// updated_at, in the exact order CreateLoanOrderDTO/UpdateLoanOrderDTO fields are read.
|
// updated_at, in the exact order CreateLoanOrderDTO/UpdateLoanOrderDTO fields are read.
|
||||||
var loanOrderWritableColumns = []string{
|
var loanOrderWritableColumns = []string{
|
||||||
@@ -125,7 +132,7 @@ func (r *repository) List(ctx context.Context, filter loanorders.ListFilter) (lo
|
|||||||
offsetPlaceholder := len(args) + 2
|
offsetPlaceholder := len(args) + 2
|
||||||
query := fmt.Sprintf(
|
query := fmt.Sprintf(
|
||||||
`SELECT %s%s%s ORDER BY lo.id DESC LIMIT $%d OFFSET $%d`,
|
`SELECT %s%s%s ORDER BY lo.id DESC LIMIT $%d OFFSET $%d`,
|
||||||
loanOrderSelectColumns, loanOrderFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
|
loanOrderListColumns, loanOrderListFromClause, whereClause, limitPlaceholder, offsetPlaceholder,
|
||||||
)
|
)
|
||||||
|
|
||||||
rows, err := r.client.Query(ctx, query, append(args, filter.Limit, offset)...)
|
rows, err := r.client.Query(ctx, query, append(args, filter.Limit, offset)...)
|
||||||
@@ -134,9 +141,9 @@ func (r *repository) List(ctx context.Context, filter loanorders.ListFilter) (lo
|
|||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var items []loanorders.LoanOrderDTO
|
items := []loanorders.LoanOrderListItemDTO{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
item, err := scanLoanOrder(rows)
|
item, err := scanLoanOrderListItem(rows)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return loanorders.ListLoanOrderDTO{}, err
|
return loanorders.ListLoanOrderDTO{}, err
|
||||||
}
|
}
|
||||||
@@ -274,6 +281,32 @@ func (r *repository) Delete(ctx context.Context, id int64) error {
|
|||||||
return r.generic.Delete(ctx, id)
|
return r.generic.Delete(ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func scanLoanOrderListItem(row genericrepo.Scanner) (loanorders.LoanOrderListItemDTO, error) {
|
||||||
|
var item loanorders.LoanOrderListItemDTO
|
||||||
|
var loanTypeId, branchId int64
|
||||||
|
var loanTypeNameJSON, branchNameJSON []byte
|
||||||
|
|
||||||
|
err := row.Scan(
|
||||||
|
&item.Id, &loanTypeId, &loanTypeNameJSON, &item.CreatedAt, &item.Region,
|
||||||
|
&branchId, &branchNameJSON, &item.CustomerName, &item.CustomerSurname, &item.Phone, &item.Status,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return loanorders.LoanOrderListItemDTO{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var loanTypeName, branchName shared.LocalizedText
|
||||||
|
_ = shared.UnmarshalLocalized(loanTypeNameJSON, &loanTypeName)
|
||||||
|
_ = shared.UnmarshalLocalized(branchNameJSON, &branchName)
|
||||||
|
|
||||||
|
if loanTypeId != 0 {
|
||||||
|
item.LoanType = &shared.NamedInfo{Id: loanTypeId, Name: loanTypeName}
|
||||||
|
}
|
||||||
|
if branchId != 0 {
|
||||||
|
item.Branch = &shared.NamedInfo{Id: branchId, Name: branchName}
|
||||||
|
}
|
||||||
|
return item, nil
|
||||||
|
}
|
||||||
|
|
||||||
func scanLoanOrder(row genericrepo.Scanner) (loanorders.LoanOrderDTO, error) {
|
func scanLoanOrder(row genericrepo.Scanner) (loanorders.LoanOrderDTO, error) {
|
||||||
var item loanorders.LoanOrderDTO
|
var item loanorders.LoanOrderDTO
|
||||||
var loanTypeNameJSON, branchNameJSON, provinceNameJSON []byte
|
var loanTypeNameJSON, branchNameJSON, provinceNameJSON []byte
|
||||||
|
|||||||
@@ -233,7 +233,21 @@ type ListFilter struct {
|
|||||||
Limit int
|
Limit int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListLoanOrderDTO struct {
|
// LoanOrderListItemDTO is the list row; passport, work, card and guarantor
|
||||||
Count int64 `json:"count"`
|
// details come from GET /loan-orders/:id.
|
||||||
LoanOrders []LoanOrderDTO `json:"loanOrders"`
|
type LoanOrderListItemDTO struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
LoanType *shared.NamedInfo `json:"loanType,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
Region string `json:"region"`
|
||||||
|
Branch *shared.NamedInfo `json:"branch,omitempty"`
|
||||||
|
CustomerName string `json:"customerName"`
|
||||||
|
CustomerSurname string `json:"customerSurname"`
|
||||||
|
Phone string `json:"phone"`
|
||||||
|
Status *string `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListLoanOrderDTO struct {
|
||||||
|
Count int64 `json:"count"`
|
||||||
|
LoanOrders []LoanOrderListItemDTO `json:"loanOrders"`
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user