ch some
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/lending/loanorders"
|
||||
"online-back/internal/lending/shared"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/client/postgresql"
|
||||
"online-back/pkg/logging"
|
||||
"online-back/pkg/repository/genericrepo"
|
||||
@@ -76,11 +76,11 @@ func resolveSource(source string) string {
|
||||
|
||||
func createArgs(dto loanorders.CreateLoanOrderDTO) []interface{} {
|
||||
return []interface{}{
|
||||
dto.UniqueId, resolveSource(dto.Source), loanorders.FlexInt64Ptr(dto.UserId), dto.LoanType.Int64(), dto.Region, dto.BranchId.Int64(),
|
||||
dto.UniqueId, resolveSource(dto.Source), shared.OptionalInt64(dto.UserId), dto.LoanType.Int64(), dto.Region, dto.BranchId.Int64(),
|
||||
dto.CustomerName, dto.CustomerSurname, dto.CustomerPatronicName,
|
||||
dto.PassportAddress, dto.RealAddress, dto.PassportSerie, dto.PassportId, dto.PassportGivenAt.Time(), dto.PassportGivenBy,
|
||||
dto.BornPlace, dto.BornAt.Time(), dto.Email, dto.Phone, dto.PhoneAdditional, dto.PhoneHome,
|
||||
dto.WorkRegion, loanorders.FlexInt64Ptr(dto.WorkProvinceId), dto.WorkCompany, dto.WorkCompanyAccountantNumber, loanorders.FlexTimePtr(dto.WorkStartedAt),
|
||||
dto.WorkRegion, shared.OptionalInt64(dto.WorkProvinceId), dto.WorkCompany, dto.WorkCompanyAccountantNumber, shared.OptionalTime(dto.WorkStartedAt),
|
||||
dto.WorkSalary, dto.WorkPosition, dto.Education, dto.MarriageStatus,
|
||||
dto.PassportOne, dto.PassportTwo, dto.PassportThree, dto.PassportFour,
|
||||
dto.LoanAmount, dto.CardNumber, dto.CardName, dto.CardMonth, dto.CardYear,
|
||||
@@ -89,17 +89,17 @@ func createArgs(dto loanorders.CreateLoanOrderDTO) []interface{} {
|
||||
dto.Guarantor2Name, dto.Guarantor2Surname, dto.Guarantor2PatronicName, dto.Guarantor2PassportSerie, dto.Guarantor2PassportId,
|
||||
dto.Guarantor2CardNumber, dto.Guarantor2CardName, dto.Guarantor2CardMonth, dto.Guarantor2CardYear, dto.Guarantor2Note,
|
||||
dto.LoanCardNumber, dto.LoanCardName, dto.LoanCardMonth, dto.LoanCardYear,
|
||||
loanorders.FlexInt64Ptr(dto.LoanOrderRequiredDocId), dto.Status, dto.Satisfiable, dto.Notes,
|
||||
shared.OptionalInt64(dto.LoanOrderRequiredDocId), dto.Status, dto.Satisfiable, dto.Notes,
|
||||
}
|
||||
}
|
||||
|
||||
func updateArgs(dto loanorders.UpdateLoanOrderDTO) []interface{} {
|
||||
return []interface{}{
|
||||
dto.UniqueId, resolveSource(dto.Source), loanorders.FlexInt64Ptr(dto.UserId), dto.LoanType.Int64(), dto.Region, dto.BranchId.Int64(),
|
||||
dto.UniqueId, resolveSource(dto.Source), shared.OptionalInt64(dto.UserId), dto.LoanType.Int64(), dto.Region, dto.BranchId.Int64(),
|
||||
dto.CustomerName, dto.CustomerSurname, dto.CustomerPatronicName,
|
||||
dto.PassportAddress, dto.RealAddress, dto.PassportSerie, dto.PassportId, dto.PassportGivenAt.Time(), dto.PassportGivenBy,
|
||||
dto.BornPlace, dto.BornAt.Time(), dto.Email, dto.Phone, dto.PhoneAdditional, dto.PhoneHome,
|
||||
dto.WorkRegion, loanorders.FlexInt64Ptr(dto.WorkProvinceId), dto.WorkCompany, dto.WorkCompanyAccountantNumber, loanorders.FlexTimePtr(dto.WorkStartedAt),
|
||||
dto.WorkRegion, shared.OptionalInt64(dto.WorkProvinceId), dto.WorkCompany, dto.WorkCompanyAccountantNumber, shared.OptionalTime(dto.WorkStartedAt),
|
||||
dto.WorkSalary, dto.WorkPosition, dto.Education, dto.MarriageStatus,
|
||||
dto.PassportOne, dto.PassportTwo, dto.PassportThree, dto.PassportFour,
|
||||
dto.LoanAmount, dto.CardNumber, dto.CardName, dto.CardMonth, dto.CardYear,
|
||||
@@ -108,7 +108,7 @@ func updateArgs(dto loanorders.UpdateLoanOrderDTO) []interface{} {
|
||||
dto.Guarantor2Name, dto.Guarantor2Surname, dto.Guarantor2PatronicName, dto.Guarantor2PassportSerie, dto.Guarantor2PassportId,
|
||||
dto.Guarantor2CardNumber, dto.Guarantor2CardName, dto.Guarantor2CardMonth, dto.Guarantor2CardYear, dto.Guarantor2Note,
|
||||
dto.LoanCardNumber, dto.LoanCardName, dto.LoanCardMonth, dto.LoanCardYear,
|
||||
loanorders.FlexInt64Ptr(dto.LoanOrderRequiredDocId), dto.Status, dto.Satisfiable, dto.Notes,
|
||||
shared.OptionalInt64(dto.LoanOrderRequiredDocId), dto.Status, dto.Satisfiable, dto.Notes,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package loanorders
|
||||
import (
|
||||
"time"
|
||||
|
||||
"online-back/internal/lending/shared"
|
||||
"online-back/internal/shared"
|
||||
)
|
||||
|
||||
type LoanOrderDTO struct {
|
||||
@@ -85,143 +85,143 @@ type LoanOrderDTO struct {
|
||||
}
|
||||
|
||||
type CreateLoanOrderDTO struct {
|
||||
Source string `json:"source"`
|
||||
UserId *FlexibleInt64 `json:"userId" swaggertype:"integer"`
|
||||
UniqueId *string `json:"uniqueId"`
|
||||
LoanType FlexibleInt64 `json:"loanType" binding:"required" swaggertype:"integer"`
|
||||
Region string `json:"region" binding:"required"`
|
||||
BranchId FlexibleInt64 `json:"branchId" binding:"required" swaggertype:"integer"`
|
||||
CustomerName string `json:"customerName" binding:"required"`
|
||||
CustomerSurname string `json:"customerSurname" binding:"required"`
|
||||
CustomerPatronicName *string `json:"customerPatronicName"`
|
||||
PassportAddress string `json:"passportAddress" binding:"required"`
|
||||
RealAddress string `json:"realAddress" binding:"required"`
|
||||
PassportSerie string `json:"passportSerie" binding:"required"`
|
||||
PassportId string `json:"passportId" binding:"required"`
|
||||
PassportGivenAt FlexibleTime `json:"passportGivenAt" binding:"required" swaggertype:"string" format:"date"`
|
||||
PassportGivenBy string `json:"passportGivenBy" binding:"required"`
|
||||
BornPlace string `json:"bornPlace" binding:"required"`
|
||||
BornAt FlexibleTime `json:"bornAt" binding:"required" swaggertype:"string" format:"date"`
|
||||
Email *string `json:"email"`
|
||||
Phone string `json:"phone" binding:"required"`
|
||||
PhoneAdditional *string `json:"phoneAdditional"`
|
||||
PhoneHome *string `json:"phoneHome"`
|
||||
WorkRegion *string `json:"workRegion"`
|
||||
WorkProvinceId *FlexibleInt64 `json:"workProvinceId" swaggertype:"integer"`
|
||||
WorkCompany *string `json:"workCompany"`
|
||||
WorkCompanyAccountantNumber *string `json:"workCompanyAccountantNumber"`
|
||||
WorkStartedAt *FlexibleTime `json:"workStartedAt" swaggertype:"string" format:"date"`
|
||||
WorkSalary *string `json:"workSalary"`
|
||||
WorkPosition *string `json:"workPosition"`
|
||||
Education string `json:"education" binding:"required"`
|
||||
MarriageStatus string `json:"marriageStatus" binding:"required"`
|
||||
PassportOne string `json:"passportOne" binding:"required"`
|
||||
PassportTwo string `json:"passportTwo" binding:"required"`
|
||||
PassportThree string `json:"passportThree" binding:"required"`
|
||||
PassportFour string `json:"passportFour" binding:"required"`
|
||||
LoanAmount *string `json:"loanAmount"`
|
||||
CardNumber *string `json:"cardNumber"`
|
||||
CardName *string `json:"cardName"`
|
||||
CardMonth *string `json:"cardMonth"`
|
||||
CardYear *string `json:"cardYear"`
|
||||
GuarantorName *string `json:"guarantorName"`
|
||||
GuarantorSurname *string `json:"guarantorSurname"`
|
||||
GuarantorPatronicName *string `json:"guarantorPatronicName"`
|
||||
GuarantorPassportSerie *string `json:"guarantorPassportSerie"`
|
||||
GuarantorPassportId *string `json:"guarantorPassportId"`
|
||||
GuarantorCardNumber *string `json:"guarantorCardNumber"`
|
||||
GuarantorCardName *string `json:"guarantorCardName"`
|
||||
GuarantorCardMonth *string `json:"guarantorCardMonth"`
|
||||
GuarantorCardYear *string `json:"guarantorCardYear"`
|
||||
GuarantorNote *string `json:"guarantorNote"`
|
||||
Guarantor2Name *string `json:"guarantor2Name"`
|
||||
Guarantor2Surname *string `json:"guarantor2Surname"`
|
||||
Guarantor2PatronicName *string `json:"guarantor2PatronicName"`
|
||||
Guarantor2PassportSerie *string `json:"guarantor2PassportSerie"`
|
||||
Guarantor2PassportId *string `json:"guarantor2PassportId"`
|
||||
Guarantor2CardNumber *string `json:"guarantor2CardNumber"`
|
||||
Guarantor2CardName *string `json:"guarantor2CardName"`
|
||||
Guarantor2CardMonth *string `json:"guarantor2CardMonth"`
|
||||
Guarantor2CardYear *string `json:"guarantor2CardYear"`
|
||||
Guarantor2Note *string `json:"guarantor2Note"`
|
||||
LoanCardNumber *string `json:"loanCardNumber"`
|
||||
LoanCardName *string `json:"loanCardName"`
|
||||
LoanCardMonth *string `json:"loanCardMonth"`
|
||||
LoanCardYear *string `json:"loanCardYear"`
|
||||
LoanOrderRequiredDocId *FlexibleInt64 `json:"loanOrderRequiredDocId" swaggertype:"integer"`
|
||||
Status *string `json:"status"`
|
||||
Satisfiable *string `json:"satisfiable"`
|
||||
Notes *string `json:"notes"`
|
||||
Source string `json:"source"`
|
||||
UserId *shared.FlexibleInt64 `json:"userId" swaggertype:"integer"`
|
||||
UniqueId *string `json:"uniqueId"`
|
||||
LoanType shared.FlexibleInt64 `json:"loanType" binding:"required" swaggertype:"integer"`
|
||||
Region string `json:"region" binding:"required"`
|
||||
BranchId shared.FlexibleInt64 `json:"branchId" binding:"required" swaggertype:"integer"`
|
||||
CustomerName string `json:"customerName" binding:"required"`
|
||||
CustomerSurname string `json:"customerSurname" binding:"required"`
|
||||
CustomerPatronicName *string `json:"customerPatronicName"`
|
||||
PassportAddress string `json:"passportAddress" binding:"required"`
|
||||
RealAddress string `json:"realAddress" binding:"required"`
|
||||
PassportSerie string `json:"passportSerie" binding:"required"`
|
||||
PassportId string `json:"passportId" binding:"required"`
|
||||
PassportGivenAt shared.FlexibleTime `json:"passportGivenAt" binding:"required" swaggertype:"string" format:"date"`
|
||||
PassportGivenBy string `json:"passportGivenBy" binding:"required"`
|
||||
BornPlace string `json:"bornPlace" binding:"required"`
|
||||
BornAt shared.FlexibleTime `json:"bornAt" binding:"required" swaggertype:"string" format:"date"`
|
||||
Email *string `json:"email"`
|
||||
Phone string `json:"phone" binding:"required"`
|
||||
PhoneAdditional *string `json:"phoneAdditional"`
|
||||
PhoneHome *string `json:"phoneHome"`
|
||||
WorkRegion *string `json:"workRegion"`
|
||||
WorkProvinceId *shared.FlexibleInt64 `json:"workProvinceId" swaggertype:"integer"`
|
||||
WorkCompany *string `json:"workCompany"`
|
||||
WorkCompanyAccountantNumber *string `json:"workCompanyAccountantNumber"`
|
||||
WorkStartedAt *shared.FlexibleTime `json:"workStartedAt" swaggertype:"string" format:"date"`
|
||||
WorkSalary *string `json:"workSalary"`
|
||||
WorkPosition *string `json:"workPosition"`
|
||||
Education string `json:"education" binding:"required"`
|
||||
MarriageStatus string `json:"marriageStatus" binding:"required"`
|
||||
PassportOne string `json:"passportOne" binding:"required"`
|
||||
PassportTwo string `json:"passportTwo" binding:"required"`
|
||||
PassportThree string `json:"passportThree" binding:"required"`
|
||||
PassportFour string `json:"passportFour" binding:"required"`
|
||||
LoanAmount *string `json:"loanAmount"`
|
||||
CardNumber *string `json:"cardNumber"`
|
||||
CardName *string `json:"cardName"`
|
||||
CardMonth *string `json:"cardMonth"`
|
||||
CardYear *string `json:"cardYear"`
|
||||
GuarantorName *string `json:"guarantorName"`
|
||||
GuarantorSurname *string `json:"guarantorSurname"`
|
||||
GuarantorPatronicName *string `json:"guarantorPatronicName"`
|
||||
GuarantorPassportSerie *string `json:"guarantorPassportSerie"`
|
||||
GuarantorPassportId *string `json:"guarantorPassportId"`
|
||||
GuarantorCardNumber *string `json:"guarantorCardNumber"`
|
||||
GuarantorCardName *string `json:"guarantorCardName"`
|
||||
GuarantorCardMonth *string `json:"guarantorCardMonth"`
|
||||
GuarantorCardYear *string `json:"guarantorCardYear"`
|
||||
GuarantorNote *string `json:"guarantorNote"`
|
||||
Guarantor2Name *string `json:"guarantor2Name"`
|
||||
Guarantor2Surname *string `json:"guarantor2Surname"`
|
||||
Guarantor2PatronicName *string `json:"guarantor2PatronicName"`
|
||||
Guarantor2PassportSerie *string `json:"guarantor2PassportSerie"`
|
||||
Guarantor2PassportId *string `json:"guarantor2PassportId"`
|
||||
Guarantor2CardNumber *string `json:"guarantor2CardNumber"`
|
||||
Guarantor2CardName *string `json:"guarantor2CardName"`
|
||||
Guarantor2CardMonth *string `json:"guarantor2CardMonth"`
|
||||
Guarantor2CardYear *string `json:"guarantor2CardYear"`
|
||||
Guarantor2Note *string `json:"guarantor2Note"`
|
||||
LoanCardNumber *string `json:"loanCardNumber"`
|
||||
LoanCardName *string `json:"loanCardName"`
|
||||
LoanCardMonth *string `json:"loanCardMonth"`
|
||||
LoanCardYear *string `json:"loanCardYear"`
|
||||
LoanOrderRequiredDocId *shared.FlexibleInt64 `json:"loanOrderRequiredDocId" swaggertype:"integer"`
|
||||
Status *string `json:"status"`
|
||||
Satisfiable *string `json:"satisfiable"`
|
||||
Notes *string `json:"notes"`
|
||||
}
|
||||
|
||||
type UpdateLoanOrderDTO struct {
|
||||
UniqueId *string `json:"uniqueId"`
|
||||
Source string `json:"source"`
|
||||
UserId *FlexibleInt64 `json:"userId" swaggertype:"integer"`
|
||||
LoanType FlexibleInt64 `json:"loanType" binding:"required" swaggertype:"integer"`
|
||||
Region string `json:"region" binding:"required"`
|
||||
BranchId FlexibleInt64 `json:"branchId" binding:"required" swaggertype:"integer"`
|
||||
CustomerName string `json:"customerName" binding:"required"`
|
||||
CustomerSurname string `json:"customerSurname" binding:"required"`
|
||||
CustomerPatronicName *string `json:"customerPatronicName"`
|
||||
PassportAddress string `json:"passportAddress" binding:"required"`
|
||||
RealAddress string `json:"realAddress" binding:"required"`
|
||||
PassportSerie string `json:"passportSerie" binding:"required"`
|
||||
PassportId string `json:"passportId" binding:"required"`
|
||||
PassportGivenAt FlexibleTime `json:"passportGivenAt" binding:"required" swaggertype:"string" format:"date"`
|
||||
PassportGivenBy string `json:"passportGivenBy" binding:"required"`
|
||||
BornPlace string `json:"bornPlace" binding:"required"`
|
||||
BornAt FlexibleTime `json:"bornAt" binding:"required" swaggertype:"string" format:"date"`
|
||||
Email *string `json:"email"`
|
||||
Phone string `json:"phone" binding:"required"`
|
||||
PhoneAdditional *string `json:"phoneAdditional"`
|
||||
PhoneHome *string `json:"phoneHome"`
|
||||
WorkRegion *string `json:"workRegion"`
|
||||
WorkProvinceId *FlexibleInt64 `json:"workProvinceId" swaggertype:"integer"`
|
||||
WorkCompany *string `json:"workCompany"`
|
||||
WorkCompanyAccountantNumber *string `json:"workCompanyAccountantNumber"`
|
||||
WorkStartedAt *FlexibleTime `json:"workStartedAt" swaggertype:"string" format:"date"`
|
||||
WorkSalary *string `json:"workSalary"`
|
||||
WorkPosition *string `json:"workPosition"`
|
||||
Education string `json:"education" binding:"required"`
|
||||
MarriageStatus string `json:"marriageStatus" binding:"required"`
|
||||
PassportOne string `json:"passportOne" binding:"required"`
|
||||
PassportTwo string `json:"passportTwo" binding:"required"`
|
||||
PassportThree string `json:"passportThree" binding:"required"`
|
||||
PassportFour string `json:"passportFour" binding:"required"`
|
||||
LoanAmount *string `json:"loanAmount"`
|
||||
CardNumber *string `json:"cardNumber"`
|
||||
CardName *string `json:"cardName"`
|
||||
CardMonth *string `json:"cardMonth"`
|
||||
CardYear *string `json:"cardYear"`
|
||||
GuarantorName *string `json:"guarantorName"`
|
||||
GuarantorSurname *string `json:"guarantorSurname"`
|
||||
GuarantorPatronicName *string `json:"guarantorPatronicName"`
|
||||
GuarantorPassportSerie *string `json:"guarantorPassportSerie"`
|
||||
GuarantorPassportId *string `json:"guarantorPassportId"`
|
||||
GuarantorCardNumber *string `json:"guarantorCardNumber"`
|
||||
GuarantorCardName *string `json:"guarantorCardName"`
|
||||
GuarantorCardMonth *string `json:"guarantorCardMonth"`
|
||||
GuarantorCardYear *string `json:"guarantorCardYear"`
|
||||
GuarantorNote *string `json:"guarantorNote"`
|
||||
Guarantor2Name *string `json:"guarantor2Name"`
|
||||
Guarantor2Surname *string `json:"guarantor2Surname"`
|
||||
Guarantor2PatronicName *string `json:"guarantor2PatronicName"`
|
||||
Guarantor2PassportSerie *string `json:"guarantor2PassportSerie"`
|
||||
Guarantor2PassportId *string `json:"guarantor2PassportId"`
|
||||
Guarantor2CardNumber *string `json:"guarantor2CardNumber"`
|
||||
Guarantor2CardName *string `json:"guarantor2CardName"`
|
||||
Guarantor2CardMonth *string `json:"guarantor2CardMonth"`
|
||||
Guarantor2CardYear *string `json:"guarantor2CardYear"`
|
||||
Guarantor2Note *string `json:"guarantor2Note"`
|
||||
LoanCardNumber *string `json:"loanCardNumber"`
|
||||
LoanCardName *string `json:"loanCardName"`
|
||||
LoanCardMonth *string `json:"loanCardMonth"`
|
||||
LoanCardYear *string `json:"loanCardYear"`
|
||||
LoanOrderRequiredDocId *FlexibleInt64 `json:"loanOrderRequiredDocId" swaggertype:"integer"`
|
||||
Status *string `json:"status"`
|
||||
Satisfiable *string `json:"satisfiable"`
|
||||
Notes *string `json:"notes"`
|
||||
UniqueId *string `json:"uniqueId"`
|
||||
Source string `json:"source"`
|
||||
UserId *shared.FlexibleInt64 `json:"userId" swaggertype:"integer"`
|
||||
LoanType shared.FlexibleInt64 `json:"loanType" binding:"required" swaggertype:"integer"`
|
||||
Region string `json:"region" binding:"required"`
|
||||
BranchId shared.FlexibleInt64 `json:"branchId" binding:"required" swaggertype:"integer"`
|
||||
CustomerName string `json:"customerName" binding:"required"`
|
||||
CustomerSurname string `json:"customerSurname" binding:"required"`
|
||||
CustomerPatronicName *string `json:"customerPatronicName"`
|
||||
PassportAddress string `json:"passportAddress" binding:"required"`
|
||||
RealAddress string `json:"realAddress" binding:"required"`
|
||||
PassportSerie string `json:"passportSerie" binding:"required"`
|
||||
PassportId string `json:"passportId" binding:"required"`
|
||||
PassportGivenAt shared.FlexibleTime `json:"passportGivenAt" binding:"required" swaggertype:"string" format:"date"`
|
||||
PassportGivenBy string `json:"passportGivenBy" binding:"required"`
|
||||
BornPlace string `json:"bornPlace" binding:"required"`
|
||||
BornAt shared.FlexibleTime `json:"bornAt" binding:"required" swaggertype:"string" format:"date"`
|
||||
Email *string `json:"email"`
|
||||
Phone string `json:"phone" binding:"required"`
|
||||
PhoneAdditional *string `json:"phoneAdditional"`
|
||||
PhoneHome *string `json:"phoneHome"`
|
||||
WorkRegion *string `json:"workRegion"`
|
||||
WorkProvinceId *shared.FlexibleInt64 `json:"workProvinceId" swaggertype:"integer"`
|
||||
WorkCompany *string `json:"workCompany"`
|
||||
WorkCompanyAccountantNumber *string `json:"workCompanyAccountantNumber"`
|
||||
WorkStartedAt *shared.FlexibleTime `json:"workStartedAt" swaggertype:"string" format:"date"`
|
||||
WorkSalary *string `json:"workSalary"`
|
||||
WorkPosition *string `json:"workPosition"`
|
||||
Education string `json:"education" binding:"required"`
|
||||
MarriageStatus string `json:"marriageStatus" binding:"required"`
|
||||
PassportOne string `json:"passportOne" binding:"required"`
|
||||
PassportTwo string `json:"passportTwo" binding:"required"`
|
||||
PassportThree string `json:"passportThree" binding:"required"`
|
||||
PassportFour string `json:"passportFour" binding:"required"`
|
||||
LoanAmount *string `json:"loanAmount"`
|
||||
CardNumber *string `json:"cardNumber"`
|
||||
CardName *string `json:"cardName"`
|
||||
CardMonth *string `json:"cardMonth"`
|
||||
CardYear *string `json:"cardYear"`
|
||||
GuarantorName *string `json:"guarantorName"`
|
||||
GuarantorSurname *string `json:"guarantorSurname"`
|
||||
GuarantorPatronicName *string `json:"guarantorPatronicName"`
|
||||
GuarantorPassportSerie *string `json:"guarantorPassportSerie"`
|
||||
GuarantorPassportId *string `json:"guarantorPassportId"`
|
||||
GuarantorCardNumber *string `json:"guarantorCardNumber"`
|
||||
GuarantorCardName *string `json:"guarantorCardName"`
|
||||
GuarantorCardMonth *string `json:"guarantorCardMonth"`
|
||||
GuarantorCardYear *string `json:"guarantorCardYear"`
|
||||
GuarantorNote *string `json:"guarantorNote"`
|
||||
Guarantor2Name *string `json:"guarantor2Name"`
|
||||
Guarantor2Surname *string `json:"guarantor2Surname"`
|
||||
Guarantor2PatronicName *string `json:"guarantor2PatronicName"`
|
||||
Guarantor2PassportSerie *string `json:"guarantor2PassportSerie"`
|
||||
Guarantor2PassportId *string `json:"guarantor2PassportId"`
|
||||
Guarantor2CardNumber *string `json:"guarantor2CardNumber"`
|
||||
Guarantor2CardName *string `json:"guarantor2CardName"`
|
||||
Guarantor2CardMonth *string `json:"guarantor2CardMonth"`
|
||||
Guarantor2CardYear *string `json:"guarantor2CardYear"`
|
||||
Guarantor2Note *string `json:"guarantor2Note"`
|
||||
LoanCardNumber *string `json:"loanCardNumber"`
|
||||
LoanCardName *string `json:"loanCardName"`
|
||||
LoanCardMonth *string `json:"loanCardMonth"`
|
||||
LoanCardYear *string `json:"loanCardYear"`
|
||||
LoanOrderRequiredDocId *shared.FlexibleInt64 `json:"loanOrderRequiredDocId" swaggertype:"integer"`
|
||||
Status *string `json:"status"`
|
||||
Satisfiable *string `json:"satisfiable"`
|
||||
Notes *string `json:"notes"`
|
||||
}
|
||||
|
||||
type ListFilter struct {
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
package loanorders
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FlexibleTime time.Time
|
||||
|
||||
func (t FlexibleTime) Time() time.Time { return time.Time(t) }
|
||||
|
||||
func (t FlexibleTime) IsZero() bool { return time.Time(t).IsZero() }
|
||||
|
||||
func (t FlexibleTime) MarshalJSON() ([]byte, error) {
|
||||
return time.Time(t).MarshalJSON()
|
||||
}
|
||||
|
||||
func (t *FlexibleTime) UnmarshalJSON(b []byte) error {
|
||||
*t = FlexibleTime{}
|
||||
raw := strings.TrimSpace(string(b))
|
||||
if raw == "" || raw == "null" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var n json.Number
|
||||
if err := json.Unmarshal(b, &n); err == nil {
|
||||
s := n.String()
|
||||
if parsed, ok := parseFlexibleTime(s); ok {
|
||||
*t = parsed
|
||||
return nil
|
||||
}
|
||||
if unix, err := n.Int64(); err == nil && unix > 0 {
|
||||
*t = FlexibleTime(time.Unix(unix, 0).UTC())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return nil
|
||||
}
|
||||
if parsed, ok := parseFlexibleTime(s); ok {
|
||||
*t = parsed
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseFlexibleTime(s string) (FlexibleTime, bool) {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return FlexibleTime{}, false
|
||||
}
|
||||
switch strings.ToLower(s) {
|
||||
case "string", "undefined", "null", "none", "invalid", "nan", "-":
|
||||
return FlexibleTime{}, false
|
||||
}
|
||||
for _, layout := range []string{
|
||||
time.RFC3339Nano,
|
||||
time.RFC3339,
|
||||
"2006-01-02T15:04:05Z07:00",
|
||||
"2006-01-02T15:04:05.000Z",
|
||||
"2006-01-02T15:04:05",
|
||||
"2006-01-02 15:04:05",
|
||||
"2006-01-02",
|
||||
"02.01.2006",
|
||||
"02/01/2006",
|
||||
"02-01-2006",
|
||||
"2006/01/02",
|
||||
"20060102",
|
||||
} {
|
||||
if parsed, err := time.Parse(layout, s); err == nil {
|
||||
return FlexibleTime(parsed), true
|
||||
}
|
||||
}
|
||||
return FlexibleTime{}, false
|
||||
}
|
||||
|
||||
type FlexibleInt64 int64
|
||||
|
||||
func (n FlexibleInt64) Int64() int64 { return int64(n) }
|
||||
|
||||
func (n *FlexibleInt64) UnmarshalJSON(b []byte) error {
|
||||
if string(b) == "null" {
|
||||
*n = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var v int64
|
||||
if err := json.Unmarshal(b, &v); err == nil {
|
||||
*n = FlexibleInt64(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
*n = 0
|
||||
return nil
|
||||
}
|
||||
v, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*n = FlexibleInt64(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
func FlexInt64Ptr(v *FlexibleInt64) *int64 {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
i := v.Int64()
|
||||
return &i
|
||||
}
|
||||
|
||||
func FlexTimePtr(v *FlexibleTime) *time.Time {
|
||||
if v == nil || v.IsZero() {
|
||||
return nil
|
||||
}
|
||||
t := v.Time()
|
||||
return &t
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/handlers"
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -112,7 +113,7 @@ func (h *handler) respondList(c *gin.Context, filter ListFilter) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-orders/{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
|
||||
@@ -183,7 +184,7 @@ func (h *handler) create(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-orders/{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
|
||||
@@ -226,7 +227,7 @@ func (h *handler) update(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-orders/{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
|
||||
@@ -248,28 +249,14 @@ func (h *handler) delete(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData("loan order removed"))
|
||||
}
|
||||
|
||||
func parseID(raw string) (int64, bool) {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return id, 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 := queryValue(c, "branch_id", "branchId"); raw != "" {
|
||||
id, ok := parseID(raw)
|
||||
id, ok := shared.ParseID(raw)
|
||||
if !ok {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
@@ -277,7 +264,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
}
|
||||
|
||||
if raw := queryValue(c, "user_id", "userId"); raw != "" {
|
||||
id, ok := parseID(raw)
|
||||
id, ok := shared.ParseID(raw)
|
||||
if !ok {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
@@ -297,8 +284,8 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
if err != nil || limit < 1 {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
if limit > maxLimit {
|
||||
limit = maxLimit
|
||||
if limit > shared.MaxLimit {
|
||||
limit = shared.MaxLimit
|
||||
}
|
||||
filter.Limit = limit
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/lending/loanpaidletter"
|
||||
"online-back/internal/lending/shared"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/client/postgresql"
|
||||
"online-back/pkg/logging"
|
||||
"online-back/pkg/repository/genericrepo"
|
||||
@@ -111,12 +111,12 @@ func buildListQuery(filter loanpaidletter.ListFilter) (whereClause string, args
|
||||
var conditions []string
|
||||
|
||||
if filter.PassportId != "" {
|
||||
args = append(args, likePattern(filter.PassportId))
|
||||
args = append(args, shared.LikePattern(filter.PassportId))
|
||||
conditions = append(conditions, fmt.Sprintf("l.passport_id ILIKE $%d", len(args)))
|
||||
}
|
||||
|
||||
if filter.Name != "" {
|
||||
args = append(args, likePattern(filter.Name))
|
||||
args = append(args, shared.LikePattern(filter.Name))
|
||||
n := len(args)
|
||||
conditions = append(conditions, fmt.Sprintf(`(
|
||||
l.customer_name ILIKE $%[1]d OR l.customer_surname ILIKE $%[1]d OR COALESCE(l.customer_patronic_name, '') ILIKE $%[1]d
|
||||
@@ -152,13 +152,6 @@ func buildListQuery(filter loanpaidletter.ListFilter) (whereClause string, args
|
||||
return " WHERE " + strings.Join(conditions, " AND "), args
|
||||
}
|
||||
|
||||
func likePattern(term string) string {
|
||||
term = strings.ReplaceAll(term, `\`, `\\`)
|
||||
term = strings.ReplaceAll(term, `%`, `\%`)
|
||||
term = strings.ReplaceAll(term, `_`, `\_`)
|
||||
return "%" + term + "%"
|
||||
}
|
||||
|
||||
func (r *repository) ListBranchesByProvince(ctx context.Context, provinceID int64, activeOnly bool) (loanpaidletter.ListBranchesByProvinceDTO, error) {
|
||||
args := []interface{}{provinceID}
|
||||
where := ` WHERE province_id = $1`
|
||||
|
||||
@@ -3,7 +3,7 @@ package loanpaidletter
|
||||
import (
|
||||
"time"
|
||||
|
||||
"online-back/internal/lending/shared"
|
||||
"online-back/internal/shared"
|
||||
)
|
||||
|
||||
type LoanPaidLetterDTO struct {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/handlers"
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -83,7 +84,7 @@ func (h *handler) list(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-paid-off-letters/branches [get]
|
||||
func (h *handler) listBranchesByProvince(c *gin.Context) {
|
||||
provinceID, ok := parseID(c.Query("province_id"))
|
||||
provinceID, ok := shared.ParseID(c.Query("province_id"))
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
@@ -122,7 +123,7 @@ func (h *handler) listBranchesByProvince(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-paid-off-letters/{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
|
||||
@@ -189,7 +190,7 @@ func (h *handler) create(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-paid-off-letters/{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
|
||||
@@ -232,7 +233,7 @@ func (h *handler) update(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-paid-off-letters/{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
|
||||
@@ -254,24 +255,10 @@ func (h *handler) delete(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData("loan paid off letter removed"))
|
||||
}
|
||||
|
||||
func parseID(raw string) (int64, bool) {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return id, 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("page"); raw != "" {
|
||||
@@ -284,7 +271,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
|
||||
@@ -307,7 +294,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
}
|
||||
|
||||
if raw := c.Query("branch_id"); raw != "" {
|
||||
id, ok := parseID(raw)
|
||||
id, ok := shared.ParseID(raw)
|
||||
if !ok {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
@@ -319,7 +306,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
raw = strings.TrimSpace(c.Query("userId"))
|
||||
}
|
||||
if raw != "" {
|
||||
id, ok := parseID(raw)
|
||||
id, ok := shared.ParseID(raw)
|
||||
if !ok {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"online-back/internal/lending/loansdocument"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/client/postgresql"
|
||||
"online-back/pkg/logging"
|
||||
"online-back/pkg/repository/genericrepo"
|
||||
@@ -47,7 +48,7 @@ func buildListQuery(filter loansdocument.ListFilter) (whereClause string, args [
|
||||
var conditions []string
|
||||
|
||||
if filter.DocumentName != "" {
|
||||
args = append(args, likePattern(filter.DocumentName))
|
||||
args = append(args, shared.LikePattern(filter.DocumentName))
|
||||
n := len(args)
|
||||
conditions = append(conditions, fmt.Sprintf(`d.name ILIKE $%d`, n))
|
||||
}
|
||||
@@ -64,13 +65,6 @@ func buildListQuery(filter loansdocument.ListFilter) (whereClause string, args [
|
||||
return " WHERE " + strings.Join(conditions, " AND "), args
|
||||
}
|
||||
|
||||
func likePattern(term string) string {
|
||||
term = strings.ReplaceAll(term, `\`, `\\`)
|
||||
term = strings.ReplaceAll(term, `%`, `\%`)
|
||||
term = strings.ReplaceAll(term, `_`, `\_`)
|
||||
return "%" + term + "%"
|
||||
}
|
||||
|
||||
func (r *repository) GetByID(ctx context.Context, id int64) (loansdocument.LoanDocumentDTO, error) {
|
||||
return r.generic.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/handlers"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -79,7 +80,7 @@ func (h *handler) list(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loans-documents/{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
|
||||
@@ -143,7 +144,7 @@ func (h *handler) create(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loans-documents/{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
|
||||
@@ -184,7 +185,7 @@ func (h *handler) update(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loans-documents/{id}/active [put]
|
||||
func (h *handler) updateActive(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
|
||||
@@ -223,7 +224,7 @@ func (h *handler) updateActive(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loans-documents/{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
|
||||
@@ -241,24 +242,10 @@ func (h *handler) delete(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData("loan document removed"))
|
||||
}
|
||||
|
||||
func parseID(raw string) (int64, bool) {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return id, 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("page"); raw != "" {
|
||||
@@ -271,7 +258,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
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/lending/loansrepayment"
|
||||
"online-back/internal/lending/shared"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/client/postgresql"
|
||||
"online-back/pkg/logging"
|
||||
"online-back/pkg/repository/genericrepo"
|
||||
@@ -77,7 +77,7 @@ func (r *repository) List(ctx context.Context, filter loansrepayment.ListFilter)
|
||||
func buildListQuery(filter loansrepayment.ListFilter) (whereClause string, args []interface{}) {
|
||||
var conditions []string
|
||||
if filter.PassportId != "" {
|
||||
args = append(args, likePattern(filter.PassportId))
|
||||
args = append(args, shared.LikePattern(filter.PassportId))
|
||||
conditions = append(conditions, fmt.Sprintf("l.passport_id ILIKE $%d", len(args)))
|
||||
}
|
||||
|
||||
@@ -98,13 +98,6 @@ func buildListQuery(filter loansrepayment.ListFilter) (whereClause string, args
|
||||
return " WHERE " + strings.Join(conditions, " AND "), args
|
||||
}
|
||||
|
||||
func likePattern(term string) string {
|
||||
term = strings.ReplaceAll(term, `\`, `\\`)
|
||||
term = strings.ReplaceAll(term, `%`, `\%`)
|
||||
term = strings.ReplaceAll(term, `_`, `\_`)
|
||||
return "%" + term + "%"
|
||||
}
|
||||
|
||||
func (r *repository) GetByID(ctx context.Context, id int64) (loansrepayment.LoanRepaymentDTO, error) {
|
||||
query := `SELECT ` + loanColumns + loanFromClause + ` WHERE l.id = $1`
|
||||
return scanLoanRepayment(r.client.QueryRow(ctx, query, id))
|
||||
|
||||
@@ -3,7 +3,7 @@ package loansrepayment
|
||||
import (
|
||||
"time"
|
||||
|
||||
"online-back/internal/lending/shared"
|
||||
"online-back/internal/shared"
|
||||
)
|
||||
|
||||
type LoanRepaymentDTO struct {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/handlers"
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -78,7 +79,7 @@ func (h *handler) list(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loans-repayment/{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
|
||||
@@ -145,7 +146,7 @@ func (h *handler) create(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loans-repayment/{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
|
||||
@@ -188,7 +189,7 @@ func (h *handler) update(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loans-repayment/{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
|
||||
@@ -210,24 +211,10 @@ func (h *handler) delete(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData("loan repayment removed"))
|
||||
}
|
||||
|
||||
func parseID(raw string) (int64, bool) {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return id, 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("page"); raw != "" {
|
||||
@@ -240,7 +227,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
|
||||
@@ -255,7 +242,7 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
raw = strings.TrimSpace(c.Query("userId"))
|
||||
}
|
||||
if raw != "" {
|
||||
id, ok := parseID(raw)
|
||||
id, ok := shared.ParseID(raw)
|
||||
if !ok {
|
||||
return ListFilter{}, false
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"online-back/internal/lending/loantype"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/client/postgresql"
|
||||
"online-back/pkg/logging"
|
||||
"online-back/pkg/repository/genericrepo"
|
||||
@@ -47,7 +48,7 @@ func (r *repository) List(ctx context.Context, filter loantype.ListFilter) (loan
|
||||
func buildListQuery(filter loantype.ListFilter) (whereClause string, args []interface{}) {
|
||||
var conditions []string
|
||||
if filter.LoanTypeName != "" {
|
||||
args = append(args, likePattern(filter.LoanTypeName))
|
||||
args = append(args, shared.LikePattern(filter.LoanTypeName))
|
||||
n := len(args)
|
||||
conditions = append(conditions, fmt.Sprintf(`(
|
||||
lt.name->>'en' ILIKE $%[1]d OR lt.name->>'ru' ILIKE $%[1]d OR lt.name->>'tm' ILIKE $%[1]d
|
||||
@@ -61,13 +62,6 @@ func buildListQuery(filter loantype.ListFilter) (whereClause string, args []inte
|
||||
return " WHERE " + strings.Join(conditions, " AND "), args
|
||||
}
|
||||
|
||||
func likePattern(term string) string {
|
||||
term = strings.ReplaceAll(term, `\`, `\\`)
|
||||
term = strings.ReplaceAll(term, `%`, `\%`)
|
||||
term = strings.ReplaceAll(term, `_`, `\_`)
|
||||
return "%" + term + "%"
|
||||
}
|
||||
|
||||
func (r *repository) GetByID(ctx context.Context, id int64) (loantype.LoanTypeDTO, error) {
|
||||
return r.generic.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/handlers"
|
||||
"online-back/internal/shared"
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -77,7 +78,7 @@ func (h *handler) list(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-types/{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
|
||||
@@ -141,7 +142,7 @@ func (h *handler) create(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-types/{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
|
||||
@@ -180,7 +181,7 @@ func (h *handler) update(c *gin.Context) {
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /loan-types/{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
|
||||
@@ -198,24 +199,10 @@ func (h *handler) delete(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData("loan type removed"))
|
||||
}
|
||||
|
||||
func parseID(raw string) (int64, bool) {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return id, 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("page"); raw != "" {
|
||||
@@ -228,7 +215,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
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type LocalizedText struct {
|
||||
En string `json:"en"`
|
||||
Ru string `json:"ru"`
|
||||
Tm string `json:"tm"`
|
||||
}
|
||||
|
||||
type UserInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
type NamedInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name LocalizedText `json:"name"`
|
||||
}
|
||||
|
||||
// TextInfo is for catalog rows whose name is a plain string (not localized JSON).
|
||||
type TextInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type BranchInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
Name LocalizedText `json:"name"`
|
||||
UniqueCode string `json:"uniqueCode,omitempty"`
|
||||
}
|
||||
|
||||
const UserDisplaySQL = `COALESCE(NULLIF(TRIM(CONCAT_WS(' ', u.first_name, u.last_name)), ''), NULLIF(u.name, ''), u.username, '')`
|
||||
|
||||
const UserInfoSQL = UserDisplaySQL + `, COALESCE(u.username, ''), COALESCE(u.phone, ''), COALESCE(u.email, '')`
|
||||
|
||||
func PrefixedColumns(alias string, cols []string) string {
|
||||
parts := make([]string, len(cols))
|
||||
for i, col := range cols {
|
||||
parts[i] = alias + "." + col
|
||||
}
|
||||
return strings.Join(parts, ", ")
|
||||
}
|
||||
|
||||
func UnmarshalLocalized(raw []byte, dest *LocalizedText) error {
|
||||
if len(raw) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := json.Unmarshal(raw, dest); err != nil {
|
||||
*dest = LocalizedText{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user