制作Django Rest框架(DRF)的方法

2024-09-30 01:33:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在构建一个支持多种贷款产品的业务应用程序。在

例如:住房贷款、汽车贷款、个人贷款、电子商务贷款。在

主要步骤包括:

  1. 入职(产生潜在客户)
  2. 用户信息(和验证)
  3. 贷款信息(可信度)
  4. 支付

业务流程的一个例子是:

  1. 客户上车,登记他的手机号码,通过OTP验证

  2. 填写个人信息

  3. 提供贷款金额

  4. 检查贷款可信度

  5. 分配资金(在XYZ验证之后)

  6. 提供银行账户详细信息

  7. 核实银行账户(只有在您获得abc信息后)

  8. 执行eKYC

  9. 支付

现在,我正在使用Django-REST框架来构建webapi。然而,有一个问题。在

在我们的另一个产品中,流程可以是不同的。Step 4和{}可以互换,但是{}需要在同一位置进行。基本上,我应该具有重新排列活动(节点)的灵活性。在

目前为止,编写的api(尽管是模块化的)只针对一个产品。如何使用DRF作为工作流方法?或者使用DRF之上可以控制流的任何库。在


Tags: 用户信息应用程序客户产品步骤账户银行
1条回答
网友
1楼 · 发布于 2024-09-30 01:33:11

我们有一个类似的用例,并使用了一个流库,它将基于条件驱动流捕获整个工作流。在

您可以查看Viewflow:https://github.com/viewflow/viewflow

基本上,这就像设置一个流,并利用条件来引导和重定向到不同的机制。他们简单的快速入门页面告诉您如何实现它:http://docs.viewflow.io/viewflow_quickstart.html

我只是在你的案例中尝试了一些样本流程:

class CustomerProcessFlow(Flow):
    process_class = CustomerProcess

    start = (
        flow.Start(
            views.CustomerOnBoardView # Let's say this is your customer onboard view
            fields=["customer_name", "customer_address", "customer_phone"]
        ).Permission(
            auto_create=True
        ).Next(this.validate_customer)
    )

    validate_customer = (
        flow.View(
            views.ValidateCustomerDataView # Validation for customer data,
            fields=["approved"]
        ).Permission(
            auto_create=True
        ).Next(this.loan_amount)
    )

    loan_amount = (
        flow.View(
            views.LoanView # Provide Loan
            fields=["loan_amount"]
        ).Permission(
            auto_create=True
        ).Next(this.check_customer_association)
    )

    check_customer_association = (
        flow.If(lambda customer_association: ! customer.type.normal)
        .Then(this.step_4_6)
        .Else(this.step_6_4)
    )

    step_4_6 = (
        flow.Handler ( this.check_load_credibility_data )
        .Next( this.provide_bank_details_data )
    )

    step_6_4 = (
        flow.Handler( this.provide_bank_details_data )
        .Next(this.check_load_credibility)
    )

    this.check_load_credibility = (
        flow.Handler( this.check_load_credibility_data )
        .Next( this.end )
    )

    this.provide_bank_details_data = (
        flow.Handler( this.provide_bank_details_data )
        .Next(this.end)
    )

    end = flow.End()

    def check_load_credibility_data(self, customer):
        # Load credibility

    def provide_bank_details_data(self, customer):
        # Bank Details

可以看到一个例子here

相关问题 更多 >

    热门问题