Skip to content

Commit

Permalink
Add employee endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
barcellos-pedro committed Feb 8, 2024
1 parent e7566e8 commit 58fc49e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ public CollectionModel<EntityModel<Employee>> getAll() {
return service.getAll();
}

@GetMapping("/role")
public CollectionModel<EntityModel<Employee>> getAllByRole(@RequestParam(name = "search", defaultValue = "") String role) {
return service.getAllByRole(role);
}

@GetMapping("/{id}")
public EntityModel<Employee> getById(@PathVariable Long id) {
return service.getById(id);
return service.getById(id);
}

@PostMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/*
JPA Query Methods
https://docs.spring.io/spring-data/jpa/reference/jpa/query-methods.html
* */

package com.pedro.rest.repository;

import com.pedro.rest.model.Employee;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface EmployeeRepository extends JpaRepository<Employee, Long> {
List<Employee> findByRoleIgnoreCaseContaining(String role);
}
2 changes: 2 additions & 0 deletions src/main/java/com/pedro/rest/service/EmployeeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
public interface EmployeeService {
CollectionModel<EntityModel<Employee>> getAll();

CollectionModel<EntityModel<Employee>> getAllByRole(String role);

EntityModel<Employee> getById(Long id);

ResponseEntity<?> create(Employee employee);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public CollectionModel<EntityModel<Employee>> getAll() {
return assembler.toCollectionModel(repository.findAll());
}

@Override
public CollectionModel<EntityModel<Employee>> getAllByRole(String role) {
return assembler.toCollectionModel(repository.findByRoleIgnoreCaseContaining(role));
}

@Override
public EntityModel<Employee> getById(Long id) {
var employee = repository.findById(id).orElseThrow(() -> new EmployeeNotFoundException(id));
Expand Down

0 comments on commit 58fc49e

Please sign in to comment.