Recent - srujanabala/springboot-couchbase GitHub Wiki

Cluster cluster = CouchbaseCluster.create(env,

"192.168.4.1", "192.168.4.2");

@PostMapping(path = "/sdk/get",consumes = "application/json")

        public ResponseEntity<Student> testApi(@RequestBody Student student) throws JsonProcessingException {



                    ObjectMapper mapper = new ObjectMapper();



                    JsonObject content = JsonObject.fromJson(mapper.writeValueAsString(student));



                    JsonDocument document = JsonDocument.create(student.getId(), 3000, content);



                    CouchBaseHelper.getBucket().insert(document);



                    return new ResponseEntity<>(student, HttpStatus.CREATED);               



        }

@GetMapping(path = "/sdk/get/{id}")

        public Student getStudentByIdUsingSDK(@PathVariable("id") final String id)throws Exception {



                    ObjectMapper objectMapper = new ObjectMapper();



                    JsonDocument document = CouchBaseHelper.getBucket().get(id);



                    return objectMapper.readValue(document.content().toString(), Student.class);



                    /*return  Optional.ofNullable(document)



                                            .map(JsonDocument::content)



                                            .map(content -> {



                                                        try {



                                                                    return objectMapper.readValue(content.toString(), Student.class);



                                                        } catch (JsonParseException e) {



                                                                    // TODO Auto-generated catch block



                                                                    e.printStackTrace();



                                                        } catch (JsonMappingException e) {



                                                                    // TODO Auto-generated catch block



                                                                    e.printStackTrace();



                                                        } catch (IOException e) {



                                                                    // TODO Auto-generated catch block



                                                                    e.printStackTrace();



                                                        }



                                                        return null;



                                            }).orElseThrow(() -> new DocumentDoesNotExistException("Data Not found"));*/



        }







        @PostMapping(path = "/sdk/post",consumes = "application/json")



        public ResponseEntity<Student> testApi(@RequestBody Student student) throws JsonProcessingException {



                    ObjectMapper mapper = new ObjectMapper();



                    JsonObject content = JsonObject.fromJson(mapper.writeValueAsString(student));



                    JsonDocument document = JsonDocument.create(student.getId(), 3, content);



                    CouchBaseHelper.getBucket().insert(document);



                    return new ResponseEntity<>(student, HttpStatus.CREATED);               



        }

document

⚠️ **GitHub.com Fallback** ⚠️