From 4da1101f1cad4953895d3284d65e617e6552bfcc Mon Sep 17 00:00:00 2001 From: Andrea Brighi Date: Tue, 9 May 2023 18:59:38 +0200 Subject: [PATCH] docs: add documentation --- .../accessdata/adapter/Adapter.kt | 11 +++ .../accessdata/api/AccessApi.kt | 20 +++++ .../accessdata/api/RetrofitHelper.kt | 8 ++ .../datasource/AccessDomainRepositoryImpl.kt | 48 ++++++++++- .../datasource/AccessLocalDataStorage.kt | 18 ++++ .../datasource/AccessLocalDataStorageImpl.kt | 19 ++++- .../datasource/AccessRemoteDataStorage.kt | 20 ++++- .../datasource/AccessRemoteDataStorageImpl.kt | 24 ++++++ .../accessdata/exception/DownloadException.kt | 4 + .../exception/MissingUserException.kt | 3 + .../exception/SavingUserException.kt | 3 + .../accessdata/storage/UserStorage.kt | 18 ++++ .../accessdata/storage/UserStorageImpl.kt | 12 +++ .../accessdomain/entities/User.kt | 82 ++++++++++++++++++- .../accessdomain/entities/UserImpl.kt | 3 + .../policies/EmailFormatPolicy.kt | 10 +++ .../policies/PasswordFormatPolicy.kt | 10 +++ .../accessdomain/policies/Policy.kt | 9 ++ .../repository/AccessDomainRepository.kt | 28 +++++++ .../accessdomain/usecase/AccessUseCase.kt | 29 +++++++ 20 files changed, 373 insertions(+), 6 deletions(-) diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/adapter/Adapter.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/adapter/Adapter.kt index e47108cb..5ea2404f 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/adapter/Adapter.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/adapter/Adapter.kt @@ -6,8 +6,15 @@ import access.communication.User as UserRemote import access.communication.Role as RoleRemote import access.communication.user as userRemote +/** + * Adapter is used to convert data from domain to remote and vice versa. + */ object Adapter { + /** + * Converts a user from domain to remote. + * @return the converted remote user. + */ fun User.fromDomainToRemote(): UserRemote { val user = this return userRemote { @@ -26,6 +33,10 @@ object Adapter { } } + /** + * Converts a user from remote to domain. + * @return the converted domain user. + */ fun UserRemote.fromRemoteToDomain(): User { val user = this return User.build { diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/api/AccessApi.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/api/AccessApi.kt index 3affa490..a90d321d 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/api/AccessApi.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/api/AccessApi.kt @@ -8,14 +8,34 @@ import retrofit2.http.HTTP import retrofit2.http.POST import retrofit2.http.PUT +/** + * AccessApi is the API interface for the access data. + * + * Use retrofit annotations to define the HTTP request. + */ interface AccessApi { + /** + * Logs a user. + * @param user is the user to log. + * @return the [Call] with the logged user response or error. + */ @POST("/login") fun getUser(@Body user: User): Call + /** + * Creates a new user. + * @param user is the user to create. + * @return the [Call] with the created user or error. + */ @PUT("/register") fun createNewUser(@Body user: User): Call + /** + * Deletes a user. + * @param user is the user to delete. + * @return the [Call] with the deleted user response or error. + */ @HTTP(method = "DELETE", path = "/remove", hasBody = true) fun deleteUser(@Body user: User): Call } diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/api/RetrofitHelper.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/api/RetrofitHelper.kt index 3cc8959f..2187da42 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/api/RetrofitHelper.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/api/RetrofitHelper.kt @@ -4,7 +4,15 @@ import io.github.andreabrighi.converter.RetrofitJsonConverterFactory import okhttp3.OkHttpClient import retrofit2.Retrofit +/** + * RetrofitHelper is an helper to create a Retrofit instance. + */ object RetrofitHelper { + /** + * Creates a Retrofit instance. + * @param baseUrl is the base url of the API. + * @return the Retrofit instance. + */ fun getInstance(baseUrl: String): Retrofit { val httpClient = OkHttpClient.Builder() return Retrofit diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessDomainRepositoryImpl.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessDomainRepositoryImpl.kt index 3bb81c3f..d0ee8a7a 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessDomainRepositoryImpl.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessDomainRepositoryImpl.kt @@ -3,29 +3,75 @@ package com.intelligentbackpack.accessdata.datasource import com.intelligentbackpack.accessdomain.entities.User import com.intelligentbackpack.accessdomain.repository.AccessDomainRepository +/** + * AccessDomainRepositoryImpl is the implementation of the AccessDomainRepository. + * @param accessLocalDataStorage is the local data storage. + * @param accessRemoteDataStorage is the remote data storage. + */ class AccessDomainRepositoryImpl( private val accessLocalDataStorage: AccessLocalDataStorage, private val accessRemoteDataStorage: AccessRemoteDataStorage ) : AccessDomainRepository { + /** + * Creates a new user. + * @param user is the user to create. + * @return the created user. + * @throws Exception if the user cannot be created. + * + * The user is created in the remote data storage and then saved in the local data storage. + */ override fun createUser(user: User): User = accessRemoteDataStorage.createUser(user) .also { accessLocalDataStorage.saveUser(it) } + /** + * Checks if a user is logged. + * @return true if the user is logged, false otherwise. + * + * The user is checked in the local data storage. + */ override fun isUserLogged(): Boolean = accessLocalDataStorage.isUserSaved() + /** + * Logs a user using email and password. + * @param email is the user email. + * @param password is the user password. + * @return the logged user. + * @throws Exception if the user cannot be logged. + * + * The user is logged in the remote data storage and then saved in the local data storage. + */ override fun loginWithData(email: String, password: String): User = accessRemoteDataStorage .accessWithData(email, password) .also { accessLocalDataStorage.saveUser(it) } + /** + * Logs the saved user. + * @return the logged user. + * @throws Exception if the user cannot be logged. + * + * The user is logged in the remote data storage. + */ override fun automaticLogin(): User = accessLocalDataStorage.getUser() - + /** + * Logs out the user. + * @throws Exception if the user cannot be logged out. + * + * The user is deleted in the local data storage. + */ override fun logoutUser() = accessLocalDataStorage.deleteUser() + /** + * Deletes the user. + * @throws Exception if the user cannot be deleted. + * + * The user is deleted in the remote data storage and then in the local data storage. + */ override fun deleteUser() { accessRemoteDataStorage.deleteUser(accessLocalDataStorage.getUser()) accessLocalDataStorage.deleteUser() diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorage.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorage.kt index ea2a3dc1..02923678 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorage.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorage.kt @@ -2,13 +2,31 @@ package com.intelligentbackpack.accessdata.datasource import com.intelligentbackpack.accessdomain.entities.User +/** + * AccessLocalDataStorage is the interface for access to the local data storage. + */ interface AccessLocalDataStorage { + /** + * Checks if the user is saved. + * @return true if the user is saved, false otherwise. + */ fun isUserSaved(): Boolean + /** + * Saves the user. + * @param user is the user to save. + */ fun saveUser(user: User) + /** + * Gets the user. + * @return the user. + */ fun getUser(): User + /** + * Deletes the user. + */ fun deleteUser() } \ No newline at end of file diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorageImpl.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorageImpl.kt index 4cb9c895..36ecb57e 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorageImpl.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorageImpl.kt @@ -5,21 +5,36 @@ import com.intelligentbackpack.accessdata.exception.SavingUserException import com.intelligentbackpack.accessdata.storage.UserStorage import com.intelligentbackpack.accessdomain.entities.User +/** + * AccessLocalDataStorageImpl is the implementation of AccessLocalDataStorage. + * @param storage is the storage of the user data [UserStorage]. + */ class AccessLocalDataStorageImpl(private val storage: UserStorage) : AccessLocalDataStorage { override fun isUserSaved(): Boolean { return storage.isUserSaved() } + /** + * Saves the user. + * @param user is the user to save. + * @throws SavingUserException if the user cannot be saved. + */ + @Throws(SavingUserException::class) override fun saveUser(user: User) { try { storage.saveUser(user) - } - catch (e: Exception) { + } catch (e: Exception) { throw SavingUserException() } } + /** + * Gets the user. + * @return the user. + * @throws MissingUserException if the user is not saved. + */ + @Throws(MissingUserException::class) override fun getUser(): User { if (!storage.isUserSaved()) throw MissingUserException() diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessRemoteDataStorage.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessRemoteDataStorage.kt index 3f16c6b0..160112d1 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessRemoteDataStorage.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessRemoteDataStorage.kt @@ -2,11 +2,29 @@ package com.intelligentbackpack.accessdata.datasource import com.intelligentbackpack.accessdomain.entities.User +/** + * AccessRemoteDataStorage is the interface for access to the remote data storage. + */ interface AccessRemoteDataStorage { + /** + * Creates a user. + * @param user is the user to create. + * @return the created user. + */ fun createUser(user: User): User - fun accessWithData(email: String, password: String) : User + /** + * Logs a user using email and password. + * @param email is the user email. + * @param password is the user password. + * @return the logged user. + */ + fun accessWithData(email: String, password: String): User + /** + * Logs the saved user. + * @return the logged user. + */ fun deleteUser(user: User) } \ No newline at end of file diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessRemoteDataStorageImpl.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessRemoteDataStorageImpl.kt index 1ada4c89..a772daf1 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessRemoteDataStorageImpl.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessRemoteDataStorageImpl.kt @@ -8,10 +8,21 @@ import com.intelligentbackpack.accessdata.adapter.Adapter.fromRemoteToDomain import com.intelligentbackpack.accessdata.exception.DownloadException import org.json.JSONObject +/** + * AccessRemoteDataStorageImpl is the implementation of AccessRemoteDataStorage. + * @param baseUrl is the base url of the remote data storage. + */ class AccessRemoteDataStorageImpl(baseUrl: String) : AccessRemoteDataStorage { private val accessApi = RetrofitHelper.getInstance(baseUrl).create(AccessApi::class.java) + /** + * Creates a user. + * @param user is the user to create. + * @return the created user. + * @throws DownloadException if the user cannot be created. + */ + @Throws(DownloadException::class) override fun createUser(user: User): User { val response = accessApi.createNewUser(user.fromDomainToRemote()).execute() return if (response.isSuccessful) { @@ -22,6 +33,14 @@ class AccessRemoteDataStorageImpl(baseUrl: String) : AccessRemoteDataStorage { } } + /** + * Logs a user using email and password. + * @param email is the user email. + * @param password is the user password. + * @return the logged user. + * @throws DownloadException if the user cannot be logged. + */ + @Throws(DownloadException::class) override fun accessWithData(email: String, password: String): User { val response = accessApi.getUser( access.communication.User.newBuilder() @@ -37,6 +56,11 @@ class AccessRemoteDataStorageImpl(baseUrl: String) : AccessRemoteDataStorage { } } + /** + * Delete the user. + * @throws DownloadException if the user cannot be deleted. + */ + @Throws(DownloadException::class) override fun deleteUser(user: User) { val response = accessApi.deleteUser(user.fromDomainToRemote()).execute() if (!response.isSuccessful) { diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/DownloadException.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/DownloadException.kt index 88cab189..458cc058 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/DownloadException.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/DownloadException.kt @@ -1,3 +1,7 @@ package com.intelligentbackpack.accessdata.exception +/** + * DownloadException is an exception that is thrown when there is an error during the download. + * @param message is the message of the exception. + */ class DownloadException(message: String) : Exception(message) diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/MissingUserException.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/MissingUserException.kt index bfacf6b7..d1d723c5 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/MissingUserException.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/MissingUserException.kt @@ -1,3 +1,6 @@ package com.intelligentbackpack.accessdata.exception +/** + * MissingUserException is an exception that is thrown when the user is not saved. + */ class MissingUserException : Exception() \ No newline at end of file diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/SavingUserException.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/SavingUserException.kt index 0e723a21..6ca35dcb 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/SavingUserException.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/exception/SavingUserException.kt @@ -1,3 +1,6 @@ package com.intelligentbackpack.accessdata.exception +/** + * SavingUserException is an exception that is thrown when there is an error during the saving of the user. + */ class SavingUserException : Exception() \ No newline at end of file diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/storage/UserStorage.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/storage/UserStorage.kt index 646cd491..17d41421 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/storage/UserStorage.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/storage/UserStorage.kt @@ -2,14 +2,32 @@ package com.intelligentbackpack.accessdata.storage import com.intelligentbackpack.accessdomain.entities.User +/** + * UserStorage is the interface for storage the user data. + */ interface UserStorage { + /** + * Checks if the user is saved. + * @return true if the user is saved, false otherwise. + */ fun isUserSaved(): Boolean + /** + * Saves the user. + * @param user is the user to save. + */ fun saveUser(user: User) + /** + * Gets the user. + * @return the user. + */ fun getUser(): User + /** + * Deletes the user. + */ fun deleteUser() diff --git a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/storage/UserStorageImpl.kt b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/storage/UserStorageImpl.kt index c5e59a8b..61c75986 100644 --- a/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/storage/UserStorageImpl.kt +++ b/accessData/src/main/kotlin/com/intelligentbackpack/accessdata/storage/UserStorageImpl.kt @@ -8,6 +8,12 @@ import androidx.security.crypto.MasterKey import com.intelligentbackpack.accessdomain.entities.Role import com.intelligentbackpack.accessdomain.entities.User +/** + * UserStorageImpl is the implementation of UserStorage. + * @param context is the context of the application. + * + * This class uses SharedPreferences to save the user. + */ class UserStorageImpl(private val context: Context) : UserStorage { private val name = "IntelligentBackpackSharedPref" @@ -17,6 +23,12 @@ class UserStorageImpl(private val context: Context) : UserStorage { return sp.contains("email") } + /** + * Saves the user. + * @param user is the user to save. + * + * This function save the user password encrypted. + */ override fun saveUser(user: User) { val sp: SharedPreferences = context.getSharedPreferences(name, MODE_PRIVATE) val masterKey: MasterKey = diff --git a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/entities/User.kt b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/entities/User.kt index 0e7bb9a9..283a53a6 100644 --- a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/entities/User.kt +++ b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/entities/User.kt @@ -5,34 +5,112 @@ import com.intelligentbackpack.accessdomain.policies.PasswordFormatPolicy import com.intelligentbackpack.accessdomain.policies.Policy import java.util.Locale +/** + * User role is used to define the user's permissions. + */ enum class Role { - USER, TEACHER, STUDENT + /** + * User role is the default role. + */ + USER, + + /** + * Teacher role is used to define the teacher's permissions. + */ + TEACHER, + + /** + * Student role is used to define the student's permissions. + */ + STUDENT } +/** + * Type-alias for email. + */ typealias Email = String + +/** + * Type-alias for password. + */ typealias Password = String +/** + * User interface. + */ interface User { - + /** + * User email. + */ val email: Email + + /** + * User name. + */ val name: String + + /** + * User surname. + */ val surname: String + + /** + * User password. + */ val password: Password + + /** + * User role. + */ val role: Role companion object { + /** + * User builder. + */ inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build() } + /** + * User builder. + */ class Builder { + /** + * User email in builder. + * + * Must be a valid email (see [EmailFormatPolicy]). + */ lateinit var email: Email + + /** + * User name in builder. + */ var name: String = "" + + /** + * User surname in builder. + */ var surname: String = "" + + /** + * User password in builder. + * + * Must be a valid password (see [PasswordFormatPolicy]). + */ lateinit var password: Password + + /** + * User role in builder. + */ var role: Role = Role.USER private val emailPolicies: List> = listOf(EmailFormatPolicy) private val passwordPolicies: List> = listOf(PasswordFormatPolicy) + /** + * Build the user. + * + * @throws IllegalArgumentException if the email, name, surname or password are not valid (blank or doesn't respect the policies). + */ fun build(): User = with(this) { val trimEmail = email.trim() diff --git a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/entities/UserImpl.kt b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/entities/UserImpl.kt index 9bc8ee0d..f31efadf 100644 --- a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/entities/UserImpl.kt +++ b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/entities/UserImpl.kt @@ -1,5 +1,8 @@ package com.intelligentbackpack.accessdomain.entities +/** + * UserImpl is an internal implementation of User interface. + */ internal data class UserImpl( override val email: String, override val name: String, diff --git a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/EmailFormatPolicy.kt b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/EmailFormatPolicy.kt index bc626ab8..da2fc20a 100644 --- a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/EmailFormatPolicy.kt +++ b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/EmailFormatPolicy.kt @@ -2,6 +2,16 @@ package com.intelligentbackpack.accessdomain.policies import com.intelligentbackpack.accessdomain.entities.Email +/** + * EmailFormatPolicy is a policy that checks if the email respects the format. + * + * The email must contain at least: + * - one @ + * - one . + * - 2 characters after the last . + * - no spaces + * - no , or @ before the last . + */ object EmailFormatPolicy : Policy { private val regex = Regex("^[^\\s@]+@([^\\s@.,]+\\.)+[^\\s@.,]{2,}\$") diff --git a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/PasswordFormatPolicy.kt b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/PasswordFormatPolicy.kt index 28ebe690..e71c176f 100644 --- a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/PasswordFormatPolicy.kt +++ b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/PasswordFormatPolicy.kt @@ -1,5 +1,15 @@ package com.intelligentbackpack.accessdomain.policies +/** + * PasswordFormatPolicy is a policy that checks if the password respects the format. + * + * The password must contain at least: + * - one uppercase letter + * - one lowercase letter + * - one digit + * - one special character + * - 8 characters + */ object PasswordFormatPolicy : Policy { private val regex = Regex("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$") diff --git a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/Policy.kt b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/Policy.kt index b101d312..95dee232 100644 --- a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/Policy.kt +++ b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/policies/Policy.kt @@ -1,5 +1,14 @@ package com.intelligentbackpack.accessdomain.policies +/** + * Policy interface. + * @param T is the type of the entity to check. + */ interface Policy { + /** + * Checks if the entity respects the policy. + * @param entity is the entity to check. + * @return true if the entity respects the policy, false otherwise. + */ fun isRespected(entity: T): Boolean } diff --git a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/repository/AccessDomainRepository.kt b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/repository/AccessDomainRepository.kt index 42da37a0..ed1c3db4 100644 --- a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/repository/AccessDomainRepository.kt +++ b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/repository/AccessDomainRepository.kt @@ -2,17 +2,45 @@ package com.intelligentbackpack.accessdomain.repository import com.intelligentbackpack.accessdomain.entities.User +/** + * AccessDomainRepository is the repository interface for the access domain. + */ interface AccessDomainRepository { + /** + * Creates a new user. + * @param user is the user to create. + * @return the created user. + */ fun createUser(user: User): User + /** + * Checks if a user is logged. + * @return true if the user is logged, false otherwise. + */ fun isUserLogged(): Boolean + /** + * Logs a user using email and password. + * @param email is the user email. + * @param password is the user password. + * @return the logged user. + */ fun loginWithData(email: String, password: String): User + /** + * Logs the saved user. + * @return the logged user. + */ fun automaticLogin(): User + /** + * Logs out the user. + */ fun logoutUser() + /** + * Deletes the user. + */ fun deleteUser() } diff --git a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/usecase/AccessUseCase.kt b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/usecase/AccessUseCase.kt index d9d99274..d6416729 100644 --- a/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/usecase/AccessUseCase.kt +++ b/accessDomain/src/main/kotlin/com/intelligentbackpack/accessdomain/usecase/AccessUseCase.kt @@ -3,17 +3,46 @@ package com.intelligentbackpack.accessdomain.usecase import com.intelligentbackpack.accessdomain.entities.User import com.intelligentbackpack.accessdomain.repository.AccessDomainRepository +/** + * AccessUseCase is the use case for the access domain. + * @param repository is the repository to use. + */ class AccessUseCase(private val repository: AccessDomainRepository) { + /** + * Creates a new user. + * @param user is the user to create. + * @return the created user. + */ suspend fun createUser(user: User) = repository.createUser(user) + /** + * Checks if a user is logged. + * @return true if the user is logged, false otherwise. + */ suspend fun isUserLogged() = repository.isUserLogged() + /** + * Logs a user using email and password. + * @param email is the user email. + * @param password is the user password. + * @return the logged user. + */ suspend fun loginWithData(email: String, password: String) = repository.loginWithData(email, password) + /** + * Logs the saved user. + * @return the logged user. + */ suspend fun automaticLogin() = repository.automaticLogin() + /** + * Logs out the user. + */ suspend fun logoutUser() = repository.logoutUser() + /** + * Deletes the user. + */ suspend fun deleteUser() = repository.deleteUser() }