Created
July 18, 2022 19:38
-
-
Save mafei-dev/3047cba15c6c10e1b2d16c6a32a2fd32 to your computer and use it in GitHub Desktop.
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
package org.mono.stacksaga.example.userservice.service; | |
import lombok.AllArgsConstructor; | |
import org.mono.stacksaga.example.userservice.entity.UserEntity; | |
import org.mono.stacksaga.example.userservice.repository.UserRepository; | |
import org.springframework.stereotype.Service; | |
import javax.transaction.Transactional; | |
import java.util.Optional; | |
@Service | |
@Transactional | |
@AllArgsConstructor | |
public class UserService { | |
private final UserRepository userRepository; | |
/** | |
* check the user is exists or not | |
* | |
* @param userUid the user uid of you are going to check the status | |
* @return if the user is active or not. if user active = true, if not = false and if the user doesn't exist, | |
* return false. | |
*/ | |
public boolean checkUserIsActive(String userUid) { | |
Optional<UserEntity> user = userRepository.findById(userUid); | |
if (user.isPresent()) { | |
return user.get().getIsActive(); | |
} else { | |
return false; | |
} | |
} | |
/** | |
* increment user points by one | |
* | |
* @param userUid the user id of the user who going have the points | |
*/ | |
public void incrementPointsByOne(String userUid) { | |
userRepository.incrementPointsByOne(userUid); | |
} | |
/** | |
* compensation of the increment user points by one | |
* | |
* @param userUid the user id of the user who going have the points | |
*/ | |
public void incrementPointsByOneRevert(String userUid) { | |
userRepository.incrementPointsByOneRevert(userUid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment