Skip to content

mammadmaheri7/IE_finalProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Standards for IE. Final Project

Project is Live at heroku:

Contributors:

  • Seyed AmirHussein Rahnamafard
  • Mohammad Maheri
  • Navid Mahdian

Insert a new form to database:

  • Request:

    • Post
    • /api/forms
      {
          "title": "First Form", 
          "fields":
          [
              {
                  "name": "First_Name" , 
                  "title": "First Name" , 
                  "type": "Text",
                  "required": true
              }, 
              {
                  "name": "Your_Location" , 
                  "title": "Your Location" , 
                  "type": "Location",
                  "required": false
              }, 
              {
                  "name": "Request_Type" , 
                  "title": "Request Type" , 
                  "type": "Text" , 
                  "options":
                  [
                      {"label" : "Help" , "value" : "Help"}, 
                      {"label" : "Info" , "value" : "Information"} 
                  ] 
              }, 
              {
                  "name": "Base_Location", 
                  "title": "Base Location", 
                  "type": "Location", 
                  "options":
                  [
                      {"label" : "Base1" , "value" : {"lat" : "1.2" , "long": "3.2"}}, 
                      {"label" : "Base2" , "value" : {"lat" : "2.3" , "long" : "1.434" }} 
                  ] 
              } 
          ] 
      }
  • Response if form inserted:

    {
        "status": "ok",
        "message": "'First Form' inserted successfuly.",
    }
  • Response if form NOT inserted:

    {
        "status": "error",
        "message": "Error message",
    }

Retrive List of all forms:

  • Request:

    • GET
    • /api/forms
  • Response:

    {
        "forms":
        [
            {
                "title":"First Form" , 
                "form_id": "1" , 
                "url": "/api/forms/1"                     
            },
            {
                "title":"Second Form" , 
                "form_id": "2" , 
                "url": "/api/forms/2"                     
            },
            .
            .
            .
        ] 
    }

Retrive form information by id:

  • Request:

    • GET
    • /api/forms/<FORM_ID>
  • Response:

    {
        "title":"First Form" , 
        "form_id": 1, 
        "fields":
        [
            {
                "name":"First_Name" , 
                "title": "First Name" , 
                "type": "Text",
                "required": true
            }, 
            {
                "name": "Your_Location" , 
                "title": "Your Location" , 
                "type": "Location",
                "required": false
            }, 
            {
                "name": "Request_Type" , 
                "title": "Request Type" , 
                "type": "Text" , 
                "options":
                [
                    {"label" : "Help" , "value" : "Help"}, 
                    {"label" : "Info" , "value" : "Information"} 
                ] 
            } , 
            {
                "name":"Base_Location" , 
                "title" : "Base Location" , 
                "type" : "Location" , 
                "options":
                [
                    {"label" : "Base1" , "value" : {"lat" : "1.2" , "long": "3.2"}}, 
                    {"label" : "Base2" , "value" : {"lat" : "2.3" , "long" : "1.434" }} 
                ] 
            } 
        ] 
    }

Submit a form:

  • Request:

    • POST
    • /api/forms/submit
      {
          "form_id": "1",
          "response":
          {
              "First_Name": "...",
              "Your_Location": {
                  "lat": "...",
                  "long": "...",
              },
              "Request_Type": "Information",
              "Base_Location": {
                  "lat" : "1.2" ,
                  "long": "3.2"
              },
              .
              .
              .
          }
      }
  • Response if any error occuers:

    • 400 Bad Request
    {
        "status": "error",
        "errors":
        [
            {
                "message": "Loc field is required."
            },
            {
                "message": "Date field must be a date"
            },
            .
            .
            .
        ] 
    }
  • Response if form submitted:

    {
        "status": "ok",
        "message": "'First Form' submitted successfuly.",
    }

Retrive list of all responses to a single form

  • Request:

    • GET
    • /api/forms/<FORM_ID>/responses
  • Response:

    {
        "title": "First Form",
        "form_id": 1,
        "form_fields":
        [
            {
                "name": "Home", 
                "title": "Home", 
                "type": "Location", 
                "label": "Location Label"
            },
            .
            .
            .
        ],
        "responses":
        [
            {
                "response_id": 1,
                "fields":
                [
                    {
                        "name": "Home", 
                        "title": "Home", 
                        "type": "Location", 
                        "label": "Location Label",
                        "value":
                            {
                                "lat": "1.2",
                                "long": "3.2",
                            },
                    },
                    .
                    .
                    .
                ],                     
            },
            .
            .
            .
        ] 
    }

