Skip to content

Commit 39b94d9

Browse files
committed
fixed device resource, had wrong path annotation
1 parent f7ff515 commit 39b94d9

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

src/main/java/com/armzilla/ha/dao/Device.java renamed to src/main/java/com/armzilla/ha/api/Device.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.armzilla.ha.dao;
1+
package com.armzilla.ha.api;
22

33
/**
44
* Created by arm on 4/13/15.

src/main/java/com/armzilla/ha/dao/DeviceDescriptor.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,10 @@
66
/**
77
* Created by arm on 4/13/15.
88
*/
9-
@Document(indexName = "documentdescriptor", type = "document", shards = 1, replicas = 0, refreshInterval = "-1")
9+
@Document(indexName = "device", type = "devicedescriptor", shards = 1, replicas = 0, refreshInterval = "-1")
1010
public class DeviceDescriptor{
1111
@Id
1212
private String id;
13-
14-
public DeviceDescriptor(){}
15-
16-
public String getId() {
17-
return id;
18-
}
19-
20-
public void setId(String id) {
21-
this.id = id;
22-
}
23-
2413
private String name;
2514
private String deviceType;
2615
private String offUrl;
@@ -57,4 +46,12 @@ public String getOnUrl() {
5746
public void setOnUrl(String onUrl) {
5847
this.onUrl = onUrl;
5948
}
49+
50+
public String getId() {
51+
return id;
52+
}
53+
54+
public void setId(String id) {
55+
this.id = id;
56+
}
6057
}

src/main/java/com/armzilla/ha/dao/DeviceRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
public interface DeviceRepository extends ElasticsearchRepository<DeviceDescriptor, String> {
1111
List<DeviceDescriptor> findByDeviceType(String type);
1212
List<DeviceDescriptor> findAll();
13-
DeviceDescriptor findById(String id);
13+
DeviceDescriptor findOne(String id);
1414

1515
}

src/main/java/com/armzilla/ha/devicemanagmeent/DeviceResource.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.armzilla.ha.devicemanagmeent;
22

3-
import com.armzilla.ha.dao.Device;
3+
import com.armzilla.ha.api.Device;
44
import com.armzilla.ha.dao.DeviceDescriptor;
55
import com.armzilla.ha.dao.DeviceRepository;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.http.HttpStatus;
88
import org.springframework.http.ResponseEntity;
99
import org.springframework.stereotype.Controller;
10+
import org.springframework.web.bind.annotation.PathVariable;
1011
import org.springframework.web.bind.annotation.RequestBody;
1112
import org.springframework.web.bind.annotation.RequestMapping;
1213
import org.springframework.web.bind.annotation.RequestMethod;
1314

14-
import javax.websocket.server.PathParam;
1515
import java.util.LinkedList;
1616
import java.util.List;
1717
import java.util.UUID;
@@ -48,12 +48,23 @@ public ResponseEntity<List<DeviceDescriptor>> findAllDevices() {
4848
}
4949

5050
@RequestMapping(value = "/{lightId}", method = RequestMethod.GET, produces = "application/json")
51-
public ResponseEntity<DeviceDescriptor> findByDeviceId(@PathParam("lightId") String id){
52-
DeviceDescriptor descriptor = deviceRepository.findById(id);
51+
public ResponseEntity<DeviceDescriptor> findByDevicId(@PathVariable("lightId") String id){
52+
DeviceDescriptor descriptor = deviceRepository.findOne(id);
5353
if(descriptor == null){
5454
return new ResponseEntity<>(null, null, HttpStatus.NOT_FOUND);
5555
}
5656
return new ResponseEntity<>(descriptor, null, HttpStatus.OK);
5757
}
5858

59+
@RequestMapping(value = "/{lightId}", method = RequestMethod.DELETE, produces = "application/json")
60+
public ResponseEntity<String> deleteDeviceById(@PathVariable("lightId") String id){
61+
DeviceDescriptor deleted = deviceRepository.findOne(id);
62+
if(deleted == null){
63+
return new ResponseEntity<>(null, null, HttpStatus.NOT_FOUND);
64+
}
65+
deviceRepository.delete(deleted);
66+
return new ResponseEntity<>(null, null, HttpStatus.NO_CONTENT);
67+
}
68+
69+
5970
}

src/main/java/com/armzilla/ha/hue/HueMulator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public ResponseEntity<HueApiResponse> getApi(@PathVariable(value = "userId") Str
7777
@RequestMapping(value = "/{userId}/lights/{lightId}", method = RequestMethod.GET, produces = "application/json")
7878
public ResponseEntity<DeviceResponse> getLigth(@PathVariable(value = "lightId") String lightId, @PathVariable(value = "userId") String userId, HttpServletRequest request) {
7979
log.info("hue light requested: " + lightId + " from " + request.getRemoteAddr());
80-
DeviceDescriptor device = repository.findById(lightId);
80+
DeviceDescriptor device = repository.findOne(lightId);
8181
if (device == null) {
8282
return new ResponseEntity<>(null, null, HttpStatus.NOT_FOUND);
8383
} else {
@@ -109,7 +109,7 @@ public ResponseEntity<String> stateChange(@PathVariable(value = "lightId") Strin
109109
} else {
110110
setting = "[{\"success\":{\"/lights/" + lightId + "/state/on\":false}}]";
111111
}
112-
DeviceDescriptor device = repository.findById(lightId);
112+
DeviceDescriptor device = repository.findOne(lightId);
113113
if (device == null) {
114114
return new ResponseEntity<>(null, null, HttpStatus.NOT_FOUND);
115115
}

0 commit comments

Comments
 (0)