The cloud application of “In-room Ordering” is a set of industry application template for online ordering. Customers can order, add dishes and pay bills by scanning code via mini program /APP, thus reducing the workload of service staff in stores and operating costs of restaurants. After the front-end template source open source, has won many developers praise, in order to give developers to bring better learning and development benefits, “Eat and Order” back-end data cloud function is also open source! The template’s data cloud model and cloud functions are now live in the data Cloud Provisioning model. By importing the model, you can experience the complete case of cloud integrated “Eat and Order”.

Data Cloud 3.0 is a new server development operation and maintenance platform, providing a set of solutions from back-end development, interface coordination to online operation and maintenance. Developers do not need to worry about infrastructure such as database and server, do not need to worry about setting up server test environment, data backup and service expansion and other non-business related work, only need to care about the logic itself.

The front-end source

Catering order: a set of code generation APP+ small procedures, 🔗 click here to view the source code

The back-end source

After creating the application using the EAT and Order template, we can import the data cloud model and cloud functions as required, as follows:

1.Enable the data cloud and import model

Go to the control panel of the project and select Cloud Settings in Cloud Development. If you open this screen for the first time, the data cloud is not enabled by default. Click the open button of the welcome page to start the data cloud.

After the data cloud is enabled, you can perform basic Settings on the Cloud Settings page. Next, focus on the “Data Model” page. Click “Data Model” to open the relevant page, we can create the model and cloud function by ourselves, or we can see the model with the same name of “Eating and ordering” in the “Prefabricated model” on the right. Click the small green plus sign in the lower right corner to import the model.

After the import is successful, you can see the corresponding data model displayed on the left. Click on the model to enter a preview of the relevant model data. Alternatively, clicking on “Cloud function Development” at the bottom left will pop up the cloud function management floating layer, with guidance and document links in the middle. You can create a new cloud function by clicking on the green button at the top of the left, or by clicking on an existing cloud function to learn how the preset functions and interfaces are designed.

2. Experience it

Take the shop model on the left as an example. Click on the model to open “Remote Functions”. Locate the getInfo interface in the remote function and click on it to display the code implementation on the right. In this case, a full release is required. Click the drop-down arrow on the right of the release at the top of the right, select full release, and publish all the models and cloud functions that have just been imported and take effect. Next, you can click interface tuning to open the API interface generation list. Find the getInfo interface under the Shop group and click “Try it out” to test the interface.

You will see the full requested address after the request. Next open the source code on the App side, find script/req.js about the third line, and change the request secondary prefix in the code to the actual API path for the project. Such as:

const config = {
    schema: 'https',
-    host: 'a7777777777777-pd.apicloud-saas.com',
+    host: 'a6176110219206-dev.apicloud-saas.com',
    path: 'api'
}
Copy the code

Go to the pages/main_home/main_home. STML page, right click on the blank area, and choose live Preview. Wait a moment, the preview screen will appear in the preview area on the right. Click the copy icon next to the address to get the preview address. Put it into a browser such as Chrome to observe the request and confirm that the rendered data is indeed model data from the data cloud interface of the current project.

3. Cloud model quickly

A cloud model is a cloud database. Business data can be accessed, and data access interfaces and related apis are provided.

In a project, you can model the data tables that your business needs. Again, take Shop as an example: after opening the model, the data in the model is displayed in the form of a table. The contents of the table header are the fields of the model, and the data in the table are the records saved under the model. You can add data, delete data, add fields, set association and other management operations in the header button.

4, cloud function sample code

Obtain merchant information

GET /shops/getInfo shop.getInfo = async()=> { try{ const data = await shop.findOne({where: {"status":1}}); Return {status:0, MSG :" success ",data:data}; }catch(err){return {status:1, MSG :" Failed to get business information!" ,data:err}; }};Copy the code

By reading the cloud function source code above, you can see that a cloud function composition is quite simple. In the edit state, you can see that the form displays the necessary elements of a cloud function: Select Model, make the function type “remote function”, and select the request type “get”. Complete the function name and description, and finally set up a function (method) name that serves as the function name and the remote interface’s access address.

In the function, the data operation API of the model is used to realize the specific function of the interface: in the above code, it is to find a qualified data whose status is 1 from the SHOP model. As you can see, the lookup criteria are placed in the WHERE condition as JSON. Normally, the data is successfully found and the return keyword is used to return the value for the function. This value is also returned to the front end as the data field of the response of the interface generated by the cloud function. A try-catch block is used to catch errors and is returned to the front end if the lookup fails.

You can refer to the full documentation at 🔗 Data Cloud 3 for more model approaches.

5,Management background quick start

In addition to models and cloud functions, Data Cloud 3 also provides a rapid backend generation management system.

For the convenience of users, we have built a management background module, which users can access in the test environment through “appid-dev.apicloud-saas.com/admin/” after starting the service.

This function requires global configuration to enable the session service and file storage. Perform related operations in global configuration.

If the current APPID is a6176110219206, the corresponding management address is a6176110219206-dev.apicloud-saas.com/admin/. The default account and password are: account: admin Password: 123456

In the background can carry on the relevant data setting and page rapid development. The rule for background page development is the introduction of the low-code framework AMIS. IO /amis/ zh-cn /…

6,Deep use and advancement

Back in the Data Cloud panel, you can view sample models and cloud functions. You can also learn complete data cloud usage from the Data Cloud Complete documentation. Data Cloud documentation link: docs.apicloud.com/Cloud-API/s…