stefan1anuby / Employee-Management-And-Payroll-System

0 stars 0 forks source link

Create Payroll mode, repo and service #40

Open stefan1anuby opened 1 week ago

stefan1anuby commented 1 week ago

Model could be:

@Entity
public class Payroll {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private Double salary;
    private String paymentDate;

    @OneToOne
    @JoinColumn(name = "employee_id")
    private Employee employee;

    // Getters and Setters
}

Abstract repo could be:

@Repository
public interface PayrollRepository extends JpaRepository<Payroll, Long> {
    Optional<Payroll> findByEmployeeId(Long employeeId);
}

Service could be:

@Service
public class PayrollService {

    @Autowired
    private PayrollRepository payrollRepository;

    public Payroll getPayrollByEmployeeId(Long employeeId) {
        return payrollRepository.findByEmployeeId(employeeId)
                                .orElseThrow(() -> new EntityNotFoundException("Payroll not found"));
    }

    public Payroll savePayroll(Payroll payroll) {
        return payrollRepository.save(payroll);
    }
}