Skip to content

Commit

Permalink
Feature/separate vc link (#263)
Browse files Browse the repository at this point in the history
* adding  func to create new event
  • Loading branch information
Michael-B-D committed Feb 14, 2021
1 parent b9061ec commit 8cd3a6e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
1 change: 1 addition & 0 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Event(Base):
end = Column(DateTime, nullable=False)
content = Column(String)
location = Column(String)
vc_link = Column(String)
color = Column(String, nullable=True)
availability = Column(Boolean, default=True, nullable=False)
invitees = Column(String)
Expand Down
4 changes: 2 additions & 2 deletions app/internal/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
ZOOM_REGEX = re.compile(r'https://.*?\.zoom.us/[a-z]/.[^.,\b\s]+')


def raise_if_zoom_link_invalid(location):
if ZOOM_REGEX.search(location) is None:
def raise_if_zoom_link_invalid(vc_link):
if ZOOM_REGEX.search(vc_link) is None:
raise HTTPException(status_code=HTTP_400_BAD_REQUEST,
detail="VC type with no valid zoom link")

Expand Down
12 changes: 7 additions & 5 deletions app/routers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'availability': bool,
'content': (str, type(None)),
'location': (str, type(None)),
'vc_link': (str, type(None)),
'category_id': (int, type(None)),
}

Expand Down Expand Up @@ -60,20 +61,19 @@ async def create_new_event(request: Request,
TIME_FORMAT)
owner_id = get_current_user(session).id
availability = data.get('availability', 'True') == 'True'
location_type = data['location_type']
is_zoom = location_type == 'vc_url'
location = data['location']
vc_link = data['vc_link']
category_id = data.get('category_id')

invited_emails = get_invited_emails(data['invited'])
uninvited_contacts = get_uninvited_regular_emails(session, owner_id,
title, invited_emails)

if is_zoom:
raise_if_zoom_link_invalid(location)
if vc_link is not None:
raise_if_zoom_link_invalid(vc_link)

event = create_event(session, title, start, end, owner_id, content,
location, invitees=invited_emails,
location, vc_link, invitees=invited_emails,
category_id=category_id,
availability=availability)

Expand Down Expand Up @@ -205,6 +205,7 @@ def update_event(event_id: int, event: Dict, db: Session
def create_event(db: Session, title: str, start, end, owner_id: int,
content: Optional[str] = None,
location: Optional[str] = None,
vc_link: str = None,
color: Optional[str] = None,
invitees: List[str] = None,
category_id: Optional[int] = None,
Expand All @@ -222,6 +223,7 @@ def create_event(db: Session, title: str, start, end, owner_id: int,
content=content,
owner_id=owner_id,
location=location,
vc_link=vc_link,
color=color,
emotion=get_emotion(title, content),
invitees=invitees_concatenated,
Expand Down
13 changes: 7 additions & 6 deletions app/templates/event/partials/edit_event_details_tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
</div>

<div class="form_row">
<select name="location_type" required>
<option value="" disabled selected>Type</option>
<option value="vc_url">VC URL</option>
<option value="address">Address</option>
</select>
<input type="text" name="location" placeholder="VC URL/Location">
<label for="location">Location </label>
<input type="text" id="location" name="location" placeholder="Location">
</div>

<div class="form_row">
<label for="vc_link">VC link: </label>
<input type="text" id="vc_link" name="vc_link" placeholder="VC URL">
</div>

<div class="form_row">
Expand Down
2 changes: 1 addition & 1 deletion app/templates/event/partials/view_event_details_tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>{{ event.title }}</h1>
<div class="event_info_row">
<span class="icon">ICON</span>
<address>{{ event.location }}</address>
<!-- <address>LOCATION / <a href="#">VC URL</a></address>-->
<address>VC link<a href="{{ event.vc_link }}">VC URL</a></address>
</div>

<p class="event_info_row">
Expand Down
28 changes: 15 additions & 13 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
'start_time': '12:59',
'end_date': '2021-01-28',
'end_time': '15:01',
'location_type': 'vc_url',
'location': 'https://us02web.zoom.us/j/875384596',
'location': 'fake city',
'vc_link': 'https://us02web.zoom.us/j/875384596',
'description': 'content',
'color': 'red',
'availability': 'True',
Expand All @@ -34,8 +34,8 @@
'start_time': '15:59',
'end_date': '2021-01-27',
'end_time': '15:01',
'location_type': 'vc_url',
'location': 'not a zoom link',
'location': 'fake city',
'vc_link': 'not a zoom link',
'description': 'content',
'color': 'red',
'availability': 'True',
Expand All @@ -49,8 +49,8 @@
'start_time': '15:59',
'end_date': '2021-01-27',
'end_time': '15:01',
'location_type': 'vc_url',
'location': 'https://us02web.zoom.us/j/875384596',
'location': 'fake city',
'vc_link': 'https://us02web.zoom.us/j/875384596',
'description': 'content',
'color': 'red',
'availability': 'busy',
Expand All @@ -64,8 +64,8 @@
'start_time': '12:59',
'end_date': '2021-02-04',
'end_time': '15:01',
'location_type': 'vc_url',
'location': 'https://us02web.zoom.us/j/875384596',
'location': 'fake city',
'vc_link': 'https://us02web.zoom.us/j/875384596',
'description': 'content',
'color': 'red',
'availability': 'busy',
Expand All @@ -79,8 +79,8 @@
'start_time': '12:59',
'end_date': '2021-02-11',
'end_time': '15:01',
'location_type': 'vc_url',
'location': 'https://us02web.zoom.us/j/875384596',
'location': 'fake city',
'vc_link': 'https://us02web.zoom.us/j/875384596',
'description': 'content',
'color': 'red',
'availability': 'busy',
Expand All @@ -107,7 +107,8 @@ def test_eventedit(event_test_client):

def test_eventview_with_id(event_test_client, session, event):
event_id = event.id
event_details = [event.title, event.content, event.location, event.start,
event_details = [event.title, event.content, event.location,
event.vc_link, event.start,
event.end, event.color, event.category_id]
response = event_test_client.get(f"/event/{event_id}")
assert response.ok
Expand All @@ -125,7 +126,7 @@ def test_create_event_with_default_availability(client, user, session):
'title': 'test title',
'start': datetime.strptime('2021-01-01 15:59', '%Y-%m-%d %H:%M'),
'end': datetime.strptime('2021-01-02 15:01', '%Y-%m-%d %H:%M'),
'location': 'https://us02web.zoom.us/j/875384596',
'vc_link': 'https://us02web.zoom.us/j/875384596',
'content': 'content',
'owner_id': user.id,
}
Expand All @@ -142,7 +143,7 @@ def test_create_event_with_free_availability(client, user, session):
'title': 'test title',
'start': datetime.strptime('2021-01-01 15:59', '%Y-%m-%d %H:%M'),
'end': datetime.strptime('2021-01-02 15:01', '%Y-%m-%d %H:%M'),
'location': 'https://us02web.zoom.us/j/875384596',
'vc_link': 'https://us02web.zoom.us/j/875384596',
'content': 'content',
'owner_id': user.id,
'availability': False,
Expand Down Expand Up @@ -438,6 +439,7 @@ class TestApp:
event_test_data = {
'title': "Test Title",
"location": "Fake City",
'vc_link': 'https://us02web.zoom.us/j/875384596',
"start": date_test_data[0],
"end": date_test_data[1],
"content": "Any Words",
Expand Down

0 comments on commit 8cd3a6e

Please sign in to comment.