helpbuttons / hb-front

frontend for helpbuttons.org
GNU Affero General Public License v3.0
5 stars 5 forks source link

Backend call test #5

Closed watchoutfreedom closed 2 years ago

watchoutfreedom commented 3 years ago

test communication between back and front

watchoutfreedom commented 3 years ago

I added a test branch to api call, please if you can give your thoughts

watchoutfreedom commented 3 years ago

@albjeremias can you tell @Andresargote how to receive networks data with the axios calll. I did with the button data andd got an empty array but I suppose it's normal. thanks

albjeremias commented 3 years ago

https://github.com/helpbuttons/hb-back/blob/develop/src/__tests__/controllers/network.controller.test.ts#L75

here!

const resFilter = client.get('/networks/find').query({
        filter: `{
          "where": {
            "id": 3
          },
          "include": [
            {
              "relation": "buttons",
              "scope": {
                "limit": "1"
              }
            }
          ]
        }`});

in the backend im using: https://github.com/visionmedia/superagent which is very similar to axios.

the response of the backend will be something like:

[{
          name: 'Perritos en adopcion',
          id: 3,
          url: 'net/url',
          avatar: 'image/url.png',
          description: 'Net for animal rescue',
          privacy: 'publico',
          place: 'Livorno, Italia',
          latitude: 43.33,
          longitude: 43.33,
          radius: 240,
          tags: ['Animales', 'Perritos', 'Adopcion'],
          buttonsTemplate: [],
          role: 'admin',
          buttons: [
            {
              id: 1,
              name: 'button name',
              type: 'exchange',
              tags: ['onetag'],
              description: 'description of da button',
              latitude: 3.12321321,
              longitude: 5.32421321
            }
          ]
        }]

You can start the backend with a test database, if you do: $ cp data/db.ini.json data/db.json

albjeremias commented 3 years ago

@watchoutfreedom this example also might help to get ideas: https://loopback.io/doc/en/lb4/Building-frontend-angular-application.html

hirunatan commented 3 years ago

I have sent a proposal of a way of managing backend call:

https://github.com/helpbuttons/hb-front/pull/25

I have finished the basic state module that I send some time ago, and made a possible implementation of backend communication and global state use.

This is not the only possible way of doing this, there are many others. For example, I have used rxjs observables for the async fetching of data, but also promises could have been used.

I hope that is autoexplicative, but ask me any doubts.

watchoutfreedom commented 3 years ago

I included examples for button and network and merged it 👍