Skip to content

Commit

Permalink
[CHORE] - Refactoring and reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nulzo committed Dec 4, 2023
1 parent 228d5e5 commit 59dc671
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 38 deletions.
7 changes: 2 additions & 5 deletions backend/api/endpoints/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def get(self, request: Request) -> Response:

if querystring:
if department := querystring.get("department"):
courses = courses.filter(
course_department=self.sanitize(department))
courses = courses.filter(course_department=self.sanitize(department))

if name := querystring.get("name"):
courses = courses.filter(course_name=name)
Expand All @@ -47,8 +46,7 @@ def get(self, request: Request) -> Response:
courses = courses.filter(course_id=course_id)

if course_id_contains := querystring.get("course-id-contains"):
courses = courses.filter(
course_id__contains=course_id_contains)
courses = courses.filter(course_id__contains=course_id_contains)

if greater_than_code := querystring.get("higher-than"):
courses = courses.filter(course_id__gt=greater_than_code)
Expand All @@ -64,7 +62,6 @@ def get(self, request: Request) -> Response:

def post(self, request: Request) -> Response:
serializer = CourseSerializer(data=request.data)
s = 10
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
Expand Down
11 changes: 4 additions & 7 deletions backend/api/endpoints/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from api.models.course import Course
from api.models.issue import Issues
from api.models.professor import Professor
from api.models.ticket import Ticket
from api.models.user import User
from api.serializers import TicketGetSerializer, TicketSerializer

# We don't need to check for duplicate class names and function names.
Expand All @@ -36,8 +32,7 @@ def get(self, request: Request) -> Response:
querystring = self.get_querystring(request=request)
if len(querystring) > 0:
if department := querystring.get("department"):
tickets = tickets.filter(
course_department=self.sanitize(department))
tickets = tickets.filter(course_department=self.sanitize(department))

if active := querystring.get("active"):
tickets = tickets.filter(is_active=active.capitalize())
Expand Down Expand Up @@ -69,7 +64,9 @@ def patch(self, request: Request, ticket_id: int) -> Response:
try:
ticket = Ticket.generic.get(id=ticket_id)
except Ticket.DoesNotExist:
return Response({"error": "Ticket not found"}, status=status.HTTP_404_NOT_FOUND)
return Response(
{"error": "Ticket not found"}, status=status.HTTP_404_NOT_FOUND
)

serializer = TicketSerializer(ticket, data=request.data, partial=True)
if serializer.is_valid():
Expand Down
6 changes: 3 additions & 3 deletions backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class Meta:


class TicketSerializer(serializers.ModelSerializer):
professor = serializers.PrimaryKeyRelatedField(
queryset=Professor.generic.all())
professor = serializers.PrimaryKeyRelatedField(queryset=Professor.generic.all())
course = serializers.PrimaryKeyRelatedField(queryset=Course.generic.all())
issue = serializers.PrimaryKeyRelatedField(queryset=Issues.generic.all())
tutor = serializers.PrimaryKeyRelatedField(
queryset=User.generic.all().filter(is_tutor=True))
queryset=User.generic.all().filter(is_tutor=True)
)

class Meta:
model = Ticket
Expand Down
5 changes: 2 additions & 3 deletions backend/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.contrib import admin
from django.urls import path

from api.endpoints import course, issue, professor, section, ticket, user, authenticate
from api.endpoints import authenticate, course, issue, professor, section, ticket, user

