Skip to content
Snippets Groups Projects
Commit d7a9ff32 authored by kasperlauge's avatar kasperlauge
Browse files

tweaked frontend

parent 435f1473
No related branches found
No related tags found
1 merge request!1Swagger improvements
......@@ -43,12 +43,12 @@ export class LedPresentationComponent implements OnInit {
setOff(id: number) {
this.sensorService.setLED(id, false).pipe(takeUntil(this.unsubscribe)).subscribe(result => {
this.getLEDs()
this.leds.find(led => led.id === result.id)[0] = result.value;
});
}
setOn(id: number) {
this.sensorService.setLED(id, true).pipe(takeUntil(this.unsubscribe)).subscribe(result => {
this.getLEDs()
this.leds.find(led => led.id === result.id)[0] = result.value;
});
}
......
......@@ -3,6 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { Observable } from 'rxjs';
import { Dht } from './models/dht.model';
import { LED } from './models/led.model';
@Injectable({
providedIn: 'root'
......@@ -23,7 +24,7 @@ export class SensorService {
return this.http.get<any>(`${this.rootUrl}api/actuator/led`);
}
setLED(id: number, status: boolean): Observable<any> {
setLED(id: number, status: boolean): Observable<LED> {
let data = null
if (status) {
......@@ -37,7 +38,7 @@ export class SensorService {
}
}
return this.http.post<any>(`${this.rootUrl}api/actuator/led/${id}`, data);
return this.http.post<LED>(`${this.rootUrl}api/actuator/led/${id}`, data);
}
getUltraSonic(): Observable<number> {
......
......@@ -8,23 +8,26 @@ export function setLED(req: Request, res: Response, next: NextFunction) {
//Get wanted LED and wished value
const id: string = req.params.id;
const value = req.body["value"];
const newValue = req.body["value"];
if (id == null) {
res.status(401).json({ "msg": "wrong id" })
return
res.status(401).json({ "msg": "wrong id" });
return;
}
if (id != "4" && id != "2" && id != "22") {
res.status(401).json({ "msg": "LED does not exist" })
res.status(401).json({ "msg": "LED does not exist" });
return;
}
if (value == null || !(value === 0 || value === 1)) {
res.status(401).json({ "msg": "invalid input" })
if (newValue == null || !(newValue === 0 || newValue === 1)) {
res.status(401).json({ "msg": "invalid input" });
return;
}
setLEDservice(id, value);
setLEDservice(id, newValue);
const value = getLEDservice(id);
res.status(201).json({});
res.status(201).json({id,value});
}
export function getLED(req: Request, res: Response, next: NextFunction) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment