Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add endpoint for upcoming events #7049

Merged
merged 5 commits into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,3 +857,38 @@ def clear_export_urls(event):
event.xcal_url = None
event.pentabarf_url = None
save_to_db(event)


class UpcomingEventList(EventList):
"""
List Upcoming Events
"""

def before_get(self, args, kwargs):
"""
method for assigning schema based on admin access
:param args:
:param kwargs:
:return:
"""
super().before_get(args, kwargs)
self.schema.self_view_many = 'v1.upcoming_event_list'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already defined in superclass?


def query(self, view_kwargs):
"""
query method for upcoming events list
:param view_kwargs:
:return:
"""
current_time = datetime.now(pytz.utc)
query_ = self.session.query(Event).filter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not filter deleted events. Maybe that is done automatically in the library, but can you please still verify that deleted events are not being returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, deleted events are not returned.

Event.ends_at > current_time,
Event.state == 'published',
Event.privacy == 'public').order_by(Event.starts_at)
return query_

data_layer = {
'session': db.session,
'model': Event,
'methods': {'query': query},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already defined in superclass as well I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query method is not invoked for returning the desired events without defining data_layer again in the child class. It should take methods in data_layer variable from superclass, but this isn't happening.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. The library is not really well maintained. OK

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check other things. If they are working or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, other things are working fine.

8 changes: 7 additions & 1 deletion app/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
)
from app.api.event_topics import EventTopicDetail, EventTopicList, EventTopicRelationship
from app.api.event_types import EventTypeDetail, EventTypeList, EventTypeRelationship
from app.api.events import EventDetail, EventList, EventRelationship
from app.api.events import EventDetail, EventList, EventRelationship, UpcomingEventList
from app.api.events_role_permission import (
EventsRolePermissionDetail,
EventsRolePermissionList,
Expand Down Expand Up @@ -610,6 +610,12 @@
'/users/<int:user_sales_admin_id>/sales-admin-events',
)

api.route(
UpcomingEventList,
'upcoming_event_list',
'/events/upcoming',
)

api.route(
EventDetail,
'event_detail',
Expand Down
251 changes: 251 additions & 0 deletions docs/api/blueprint/event/events.apib
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,257 @@ Delete a single event.
}


## Upcoming Events Collection [/v1/events/upcoming]

### List All Upcoming Events [GET]
Get a list of upcoming events.

+ Request

+ Headers

Accept: application/vnd.api+json

Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

{
"meta": {
"count": 1
},
"data": [
{
"relationships": {
"tickets": {
"links": {
"self": "/v1/events/1/relationships/tickets",
"related": "/v1/events/1/tickets"
}
},
"orders": {
"links": {
"self": "/v1/events/1/relationships/orders",
"related": "/v1/orders"
}
},
"owner": {
"links": {
"self": "/v1/events/1/relationships/owner",
"related": "/v1/events/1/owner"
}
},
"organizers": {
"links": {
"self": "/v1/events/1/relationships/organizers",
"related": "/v1/users"
}
},
"coorganizers": {
"links": {
"self": "/v1/events/1/relationships/coorganizers",
"related": "/v1/users"
}
},
"track-organizers": {
"links": {
"self": "/v1/events/1/relationships/track-coorganizers",
"related": "/v1/users"
}
},
"registrars": {
"links": {
"self": "/v1/events/1/relationships/registrars",
"related": "/v1/users"
}
},
"moderators": {
"links": {
"self": "/v1/events/1/relationships/moderators",
"related": "/v1/users"
}
},
"custom-forms": {
"links": {
"self": "/v1/events/1/relationships/custom-forms",
"related": "/v1/events/1/custom-forms"
}
},
"faqs": {
"links": {
"self": "/v1/events/1/relationships/faqs",
"related": "/v1/events/1/faqs"
}
},
"faq-types": {
"links": {
"self": "/v1/events/1/relationships/faq-types",
"related": "/v1/events/1/faq-types"
}
},
"attendees": {
"links": {
"self": "/v1/events/1/relationships/attendees",
"related": "/v1/events/1/attendees"
}
},
"role-invites": {
"links": {
"self": "/v1/events/1/relationships/role-invites",
"related": "/v1/events/1/role-invites"
}
},
"event-sub-topic": {
"links": {
"self": "/v1/events/1/relationships/event-sub-topic",
"related": "/v1/events/1/event-sub-topic"
}
},
"speakers-call": {
"links": {
"self": "/v1/events/1/relationships/speakers-call",
"related": "/v1/events/1/speakers-call"
}
},
"event-copyright": {
"links": {
"self": "/v1/events/1/relationships/event-copyright",
"related": "/v1/events/1/event-copyright"
}
},
"sessions": {
"links": {
"self": "/v1/events/1/relationships/sessions",
"related": "/v1/events/1/sessions"
}
},
"tax": {
"links": {
"self": "/v1/events/1/relationships/tax",
"related": "/v1/events/1/tax"
}
},
"event-topic": {
"links": {
"self": "/v1/events/1/relationships/event-topic",
"related": "/v1/events/1/event-topic"
}
},
"social-links": {
"links": {
"self": "/v1/events/1/relationships/social-links",
"related": "/v1/events/1/social-links"
}
},
"sponsors": {
"links": {
"self": "/v1/events/1/relationships/sponsors",
"related": "/v1/events/1/sponsors"
}
},
"tracks": {
"links": {
"self": "/v1/events/1/relationships/tracks",
"related": "/v1/events/1/tracks"
}
},
"event-invoices": {
"links": {
"self": "/v1/events/1/relationships/event-invoices",
"related": "/v1/events/1/event-invoices"
}
},
"session-types": {
"links": {
"self": "/v1/events/1/relationships/session-types",
"related": "/v1/events/1/session-types"
}
},
"microlocations": {
"links": {
"self": "/v1/events/1/relationships/microlocations",
"related": "/v1/events/1/microlocations"
}
},
"event-type": {
"links": {
"self": "/v1/events/1/relationships/event-type",
"related": "/v1/events/1/event-type"
}
},
"discount-codes": {
"links": {
"self": "/v1/events/1/relationships/discount-codes",
"related": "/v1/events/1/discount-codes"
}
}
},
"attributes": {
"payment-country": "US",
"paypal-email": "example@example.com",
"thumbnail-image-url": null,
"schedule-published-on": null,
"payment-currency": "USD",
"owner-description": "example",
"is-map-shown": true,
"original-image-url": "http://example.com/example.png",
"onsite-details": "example",
"owner-name": "example",
"can-pay-by-stripe": true,
"large-image-url": null,
"timezone": "UTC",
"can-pay-onsite": true,
"deleted-at": null,
"ticket-url": "http://example.com",
"can-pay-by-paypal": true,
"location-name": "example",
"is-sponsors-enabled": false,
"is-event-online": false,
"has-owner-info": false,
"is-sessions-speakers-enabled": true,
"privacy": "public",
"code-of-conduct": "example",
"state": "published",
"latitude": 1.23456789,
"starts-at": "2099-12-13T23:59:59.123456+00:00",
"searchable-location-name": "example",
"can-pay-by-cheque": true,
"can-pay-by-omise": false,
"description": "example",
"pentabarf-url": null,
"xcal-url": null,
"logo-url": "http://example.com/example.png",
"external-event-url": null,
"is-tax-enabled": true,
"icon-image-url": null,
"ical-url": null,
"name": "example",
"can-pay-by-bank": true,
"ends-at": "2099-12-14T23:59:59.123456+00:00",
"created-at": "2020-06-07T15:22:37.205399+00:00",
"longitude": 1.23456789,
"bank-details": "example",
"cheque-details": "example",
"identifier": "b8324ae2",
"refund-policy": "All sales are final. No refunds shall be issued in any case.",
"is-stripe-linked": "false"
},
"type": "event",
"id": "1",
"links": {
"self": "/v1/events/1"
}
}
],
"jsonapi": {
"version": "1.0"
},
"links": {
"self": "/v1/events/upcoming"
}
}


## Events of an Event Type [/v1/event-types/{event_type_id}/events{?page%5bsize%5d,page%5bnumber%5d,sort,filter}]
+ Parameters
+ event_type_id: 1 (integer) - ID of the event type in the form of an integer
Expand Down
13 changes: 13 additions & 0 deletions tests/hook_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,19 @@ def event_post(transaction):
db.session.commit()


@hooks.before("Events > Upcoming Events Collection > List All Upcoming Events")
def upcoming_event_get_list(transaction):
"""
GET /events/upcoming
:param transaction:
:return:
"""
with stash['app'].app_context():
event = EventFactoryBasic(state="published")
db.session.add(event)
db.session.commit()


@hooks.before("Events > Event Details > Event Details")
def event_get_detail(transaction):
"""
Expand Down