2 * In Samsung Ukraine R&D Center (SRK under a contract between)
3 * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 package com.samsung.samserver.web.rest.controller.impl;
8 import com.samsung.samserver.service.DeviceService;
9 import com.samsung.samserver.web.rest.controller.IRestDashboard;
10 import com.samsung.samserver.web.rest.service.*;
11 import com.samsung.samserver.web.rest.service.ui.GetDevicesRestService;
12 import com.samsung.samserver.web.rest.service.ui.UpdateDevicesRestService;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.data.domain.Pageable;
15 import org.springframework.http.*;
16 import org.springframework.web.bind.annotation.*;
17 import javax.validation.Valid;
18 import java.util.List;
21 * REST dashboard controller.
23 * @author <A HREF="mailto:m.dalakov@samsung.com">Mykhailo Dalakov</A>
27 public class RestDashboard implements IRestDashboard {
30 private DeviceService deviceService;
33 private UserJWTService userJWTService;
36 private AccountService accountService;
39 private GetDevicesRestService getDevicesRestService;
42 private UpdateDevicesRestService updateDevicesRestService;
45 * GET /devices : get all the devices.
47 * @return the ResponseEntity with status 200 (OK) and the list of devices in body
50 public ResponseEntity<List<GetDevicesRestService.UIDevice>> getAllDevices(Pageable pageable) {
51 return getDevicesRestService.getAllDevices(pageable);
57 * @return the ResponseEntity with status 200 (OK) and JWT
60 public ResponseEntity<UserJWTService.JWTToken> login(@Valid @RequestBody UserJWTService.UILogin uiLogin) {
61 return userJWTService.authorize(uiLogin);
65 * POST request register the user.
67 * @param uiRegistration the managed user View Model
70 public void registerAccount(@Valid @RequestBody AccountService.UIRegistration uiRegistration){
71 accountService.registerAccount(uiRegistration);
75 * DELETE request logout
77 * @return the ResponseEntity with status 200 (OK)
80 public ResponseEntity<Void> logout() {
81 return ResponseEntity.ok().headers(new HttpHeaders()).build();
85 * PUT /devices/update : Updates an existing devices.
87 * @param uiDeviceUpdate list the device info to update
88 * @return the ResponseEntity with status 200 (OK)
89 * or with status 400 (Bad Request) if the uiDeviceUpdate is not valid
92 public ResponseEntity<Void> updateDevice(@Valid @RequestBody List<UpdateDevicesRestService.UIDeviceUpdate> uiDeviceUpdate) {
93 return updateDevicesRestService.updateDevice(uiDeviceUpdate);