-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestServiceController.java
55 lines (45 loc) · 1.95 KB
/
TestServiceController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.gauri.cosmosdemo.service;
import com.gauri.cosmosdemo.db.changefeed.EmployeeChangeFeedListener;
import com.gauri.cosmosdemo.db.core.CosmosDAL;
import com.gauri.cosmosdemo.db.models.DuplicateEmployee;
import com.gauri.cosmosdemo.db.models.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@RestController
@RequestMapping(path = "/test")
public class TestServiceController {
@Autowired
EmployeeChangeFeedListener employeeChangeFeedListener;
@Autowired
CosmosDAL cosmosDAL;
@GetMapping("/terminateChangeFeedEmployee")
public ResponseEntity<String> getTerminateChangeFeedEmployee()
{
employeeChangeFeedListener.cancelSubscription();
return new ResponseEntity<String>("Terminated ", HttpStatus.OK);
}
@GetMapping("/statusChangeFeedEmployee")
public ResponseEntity<String> getStatusChangeFeedEmployee()
{
String status = employeeChangeFeedListener.subscriptionStatus();
return new ResponseEntity<String>(status, HttpStatus.OK);
}
@PostMapping(path="/insertEmployee", consumes = "application/json", produces = "application/json")
public ResponseEntity<Collection<Employee>> addNewEmployee(@RequestBody Employee employee) {
List<Employee> employees = new ArrayList<>();
employees.add(employee);
Collection<Employee> currentInsertedDocs = cosmosDAL.persistEmployee(employees);
return new ResponseEntity<Collection<Employee>>(currentInsertedDocs, HttpStatus.OK);
}
@GetMapping("/allEmployees")
public ResponseEntity<List<Employee>> getAllEmployees()
{
List<Employee> employees = cosmosDAL.getAllEmployees();
return new ResponseEntity<List<Employee>>(employees, HttpStatus.OK);
}
}