#239 Code Review of a Reward Billing Service

Companies:
T-Bank
Themes:
SpringTransactionsCode Review

Perform a code review:

Java
import java.util.Date;
import java.util.List;

/**
Service for billing employee rewards for additional work.
Each employee may do something in addition to their primary job: give lectures, speak at conferences, and so on.
Such activities are paid according to tariffs, taking the employee's achievements into account through a personal bonus coefficient.
Payment is performed through an external service called over REST.
**/

@Service
public class RewardBillingService {
    @Autowired
    private RewardRepository rewardRepository;

    @Autowired
    private TariffRepository tariffRepository;

    @Autowired
    private RewardRestClient rewardRestClient;

    @Transactional
    public void handleRewards(List<Employee> employees) {
    for (Employee employee : employees) {
        List<Reward> rewards = rewardRepository.findByEmployeeId(employee.getId());
        for (Reward reward : rewards) {
            if (List.of("speech", "lesson", "help").contains(reward.getType())) {
              Tariff tariff = tariffRepository.findByTypeAndDate(reward.getType(), new Date()).get();

              double amount = (1 + employee.getBonusCoefficient()) * tariff.getAmount();

              rewardRestClient.payReward(employee.getId(), amount);
              System.out.println("Payment sent");

              reward.setStatus("paid");
              rewardRepository.sav e(reward);
            }
        }
    }
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in