Merge branch 'feature/device-service' of https://github.com/jazzm0/microservices-demo into feature/device-service
This commit is contained in:
commit
15cb385d35
2 changed files with 31 additions and 13 deletions
|
@ -1,20 +1,22 @@
|
|||
package com.sap.tamagotchi.controller;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.sap.tamagotchi.model.CreateDevicePayload;
|
||||
import com.sap.tamagotchi.model.Device;
|
||||
import com.sap.tamagotchi.service.TamagotchiService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.sap.tamagotchi.model.Device;
|
||||
import com.sap.tamagotchi.service.TamagotchiService;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.springframework.http.ResponseEntity.ok;
|
||||
|
||||
@RestController
|
||||
public class DeviceController {
|
||||
|
||||
private static final String template = "Hello !!!!!, %s!";
|
||||
private final AtomicLong counter = new AtomicLong();
|
||||
private final TamagotchiService tamagotchiService;
|
||||
|
||||
@Autowired
|
||||
|
@ -22,17 +24,18 @@ public class DeviceController {
|
|||
this.tamagotchiService = tamagotchiService;
|
||||
}
|
||||
|
||||
@RequestMapping("devices/{deviceId}")
|
||||
@RequestMapping("/devices/{deviceId}")
|
||||
public Device getDevice(String deviceId) {
|
||||
return tamagotchiService.getDevice(deviceId);
|
||||
}
|
||||
|
||||
@RequestMapping("devices")
|
||||
@RequestMapping("/devices")
|
||||
public Collection<Device> getDevices() {
|
||||
return tamagotchiService.getDevices();
|
||||
}
|
||||
// TODO postmapping create
|
||||
// request payload
|
||||
// owner String
|
||||
// color
|
||||
|
||||
@PostMapping("/devices")
|
||||
public ResponseEntity createDevice(@RequestBody CreateDevicePayload payload) {
|
||||
return ok(tamagotchiService.createDevice(new Device(payload.getOwner(), payload.getColor())));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
package com.sap.tamagotchi.model;
|
||||
|
||||
public class CreateDevicePayload {
|
||||
private final String owner;
|
||||
private final Color color;
|
||||
|
||||
public CreateDevicePayload(String owner, Color color) {
|
||||
this.owner = owner;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue