diff --git a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/Class.kt b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/Class.kt index c106a8de..df8c0f64 100644 --- a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/Class.kt +++ b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/Class.kt @@ -45,7 +45,7 @@ interface Class { * @throws IllegalArgumentException if the name is blank */ fun create(name: String): Class { - check(name.isNotBlank()) { "name cannot be blank" } + require(name.isNotBlank()) { "name cannot be blank" } return ClassImpl(name) } } diff --git a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/School.kt b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/School.kt index 3d0152a7..b2e4fb67 100644 --- a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/School.kt +++ b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/School.kt @@ -61,8 +61,8 @@ interface School { * @throws IllegalArgumentException if the name or the city is blank */ fun create(name: String, city: String): School { - check(name.isNotBlank()) { "name cannot be blank" } - check(city.isNotBlank()) { "city cannot be blank" } + require(name.isNotBlank()) { "name cannot be blank" } + require(city.isNotBlank()) { "city cannot be blank" } return SchoolImpl(name, city) } } diff --git a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/calendar/CalendarEventFactory.kt b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/calendar/CalendarEventFactory.kt index 10788c55..54d15c61 100644 --- a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/calendar/CalendarEventFactory.kt +++ b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/calendar/CalendarEventFactory.kt @@ -108,13 +108,13 @@ object CalendarEventFactory { subject: Subject, module: String? = null, ): WeekLesson { - check(subject.isNotBlank()) { + require(subject.isNotBlank()) { "subject cannot be blank" } - check(!startTime.isAfter(endTime)) { + require(!startTime.isAfter(endTime)) { "startTime cannot be after endTime" } - check(!fromDate.isAfter(toDate)) { + require(!fromDate.isAfter(toDate)) { "fromDate cannot be after toDate" } return WeekLessonImpl( @@ -152,10 +152,10 @@ object CalendarEventFactory { subject: Subject, module: String? = null, ): DateLesson { - check(subject.isBlank()) { + require(subject.isNotBlank()) { "subject cannot be blank" } - check(startTime.isAfter(endTime)) { + require(!startTime.isAfter(endTime)) { "startTime cannot be after endTime" } return DateLessonImpl( diff --git a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/implementation/ClassImpl.kt b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/implementation/ClassImpl.kt index 8fe9172f..e63f4240 100644 --- a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/implementation/ClassImpl.kt +++ b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/implementation/ClassImpl.kt @@ -33,12 +33,11 @@ internal data class ClassImpl( * @throws IllegalArgumentException if the student is already in the class or if the student is not in the class */ override fun addStudent(student: Student): Class { - if (students.contains(student)) { - error("student is already in this class") - } else { - return copy().apply { - students = students + student - } + require(!students.contains(student)) { + "student is already in this class" + } + return copy().apply { + students = students + student } } @@ -51,21 +50,20 @@ internal data class ClassImpl( * @throws IllegalArgumentException if the professor is not in the class or if the professor doesn't teach the subjects in the class */ override fun addProfessor(professor: Professor, subjects: Set): Class { - if (subjects.isEmpty()) { - error("subjects cannot be empty") + require(subjects.isNotEmpty()) { + "subjects cannot be empty" + } + val newClass = if (professors.contains(professor)) { + val oldSubjects = professorTeachSubjects[professor] ?: error("professor is not in this class") + copy().apply { + professorTeachSubjects = professorTeachSubjects + (professor to oldSubjects + subjects) + } } else { - val newClass = if (professors.contains(professor)) { - val oldSubjects = professorTeachSubjects[professor] ?: error("professor is not in this class") - copy().apply { - professorTeachSubjects = professorTeachSubjects + (professor to oldSubjects + subjects) - } - } else { - copy().apply { - professors = professors + professor - professorTeachSubjects = professorTeachSubjects + (professor to subjects) - } + copy().apply { + professors = professors + professor + professorTeachSubjects = professorTeachSubjects + (professor to subjects) } - return newClass } + return newClass } } diff --git a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/person/Professor.kt b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/person/Professor.kt index 399ba0cf..c3853837 100644 --- a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/person/Professor.kt +++ b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/person/Professor.kt @@ -33,9 +33,9 @@ interface Professor : Person { name: String, surname: String, ): Professor { - check(email.isNotBlank()) { "email cannot be blank" } - check(name.isNotBlank()) { "name cannot be blank" } - check(surname.isNotBlank()) { "surname cannot be blank" } + require(email.isNotBlank()) { "email cannot be blank" } + require(name.isNotBlank()) { "name cannot be blank" } + require(surname.isNotBlank()) { "surname cannot be blank" } return ProfessorImpl(email, name, surname) } } diff --git a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/person/Student.kt b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/person/Student.kt index 8fc3b0ea..0c58bd3d 100644 --- a/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/person/Student.kt +++ b/schoolDomain/src/main/kotlin/com/intelligentbackpack/schooldomain/entities/person/Student.kt @@ -30,9 +30,9 @@ interface Student : Person { name: String, surname: String, ): Student { - check(email.isNotBlank()) { "email cannot be blank" } - check(name.isNotBlank()) { "name cannot be blank" } - check(surname.isNotBlank()) { "surname cannot be blank" } + require(email.isNotBlank()) { "email cannot be blank" } + require(name.isNotBlank()) { "name cannot be blank" } + require(surname.isNotBlank()) { "surname cannot be blank" } return StudentImpl(email, name, surname) } }