argos/dmp-backend/web/src/main/java/eu/eudat/controllers/UserInvitationController.java

56 lines
2.7 KiB
Java
Raw Normal View History

2018-01-05 08:47:52 +01:00
package eu.eudat.controllers;
2018-08-31 16:12:31 +02:00
import eu.eudat.data.query.items.item.userinfo.UserInfoRequestItem;
2018-06-27 12:29:21 +02:00
import eu.eudat.logic.managers.InvitationsManager;
2018-08-31 16:12:31 +02:00
import eu.eudat.logic.services.ApiContext;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.invitation.Invitation;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.userinfo.UserInfoInvitationModel;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode;
2018-01-05 08:47:52 +01:00
import org.springframework.beans.factory.annotation.Autowired;
2018-01-05 16:40:19 +01:00
import org.springframework.http.HttpStatus;
2018-01-22 08:41:31 +01:00
import org.springframework.http.ResponseEntity;
2018-01-05 16:40:19 +01:00
import org.springframework.transaction.annotation.Transactional;
2018-01-05 08:47:52 +01:00
import org.springframework.web.bind.annotation.*;
import java.util.List;
2018-01-08 12:44:48 +01:00
import java.util.UUID;
2018-01-05 08:47:52 +01:00
2018-02-01 10:08:06 +01:00
2018-02-09 16:54:41 +01:00
@RequestMapping("api/invite/")
2018-01-05 08:47:52 +01:00
@RestController
@CrossOrigin
2018-02-16 11:34:02 +01:00
public class UserInvitationController extends BaseController {
2018-01-05 08:47:52 +01:00
private InvitationsManager invitationsManager;
2018-01-05 08:47:52 +01:00
@Autowired
public UserInvitationController(ApiContext apiContext, InvitationsManager invitationsManager) {
2018-01-05 08:47:52 +01:00
super(apiContext);
this.invitationsManager = invitationsManager;
2018-01-05 08:47:52 +01:00
}
2018-01-05 16:40:19 +01:00
@Transactional
2018-02-16 11:34:02 +01:00
@RequestMapping(method = RequestMethod.POST, value = {"/users"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
2018-08-31 16:12:31 +02:00
ResponseEntity<ResponseItem<Invitation>> users(@RequestBody Invitation invitation, Principal principal) throws Exception {
this.invitationsManager.inviteUsers(invitation, principal);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Invitation>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Users have beeen invited"));
2018-01-05 08:47:52 +01:00
}
2018-01-08 12:44:48 +01:00
@Transactional
2018-02-16 11:34:02 +01:00
@RequestMapping(method = RequestMethod.GET, value = {"/exchange/{invitationID}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<UUID>> exchange(@PathVariable UUID invitationID, Principal principal) {
UUID dmpId = invitationsManager.assignUserAcceptedInvitation(invitationID, principal);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(dmpId));
2018-01-08 12:44:48 +01:00
}
2018-02-16 11:34:02 +01:00
@RequestMapping(method = RequestMethod.POST, value = {"/getUsers"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
2018-08-31 16:12:31 +02:00
ResponseEntity<ResponseItem<List<UserInfoInvitationModel>>> getUsers(@RequestBody UserInfoRequestItem userInfoRequestItem) throws IllegalAccessException, InstantiationException {
List<UserInfoInvitationModel> users = invitationsManager.getUsers(userInfoRequestItem);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<UserInfoInvitationModel>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(users));
2018-01-05 08:47:52 +01:00
}
}