Skip to content

Instantly share code, notes, and snippets.

@mafei-dev
Created July 18, 2022 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mafei-dev/3047cba15c6c10e1b2d16c6a32a2fd32 to your computer and use it in GitHub Desktop.
Save mafei-dev/3047cba15c6c10e1b2d16c6a32a2fd32 to your computer and use it in GitHub Desktop.
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