futurice/wappuapp-backend

Name: wappuapp-backend

Owner: Futurice

Description: API for Wappu app client

Created: 2016-03-08 12:28:35.0

Updated: 2018-04-06 10:03:49.0

Pushed: 2018-04-17 09:17:28.0

Homepage:

Size: 687

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Wappuapp backend

Dependencies:

Get started

Start using API endpoints.

Environments:

Techstack
Heroku/Cloud env
in/bash
ku addons:create --app wappuapp-backend papertrail
ku addons:create --app wappuapp-backend heroku-postgresql:hobby-dev
ku addons:create --app wappuapp-backend newrelic

Add Postgis:

ku pg:psql -a wappuapp-backend
te extension postgis;

Google Cloud Storage is used for storing images.

Common tasks
Release

Migrations and seeds are automatically run in Heroku when you deploy via git push. Migrations are run if knex detects new files in migrations directory. Seeds must be replayable, they must be upsert operations so they can be run on each push.

  1. Commit changes

  2. Check that tests pass, remember to test migrations locally before push

  3. Take manual backup of postgres

    heroku pg:backups capture --app wappuapp-backend

  4. Push changes to production environment:

    checkout master
    pull
    push prod
    

    For testing environments:

    You can also release a certain local branch. For example releasing from node branch to dev: git push dev my-local-branch:master.

  5. Check that the environment responds and logs(Papertrail) look ok.

    Quick test endpoints:

  6. https://wappuapp-backend.herokuapp.com/api/events

  7. https://wappuapp-backend.herokuapp.com/api/feed

  8. https://wappuapp-backend.herokuapp.com/api/action_types

Update events

NOTE: Some data is added to the original Excel file via fuzzy match mappings. This was done because initially we did not want to modify the original Excel file itself to prevent csv export and character encoding problems. This is not true anymore but some of the data is still added via fuzzy match mappings. These could be transferred to the xlsx file already.

Update markers
Shadow ban user
TE users SET is_banned = true WHERE uuid='D47DA01C-51BB-4F96-90B6-D64B77225EB7';
API Endpoints

READ THIS:

GET /api/events

List events

Query parameters:

Responses:

GET /api/events/:id

Get event details

Responses:

GET /api/teams

List all teams

Query parameters:

Responses:

POST /api/actions

Create a new action

Query parameters:

Body is one of action objects.

Responses:

PUT /api/vote

Vote on an feed item

Body is one of vote object.

Responses:

GET /api/users

Get user details

Query parameters:

Responses:

PUT /api/users/:uuid

Create or update a user

Body is one of user object.

Responses:

GET /api/users/:uuid

Get user details

Responses:

GET /api/action_types

List action types available

Body is one of action type object.

Responses:

GET /api/markers

List map markers

Body is list of marker objects.

Responses:

GET /api/cities

List participating cities

Body is list of city objects.

Query parameters:

Responses:

GET /api/feed

Get list of feed

Body is one of feed objects.

Query parameters:

Examples:

Responses:

GET /api/image/:id

Get specific image

Body is one of image objects.

Responses:

DELETE /api/feed/:id

Delete item from feed

:id Is the id of an item in the feed.

GET /api/mood

Get list of day by day mood

Query parameters:

Body is a list of mood objects.

PUT /api/mood

Create or update mood

Body is one of mood objects.

Responses:

GET /api/radio

Get list of radio stations.

Query parameters:

Responses:

GET /api/radio/:id

Get one of radio stations.

Responses:

Response objects
Event object

d": 121,
ame": "Spinnin iltapäiväkertho",
ocationName": "Spinnin kerhohuone SA014",
tartTime": "2017-02-21T10:00:00.000Z",
ndTime": "2017-04-21T15:00:00.000Z",
escription": "Raining and freezing outside? Studying terrifies and starting to miss kindergarden times? Spinni solves your problems!\r\r\r\rClimb stairs down to the basement of Sähkötalo and arrive to the club room of Spinni, SA014 on <päivämäärä> starting at 1 PM. Spinni offers some snacks, coloring books (for adults), games, lot of friends to play with - not to mention awesome music and lights. Additionally you may have a look at the regular life of electronic music club that is celebrating its 20th anniversary this year.\r\r\r\rSpinni <3 you",
rganizer": "Spinni",
ontactDetails": "spinni-hallitus@listmail.tut.fi; Valtteri Taimela, valtteri.taimela@student.tut.fi",
eemu": false,
ocation": {
"latitude": 61.450364,
"longitude": 23.858384

overImage": "https://storage.googleapis.com/wappuapp/assets/spinni.jpg",
ity": 3,
bEventId": null,
ttendingCount": 0,
adius": 400,
mages": []

Team object

d": 1,
ame": "Tietoteekkarikilta",
mage_path": "foo.com/path_to_image.jpg",
core": "10",
ity": 3

User details object

Images is an array of feed objects.


ame": "Hessu Kypärä",
eam": "TiTe",
umSimas": "1",
mages": [
{
  "id": "2",
  "type": "IMAGE",
  "votes": "0",
  "userVote": 0,
  "hotScore": "195.2537",
  "author": {
    "id": "1",
    "name": "Hessu Kypärä",
    "team": "TiTe",
    "type": "ME"
  },
  "createdAt": "2017-04-12T16:40:14.308Z",
  "location": {
    "latitude": 0.123,
    "longitude": 0.123
  },
  "url": "https://storage.googleapis.com/wappuapp/user_content/123.jpg"
}



User object

{ “uuid”: “de305d54-75b4-431b-adb2-eb6b9e546014”, “name”: “Hessu Kypärä” }

Action type object

{ “id”: “3”, “code”: “CIDER”, “name”: “Grab a cider”, “value”: 10, “cooldown”: 300000 }

Marker object

{ location: {

latitude: -1.2345,
longitude: 56.2322

},

// One of STORE, ALKO, TOILET, TAXI, BAR, RESTAURANT type: “STORE”, title: “K-Supermarket Herkkuduo”,

// Optional url url: “http://www.k-supermarket.fi/” }

Vote object

{ // one of 1, -1 “value”: 1, “feedItemId”: 12 }

City object

{ “id”: 2, “name”: “helsinki” }

Radio object

{ “id”: 2, “name”: “Radiodiodi”, “stream”: null, “website”: null, “cityId”: 2, “nowPlaying”: {

"programTitle": "Mustia kukkia ja kielimoukareita",
"programHost": "Santtu, Jaati, Lari",
"song": null,
"left": 1132504   // How much longer the program is gonna be playing, in ms

} }

Mood objects

 GET mood object

{ “date”: “2016-04-15T22:00:00.000Z”, “ratingCity”: “3.3333”, // May be null “ratingTeam”: “5.0000”, // May be null “ratingPersonal”: “10.0000” // May be null }

 PUT mood object

{ // Dacimal. Range [0, 10]. Rounded to 4th decimal mark. “rating”: 10, // Optional “description”: “Its friday!”

}

Action objects

 Basic action object

e` is one of `SIMA`, `CHECK_IN_EVENT`.

{ // required when event type 'CHECK_IN_EVENT' location: {

latitude: -1.2345,
longitude: 56.2322

}, type: “SIMA”, team: 1, user: 'UUID', // required when event type 'CHECK_IN_EVENT' eventId: 1 }

 Image action object

{ location: {

latitude: -1.2345,
longitude: 56.2322

}, type: “IMAGE”, team: 1, imageData: 'base64encodedimage', user: 'UUID' }

Feed objects

 Image feed object

{ id: 1, // location is optional so it might be not provided location: {

latitude: -1.2345,
longitude: 56.2322

}, type: “IMAGE”, createdAt: “2016-04-20T09:00:00.000Z”, votes: 10, hotScore: 178.0032, author: {

name: "Nahkasimo",
team: "Sähkökilta",
// Can be 'ME', 'OTHER_USER', 'SYSTEM'
type: "ME"

}, url: “https://storage.googleapis.com/wappuapp/user_content/123.jpg” }

Image objects

{ createdAt: “2016-04-20T09:00:00.000Z”, votes: 10, hotScore: 178.0032, author: {

name: "Nahkasimo",
team: "Sähkökilta",

}, url: “https://storage.googleapis.com/wappuapp/user_content/123.jpg” }

 Text feed object

{ id: 1, // location is optional so it might be not provided location: {

latitude: -1.2345,
longitude: 56.2322

}, type: “TEXT”, createdAt: “2016-04-20T09:00:00.000Z”, votes: 10, // If and how the user has voted. One of [-1, 0, 1]. userVote: 0, hotScore: 178.0021, author: {

name: "Nahkasimo",
team: "Sähkökilta",
// Can be 'ME', 'OTHER_USER', 'SYSTEM'
type: "ME"

}, text: “Joujou” }

rror handling

 HTTP status code is 400 or higher, response is in format:

{ “error”: “Internal Server Error” }

===

cknowledgements
 project is a grateful recipient of the [Futurice Open Source sponsorship program](http://futurice.com/blog/sponsoring-free-time-open-source-activities). ?

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.