added endpoint to get membership types and the supporting repository logic

pull/79/head
Chris Veilleux 2019-03-08 17:27:45 -06:00
parent a0368aa2de
commit 10b7ea675a
5 changed files with 41 additions and 0 deletions

View File

@ -8,6 +8,7 @@ from .endpoints.account_preferences import AccountPreferencesEndpoint
from .endpoints.device import DeviceEndpoint
from .endpoints.device_count import DeviceCountEndpoint
from .endpoints.geography import GeographyEndpoint
from .endpoints.membership import MembershipEndpoint
from .endpoints.skills import SkillsEndpoint
from .endpoints.skill_settings import SkillSettingsEndpoint
from .endpoints.voice_endpoint import VoiceEndpoint
@ -90,3 +91,10 @@ acct.add_url_rule(
view_func=geography_endpoint,
methods=['GET']
)
membership_endpoint = MembershipEndpoint.as_view('membership_endpoint')
acct.add_url_rule(
'/api/memberships',
view_func=membership_endpoint,
methods=['GET']
)

View File

@ -0,0 +1,16 @@
from http import HTTPStatus
from selene.api import SeleneEndpoint
from selene.data.account import MembershipRepository
from selene.util.db import get_db_connection
class MembershipEndpoint(SeleneEndpoint):
def get(self):
with get_db_connection(self.config['DB_CONNECTION_POOL']) as db:
membership_repository = MembershipRepository(db)
membership_types = membership_repository.get_membership_types()
for membership_type in membership_types:
membership_type.rate = float(membership_type.rate)
return membership_types, HTTPStatus.OK

View File

@ -7,4 +7,5 @@ class Membership(object):
type: str
rate: Decimal
rate_period: str
stripe_plan: str
id: str = None

View File

@ -6,6 +6,14 @@ class MembershipRepository(RepositoryBase):
def __init__(self, db):
super(MembershipRepository, self).__init__(db, __file__)
def get_membership_types(self):
db_request = self._build_db_request(
sql_file_name='get_membership_types.sql'
)
db_result = self.cursor.select_all(db_request)
return [Membership(**row) for row in db_result]
def add(self, membership: Membership):
db_request = self._build_db_request(
'add_membership.sql',

View File

@ -0,0 +1,8 @@
SELECT
id,
type,
rate,
rate_period,
stripe_plan
FROM
account.membership