Skip to content

pckv/kompis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kompis | backend

Build Status Codacy Badge

This is Kompis

The Kompis project aims to make it easy to for everyone to get home after a night out. We will provide a platform where users can ask for someone to drive them home, or drivers to advertise when they are available.

API

Users endpoints

Listings endpoints

Documentation

Users

Create user

POST /users

Creates a new user that can be logged into.

Request

Headers:

Content-Type: application/json

Body:

{
  "email": "[email protected]",
  "password": "password",
  "displayName": "Roger Doger"
}

Responses

  • 200 OK on success

Headers:

Content-Type: application/json

Body:

{
  "id": 1,
  "displayName": "Roger Doger"
}
  • 409 CONFLICT if a user with the given email exists

Authorize

POST /users/authorize

Receive authorization for use with endpoints requiring authorization. If the client supports firebase cloud messaging, a token should be provided in the body.

Request

Headers:

Content-Type: application/json

Body:

{
  "email": "[email protected]",
  "password": "password",
  "firebaseToken": "(optional)"
}

Responses

  • 200 OK on success

Headers:

Content-Type: application/json
Authorization: Bearer xxx.yyy.zzz

Body:

{
  "id": 1,
  "displayName": "Roger Doger"
}
  • 404 CONFLICT if a user with the given email does not exist
  • 403 FORBIDDEN if a user with the given email already exist

Get user

GET /users/{id:number}

Get the user with the given ID.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Responses

  • 200 OK on success

Headers:

Content-Type: application/json
Authorization: Bearer xxx.yyy.zzz

Body:

{
  "id": 1,
  "displayName": "Roger Doger"
}
  • 403 FORBIDDEN if Authorization header is invalid
  • 404 NOT FOUND if user with the given id was not found

Get current user

GET /users/current

Get the current authorized user.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Responses

  • 200 OK on success

Headers:

Authorization: Bearer xxx.yyy.zzz

Body:

{
  "id": 1,
  "displayName": "Roger Doger"
}
  • 403 FORBIDDEN if Authorization header is invalid

Delete current user

DELETE /users/current

Delete the current authorized user. All listings where this user is the assignee will be unassigned and all listings where this user is the owner will be deleted.

The client should get rid of the Authorization token manually.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Responses

  • 200 OK on success

Headers:

Authorization: Bearer xxx.yyy.zzz
  • 403 FORBIDDEN if Authorization header is invalid

Send firebase token

PUT /users/current/firebase

Update the firebase token for the current authorized user.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Parameters:

  • token - the firebase token assigned to the client of the current authorized user

Responses

  • 200 OK on success

Headers:

Authorization: Bearer xxx.yyy.zzz
  • 403 FORBIDDEN if Authorization header is invalid

Body:

{
  "id": 1,
  "displayName": "Roger Doger"
}
  • 403 FORBIDDEN if Authorization header is invalid

Listing

Get listings

GET /listings

Gets a list of all listings.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Responses

  • 200 OK on success

Headers:

Content-Type: application/json
Authorization: Bearer xxx.yyy.zzz

Body:

[
  {
    "id": 2,
    "title": "Need pickup at Oslo",
    "driver": false,
    "active": true,
    "owner": {
      "id": 1,
      "displayName": "Roger Doger"
    }, 
    "location": {
      "id": 10,
      "latitude": "98.76",
      "longitude": "54.32",
      "accuracy": "99.1"
      },
    "assignee": {
      "id": 12,
      "user": {
        "id": 9,
        "displayName": "Harry"
      },
      "location": {
        "id": 10,
        "latitude": "12.34",
        "longitude": "23.45",
        "accuracy": "99.1"
      }
    }
  }, ...
]
  • 403 FORBIDDEN if Authorization header is invalid

Create listing

POST /listings

Creates a new listing owned by the current logged in user.

Request

Headers:

Content-Type: application/json
Authorization: Bearer xxx.yyy.zzz

Body:

{
  "title": "Need pickup at Oslo",
  "driver": false, 
  "location": {
    "latitude": "98.76",
    "longitude": "54.32",
    "accuracy": "99.1"
  }
}

Responses

  • 200 OK on success

Headers:

Content-Type: application/json
Authorization: Bearer xxx.yyy.zzz

Body:

{
  "id": 2,
  "title": "Need pickup at Oslo",
  "driver": false,
  "active": true,
  "owner": {
    "id": 1,
    "displayName": "Roger Doger"
  }, 
  "location": {
    "id": 10,
    "latitude": "98.76",
    "longitude": "54.32",
    "accuracy": "99.1"
  },
  "assignee": null
}
  • 403 FORBIDDEN if Authorization header is invalid

Get listing

GET /listings/{id:number}

Gets the listing with the given ID.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Responses

  • 200 OK on success

Headers:

Content-Type: application/json
Authorization: Bearer xxx.yyy.zzz

Body:

{
  "id": 2,
  "title": "Need pickup at Oslo",
  "driver": false,
  "active": true,
  "owner": {
    "id": 1,
    "displayName": "Roger Doger"
  }, 
  "location": {
    "id": 10,
    "latitude": "98.76",
    "longitude": "54.32",
    "accuracy": "99.1"
  },
  "assignee": null
}
  • 403 FORBIDDEN if Authorization header is invalid
  • 404 NOT FOUND if a listing with the given ID was not found

Delete listing

DELETE /listings/{id:number}

Delete the listing with the given ID if it is owned by the current authorized user.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Responses

  • 200 OK on success

Headers:

Authorization: Bearer xxx.yyy.zzz
  • 403 FORBIDDEN if the listing is not owned by the current authorized user
  • 403 FORBIDDEN if Authorization header is invalid
  • 404 NOT FOUND if a listing with the given ID was not found

Activate listing

GET /listings/{id:number}/activate

Activate the listing with the given ID if it is owned by the current authorized user.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Responses

  • 200 OK on success

Headers:

Authorization: Bearer xxx.yyy.zzz
  • 403 FORBIDDEN if the listing is not owned by the current authorized user
  • 403 FORBIDDEN if Authorization header is invalid
  • 404 NOT FOUND if a listing with the given ID was not found

Deactivate listing

GET /listings/{id:number}/deactivate

Deactivate the listing with the given ID if it is owned by the current authorized user.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Responses

  • 200 OK on success

Headers:

Authorization: Bearer xxx.yyy.zzz
  • 403 FORBIDDEN if the listing is not owned by the current authorized user
  • 403 FORBIDDEN if Authorization header is invalid
  • 404 NOT FOUND if a listing with the given ID was not found

Assign current user to listing

POST /listings/{id:number}/assign

Assign the current logged in user to the listing with the given ID and store the assignees location in the listing.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Body:

{
  "latitude": "12.34",
  "longitude": "23.45",
  "accuracy": "99.1"
}

Responses

  • 200 OK on success

Headers:

Authorization: Bearer xxx.yyy.zzz
  • 403 FORBIDDEN if Authorization header is invalid
  • 404 NOT FOUND if a listing with the given ID was not found
  • 409 CONFLICT if the listing already has an assignee

Unassign user from listing

GET /listings/{id:number}/unassign

If the current authorized user is the owner of the listing with the given ID, the assignee will be removed from the listing. If the current authorized user is assigned to the listing, they will remove themselves from the listing.

Request

Headers:

Authorization: Bearer xxx.yyy.zzz

Responses

  • 200 OK on success

Headers:

Authorization: Bearer xxx.yyy.zzz
  • 403 FORBIDDEN if you either don't own the listing, or are not assigned to the listing
  • 403 FORBIDDEN if Authorization header is invalid
  • 404 NOT FOUND if a listing with the given ID was not found

About

kompiskjøring

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages