kill tamagotchi by Restcall

This commit is contained in:
Elisa Stelling 2019-12-11 11:01:49 +01:00
parent ef8bf3e86a
commit 6ab8fdedc1
2 changed files with 37 additions and 0 deletions

View file

@ -0,0 +1,24 @@
/**
* Copyright (c) 2019, SAP SE, All rights reserved.
*/
package com.sap.tamagotchi.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sap.tamagotchi.model.Owner;
@RestController
@RequestMapping("/owner")
public class OwnerController {
@Autowired
Owner owner;
@GetMapping()
public void killTamagotchi() {
owner.killRendomDevice();
}
}

View file

@ -4,6 +4,7 @@
package com.sap.tamagotchi.model;
import static com.sap.tamagotchi.service.TamagotchiService.DEVICE_EVENT_PROCESSOR_SCHEDULE;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@ -45,4 +46,16 @@ public class Owner {
tamagotchiService.takeCare(d.getId(), care);
}
}
public void killRendomDevice() {
Collection<Device> devices = tamagotchiService.getDevices();
if (devices != null) {
Device first = devices.iterator().next();
Care care = new Care();
care.setFeed(-1000);
tamagotchiService.takeCare(first.getId(), care);
}
}
}