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

Commit

Permalink
feat(access): create local data storage for access
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaBrighi committed Apr 28, 2023
1 parent c072a8e commit 4a59047
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.intelligentbackpack.accessdata.datasource

import com.intelligentbackpack.accessdomain.entities.User

interface AccessLocalDataStorage {
fun isUserSaved(): Boolean
fun saveUser(user: User)
fun getUser(): User
fun deleteUser()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.intelligentbackpack.accessdata.datasource

import com.intelligentbackpack.accessdata.exception.MissingUserException
import com.intelligentbackpack.accessdata.exception.SavingUserException
import com.intelligentbackpack.accessdata.storage.StorageUser
import com.intelligentbackpack.accessdomain.entities.User

class AccessLocalDataStorageImpl(private val storage: StorageUser) : AccessLocalDataStorage {
override fun isUserSaved(): Boolean {
return storage.isUserSaved()
}

override fun saveUser(user: User) {
try {
storage.saveUser(user)
}
catch (e: Exception) {
throw SavingUserException()
}
}

override fun getUser(): User {
if (!storage.isUserSaved())
throw MissingUserException()
return storage.getUser()
}

override fun deleteUser() {
storage.deleteUser()
}
}

0 comments on commit 4a59047

Please sign in to comment.