Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Curiouspaul1 committed Nov 24, 2023
1 parent 9846d23 commit 215b6da
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 22 deletions.
47 changes: 28 additions & 19 deletions core/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import Blueprint, request, jsonify
from schema import Rsvp, AttendeeSchema
from schema import Rsvp, AttendeeSchema, checkRsvp
from models import *

from psycopg2.errors import UniqueViolation
Expand Down Expand Up @@ -43,26 +43,31 @@ def sign_up():
'status': 'error',
'msg': f"Attendee with specified ticket id {data['ticket_id']} not found"
}, 404

event = Event.query.get(data['event_id'])
if not event:
return {
'status': 'error',
'msg': f"Event with specified id {data['event_id']} not found"
}, 404

for evnt in data['event_ids']:
event = Event.query.get(evnt)
if not event:
return {
'status': 'error',
'msg': f"Event with specified id {evnt} not found"
}, 404

try:
attendee_profile.events.append(event)
except UniqueViolation as e:
db.session.rollback()
return {
'status': 'error',
'msg': f"It seems you already rspv'd for this event"
}, 409
except Exception as e:
print(str(e))
db.session.rollback()

try:
attendee_profile.events.append(event)
db.session.commit()
except UniqueViolation as e:
db.session.rollback()
return {
'status': 'error',
'msg': f"It seems you already rspv'd for this event"
}, 409
except Exception as e:
print(str(e))
db.session.rollback()
db.session.rollback
finally:
db.session.close()

Expand All @@ -74,7 +79,7 @@ def sign_up():

@rsvp.post('/verify')
def verify():
schema = Rsvp()
schema = checkRsvp()
try:
data = schema.load(request.get_json(force=True))
except Exception as e:
Expand Down Expand Up @@ -135,7 +140,11 @@ def dumpData():
@rsvp.get('/events')
def fetch_events():
events = Event.query.all()
resp = [{'title':evnt.title, 'id':evnt.id} for evnt in events]
resp = [{
'title':evnt.title,
'id':evnt.id,
'session_id':evnt.session_id
} for evnt in events]
return {
'status': 'success',
'data': resp
Expand Down
32 changes: 32 additions & 0 deletions migrations/versions/b9c2aac40b60_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""empty message
Revision ID: b9c2aac40b60
Revises: 722c4a00db14
Create Date: 2023-11-24 09:22:21.468805
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'b9c2aac40b60'
down_revision = '722c4a00db14'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('event', schema=None) as batch_op:
batch_op.add_column(sa.Column('session_id', sa.Integer(), nullable=True))

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('event', schema=None) as batch_op:
batch_op.drop_column('session_id')

# ### end Alembic commands ###
8 changes: 5 additions & 3 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ def fetchEvents(self):
class Event(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String())
session_id = db.Column(db.Integer)


@staticmethod
def create_events():
events = [
"Introduction to GCP: A Guide to Googles Cloud-9",
"Introduction to GCP: A Guide to Google\'s Cloud-9",
"Design and Motion: The Two Infinity Stones of Memorable User Experiences",
"Transitioning from REST to GraphQL: Enhancing API Efficiency",
"Web3 for Web2 Developers",
Expand All @@ -54,8 +55,9 @@ def create_events():
"LangChain and LLMs: Building your own generation AI chatbot trained on your data with LangChain"
]

for event in events:
new = Event(title=event)
for idx, event in enumerate(events):
grp = idx//3 + 1
new = Event(title=event, session_id=grp)
db.session.add(new)

try:
Expand Down
7 changes: 7 additions & 0 deletions schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@


class Rsvp(ma.Schema):
ticket_id = fields.String(required=True)
event_ids = fields.List(
fields.Integer(),
required=True
)

class checkRsvp(ma.Schema):
ticket_id = fields.String(required=True)
event_id = fields.Integer(required=True)

Expand Down

0 comments on commit 215b6da

Please sign in to comment.