add create device
This commit is contained in:
parent
cd930c6b99
commit
41404db83a
2 changed files with 28 additions and 11 deletions
|
@ -1,20 +1,21 @@
|
||||||
package com.sap.tamagotchi.controller;
|
package com.sap.tamagotchi.controller;
|
||||||
|
|
||||||
import java.util.Collection;
|
import com.sap.tamagotchi.model.CreateDevicePayload;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import com.sap.tamagotchi.model.Device;
|
||||||
|
import com.sap.tamagotchi.service.TamagotchiService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.sap.tamagotchi.model.Device;
|
import java.util.Collection;
|
||||||
import com.sap.tamagotchi.service.TamagotchiService;
|
|
||||||
|
import static org.springframework.http.ResponseEntity.ok;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class DeviceController {
|
public class DeviceController {
|
||||||
|
|
||||||
private static final String template = "Hello !!!!!, %s!";
|
|
||||||
private final AtomicLong counter = new AtomicLong();
|
|
||||||
private final TamagotchiService tamagotchiService;
|
private final TamagotchiService tamagotchiService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -31,8 +32,9 @@ public class DeviceController {
|
||||||
public Collection<Device> getDevices() {
|
public Collection<Device> getDevices() {
|
||||||
return tamagotchiService.getDevices();
|
return tamagotchiService.getDevices();
|
||||||
}
|
}
|
||||||
// TODO postmapping create
|
|
||||||
// request payload
|
@PostMapping
|
||||||
// owner String
|
public ResponseEntity createDevice(CreateDevicePayload payload) {
|
||||||
// color
|
return ok(tamagotchiService.createDevice(new Device(payload.getOwner(), payload.getColor()))).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,19 @@
|
||||||
package com.sap.tamagotchi.model;
|
package com.sap.tamagotchi.model;
|
||||||
|
|
||||||
public class CreateDevicePayload {
|
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