Skip to content

citysciencelab/cut-dana-platform-backend

Repository files navigation

Story Backend

This backend can save stories that were created by the Story Creation Tool and provides endpoints to retrieve these stories.

The API is structured as the following:

API OVERVIEW

GET

/story                    get list of all stories
/story/1                  get metadata-json of story 1
/step/1/2/3/html          get html  of step 2.3 of story 1
/step/1/2/3/image         get image of step 2.3 of story 1

POST

/add/story/               add new story
/add/step/1/2/3/          add step 2.3 to story 1
/add/step/1/2/3/html      add html to step 2.3 of story 1
/add/step/1/2/3/image     add image to step 2.3 of story 1 

DELETE

/delete/story/1           delete story 1
/delete/step/1            delete all steps to story 1
/delete/step/1/2          delete all steps belonging to major step 2 of story 1
/delete/step/1/2/3        delete step 2.3 of story 1

GET

GET /story

Returns an overview over all stories 

GET /story/:storyId

Returns the story.json file of a story with the respective id

GET /step/

Returns all step's data as json (not including images)

GET /step/:storyId/:step_major/:step_minor/html

Returns html of a specific step of a specific story

GET /step/:storyId/:step_major/:step_minor/image

Returns image of a specific step of a specific story

POST

POST /add/story/

 
Creates a new story entry. (metadata only)

expects in body
	- name (string): the name of the story
	- category (string): the story category
	- story_json (string): the story structure as  json (originally the "story json file")

example curl:
`curl -XPOST -d '{"name": "My New Story", "category" : "test", "story_json" : "{\"relevant json\" : \"as a string\"}"}' -H 'content-type: application/json' localhost:3000/add/story`


POST /add/step/:storyId/:step_major/:step_minor



Creates a story "step" for the story specified in `:storyID` (as created by /add/story). The `:step_major` and `:step_major` parameters are the equivalent of the `1-2.html` notation we originally have in the file names.

expects in body
    - html content of the step (as character string)

example  curl:

`curl -XPOST -d '{"html": "<blink>does this html tag still work?</blink>"}' -H 'content-type: application/json' localhost:3000/add/step/1/2/3`

POST /add/step/:storyId/:step_major/:step_minor/html

post a steps html content. The matching story and step must have been created first!

example curl:
curl -X POST localhost:3000/add/step/1/1/1/html -H 'Content-Type: application/json' -d '{"html":"some <b>story</b> content!"}'

POST /add/step/:storyId/:step_major/:step_minor/image

post an image. The matching story and step must have been created first!

example curl:
curl -F "image=@./testimage.png" localhost:3000/add/step/1/1/1/image

DELETE

DELETE /story/:storyId

delete a story and all its steps. Note: Stories can only be deleted if ALL steps belonging to that story have been deleted first (see /delete/step/)!
example curl:

curl -X "DELETE" localhost:3000/delete/story/1

DELETE /step/:storyId

delete all steps belonging to a story
example curl (delete all steps of story 1):

curl -X "DELETE" localhost:3000/delete/step/1

DELETE /step/:storyId/:step_major

delete all steps with the same major step belonging to a story
example curl (delete step 2.x of story 1):

curl -X "DELETE" localhost:3000/delete/step/1/1

DELETE /step/:storyId/:step_major/:step_minor

delete a minor step in a story
example curl (delete step 2.3 of story 1):

curl -X "DELETE" localhost:3000/delete/step/1/2/3

Database setup

(following this tutorial)

install postgres

  1. install postgresql with homebrew (on Linux / OsX): brew install postgresql brew services start postgresql (you can stop services with brew services stop postgresql)

create database

  1. create a new user and database in psql console
psql postgres
CREATE ROLE me WITH LOGIN PASSWORD 'password';
CREATE DATABASE stories;
\q
  1. then run database init file in /db/setup/

psql -U me -d stories -a -f ./db/setup/db_setup.sql

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published