Skip to content

Commit

Permalink
feat: create user application service
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-acampora committed Feb 26, 2023
1 parent f370bc8 commit 73c7b46
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/kotlin/application/service/UserService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023. Smart Operating Block
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/

package application.service

import entity.user.User
import usecase.repository.UserRepository

/**
* The application service for user management.
* @param userRepository the repository to access user data.
*/
class UserService(private val userRepository: UserRepository) {

/** Get a user given its [userId]. */
fun getUser(userId: String): User? = userRepository.getUser(userId)

/** Create a [User]. */
fun createUser(user: User): User? = userRepository.createUser(user)

/** Delete a [User] given its [userId]. */
fun deleteUser(userId: String): Boolean = userRepository.deleteUser(userId)
}
27 changes: 27 additions & 0 deletions src/main/kotlin/usecase/AuthenticationUseCase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2023. Smart Operating Block
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/

package usecase

import usecase.repository.UserRepository

/**
* The use case of user authentication given the [userId] and the [password].
* @param userRepository the repository to access user data.
*/
class AuthenticationUseCase(
private val userId: String,
private val password: String,
private val userRepository: UserRepository
) : UseCase<Boolean> {

override fun execute(): Boolean =
userRepository.getUser(userId).let {
it?.password.equals(password)
}
}

0 comments on commit 73c7b46

Please sign in to comment.