Giter VIP home page Giter VIP logo

wsu_cpts_422_bats's Introduction

CptS 422: Software Engineering Principles II

Team Name

BATS: Business Analytics Tagging Service

Project Description

An api that lets businesses track analytics for their websites via logging tags within our database and then being able to simply query back to get information on total usage for different tags.

See Deliverable 1 for our Deliverable 1 document.

Testing the api

PREREQ:

-NodeJS (Recent version) -Postman (Suggested/Optional) Clone the current master branch Run "npm install" to download all necessary dependencies within the package.json Next, run "node app.js" to start up server

Create a token

POST 0.0.0.0:3000/api/tokens/ body: { "organization": "company name" }

Delete a token (and related tags and interactions)

DELETE 0.0.0.0:3000/api/tokens/ headers: { 'Authorization': Bearer 056f9979-b5bb-4741-898f-80b432461e21, }

Create/Update tag/interaction

POST 0.0.0.0:3000/api/tags/(name) body: { "value": "metadata", "interaction": "interaction type" } headers: { 'Authorization': Bearer 056f9979-b5bb-4741-898f-80b432461e21, }

View all interactions by name

GET 0.0.0.0:3000/api/tags/(name) headers: { 'Authorization': Bearer 056f9979-b5bb-4741-898f-80b432461e21, }

View all interactions

GET 0.0.0.0:3000/api/tags headers: { 'Authorization': Bearer 056f9979-b5bb-4741-898f-80b432461e21, }

Testing with website

Open frontend/index.html and go ahead and click the sample buttons to check the database use View All Interactions route with the following header: headers: { 'Authorization': Bearer 056f9979-b5bb-4741-898f-80b432461e21, }

Team Members

  • Austin Marino
  • Cole Bennett
  • Joseph Cunningham
  • Niko Kent

wsu_cpts_422_bats's People

Contributors

austinmm avatar colebennett avatar jham109 avatar jham20 avatar nikokent avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

colebennett

wsu_cpts_422_bats's Issues

Tag ids (Primary Keys) Are all the same

GET localhost:3000/api/tags/
Bearer Auth: cc93d2ef-a0ca-405d-8e8d-633b70ab51d4

{
    "Status": "Successful",
    "Result": [
        {
            "id": 2326,
            "token_id": 2326,
            "name": "groups.custom.0",
            "value": "Example Tag Value",
            "created": "2019-09-21T06:56:41.000Z",
            "token": "cc93d2ef-a0ca-405d-8e8d-633b70ab51d4",
            "organization": "BATS",
            "issued": "2019-09-21T06:56:02.000Z"
        },
        {
            "id": 2326,
            "token_id": 2326,
            "name": "groups.custom.1",
            "value": "Example Tag Value",
            "created": "2019-09-21T06:57:20.000Z",
            "token": "cc93d2ef-a0ca-405d-8e8d-633b70ab51d4",
            "organization": "BATS",
            "issued": "2019-09-21T06:56:02.000Z"
        },
        {
            "id": 2326,
            "token_id": 2326,
            "name": "groups.custom.2",
            "value": "Example Tag Value",
            "created": "2019-09-21T06:57:58.000Z",
            "token": "cc93d2ef-a0ca-405d-8e8d-633b70ab51d4",
            "organization": "BATS",
            "issued": "2019-09-21T06:56:02.000Z"
        },...

Should we display tag interactions in any of the GET 'api/tags' endpoints?

As of right now when a user calls endpoint GET 'api/tags/<name: optional>' they only get back tags but non of their interactions; linked by a foreign key to the tag(s). Should we provide a way to display interactions as a separate GET endpoint in 'api/tags' or provide a query parameter in the 'api/tags/<name: optional>' endpoint to display tag interactions alongside the tag(s).

Does anyone have a better idea on how to do this?

This endpoint creates a tag, if it is not already created, and then creates a new interaction for the tag.

router.post("/:name", async (req, res) => {
  const tag_name = req.params.name;
  const interaction = req.query.interaction;
  const value = req.query.value;
  const token_id = res.locals.token_id;
  var response = undefined;
  try {
    var query = `INSERT IGNORE INTO tags (token_id, name, value, created) VALUES (${token_id}, '${tag_name}', '${value}', CURRENT_TIMESTAMP())`;
    var results = await executeQuery(query); //Executes query
    var tag_id = results.insertId;
    //Tag already exist so we need to obtain its 'id' to enter the new interaction 
    if(tag_id == 0){
      query = `SELECT id FROM tags WHERE name='${tag_name}'`;
      results = await executeQuery(query); //Executes query
      tag_id = results[0].id; 
    }
    query = `INSERT INTO interactions (tag_id, action, time) VALUES ('${tag_id}', '${interaction}', CURRENT_TIMESTAMP())`;
    results = await executeQuery(query); //Executes query
    res.status(201);
    response = {"tag": {"id": tag_id, "name": tag_name, "value": value}, "interaction": {"id": results.insertId, "action": interaction}};
  }
  catch(err) {
    response = err;
    res.status(500);
  }  
  //returns the json of new record that was inserted into the table
  res.send(response);
});

Launch front end when server is started

Can we please add a script that will launch our front end, index.html, whenever we run the command "node app.js" or maybe add the option as a parameter like "node app.js frontend".

Move check tokens function into base.js

There currently exist two check tokens function in base.js and tokens.js which perform the same action but return slightly different values. We should just use the base.js function and adapt any routes that use the tokens.js check tokens function to use the one in base.js

Responses should match the OpenAPI spec (in docs)

We need to format the results based on the spec. Examples for responses are on that web page (when pasted into editor.swagger.io).

Also, depending on the different response code cases, we need to format the responses as well. For example, GET /tokens/{token} should return 404 response with response body {"code": 404, "message": "Token not found: ..."} if it does not exist.

All of the endpoints will have to be modified as well.

Create another field for tag table called "updated".

The "updated" field would contain the most recent time that the tag had an interaction take place. It would work similarly to when a file is "touched" and this would allow us to see what tags have been interacted with most recently without looking into the interactions table.
ALTER TABLE tags
ADD updated TIMESTAMP NOT NULL;

Using body for post requests

All post requests should use body instead of query params

to do this make sure you use req.body.

To test with postman make sure to just do raw json:

{ "organization":"some_org"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.