BauPhi / bauphi-backend

BauPhi Rest API, written using Node.js.
MIT License
0 stars 0 forks source link

[Documentation] As a developer, I would like to create a documentation for the backend service that includes planning request-response formats. #3

Open tunahanertekin opened 3 years ago

tunahanertekin commented 3 years ago

BauPhi API Usage & Backend Documentation

API is accessible in Heroku.

Recent Updates (from newest to oldest):

Index

Mobile Notifications

Generic Requests

User Related Requests

Home Related Requests

Event Related Requests

Announcement Related Requests

tunahanertekin commented 3 years ago

User Related Requests

Default Register (Add User)

It is written to add users database with default register method. (email and password)

Request

Body Parameter Description Obligation
name User's name in string format. Yes
surname User's surname in string format. Yes
password User's password in string format. Yes
email User's email address in string format. Yes
phone User's phone number in string format. Yes

Response

Default Login

In default login process, users posts their email and password and in return, they get a session key they can use to send their other requests. For development, you can assume that "session_key": "admin".

Request

Body Parameter Description Obligation
email User's email address in string format. Yes
password User's password in string format. Yes

Response

{
    "status": "SUCCESS",
    "message": "login is successful",
    "user": {
        "user_id": "2",
        "name": "Işıl",
        "surname": "Güneş",
        "email": "igunes@gmail.com",
        "phone": "+905435586504"
    },
    "session": {
        "start_time": "Thu Mar 18 2021 22:09:41 GMT+0300 (GMT+03:00)",
        "expire_time": "Fri Mar 19 2021 10:09:41 GMT+0300 (GMT+03:00)",
        "session_key": "admin"
    }
}

## Login Using OAuth
It is written to make users be able to login with their Gmail account. If it's their first login with a Google account, they will be registered and given a `session_key`. If not, their credentials will be checked and they will be given a `session_key` if their credentials hold.

### Request
- Type: POST
- URL: /api/users/google-auth

| Body Parameter  | Description | Obligation
| ------------- | ------------- | -------------
| access_token  | Access token returned by Google/Firebase. | Yes

### Response
- In success, user & session credentials are returned.
```json
{
    "status": "SUCCESS",
    "message": "user is logged in using a google account",
    "user": {
        "user_id": 22,
        "name": "discuss",
        "surname": "bank",
        "email": "connectionbauphi@gmail.com",
        "phone": "",
        "password": "6181738008c985a1b5f106b796c98e719efcc3c0ff68ddcd14a049825f4900a8",
        "registration_id": "notset",
        "is_oauth_user": true,
        "google_sub_id": "108797461518181707543"
    },
    "session": {
        "user_id": 22,
        "session_key": "6Oul3E",
        "start_time": "2021-04-15T17:18:57.110Z",
        "expire_time": "2021-04-16T05:18:57.110Z"
    }
}

Update User

It is written to update users' data.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
Body Parameter Description Obligation
name User's name in string format. No
surname User's surname in string format. No
password User's password in string format. No
email User's email address in string format. No
phone User's phone number in string format. No

Response

Delete User

It is written to delete users from database.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

tunahanertekin commented 3 years ago

Home Related Requests

Get Homes

Users' homes can be listed with this endpoint.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

Add Home

Users can add homes with this endpoint.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
Body Parameter Description Obligation
home_name A name or alias to define home. Yes
isVisible Users' permission if their homes will be listed publicly. Yes
country Country of location. Yes
state State of location. Yes
city City of location. Yes
neighbourhood Neighbourhood and exact address of location. Yes
latitude Latitude coming from client's location. Yes
longitude Longitude coming from client's location. Yes
is_pets_allowed Indicates that if home is convenient for pets. false as default. No

Response

Delete Home

Users can delete their homes using this endpoint.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
Body Parameter Description Obligation
home_name A name or alias to define home. No
isVisible Users' permission if their homes will be listed publicly. No
country Country of location. No
state State of location. No
city City of location. No
neighbourhood Neighbourhood and exact address of location. No
latitude Latitude coming from client's location. No
longitude Longitude coming from client's location. No
is_pets_allowed Indicates that if home is convenient for pets. false as default. No

Response

Victim - Volunteer Interaction (Offers/Requests)

Diagram of request/offer logic is shown below:

Send Offer (Victim-Volunteer Interaction)

Disaster victim can send offers to the home owners about staying at their homes.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
Body Parameter Description Obligation
home ID of home that victim wants to make an offer. Yes
home_owner User ID of the home owner. Yes
description Short info about the situation like how many people, contact info etc. Yes

Response

Accept Offer (Victim-Volunteer Interaction)

Home owner can accept offers received.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
Body Parameter Description Obligation
victim User ID of the victim. Yes
home ID of home that victim wants to make an offer. Yes

Response

Reject Offer (Victim-Volunteer Interaction)

Home owner can reject offers received.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
Body Parameter Description Obligation
victim User ID of the victim. Yes
home ID of home that victim wants to make an offer. Yes

Response

Delete Offer (Victim-Volunteer Interaction)

Senders can delete their requests. (If it's still pending, that means they cancelled their offer.)

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

List Offers Sent (Victim-Volunteer Interaction)

Users can list their offers sent.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

List Offers Received (Victim-Volunteer Interaction)

Users can list their offers sent.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

tunahanertekin commented 3 years ago

Event Related Requests

Get Events

It lists users' events.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

Get Event

It displays an event of a user.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

Add Event

Events can be added from this endpoint. Additional data about event can be added with "Update Event" request.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
Body Parameter Description Obligation
start_time Event starting date & time. Yes
end_time Event starting date & time. Yes
type Type of event. It can be "Meeting", "Donation/Supply" and "Donation/Money" Yes
title Title of event. Yes
description Further explanation about event. Links can be provided. Yes
is_emergency If event type is "Meeting", it indicates whether the meeting is an emergency. No
country If event type is "Meeting" or "Donation/Supply", it's the country of event. No
state If event type is "Meeting" or "Donation/Supply", it's the state of event. No
city If event type is "Meeting" or "Donation/Supply", it's the city of event. No
neighbourhood If event type is "Meeting" or "Donation/Supply", it's the neighbourhood of event. No
latitude If event type is "Meeting" or "Donation/Supply", it's the latitude of event. No
longitude If event type is "Meeting" or "Donation/Supply", it's the longitude of event. No
currency If event type is "Donation/Money", it indicates the currency used in donation. No
amount If event type is "Donation/Money", it defines the default/minimum donation. No

Response


- In failure, an error message is returned.
```json
{
    "status": "FAILURE",
    "message": "request body fields are not true"
}

Delete Event

Events can be removed with this endpoint.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response


- In failure, an error message is returned.
```json
{
    "status": "FAILURE",
    "message": "event is not found"
}

Update Event

Events can be updated with this endpoint. Additional data can also be added from here.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
Body Parameter Description Obligation
start_time Event starting date & time. No
end_time Event starting date & time. No
type Type of event. It can be "Meeting", "Donation/Supply" and "Donation/Money" No
title Title of event. No
description Further explanation about event. Links can be provided. No
is_emergency If event type is "Meeting", it indicates whether the meeting is an emergency. No
country If event type is "Meeting" or "Donation/Supply", it's the country of event. No
state If event type is "Meeting" or "Donation/Supply", it's the state of event. No
city If event type is "Meeting" or "Donation/Supply", it's the city of event. No
neighbourhood If event type is "Meeting" or "Donation/Supply", it's the neighbourhood of event. No
latitude If event type is "Meeting" or "Donation/Supply", it's the latitude of event. No
longitude If event type is "Meeting" or "Donation/Supply", it's the longitude of event. No
currency If event type is "Donation/Money", it indicates the currency used in donation. No
amount If event type is "Donation/Money", it defines the default/minimum donation. No

Response


- In failure, an error message is returned.
```json
{
    "status": "FAILURE",
    "message": "event is not found"
}

Join Event

Users can join events.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
Body Parameter Description Obligation
event ID of event. Yes
comment Little comment section about event. No

Response


- In failure, an error message is returned.
```json
{
    "status": "FAILURE",
    "message": "event is not found"
}

Cancel Event Participation

Users can cancel event participation.

Request

Header Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response


- In failure, an error message is returned.
```json
{
    "status": "FAILURE",
    "message": "event is not found"
}
tunahanertekin commented 3 years ago

Announcement Related Requests

Get Announcements

Users' announcements can be listed with this endpoint.

Request

Body Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

Get Announcement

Data of single announcement can be gathered with this endpoint.

Request

Body Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

Add Announcement

