From 3744273fb3e3b2f38162ceb86b81b3fb9fd7e670 Mon Sep 17 00:00:00 2001 From: Andrea Brighi Date: Tue, 27 Jun 2023 20:44:47 +0200 Subject: [PATCH] chore(school): add error if user is not a student in StudentAdapter --- .../schooldata/adapter/StudentAdapter.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/schoolData/src/main/kotlin/com/intelligentbackpack/schooldata/adapter/StudentAdapter.kt b/schoolData/src/main/kotlin/com/intelligentbackpack/schooldata/adapter/StudentAdapter.kt index 7109a5ed..7fbac684 100644 --- a/schoolData/src/main/kotlin/com/intelligentbackpack/schooldata/adapter/StudentAdapter.kt +++ b/schoolData/src/main/kotlin/com/intelligentbackpack/schooldata/adapter/StudentAdapter.kt @@ -1,5 +1,6 @@ package com.intelligentbackpack.schooldata.adapter +import com.intelligentbackpack.accessdomain.entities.Role import com.intelligentbackpack.accessdomain.entities.User import com.intelligentbackpack.schooldomain.entities.person.Student @@ -9,15 +10,19 @@ import com.intelligentbackpack.schooldomain.entities.person.Student object StudentAdapter { /** - * Converts a student from the access to the domain. + * Converts a user from the access to student of the school domain. * * @return the student for the domain. */ fun User.fromAccessToSchool(): Student { - return Student.create( - email = email, - name = name, - surname = surname, - ) + return if (this.role == Role.STUDENT) { + Student.create( + email = email, + name = name, + surname = surname, + ) + } else { + throw IllegalArgumentException("The user role is not valid.") + } } }