I am a bit new with Spring Boot.
I have setup a Couchbase database and created a couple of buckets one which is called Resources
I can have setup a couple of endpoints and can connect to the database through a repository
The repository is as shown: Also I have attached the
java files
I can retrieve an individual resource with it's resource id and everything works fine. However, I cannot get the findAll to work.
In addition, I cannot post a resource and have it saved.
Any ideas ?
I have zipped the src folder
Also the resource bucket has been configured with a PRIMARY index and another index on resourceId
I am confused why I get no error just an empty list when I do a findAll
Is there anything I need to configure in couchbase ?
Here is my code snippets
@RestController
class UserRestService {
private static final int
String = 0;
UserRepository userRepository;
public UserRestService(UserRepository userRepository) {
super();
this.userRepository = userRepository;
}
@GetMapping( value="/users")
// ResponseEntity< List<User>>
Flux<User> allUsers() {
return this.userRepository.findAll();
}
@GetMapping( value="/users/{resourceId}")
Mono< User> aUser(@PathVariable(value = "resourceId", required = false ) String resourceId ) {
return this.userRepository.findById(resourceId );
}
@PostMapping( value="/users/{resourceId}")
ResponseEntity< String > postUser( @RequestBody User theUser) {
this.userRepository.save(theUser);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
@Document
class User {
@NonNull
@Id
String id;
@NonNull
@Field
String role;
@Override
public String toString() {
return "User [id=" + id + ", role=" + role + ", organizationId=" + organizationId + "]";
}
@NonNull
@Field
String organizationId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getOrganizationId() {
return organizationId;
}
public void setOrganizationId(String organizationId) {
this.organizationId = organizationId;
}
}
@Repository
public interface UserRepository
extends ReactiveCrudRepository<User, String> {
Flux< User > findAll();
}