package org.ros.chatto.controller; import java.security.Principal; import java.time.Instant; import java.util.Date; import java.util.List; import javax.validation.Valid; import org.ros.chatto.dto.ChatMessageDTO; import org.ros.chatto.dto.ReencryptionDTO; import org.ros.chatto.service.ChatService; import org.ros.chatto.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/api/admin") public class AdminRESTController { @Autowired private ChatService chatService; @Autowired private UserService userService; @PostMapping(value = "/post/re-encrypt", consumes = { "application/json" }) public ResponseEntity reencryptMessages( @RequestBody @Valid List reencryptionDTOs, Principal principal) { if (reencryptionDTOs.size() > 0) { chatService.reencryptMessages(reencryptionDTOs); } return new ResponseEntity(HttpStatus.OK); } @GetMapping(value = "/get/messages/{userName}") public List sendAllMessages(@PathVariable String userName, Principal principal) { List reencryptionDTOs = chatService .getAllMessagesForReencryption(principal.getName(), userName); return reencryptionDTOs; } @GetMapping(value = "/get/messages/{userName}/{lastMessageTime}") public List sendNewMessages(@PathVariable String userName, @PathVariable Instant lastMessageTime, Principal principal) { List chatMessageDTOs = chatService.getNewMessages( principal.getName(), userName, Date.from(lastMessageTime)); return chatMessageDTOs; } @GetMapping("/get/users") public List getAllOtherUsers(Principal principal) { return userService.findAllOtherUsers(principal.getName()); } }