Skip to content

Commit

Permalink
refactor: remove unnecessary try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Faraz Maqsood committed Oct 14, 2024
1 parent 4bcf51b commit 07a50f0
Showing 1 changed file with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,9 @@ def handle_create(self, params=None):

def handle_create_comment(self, course_id):
request_data = self.initializable_attributes()
try:
body = request_data["body"]
user_id = request_data["user_id"]
course_id = course_id or str(request_data["course_id"])
except KeyError as e:
raise e
body = request_data["body"]
user_id = request_data["user_id"]
course_id = course_id or str(request_data["course_id"])
if parent_id := self.attributes.get("parent_id"):
response = forum_api.create_child_comment(
parent_id,
Expand All @@ -359,25 +356,16 @@ def handle_create_comment(self, course_id):

def handle_create_thread(self, course_id):
request_data = self.initializable_attributes()
try:
title = request_data["title"]
body = request_data["body"]
user_id = str(request_data["user_id"])
except KeyError as e:
raise e

request_data = {
"title": title,
"body": body,
"course_id": course_id or str(request_data["course_id"]),
"user_id": user_id,
"anonymous": request_data.get("anonymous", None),
"anonymous_to_peers": request_data.get("anonymous_to_peers", None),
"commentable_id": request_data.get("commentable_id", None),
"thread_type": request_data.get("thread_type", None),
"group_id": request_data.get("group_id", None),
"context": request_data.get("context", None),
}
request_data = {k: v for k, v in request_data.items() if v is not None}
response = forum_api.create_thread(**request_data)
response = forum_api.create_thread(
title=request_data["title"],
body=request_data["body"],
course_id=course_id or str(request_data["course_id"]),
user_id=str(request_data["user_id"]),
anonymous=request_data.get("anonymous", False),
anonymous_to_peers=request_data.get("anonymous_to_peers", False),
commentable_id=request_data.get("commentable_id", "course"),
thread_type=request_data.get("thread_type", "discussion"),
group_id=request_data.get("group_id", None),
context=request_data.get("context", None),
)
return response

0 comments on commit 07a50f0

Please sign in to comment.