basic frontend and backend functionality. Need to test with actual livestream
This commit is contained in:
5
server/.gitignore
vendored
5
server/.gitignore
vendored
@@ -176,4 +176,7 @@ pyrightconfig.json
|
||||
# End of https://www.toptal.com/developers/gitignore/api/python
|
||||
|
||||
*.log
|
||||
.vscode/
|
||||
.vscode/
|
||||
|
||||
# mysql dumps
|
||||
*.dump
|
||||
@@ -197,16 +197,20 @@ class MainController:
|
||||
"""
|
||||
return self.group_controller.get_group()
|
||||
|
||||
async def update_group_bio(
|
||||
self, bio: str, token: HTTPAuthorizationCredentials
|
||||
async def update_group(
|
||||
self, group: Group, token: HTTPAuthorizationCredentials
|
||||
) -> Group:
|
||||
"""
|
||||
Updates the group's bio and returns the updated group object.
|
||||
|
||||
:param str bio: The new bio for the group
|
||||
:param HTTPAuthorizationCredentials token: The OAuth token
|
||||
:return Group: The updated group object which is suitable for a response body
|
||||
"""
|
||||
_, sub = self.oauth_token.email_and_sub(token)
|
||||
self.user_controller.get_user_by_sub(sub)
|
||||
return self.group_controller.update_group_bio(bio)
|
||||
self.group_controller.update_livestream(group.livestream_id)
|
||||
return self.group_controller.update_group_bio(group.bio)
|
||||
|
||||
async def update_livestream(
|
||||
self, livestream_id: str, token: HTTPAuthorizationCredentials
|
||||
) -> Group:
|
||||
_, sub = self.oauth_token.email_and_sub(token)
|
||||
self.user_controller.get_user_by_sub(sub)
|
||||
return self.group_controller.update_livestream(livestream_id)
|
||||
|
||||
@@ -57,3 +57,13 @@ class GroupController(BaseController):
|
||||
detail=f"Error updating group bio: {e}",
|
||||
)
|
||||
return self.get_group()
|
||||
|
||||
def update_livestream(self, livestream_id: str) -> Group:
|
||||
try:
|
||||
self.group_queries.update_livestream(livestream_id)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Error updating livestram: {e}",
|
||||
)
|
||||
return self.get_group()
|
||||
|
||||
@@ -34,3 +34,15 @@ class GroupQueries(BaseQueries):
|
||||
cursor.execute(query, (bio,))
|
||||
conn.commit()
|
||||
self.close_cursor_and_conn(cursor, conn)
|
||||
|
||||
def update_livestream(self, livestream_id: str) -> None:
|
||||
cursor, conn = self.get_cursor_and_conn()
|
||||
query = f"""-- sql
|
||||
UPDATE {self.table} SET livestream_id = %s WHERE id = 1
|
||||
"""
|
||||
cursor.execute(query, (livestream_id,))
|
||||
conn.commit()
|
||||
self.close_cursor_and_conn(cursor, conn)
|
||||
|
||||
def delete_livestream(self) -> None:
|
||||
self.update_livestream(livestream_id="")
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class Group(BaseModel):
|
||||
name: str
|
||||
bio: str
|
||||
id: int | None = None
|
||||
livestream_id: str = ""
|
||||
id: Optional[int] = None
|
||||
|
||||
@@ -24,4 +24,5 @@ async def update_group(
|
||||
) -> Group:
|
||||
"""Updates the group bio, but requires the entire group object to be sent in the request body.
|
||||
Requires authentication."""
|
||||
return await controller.update_group_bio(group.bio, token)
|
||||
ic(group)
|
||||
return await controller.update_group(group, token)
|
||||
|
||||
@@ -158,7 +158,7 @@ async def test_get_group():
|
||||
async def test_update_group_bio():
|
||||
"""Tests the update_group_bio method."""
|
||||
bio = "A new bio"
|
||||
await controller.update_group_bio(bio, mock_token)
|
||||
await controller.update_group(bio, mock_token)
|
||||
MagicMock.assert_called_with(mock_oauth_token.email_and_sub, mock_token)
|
||||
MagicMock.assert_called(mock_user_controller.get_user_by_sub)
|
||||
MagicMock.assert_called(mock_group_controller.update_group_bio)
|
||||
|
||||
Reference in New Issue
Block a user