Skip to content

Commit 8f477ca

Browse files
Hieu Lam - TMAnnhathungkhangoncweitat
authored
feature-8962: Store number count against station and session detail (#8997)
* feature-8958: Store check in kiosk id to mark association * feature-8958: Store check in kiosk id to mark association * feature-8958: Store check in kiosk id to mark association set validate for station type and station name * feature-8962: Store number count against station and session detail * feature-8958: Store check in kiosk id to mark association fix ci/cd * feature-8958: Store check in kiosk id to mark association fix ci and update latest branch from development * feature-8958: Store check in kiosk id to mark association fix ci and update latest branch from development * feature-8958: Store check in kiosk id to mark association fix ci and update latest branch from development * feature-8958: Store check in kiosk id to mark association fix ci and update latest branch from development * feature-8958: Store check in kiosk id to mark association fix ci and update latest branch from development * feature-8958: Store check in kiosk id to mark association fix ci and update latest branch from development * feature-8958: Store check in kiosk id to mark association * feature-8962: Store number count against station and session detail * feature-8962: Store number count against station and session detail * feature-8958: Store check in kiosk id to mark association update station_type, remove session, add new 2 types check in and check out * feature-8962: Store number count against station and session detail * feature-8962: Store number count against station and session detail * feature-8962: Store number count against station and session detail * feature-8958: Store check in kiosk id to mark association * feature-8958: Store check in kiosk id to mark association * fix multiple migration head * fx ci/cd * feature-8962: Store number count against station and session detail * feature-8962: Store number count against station and session detail * feature-8962: Store number count against station and session detail * feature-8962: Merge code development * feature-8962: Merge code development --------- Co-authored-by: nnhathung <[email protected]> Co-authored-by: Khang On - TMA <[email protected]> Co-authored-by: cweitat <[email protected]>
1 parent 7dbf33f commit 8f477ca

File tree

8 files changed

+260
-8
lines changed

8 files changed

+260
-8
lines changed

app/api/routes.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@
231231
StationListPost,
232232
StationRelationship,
233233
)
234+
from app.api.station_store_paxs import (
235+
StationStorePaxDetail,
236+
StationStorePaxList,
237+
StationStorePaxListPost,
238+
StationStorePaxRelationship,
239+
)
234240
from app.api.stripe_authorization import (
235241
StripeAuthorizationDetail,
236242
StripeAuthorizationListPost,
@@ -2086,6 +2092,31 @@
20862092
'user_check_in_session',
20872093
'/user-check-in/<int:id>/relationships/session',
20882094
)
2095+
api.route(
2096+
StationStorePaxListPost,
2097+
'station_store_pax_list_post',
2098+
'/station-store-paxs',
2099+
)
2100+
api.route(
2101+
StationStorePaxList,
2102+
'station_store_pax_list',
2103+
'/stations/<int:station_id>/station-store-paxs',
2104+
'/sessions/<int:session_id>/station-store-paxs',
2105+
'/stations/<int:station_id>/sessions/<int:session_id>/station-store-paxs',
2106+
)
2107+
api.route(
2108+
StationStorePaxDetail, 'station_store_pax_detail', '/station-store-paxs/<int:id>'
2109+
)
2110+
api.route(
2111+
StationStorePaxRelationship,
2112+
'station_store_pax_station',
2113+
'/station-store-paxs/<int:id>/relationships/station',
2114+
)
2115+
api.route(
2116+
StationStorePaxRelationship,
2117+
'station_store_pax_session',
2118+
'/station-store-paxs/<int:id>/relationships/session',
2119+
)
20892120
api.route(
20902121
BadgeFormListPost,
20912122
'badge_form_list_post',

app/api/schema/station.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class Meta:
2121

2222
id = fields.Integer(dump_only=True)
2323
station_name = fields.String(required=True, validate=validate.Length(min=1))
24-
station_type = fields.String(required=True,
25-
validate=validate.OneOf(choices=STATION_CHOICES))
24+
station_type = fields.String(
25+
required=True, validate=validate.OneOf(choices=STATION_CHOICES)
26+
)
2627
microlocation_id = fields.Function(lambda obj: obj.microlocation.id)
2728

2829
room = fields.Function(lambda obj: obj.microlocation.room)

app/api/schema/station_store_pax.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from marshmallow_jsonapi import fields
2+
from marshmallow_jsonapi.flask import Relationship, Schema
3+
4+
from app.api.helpers.utilities import dasherize
5+
from utils.common import use_defaults
6+
7+
8+
@use_defaults()
9+
class StationStorePaxSchema(Schema):
10+
"""API Schema for Station Store Pax database model"""
11+
12+
class Meta:
13+
"""Meta class for Station Schema"""
14+
15+
type_ = 'station-store-pax'
16+
self_view = 'v1.station_store_pax_detail'
17+
self_view_kwargs = {'id': '<id>'}
18+
inflect = dasherize
19+
20+
id = fields.Integer(dump_only=True)
21+
current_pax = fields.Integer(required=True)
22+
created_at = fields.DateTime(dump_only=True)
23+
modified_at = fields.DateTime(dump_only=True)
24+
station = Relationship(
25+
self_view='v1.station_store_pax_station',
26+
self_view_kwargs={'id': '<id>'},
27+
related_view='v1.station_detail',
28+
related_view_kwargs={'id': '<station_id>'},
29+
schema='StationSchema',
30+
type_='station',
31+
)
32+
session = Relationship(
33+
self_view='v1.station_store_pax_session',
34+
self_view_kwargs={'id': '<id>'},
35+
related_view='v1.session_detail',
36+
related_view_kwargs={'id': '<session_id>'},
37+
schema='SessionSchema',
38+
type_='session',
39+
)

app/api/station_store_paxs.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
2+
from flask_rest_jsonapi.exceptions import ObjectNotFound
3+
4+
from app.api.helpers.permission_manager import has_access
5+
from app.api.helpers.permissions import jwt_required
6+
from app.api.helpers.utilities import require_relationship
7+
from app.api.schema.station_store_pax import StationStorePaxSchema
8+
from app.models import db
9+
from app.models.session import Session
10+
from app.models.station import Station
11+
from app.models.station_store_pax import StationStorePax
12+
13+
14+
class StationStorePaxList(ResourceList):
15+
"""Create and List Station Store Pax"""
16+
17+
def query(self, view_kwargs):
18+
"""
19+
query method for different view_kwargs
20+
:param view_kwargs:
21+
:return:
22+
"""
23+
query_ = self.session.query(StationStorePax)
24+
if view_kwargs.get('station_id'):
25+
query_ = query_.join(Station).filter_by(id=view_kwargs.get('station_id'))
26+
if view_kwargs.get('session_id'):
27+
query_ = query_.join(Session).filter_by(id=view_kwargs.get('session_id'))
28+
29+
return query_
30+
31+
view_kwargs = True
32+
decorators = (jwt_required,)
33+
methods = [
34+
'GET',
35+
]
36+
schema = StationStorePaxSchema
37+
data_layer = {
38+
'session': db.session,
39+
'model': StationStorePax,
40+
'methods': {'query': query},
41+
}
42+
43+
44+
class StationStorePaxDetail(ResourceDetail):
45+
"""StationStorePax detail by id"""
46+
47+
@staticmethod
48+
def before_patch(_args, _kwargs, data):
49+
"""
50+
before patch method
51+
:param _args:
52+
:param kwargs:
53+
:param data:
54+
:return:
55+
"""
56+
if data['station']:
57+
require_relationship(['station'], data)
58+
if not has_access('is_coorganizer', station=data['station']):
59+
raise ObjectNotFound(
60+
{'parameter': 'station'},
61+
f"Station: {data['station']} not found",
62+
)
63+
64+
if data['session']:
65+
require_relationship(['session'], data)
66+
if not has_access('is_coorganizer', session=data['session']):
67+
raise ObjectNotFound(
68+
{'parameter': 'session'},
69+
f"Session: {data['session']} not found",
70+
)
71+
72+
schema = StationStorePaxSchema
73+
data_layer = {
74+
'session': db.session,
75+
'model': StationStorePax,
76+
}
77+
78+
79+
class StationStorePaxRelationship(ResourceRelationship):
80+
"""StationStorePax Relationship (Required)"""
81+
82+
decorators = (jwt_required,)
83+
methods = ['GET', 'PATCH']
84+
schema = StationStorePaxSchema
85+
data_layer = {'session': db.session, 'model': StationStorePax}
86+
87+
88+
class StationStorePaxListPost(ResourceList):
89+
"""Create and List StationStorePax"""
90+
91+
@staticmethod
92+
def before_post(_args, _kwargs, data):
93+
"""
94+
method to check for required relationship with event and microlocation
95+
:param data:
96+
:return:
97+
"""
98+
require_relationship(['station'], data)
99+
if not has_access('is_coorganizer', station=data['station']):
100+
raise ObjectNotFound(
101+
{'parameter': 'station'},
102+
f"Station: {data['station']} not found",
103+
)
104+
105+
require_relationship(['session'], data)
106+
if not has_access('is_coorganizer', session=data['session']):
107+
raise ObjectNotFound(
108+
{'parameter': 'session'},
109+
f"Session: {data['session']} not found",
110+
)
111+
112+
schema = StationStorePaxSchema
113+
methods = [
114+
'POST',
115+
]
116+
data_layer = {'session': db.session, 'model': StationStorePax}

app/models/station.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ class Station(db.Model):
77
id = db.Column(db.Integer, primary_key=True)
88
station_name = db.Column(db.String, nullable=False)
99
station_type = db.Column(db.String, nullable=True)
10-
microlocation_id = db.Column(db.Integer, db.ForeignKey('microlocations.id',
11-
ondelete='CASCADE'))
12-
microlocation = db.relationship('Microlocation', backref='stations',
13-
foreign_keys=[microlocation_id])
10+
microlocation_id = db.Column(
11+
db.Integer, db.ForeignKey('microlocations.id', ondelete='CASCADE')
12+
)
13+
microlocation = db.relationship(
14+
'Microlocation', backref='stations', foreign_keys=[microlocation_id]
15+
)
1416
event_id = db.Column(db.Integer, db.ForeignKey('events.id', ondelete='CASCADE'))
1517
event = db.relationship('Event', backref='stations', foreign_keys=[event_id])
1618

app/models/station_store_pax.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from datetime import datetime
2+
3+
from app.models import db
4+
5+
6+
class StationStorePax(db.Model):
7+
"""Station Store Pax database model"""
8+
9+
__tablename__ = 'station_store_paxs'
10+
id = db.Column(db.Integer, primary_key=True)
11+
station_id = db.Column(db.Integer, db.ForeignKey('station.id', ondelete='CASCADE'))
12+
station = db.relationship(
13+
'Station', backref='station_store_paxs', foreign_keys=[station_id]
14+
)
15+
session_id = db.Column(db.Integer, db.ForeignKey('sessions.id', ondelete='CASCADE'))
16+
session = db.relationship(
17+
'Session', backref='station_store_paxs', foreign_keys=[session_id]
18+
)
19+
current_pax = db.Column(db.Integer, default=0)
20+
created_at: datetime = db.Column(db.DateTime(timezone=True), default=datetime.utcnow)
21+
modified_at: datetime = db.Column(
22+
db.DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow
23+
)
24+
25+
def __repr__(self):
26+
return f'<StationStorePax {self.id}>'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""empty message
2+
3+
Revision ID: 4e6420d3dbc8
4+
Revises: 3b784f9c98c7
5+
Create Date: 2023-07-20 10:58:04.278543
6+
7+
"""
8+
9+
from alembic import op
10+
import sqlalchemy as sa
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = '4e6420d3dbc8'
15+
down_revision = '3b784f9c98c7'
16+
17+
18+
def upgrade():
19+
# ### commands auto generated by Alembic - please adjust! ###
20+
op.create_table('station_store_paxs',
21+
sa.Column('id', sa.Integer(), nullable=False),
22+
sa.Column('station_id', sa.Integer(), nullable=True),
23+
sa.Column('session_id', sa.Integer(), nullable=True),
24+
sa.Column('current_pax', sa.Integer(), nullable=True),
25+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
26+
sa.Column('modified_at', sa.DateTime(timezone=True), nullable=True),
27+
sa.ForeignKeyConstraint(['session_id'], ['sessions.id'], ondelete='CASCADE'),
28+
sa.ForeignKeyConstraint(['station_id'], ['station.id'], ondelete='CASCADE'),
29+
sa.PrimaryKeyConstraint('id')
30+
)
31+
# ### end Alembic commands ###
32+
33+
34+
def downgrade():
35+
# ### commands auto generated by Alembic - please adjust! ###
36+
op.drop_table('station_store_paxs')
37+
# ### end Alembic commands ###

migrations/versions/rev-2023-07-21-09:59:29-e3075e4e1327_.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""empty message
22
33
Revision ID: e3075e4e1327
4-
Revises: 9881f067213b
4+
Revises: 4e6420d3dbc8
55
Create Date: 2023-07-21 09:59:29.133119
66
77
"""
@@ -11,7 +11,7 @@
1111

1212
# revision identifiers, used by Alembic.
1313
revision = 'e3075e4e1327'
14-
down_revision = '3b784f9c98c7'
14+
down_revision = '4e6420d3dbc8'
1515

1616

1717
def upgrade():

0 commit comments

Comments
 (0)