Users can add announcements with this endpoint.

Request

Body Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
image Link or base64 format text of announcement. Yes
phone Phone for further communication. Yes
title Title of announcement. Yes
description Description of announcement. Yes
isHuman Seperator showing if it's for human or pet. Yes

Response

Delete Announcement

Users can delete their announcements with this endpoint.

Request

Body Parameter Description Obligation
session_key Session key for user. (use "admin") Yes

Response

Update Announcement

Users can update announcements with this endpoint.

Request

Body Parameter Description Obligation
session_key Session key for user. (use "admin") Yes
image Link or base64 format text of announcement. No
phone Phone for further communication. No
title Title of announcement. No
description Description of announcement. No
isHuman Seperator showing if it's for human or pet. No

Response

tunahanertekin commented 3 years ago

Generic Requests

List Event Participants

Users' can display who are attending an event.

Request

Response

AutoLocation Using 3rd Party API

Users can add homes with using AutoLocation feature of BauPhi. Addresses are detected by Nominatim API.

Request

Body Parameter Description Obligation
latitude Latitude of user's device. Yes
longitude Longitude of user's device. Yes

Response

{
    "status": "SUCCESS",
    "message": "location api response is returned",
    "api_response": {
        "api_status": "SUCCESS",
        "api_message": "address is returned",
        "home_name": "Çamlıdere/Ankara",
        "country": "Türkiye",
        "state": "Ankara",
        "city": "Çamlıdere",
        "neighbourhood": "Bayındır"
    }
}

List Close Homes

Users can list homes that are close to them with this endpoint.

Request

Body Parameter Description Obligation
latitude Latitude coming from client's location. Yes
longitude Longitude coming from client's location. Yes

Response

List Close Events

Users can list events that are close to them with this endpoint.

Request

Query Parameter Description Obligation
type Indicates event type. May be meeting or supply. No
Body Parameter Description Obligation
latitude Latitude coming from client's location. Yes
longitude Longitude coming from client's location. Yes

Response

Get User Details (For Development Usage)

Developers can track all info of a user.

Request

Response

Get All Homes (For Development Usage)

Developers can list all homes.

Request

Response

{ "status": "SUCCESS", "message": "all homes in db are returned", "homes": [ { "home_id": 1, "home_owner": 4, "home_name": "Gazi Mahallesi/Ankara", "isVisible": false, "country": "Türkiye", "state": "Ankara", "city": "Yenimahalle", "neighbourhood": "Gazi Mahallesi, Tanaçan Sokak", "latitude": 39.9427, "longitude": 32.809982 }, { "home_id": 2, "home_owner": 3, "home_name": "Naci Çakır Mahallesi/Ankara", "isVisible": true, "country": "Türkiye", "state": "Ankara", "city": "Çankaya", "neighbourhood": "Naci Çakır Mahallesi, 766. Sokak", "latitude": 39.875282, "longitude": 32.844337 }, { "home_id": 10, "home_owner": 1, "home_name": "Ostim Mahallesi/Ankara", "isVisible": true, "country": "Türkiye", "state": "Ankara", "city": "Yenimahalle", "neighbourhood": "Ostim Mahallesi, ", "latitude": 39.982697, "longitude": 32.753178 } ] }


- In failure, an error message is returned..
```json
{
    "status": "FAILURE",
    "message": "db error"
}

Get All Events (For Development Usage)

Developers can list all events.

Request

Response

{ "status": "SUCCESS", "message": "all events in db are returned", "events": [ { "event_id": 4, "event_starter": 2, "start_time": "2021-03-30T04:21:03.513Z", "end_time": "2021-03-30T05:21:03.513Z", "title": "Event no. 4 Meeting", "description": "Admonitus distincte jam est cogitatio succedens opinantem archetypi. Ita geometriam sub parentibus pensitatis pro. ", "type": "Meeting" }, { "event_id": 9, "event_starter": 1, "start_time": "2021-03-31T03:21:06.015Z", "end_time": "2021-03-31T04:21:06.015Z", "title": "Event no. 9 Donation/Money", "description": "Admonitus distincte jam est cogitatio succedens opinantem archetypi. Ita geometriam sub parentibus pensitatis pro. ", "type": "Donation/Money" }, { "event_id": 5, "event_starter": 5, "start_time": "2021-04-01T03:21:04.006Z", "end_time": "2021-04-01T03:21:04.006Z", "title": "Event no. 5 Donation/Supply", "description": "Admonitus distincte jam est cogitatio succedens opinantem archetypi. Ita geometriam sub parentibus pensitatis pro. ", "type": "Donation/Supply" }, { "event_id": 6, "event_starter": 1, "start_time": "2021-04-04T03:21:04.516Z", "end_time": "2021-04-04T06:21:04.516Z", "title": "Event no. 6 Donation/Supply", "description": "Admonitus distincte jam est cogitatio succedens opinantem archetypi. Ita geometriam sub parentibus pensitatis pro. ", "type": "Donation/Supply" } ] }


- In failure, an error message is returned..
```json
{
    "status": "FAILURE",
    "message": "db error"
}

