Skip to content

Commit 28251a5

Browse files
committed
added views and urls to the api for Task, Topic, and Time
1 parent c1b8da3 commit 28251a5

5 files changed

Lines changed: 33 additions & 12 deletions

File tree

server/server/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
2828
path("api/healthcheck/", include("healthcheck.urls")),
2929
path("api/user/", include("user_profile.urls")),
30-
path("api/task/", include("task_planner.urls")),
30+
path("api/planner/", include("task_planner.urls")),
3131
]

server/task_planner/serializers.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,30 @@ class Meta:
88
fields = "__all__"
99

1010

11+
class TopicDetailSerializer(serializers.ModelSerializer):
12+
# Temporary serializer while trying to figure out issue with color_hex
13+
class Meta:
14+
model = Topic
15+
fields = (
16+
"id",
17+
"name",
18+
)
19+
20+
1121
class TimeSerializer(serializers.ModelSerializer):
1222
class Meta:
1323
model = Time
1424
fields = "__all__"
1525

1626

1727
class TaskSerializer(serializers.ModelSerializer):
18-
topics = TopicSerializer(read_only=True)
19-
times = TimeSerializer(read_only=True)
28+
# 1. This should be TopicSerializer instead but breaks because of
29+
# color_hex for some reason
30+
# 2. This method is also not working for showing multiple topics
31+
topics = TopicDetailSerializer(read_only=True)
32+
33+
# Should also link the times to the Task here, not sure how to do that yet
34+
# times = TimeSerializer(read_only=True)
2035

2136
class Meta:
2237
model = Task
@@ -27,5 +42,5 @@ class Meta:
2742
"completed",
2843
"user",
2944
"topics",
30-
"times",
45+
# "times",
3146
)

server/task_planner/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44

55
app_name = "task_planner"
66
urlpatterns = [
7-
path("", views.TaskList.as_view(), name="task-list"),
7+
path("task/", views.TaskList.as_view(), name="task-list"),
8+
path("topic/", views.TopicList.as_view(), name="topic-list"),
9+
path("time/", views.TimeList.as_view(), name="time-list"),
810
]

server/user_profile/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Create your models here.
77
User = get_user_model()
88

9+
910
class Profile(models.Model):
1011
user = models.OneToOneField(User, on_delete=models.CASCADE)
1112
bio = models.TextField(blank=True)
@@ -14,6 +15,7 @@ class Profile(models.Model):
1415
def __str__(self):
1516
return f"Profile: {self.user.username}"
1617

18+
1719
@receiver(post_save, sender=User)
1820
def create_or_update_user_profile(sender, instance, created, **kwargs):
1921
Profile.objects.get_or_create(user=instance)

server/user_profile/serializers.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
from rest_framework import serializers
22
from .models import Profile, User
33

4+
45
class ProfileSerializer(serializers.ModelSerializer):
56
class Meta:
67
model = Profile
78
fields = "__all__"
89

10+
911
class UserSerializer(serializers.ModelSerializer):
1012
profile = ProfileSerializer(read_only=True)
1113

1214
class Meta:
1315
model = User
1416
fields = (
15-
"id",
16-
"username",
17-
"email",
18-
"first_name",
19-
"last_name",
20-
"is_staff",
17+
"id",
18+
"username",
19+
"email",
20+
"first_name",
21+
"last_name",
22+
"is_staff",
2123
"is_superuser",
2224
"profile",
23-
)
25+
)

0 commit comments

Comments
 (0)