urlpatterns = [
# API Config URLS
Expand Down Expand Up @@ -72,7 +72,6 @@
# path("api/announcements/")
# path("api/announcements/<str:annonucement_id>")
# Course URLS
path("api/courses/", view=course.APICourseList.as_view(),
name="Course List View"),
path("api/courses/", view=course.APICourseList.as_view(), name="Course List View"),
# path("api/courses/<str:course_pk>", view=routing.MessageViewSet.as_view()),
]
3 changes: 2 additions & 1 deletion frontend/src/API/tickets/ticketRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export function updateTicket(data: any) {
"X-CSRFToken": csrftoken,
},
})
.then((res) => res.data).catch((e) => (console.log(e)));
.then((res) => res.data)
.catch((e) => console.log(e));
}
3 changes: 1 addition & 2 deletions frontend/src/components/fields/CheckDropField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export default function CheckDropField({ control, name }: any) {
key={field.id}
className="capitalize"
checked={field.value}
onCheckedChange={field.onChange
}
onCheckedChange={field.onChange}
>
Successful
</DropdownMenuCheckboxItem>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/fields/SearchFilterField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default function SearchFilterField({
>
{field.value
? items?.data.find(
(tutor: any) => tutor.MSOID === field.value,
)?.name
(tutor: any) => tutor.MSOID === field.value,
)?.name
: "select an issue"}
<CaretSortIcon
key="issue_sort_icon"
Expand Down
22 changes: 11 additions & 11 deletions frontend/src/forms/TicketForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ export default function TicketForm() {
className={cn(
"w-full md:w-[35vw] lg:w-[30vw] xl:w-[40vw] justify-between",
!field.value &&
"text-muted-foreground font-normal",
"text-muted-foreground font-normal",
)}
>
{field.value
? professors?.data.find(
(professor: any) =>
professor.professor_id === field.value,
)?.full_name
(professor: any) =>
professor.professor_id === field.value,
)?.full_name
: "select a professor"}
<CaretSortIcon className="ml-2 h-4 w-4 shrink-0" />
</Button>
Expand Down Expand Up @@ -287,13 +287,13 @@ export default function TicketForm() {
className={cn(
"w-full md:w-[35vw] lg:w-[30vw] xl:w-[40vw] justify-between",
!field.value &&
"text-muted-foreground font-normal",
"text-muted-foreground font-normal",
)}
>
{field.value
? courses?.data.find(
(course: any) => course.id === field.value,
)?.course_code
(course: any) => course.id === field.value,
)?.course_code
: "select a course"}
<CaretSortIcon
key="course_sort_icon"
Expand Down Expand Up @@ -390,14 +390,14 @@ export default function TicketForm() {
className={cn(
"w-full md:w-[35vw] lg:w-[30vw] xl:w-[40vw] justify-between",
!field.value &&
"text-muted-foreground font-normal",
"text-muted-foreground font-normal",
)}
>
{field.value
? issues?.data.find(
(issue: any) =>
issue.issue_id === field.value,
)?.problem_type
(issue: any) =>
issue.issue_id === field.value,
)?.problem_type
: "select an issue"}
<CaretSortIcon
key="issue_sort_icon"
Expand Down
26 changes: 22 additions & 4 deletions frontend/src/forms/TutorTicketForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const FormSchema = z.object({
status: z.string().min(1).max(10),
tutor: z.string(),
was_successful: z.boolean(),
difficulty: z.string()
difficulty: z.string(),
});

export default function TutorTicketForm({ ticket }: any) {
Expand Down Expand Up @@ -76,7 +76,7 @@ export default function TutorTicketForm({ ticket }: any) {
status: ticket.status,
tutor: "",
was_successful: ticket.was_successful,
difficulty: ""
difficulty: "",
},
});

Expand Down Expand Up @@ -270,8 +270,26 @@ export default function TutorTicketForm({ ticket }: any) {
}
/>
<div className="flex justify-end space-x-2">
<Button onClick={() => form.resetField('description')} disabled={!form.formState.isDirty} variant="outline" className={`mt-4 border-warning/50 text-warning hover:bg-warning/20 hover:text-warning ${!form.formState.isDirty && "hidden"}`}>Discard</Button>
<Button type="submit" disabled={!form.formState.isDirty} variant="outline" className={`mt-4 ${!form.formState.isDirty && "hidden"}`}>Update</Button>
<Button
onClick={() => form.resetField("description")}
disabled={!form.formState.isDirty}
variant="outline"
className={`mt-4 border-warning/50 text-warning hover:bg-warning/20 hover:text-warning ${
!form.formState.isDirty && "hidden"
}`}
>
Discard
</Button>
<Button
type="submit"
disabled={!form.formState.isDirty}
variant="outline"
className={`mt-4 ${
!form.formState.isDirty && "hidden"
}`}
>
Update
</Button>
</div>
</div>
</div>
Expand Down

0 comments on commit 59dc671

Please sign in to comment.