Commit 7d0a9238 authored by 0Tyler's avatar 0Tyler

gateway api update

parent 1bd0abe5
......@@ -3,36 +3,71 @@ package edu.prlab.tyler.iotgateway.gateway.controllers;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import edu.prlab.tyler.iotgateway.gateway.pojo.PrivacyChoiceIndex;
import edu.prlab.tyler.iotgateway.gateway.services.DeviceService;
import edu.prlab.tyler.iotgateway.gateway.services.PrivacyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
@RestController
public class GatewayController {
private DeviceService deviceService;
private PrivacyService privacyService;
public GatewayController(PrivacyService privacyService) {
@Autowired
public GatewayController(PrivacyService privacyService,
DeviceService deviceService) {
this.deviceService = deviceService;
this.privacyService = privacyService;
}
// TODO
// @GetMapping("")
// public ResponseEntity<Iterable<Device>> readDevicesOfUser() {
//
// }
// TODO
//區塊鍊上綁定
//回傳Device(暫時從DB撈)
@PostMapping("/device/{udn}")
public ResponseEntity<Device> bindDeviceAndGateway(@PathVariable(value = "udn") String udn) {
return deviceService.bindDeviceAndGateway(udn)
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.noContent().build());
}
@GetMapping("/privacy/{UDN}")
// TODO
//取得與該gateway所綁定的裝置列表
//回傳Device列表(暫時從DB撈)
@GetMapping("/device")
public ResponseEntity<Iterable<Device>> readDevices() {
return deviceService.readDevices()
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.noContent().build());
}
@GetMapping("/device/{UDN}")
public ResponseEntity<PrivacyPolicyReport> readPrivacyPolicyReportByDevice(@PathVariable(value = "UDN") String UDN) {
return privacyService.getRelatedPrivacyPolicies(UDN)
.map(ResponseEntity::ok)
.orElseGet(()->ResponseEntity.noContent().build());
.orElseGet(() -> ResponseEntity.noContent().build());
}
@PostMapping("/choice")
public ResponseEntity<PrivacyChoice> setPrivacyChoice(@RequestBody PrivacyChoice privacyChoice) {
public ResponseEntity<PrivacyChoice> setPrivacyChoice(@RequestBody PrivacyChoice privacyChoice) {
return privacyService.setPrivacyPolicyChoice(privacyChoice)
.map(ResponseEntity::ok)
.orElseGet(()->ResponseEntity.noContent().build());
.orElseGet(() -> ResponseEntity.noContent().build());
}
// TODO
//根據使用者取得在此gateway上該使用者的隱私選擇列表(根據時間排序),
//暫時從DB撈,無特定使用者
@GetMapping("/choice")
public ResponseEntity<Iterable<PrivacyChoiceIndex>> readPrivacyChoiceRecordsByUser() {
return Optional.of(privacyService.getPrivacyPolicyChoices())
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.noContent().build());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment