2017-12-15 11:26:25 +01:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
2018-01-31 16:39:16 +01:00
|
|
|
import eu.eudat.managers.UserManager;
|
|
|
|
import eu.eudat.models.helpers.common.DataTableData;
|
|
|
|
import eu.eudat.models.helpers.responses.ResponseItem;
|
|
|
|
import eu.eudat.models.security.Principal;
|
|
|
|
import eu.eudat.models.userinfo.UserInfoTableRequestItem;
|
|
|
|
import eu.eudat.models.userinfo.UserListingModel;
|
|
|
|
import eu.eudat.security.claims.ClaimedAuthorities;
|
2018-01-04 10:32:39 +01:00
|
|
|
import eu.eudat.services.ApiContext;
|
2018-01-31 16:39:16 +01:00
|
|
|
import eu.eudat.types.ApiMessageCode;
|
2017-12-15 11:26:25 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-01-31 16:39:16 +01:00
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
|
|
import static eu.eudat.types.Authorities.ADMIN;
|
2017-12-15 11:26:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2018-02-09 16:54:41 +01:00
|
|
|
@RequestMapping(value = "api/user")
|
2018-01-31 16:39:16 +01:00
|
|
|
public class Users extends BaseController {
|
2018-01-04 10:32:39 +01:00
|
|
|
|
2018-01-31 16:39:16 +01:00
|
|
|
@Autowired
|
|
|
|
public Users(ApiContext apiContext) {
|
|
|
|
super(apiContext);
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:04:36 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, consumes = "application/json", produces = "application/json")
|
2018-01-31 16:39:16 +01:00
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity<ResponseItem<DataTableData<UserListingModel>>> getPaged(@Valid @RequestBody UserInfoTableRequestItem userInfoTableRequestItem, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
|
|
|
|
try {
|
2018-02-16 08:45:18 +01:00
|
|
|
DataTableData<UserListingModel> dataTable = UserManager.getPaged(this.getApiContext(), userInfoTableRequestItem);
|
2018-01-31 16:39:16 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<UserListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<UserListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
2018-02-01 15:04:36 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/updateRoles"}, consumes = "application/json", produces = "application/json")
|
2018-01-31 16:39:16 +01:00
|
|
|
public @ResponseBody
|
2018-02-01 15:04:36 +01:00
|
|
|
ResponseEntity<ResponseItem<UserListingModel>> updateRoles(@Valid @RequestBody UserListingModel userListingModel, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
|
2018-01-31 16:39:16 +01:00
|
|
|
try {
|
|
|
|
UserManager.editRoles(this.getApiContext(), userListingModel);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserListingModel>().status(ApiMessageCode.NO_MESSAGE));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<UserListingModel>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-15 11:26:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-17 13:03:51 +01:00
|
|
|
|
2017-12-15 11:26:25 +01:00
|
|
|
|