Web app - adamkral12/PA165 GitHub Wiki

Starting web app

mvn clean install && cd Secret-agency-web && mvn spring-boot:run

application runs on http://localhost:8080/pa165/

Authentication

There are 3 predefined users (agents) now. Their credentials and roles are the following:

CodeName Password Role
Bures nikdyNeodstoupim Admin
007 Shaken,notStirred User
Ovar putin User

Login

you need to login to get the session cookie

curl -X POST -F 'username=Bures' -F 'password=nikdyNeodstoupim' -D - http://localhost:8080/pa165/login --silent | grep "Set-Cookie: JSESSIONID"

this should output something like Set-Cookie: JSESSIONID=E95FD245A71BDEFAE0E9A269452557F5; Path=/pa165; HttpOnly

part JSESSIONID=E95FD245A71BDEFAE0E9A269452557F5; Path=/pa165; HttpOnly will be referenced as {COOKIE_VALUE} in the rest of curl commands

Testing API

You need to obtain JSESSIONID to test Rest api. How to do it is described in previous section.

Departments

  1. Get all departments
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/departments/

  2. Get department by id
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/departments/1

  3. Create department
    curl --cookie "{COOKIE_VALUE}" -X POST -i -H "Content-Type: application/json" --data \ '{ "city": "Ostrava", "country": "Czech Republic","longitude": 123213.32,"latitude": 123.231,"specialization": "ASSASSINATION"}'\ http://localhost:8080/pa165/rest/departments/

  4. Get all specializations
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/departments/specializations

  5. Get departments by specialization
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/departments/specialization/ASSASSINATION

  6. get departments by city
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/departments/city/Prague

  7. get departments by country
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/departments/country/Czech%20Republic

  8. get departments by area
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/departments/area/50.08804/14.4207/20

Reports

  1. Get all reports
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/reports/

  2. Get report by id
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/reports/report/1

  3. Create report
    curl --cookie "{COOKIE_VALUE}" -X POST -i -H "Content-Type: application/json" --data \ '{ "text": "This message was never written before", "missionResult": "FAILED","agentId": 1,"missionId": 1}'\ http://localhost:8080/pa165/rest/reports/

  4. Update report's text
    curl --cookie "{COOKIE_VALUE}" -X PUT -i -H "Content-Type: application/json" --data \ '{ "id": 1, "text": "The report I made before was full of bullshit"}'\ http://localhost:8080/pa165/rest/reports/report/{id}

  5. Delete report
    curl --cookie "{COOKIE_VALUE}" -i -X PUT http://localhost:8080/pa165/rest/reports/report/1

  6. Approve report
    curl --cookie "{COOKIE_VALUE}" -i -X PUT http://localhost:8080/pa165/rest/reports/report/1/approve/

  7. Deny report
    curl --cookie "{COOKIE_VALUE}" -i -X PUT http://localhost:8080/pa165/rest/reports/report/1/deny/

  8. Get reports from an interval
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/reports/interval/2018-01-01/2018-12-12/

  9. Get reports with mission result
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/reports/missionResult/FAILED/

  10. Get reports with status
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/reports/reportStatus/NEW/

Missions

  1. get all missions
    curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/missions

  2. get mission by id curl --cookie "{COOKIE_VALUE}" -i -X GET http://localhost:8080/pa165/rest/missions/1

  3. create mission curl --cookie "{COOKIE_VALUE}" -X POST -i -H "Content-Type: application/json" --data '{ "latitude": "23.52", "longitude": "15.22", "missionType": "SABOTAGE", "started":"2013-02-11"}' http://localhost:8080/pa165/rest/missions

  4. delete mission curl --cookie "{COOKIE_VALUE}" -i -X DELETE http://localhost:8080/pa165/rest/missions/1

Development

Starting frontend

cd Secret-agency-web/src/main/react/secret-agency && npm install && npm run start

the app should start on http://localhost:3000/

Before you push, you need to build the app (if we don't figure out how to do it automatically)

npm run build

⚠️ **GitHub.com Fallback** ⚠️