Retrive details of a single response to a single form

  • Request:

    • GET
    • /api/forms/<FORM_ID>/responses/<RESPONSE_ID>
  • Response:

        {
            "form_id": 1,
            "response_id": 1,
            "fields":
            [
                {
                    "name": "Home", 
                    "title": "Home", 
                    "type": "Location", 
                    "value":
                        {
                            "label": "Location Label",
                            "lat": "1.2",
                            "long": "3.2",
                        },
                },
                .
                .
                .
            ],          
        }

Insert a new polygon area to database:

  • Request:

    • POST
    • /api/polygons/
      {
          "type": "Feature",
          "properties":
              {
                  "name": "Tehran"
              },
          "geometry":
              {
                  "type": "Polygon",
                  "coordinates": [
                      [
                          [
                              53.514404296875,
                              34.59704151614417
                          ],
                          [
                              51.416015625,
                              34.854382885097905
                          ],
                          [
                              51.6851806640625,
                              33.82023008524739
                          ],
                          [
                              53.514404296875,
                              34.59704151614417
                          ]
                      ]
                  ]
              }
      }
  • Response if polygon inserted:

    {
        "status": "ok",
        "message": "'Tehran' inserted successfuly.",
    }
  • Response if polygon NOT inserted:

    {
        "status": "error",
        "message": "Error message",
    }

    geojson.io

Retrieve All polygons area contains a geo-location inside themeselves:

  • Request:

    • GET
    • /api/polygons/filter/?lat=<LATITUDE>&long=<LONGITUDE>
  • Response for filtered request:

    {
        "polygons":
        [
            {
                "polygon_id": 1,
                "name": "Tehran",
            },
            .
            .
            .
        ]
    }

Retrieve All polygons:

  • Request:

    • GET
    • /api/polygons/
  • Response:

    {
        "polygons":
        [
            {
                "polygon_id": 1,
                "name": "Tehran",
            },
            .
            .
            .
        ]
    }

Filter the responses to a single form by polygon areas:

  • Request:

    • GET
    • /api/forms/<FORM_ID>/responses/filter/?field=<FIELD_NAME>&polygon_id=<POLYGON_ID>
  • Response for filtered request:

    {
        "title": "First Form",
        "form_id": 1,
        "responses":
        [
            {
                "response_id": 1,
                "fields":
                [
                    {
                        "name": "Request_Type" , 
                        "title": "Request Type" , 
                        "type": "Text" , 
                        "value": "Submitted value by user",
                    },
                    .
                    .
                    .
                ]                     
            },
            .
            .
            .
        ] 
    }

Filter the responses to a single form by custom field:

  • Request:

    • GET
    • /api/forms/<FORM_ID>/responses/customFilter/?field=<FIELD_NAME>&lt=<LOWER_BOUND>&gt=<UPPER_BOUND>&eq=<EXACT_VALUE>
    • Numeric:

      /api/forms/1/responses/customFilter/?field=Age&eq=25
      /api/forms/1/responses/customFilter/?field=Age&gt=18
      /api/forms/1/responses/customFilter/?field=Age&lt=30
      /api/forms/1/responses/customFilter/?field=Age&lt=30&gt=18
      
    • Date:

      /api/forms/1/responses/customFilter/?field=Submit_Date&eq=2020-01-01
      /api/forms/1/responses/customFilter/?field=Submit_Date&lt=2020-02-30
      /api/forms/1/responses/customFilter/?field=Submit_Date&gt=2020-01-01
      /api/forms/1/responses/customFilter/?field=Submit_Date&lt=2020-02-30&gt=2020-01-01
      
    • String:

      /api/forms/1/responses/customFilter/?field=First_Name&eq=Ali
      
  • Response for filtered request:

    {
        "title": "First Form",
        "form_id": 1,
        "responses":
        [
            {
                "response_id": 1,
                "fields":
                [
                    {
                        "name": "Age" , 
                        "title": "Age" , 
                        "type": "Number" , 
                        "value": 23,
                    },
                    .
                    .
                    .
                ]                     
            },
            .
            .
            .
        ] 
    }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •