Skip to content

Commit

Permalink
Move repository functions to own modules (#370)
Browse files Browse the repository at this point in the history
* 🔨 Move repository functions to own modules

* 🧪 Test repo module init
  • Loading branch information
devmount authored Apr 24, 2024
1 parent 98a6795 commit 4868d5c
Show file tree
Hide file tree
Showing 37 changed files with 871 additions and 845 deletions.
2 changes: 1 addition & 1 deletion backend/src/appointment/commands/create_invite_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def run(n: int):
_, session = get_engine_and_session()
db = session()

codes = repo.generate_invite_codes(db, n)
codes = repo.invite.generate_codes(db, n)

db.close()

Expand Down
2 changes: 1 addition & 1 deletion backend/src/appointment/controller/apis/fxa_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def token_saver(self, token):
if self.subscriber_id is None:
return

repo.update_subscriber_external_connection_token(next(get_db()), json.dumps(token), self.subscriber_id, models.ExternalConnectionType.fxa)
repo.external_connection.update_token(next(get_db()), json.dumps(token), self.subscriber_id, models.ExternalConnectionType.fxa)

def get_profile(self):
"""Retrieve the user's profile information"""
Expand Down
2 changes: 1 addition & 1 deletion backend/src/appointment/controller/apis/google_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def sync_calendars(self, db, subscriber_id: int, token):

# add calendar
try:
repo.update_or_create_subscriber_calendar(
repo.calendar.update_or_create(
db=db,
calendar=cal,
calendar_url=calendar.get("id"),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/appointment/controller/apis/zoom_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def token_saver(self, token):
return

# get_db is a generator function, retrieve the only yield
repo.update_subscriber_external_connection_token(next(get_db()), json.dumps(token), self.subscriber_id, models.ExternalConnectionType.zoom)
repo.external_connection.update_token(next(get_db()), json.dumps(token), self.subscriber_id, models.ExternalConnectionType.zoom)

def get_me(self):
return self.client.get(f'{self.OAUTH_REQUEST_URL}/users/me').json()
Expand Down
2 changes: 1 addition & 1 deletion backend/src/appointment/controller/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def existing_events_for_schedule(
# handle calendar events
for calendar in calendars:
if calendar.provider == CalendarProvider.google:
external_connection = utils.list_first(repo.get_external_connections_by_type(db, subscriber.id, schemas.ExternalConnectionType.google))
external_connection = utils.list_first(repo.external_connection.get_by_type(db, subscriber.id, schemas.ExternalConnectionType.google))

if external_connection is None or external_connection.token is None:
raise RemoteCalendarConnectionError()
Expand Down
26 changes: 13 additions & 13 deletions backend/src/appointment/controller/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def model_to_csv_buffer(models):

def download(db, subscriber: Subscriber):
"""Generate a zip file of csvs that contain a copy of the subscriber's information."""
attendees = repo.get_attendees_by_subscriber(db, subscriber_id=subscriber.id)
appointments = repo.get_appointments_by_subscriber(db, subscriber_id=subscriber.id)
calendars = repo.get_calendars_by_subscriber(db, subscriber_id=subscriber.id)
attendees = repo.attendee.get_by_subscriber(db, subscriber_id=subscriber.id)
appointments = repo.appointment.get_by_subscriber(db, subscriber_id=subscriber.id)
calendars = repo.calendar.get_by_subscriber(db, subscriber_id=subscriber.id)
subscribers = [subscriber]
slots = repo.get_slots_by_subscriber(db, subscriber_id=subscriber.id)
slots = repo.slot.get_by_subscriber(db, subscriber_id=subscriber.id)
external_connections = subscriber.external_connections
schedules = repo.get_schedules_by_subscriber(db, subscriber.id)
availability = [repo.get_availability_by_schedule(db, schedule.id) for schedule in schedules]
schedules = repo.schedule.get_by_subscriber(db, subscriber.id)
availability = [repo.schedule.get_availability(db, schedule.id) for schedule in schedules]

# Convert models to csv
attendee_buffer = model_to_csv_buffer(attendees)
Expand Down Expand Up @@ -79,21 +79,21 @@ def download(db, subscriber: Subscriber):

def delete_account(db, subscriber: Subscriber):
# Ok nuke everything (thanks cascade=all,delete)
repo.delete_subscriber(db, subscriber)
repo.subscriber.delete(db, subscriber)

# Make sure we actually nuked the subscriber
if repo.get_subscriber(db, subscriber.id) is not None:
if repo.subscriber.get(db, subscriber.id) is not None:
raise AccountDeletionSubscriberFail(
subscriber.id,
"There was a problem deleting your data. This incident has been logged and your data will manually be removed.",
)

empty_check = [
len(repo.get_attendees_by_subscriber(db, subscriber.id)),
len(repo.get_slots_by_subscriber(db, subscriber.id)),
len(repo.get_appointments_by_subscriber(db, subscriber.id)),
len(repo.get_calendars_by_subscriber(db, subscriber.id)),
len(repo.get_schedules_by_subscriber(db, subscriber.id))
len(repo.attendee.get_by_subscriber(db, subscriber.id)),
len(repo.slot.get_by_subscriber(db, subscriber.id)),
len(repo.appointment.get_by_subscriber(db, subscriber.id)),
len(repo.calendar.get_by_subscriber(db, subscriber.id)),
len(repo.schedule.get_by_subscriber(db, subscriber.id))
]

# Check if we have any left-over subscriber data
Expand Down
Loading

0 comments on commit 4868d5c

Please sign in to comment.