#239 Code Review of a Reward Billing Service
Perform a code review:
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
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor