Skip to content

Commit d93d583

Browse files
committed
Updated type annotations of student_id and course_id in example.
1 parent 7cee8d0 commit d93d583

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

examples/coursebooking/application.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,28 @@ def register_course(self, name: str, places: int) -> CourseID:
3131
self.save(course)
3232
return course.id
3333

34-
def join_course(self, student_id: str, course_id: str) -> None:
34+
def join_course(self, student_id: StudentID, course_id: CourseID) -> None:
3535
course = self.get_course(course_id)
3636
student = self.get_student(student_id)
3737
course.accept_student(student_id)
3838
student.join_course(course_id)
3939
self.save(course, student)
4040

41-
def list_students_for_course(self, course_id: str) -> list[str]:
41+
def list_students_for_course(self, course_id: CourseID) -> list[str]:
4242
course = self.get_course(course_id)
4343
return [self.get_student(s).name for s in course.student_ids]
4444

45-
def list_courses_for_student(self, student_id: str) -> list[str]:
45+
def list_courses_for_student(self, student_id: StudentID) -> list[str]:
4646
student = self.get_student(student_id)
4747
return [self.get_course(s).name for s in student.course_ids]
4848

49-
def get_student(self, student_id: str) -> Student:
49+
def get_student(self, student_id: StudentID) -> Student:
5050
try:
5151
return self.repository.get(student_id)
5252
except AggregateNotFoundError:
5353
raise StudentNotFoundError from None
5454

55-
def get_course(self, course_id: str) -> Course:
55+
def get_course(self, course_id: CourseID) -> Course:
5656
try:
5757
return self.repository.get(course_id)
5858
except AggregateNotFoundError:

examples/coursebooking/domainmodel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ def create_id() -> StudentID:
6060
def __init__(self, name: str, max_courses: int) -> None:
6161
self.name = name
6262
self.max_courses = max_courses
63-
self.course_ids: list[str] = []
63+
self.course_ids: list[CourseID] = []
6464

6565
@event("CourseJoined")
66-
def join_course(self, course_id: str) -> None:
66+
def join_course(self, course_id: CourseID) -> None:
6767
if len(self.course_ids) >= self.max_courses:
6868
raise TooManyCoursesError
6969
self.course_ids.append(course_id)
@@ -77,10 +77,10 @@ def create_id() -> CourseID:
7777
def __init__(self, name: str, places: int) -> None:
7878
self.name = name
7979
self.places = places
80-
self.student_ids: list[str] = []
80+
self.student_ids: list[StudentID] = []
8181

8282
@event("StudentAccepted")
83-
def accept_student(self, student_id: str) -> None:
83+
def accept_student(self, student_id: StudentID) -> None:
8484
if len(self.student_ids) >= self.places:
8585
raise FullyBookedError
8686
if student_id in self.student_ids:

0 commit comments

Comments
 (0)