Skip to content

Commit

Permalink
premission, get all and JPA
Browse files Browse the repository at this point in the history
  • Loading branch information
Junotas committed Jul 17, 2024
1 parent f6cc610 commit d2fa545
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ public TimeReportController(TimeReportService timeReportService) {
this.timeReportService = timeReportService;
}

@GetMapping
public ResponseEntity<List<TimeReport>> getAllTimeReports() {
List<TimeReport> allReports = timeReportService.getAllTimeReports();
return ResponseEntity.ok(allReports);
}

@GetMapping("/{timePeriod}/{id}")
public ResponseEntity<List<TimeReport>> getAllTimeReports(@PathVariable String timePeriod,
@PathVariable Long id) {
public ResponseEntity<List<TimeReport>> getTimeReportsByPeriodAndEmployee(@PathVariable String timePeriod,
@PathVariable Long id) {
return ResponseEntity.ok(timeReportService.getTimeReports(timePeriod, id));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import org.example.workreportbackend.entity.TimeReport;
import org.example.workreportbackend.entity.Employee;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDateTime;
import java.util.List;

public interface TimeReportRepository extends CrudRepository<TimeReport, Long> {
public interface TimeReportRepository extends JpaRepository<TimeReport, Long> {
List<TimeReport> findAllByEmployeeAndStartTimeGreaterThan(Employee employee, LocalDateTime startTime);
List<TimeReport> findAllByEmployeeAndEndTimeLessThan(Employee employee, LocalDateTime endTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public TimeReportService(TimeReportRepository timeReportRepository, EmployeeRepo
this.employeeRepository = employeeRepository;
}

public List<TimeReport> getAllTimeReports() {
return timeReportRepository.findAll();
}

public List<TimeReport> getTimeReports(String timePeriod, Long employeeId) {
Employee employee = employeeRepository.findById(employeeId).orElseThrow();
if (timePeriod.equals("past")) {
Expand Down

0 comments on commit d2fa545

Please sign in to comment.