Update Tranaction
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/constants/transaction"
|
||||
"furtuna-be/internal/entity"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type Transaction struct {
|
||||
@@ -19,9 +20,41 @@ type TransactionSearch struct {
|
||||
Type string `form:"type,default="`
|
||||
}
|
||||
|
||||
type ApprovalRequest struct {
|
||||
Status string `json:"status" validate:"required,approvalStatus"`
|
||||
TransactionID string `json:"transaction_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (a *ApprovalRequest) ToEntity() *entity.TransactionApproval {
|
||||
return &entity.TransactionApproval{
|
||||
Status: a.Status,
|
||||
TransactionID: a.TransactionID,
|
||||
}
|
||||
}
|
||||
|
||||
func approvalStatus(fl validator.FieldLevel) bool {
|
||||
status := fl.Field().String()
|
||||
return status == "APPROVE" || status == "REJECT"
|
||||
}
|
||||
|
||||
func (a *ApprovalRequest) Validate() error {
|
||||
validate := validator.New()
|
||||
err := validate.RegisterValidation("approvalStatus", approvalStatus)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validate.Struct(a); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TransactionSearch) ToEntity(ctx mycontext.Context) entity.TransactionSearch {
|
||||
return entity.TransactionSearch{
|
||||
PartnerID: ctx.GetPartnerID(),
|
||||
SiteID: ctx.GetSiteID(),
|
||||
Type: t.Type,
|
||||
Status: t.Status,
|
||||
Limit: t.Limit,
|
||||
|
||||
Reference in New Issue
Block a user