This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(access): create local data storage for access
- Loading branch information
1 parent
c072a8e
commit 4a59047
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...a/src/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
31 changes: 31 additions & 0 deletions
31
...c/main/kotlin/com/intelligentbackpack/accessdata/datasource/AccessLocalDataStorageImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |