[SECARSP-115] *add update devices func (lock)
[platform/core/security/suspicious-activity-monitor.git] / server / src / main / java / com / samsung / samserver / web / rest / controller / impl / RestDashboard.java
1 /*
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.
5  */
6 package com.samsung.samserver.web.rest.controller.impl;
7
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;
19
20 /**
21  * REST dashboard controller.
22  *
23  * @author <A HREF="mailto:m.dalakov@samsung.com">Mykhailo Dalakov</A>
24  * @version 1.0
25  */
26 @RestController
27 public class RestDashboard  implements IRestDashboard {
28
29     @Autowired
30     private DeviceService deviceService;
31
32     @Autowired
33     private UserJWTService userJWTService;
34
35     @Autowired
36     private AccountService accountService;
37
38     @Autowired
39     private GetDevicesRestService getDevicesRestService;
40
41     @Autowired
42     private UpdateDevicesRestService updateDevicesRestService;
43
44     /**
45      * GET  /devices : get all the devices.
46      *
47      * @return the ResponseEntity with status 200 (OK) and the list of devices in body
48      */
49     @Override
50     public ResponseEntity<List<GetDevicesRestService.UIDevice>> getAllDevices(Pageable pageable) {
51         return getDevicesRestService.getAllDevices(pageable);
52     }
53
54     /**
55      * POST request login
56      *
57      * @return the ResponseEntity with status 200 (OK) and JWT
58      */
59     @Override
60     public ResponseEntity<UserJWTService.JWTToken> login(@Valid @RequestBody UserJWTService.UILogin uiLogin) {
61         return userJWTService.authorize(uiLogin);
62     }
63
64     /**
65      * POST request register the user.
66      *
67      * @param uiRegistration the managed user View Model
68      */
69     @Override
70     public void registerAccount(@Valid @RequestBody AccountService.UIRegistration uiRegistration){
71         accountService.registerAccount(uiRegistration);
72     }
73
74     /**
75      * DELETE request logout
76      *
77      * @return the ResponseEntity with status 200 (OK)
78      */
79     @Override
80     public ResponseEntity<Void> logout() {
81         return ResponseEntity.ok().headers(new HttpHeaders()).build();
82     }
83
84     /**
85      * PUT  /devices/update : Updates an existing devices.
86      *
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
90      */
91     @Override
92     public ResponseEntity<Void> updateDevice(@Valid @RequestBody List<UpdateDevicesRestService.UIDeviceUpdate> uiDeviceUpdate) {
93         return updateDevicesRestService.updateDevice(uiDeviceUpdate);
94     }
95
96 }