Repository: fossasia/open-event-server

Issue:
Store check in kiosk id to mark association
Allow organiser to create station name for each event

- station name
- location (based on the locations available for the venue) - if registration is selected, location can be empty
- type (registration / daily / check in / check out )


Discussion:
Hi @cweitat @mariobehling  @DonChiaQE 
Could you please share me the sample request (CURD) for this API.

@lthanhhieu 
There should be two APIs for this one

First is storing a new station POST
eventId, microlocation_id, station_name, station_type 

Second need GET
microlocation_id, room, station_name, station_type 
For microlocation_id and room pls refer here https://test-api.eventyay.com/#microlocations-microlocation-details

If type is registration & daily, microlocation_id and room can be null on GET

This should be a new DB TABLE
Hi @cweitat 

APIs spec for create and get station, could you help me to take a look and let me know if it okay

**POST: /v1/station**
**_Request_**

{
    "data": {
        "attributes": {
            "station-name": "station name",
            "station-type": "registration" // registration | daily | session
        },
        "relationships": {
            "event": {
                "data": {
                    "type": "event",
                    "id": "1"
                }
            },
            "microlocation": {
                "data": {
                    "type": "microlocation",
                    "id": "1"
                }
            }
        },
        "type": "station"
    }
}

**_Response_**
Success Http status: 201 CREATED
{
    "data": {
        "type": "station",
        "attributes": {
            "station-name": "station name",
            "microlocation-id": "1",
            "station-type": "registration",
            "room": "room 1"
        },
        "id": 17
    }
}

**Error : station type is invalid**
Http status 422 UNPROCESSABLE ENTITY

{
    "errors": [
        {
            "detail": "Not a valid choice.",
            "source": {
                "pointer": "/data/attributes/station-type"
            },
            "status": "422",
            "title": "Validation error"
        }
    ]
}

**GET: /v1/station/{station-id}**

**_Response_**

{
    "data": {
        "type": "station",
        "attributes": {
            "station-name": "station name",
            "microlocation-id": "1",
            "station-type": "registration",
            "room": "room 1"
        },
        "id": 17
    }
}

**Error Response if station can not be found:**
Http status 404 NOT FOUND

{
    "errors": [
        {
            "status": 404,
            "source": {
                "pointer": ""
            },
            "title": "Object not found",
            "detail": "Object Not Found"
        }
    ],
    "jsonapi": {
        "version": "1.0"
    }
}

**GET all station of event: /v1/events/{event-id}/stations**

{
    "data": [
        {
            "type": "station",
            "attributes": {
                "station-name": "station name 1",
                "microlocation-id": "1",
                "station-type": daily
                "room": "room"
            }
            "id": 4
        },
        {
            "type": "station",
            "attributes": {
                "station-name": "station name 2",
                "station-type": "registration"
            }
            "id": 5
        }
    ],
    "meta": {
        "count": 15
    }
}


@lthanhhieu what if not successful? what does it returns for POST

Also another GET which is to get all stations of the event
> @lthanhhieu what if not successful? what does it returns for POST
> 
> Also another GET which is to get all stations of the event

Hi @cweitat 
I have updated APIs spec in previous comment since there're the relationship between station with event and microlocation. 

For event, it has one-to-many with station, but with microlocation, is it one-to-many or 1:1 with station?

and another one is does we need paging for API get all stations of event?

@lthanhhieu, @mariobehling  : FYI
@nnhathung don't need pagination 
1 Micro location can have multiple stations
Hi @cweitat , thanks for confirming.

Resolving patch:
diff --git a/app/api/station.py b/app/api/station.py
--- a/app/api/station.py
+++ b/app/api/station.py
@@ -2,7 +2,6 @@
 from flask_rest_jsonapi.exceptions import ObjectNotFound
 
 from app.api.helpers.db import safe_query_kwargs
-from app.api.helpers.errors import UnprocessableEntityError
 from app.api.helpers.permission_manager import has_access
 from app.api.helpers.permissions import jwt_required
 from app.api.helpers.utilities import require_relationship
@@ -69,21 +68,6 @@ def before_patch(args, kwargs, data):
                     {'parameter': 'microlocation'},
                     "Microlocation: microlocation_id is missing from your request.",
                 )
-        station = Station.query.filter_by(
-            station_type=data.get('station_type'),
-            microlocation_id=data.get('microlocation'),
-            event_id=data.get('event'),
-        ).first()
-        if station:
-            raise UnprocessableEntityError(
-                {
-                    'station_type': data.get('station_type'),
-                    'microlocation_id': data.get('microlocation'),
-                    'event_id': data.get('event'),
-                },
-                "A Station already exists for the provided Event ID"
-                ", Microlocation ID and Station type",
-            )
 
     schema = StationSchema
     data_layer = {
@@ -129,33 +113,6 @@ def before_post(args, kwargs, data):
                     "Microlocation: missing from your request.",
                 )
 
-    def before_create_object(self, data, view_kwargs):
-        """
-        function to check if station already exist
-        @param data:
-        @param view_kwargs:
-        """
-        station = (
-            self.session.query(Station)
-            .filter_by(
-                station_type=data.get('station_type'),
-                microlocation_id=data.get('microlocation'),
-                event_id=data.get('event'),
-            )
-            .first()
-        )
-        if station:
-            raise UnprocessableEntityError(
-                {
-                    'station_type': data.get('station_type'),
-                    'microlocation_id': data.get('microlocation'),
-                    'event_id': data.get('event'),
-                    'view_kwargs': view_kwargs,
-                },
-                "A Station already exists for the provided Event ID"
-                ", Microlocation ID and Station type",
-            )
-
     schema = StationSchema
     methods = [
         'POST',
@@ -163,5 +120,4 @@ def before_create_object(self, data, view_kwargs):
     data_layer = {
         'session': db.session,
         'model': Station,
-        'methods': {'before_create_object': before_create_object},
     }


Test patch: