Tenho o modelo:
@Data
@RedisHash("customer")
public class Customer {
@Id
private String id;
@NotNull
private String firstName;
...
Tenho a seguinte interface:
@EnableRedisRepositories
public interface CustomerRepository extends JpaRepository<Customer, String> {
Optional<Customer> findByFirstName(String firstName);
}
O Service:
@Service
@Transactional
public class CustomerService {
private final CustomerRepository repository;
public CustomerService(CustomerRepository repository) {
this.repository = repository;
}
...
public Optional<Customer> retrieveCustomersByName(String name) {
return repository.findByFirstName(name);
}
}
E o seguinte restcontroller:
@RestController
@RequestMapping("/customers")
public class CustomerController {
@Autowired
private CustomerService customerService;
....
@GetMapping("/{firstName}")
public ResponseEntity<?> getCustomers(@PathVariable String firstName) {
Optional<?> customer = customerService.retrieveCustomersByName(firstName);
if (!customer.isPresent()) {
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(customer);
}
}
Todos os metodos de crud estão ok!
Porem quando faço a consulta pelo postman ele não retorna nenhum resultado do redis. O que devo fazer?
url usada no postman:
http://localhost:9000/api/customers/paulo
arquivo application.yml:
server:
port: 9000
servlet:
contextPath: /api