Get All Announcements (For Development Usage)

Developers can list all announcements.

Request

Response

{ "status": "SUCCESS", "message": "all announcements in db are returned", "announcements": [ { "announcement_id": 1, "ann_starter": 1, "isHuman": true, "image": null, "phone": "+908139205912", "title": "Et impellit synopsis in cognitio pluribus machinam.", "description": "Cera ad unde co ipsa ideo eo spem prae mo. Memoriae fatendum reversus uno eos habeatur. Remanetne ad eversioni de scriptura considero procedere eo se. Ei id ea ingenio remotis co humanam. " }, { "announcement_id": 5, "ann_starter": 4, "isHuman": false, "image": null, "phone": "+908139205912", "title": "Et impellit synopsis in cognitio pluribus machinam.", "description": "Cera ad unde co ipsa ideo eo spem prae mo. Memoriae fatendum reversus uno eos habeatur. Remanetne ad eversioni de scriptura considero procedere eo se. Ei id ea ingenio remotis co humanam. " } ] }


- In failure, an error message is returned..
```json
{
    "status": "FAILURE",
    "message": "db error"
}

Get Last Earthquakes

Users can see last earthquakes.

Request

Body Parameter Description Obligation
latitude Latitude of user's device. No
longitude Longitude of user's device. No

Response

{ "status": "SUCCESS", "message": "last ten earthquakes are listed", "earthquakes": [ { "magnitude": 2.2, "location": "MIDILLI ADASI (EGE DENIZI)", "depth": "7.9 km", "date": "2021.04.16 18:00:55", "distance": "1547 km" }, { "magnitude": 1.9, "location": "TAHTALI-GONEN (BALIKESIR)", "depth": "25.3 km", "date": "2021.04.16 17:52:18", "distance": "1684 km" }, { "magnitude": 2.9, "location": "MIDILLI ADASI (EGE DENIZI)", "depth": "2.1 km", "date": "2021.04.16 17:16:21", "distance": "1584 km" }, { "magnitude": 2.1, "location": "YORELI-YAVUZELI (GAZIANTEP)", "depth": "0 km", "date": "2021.04.16 17:12:20", "distance": "1799 km" }, { "magnitude": 2, "location": "SIVRICE (ELAZIG)", "depth": "11.1 km", "date": "2021.04.16 16:50:36", "distance": "1987 km" } ] }


- In failure, an error message is returned..
```json
{
    "status": "FAILURE",
    "message": "external error"
}

Get All Money Donations

Users can list all funding events.

Request

Response


- In failure, an error message is returned..
```json
{
    "status": "FAILURE",
    "message": "db error"
}
tunahanertekin commented 3 years ago

Mobile Notifications

In #19, we defined the data flow for creating a push notification system. Since the notifications are being sent via FCM registration id's, users (mobile agents) must add their unique registration id's using either "Add User" or "Update User" requests. The field to be updated is called registration_id.

Functional Usage

Test Endpoint

You can send test notifications to any mobile agent using this endpoint.

Request

Body Parameter Description Obligation
reg_ids An array of string that contains registration id's of users. Yes
title Notification title. Yes
message Notification message. Yes

Response


{
    "status": "SUCCESS",
    "message": "response json is returned by fcm",
    "data": {
        "multicast_id": 7935663576579045000,
        "success": 0,
        "failure": 2,
        "canonical_ids": 0,
        "results": [
            {
                "error": "InvalidRegistration"
            },
            {
                "error": "InvalidRegistration"
            }
        ]
    }
}
{
    "status": "FAILURE",
    "message": "request's field number is wrong :::"
}