Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
chore(school): add error if user is not a student in StudentAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaBrighi committed Jun 27, 2023
1 parent 90af968 commit 3744273
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.")
}
}
}

0 comments on commit 3744273

Please sign in to comment.