Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Controller
- @RequestMapping(value = "/tickets", method = RequestMethod.GET)
- public ResponseEntity<List<TicketDto>> getAllTickets() {
- List<TicketDto> tickets = ticketService.findAllTickets(getUser());
- return new ResponseEntity<List<TicketDto>>(tickets, HttpStatus.OK);
- }
- private User getUser() {
- Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
- String name = authentication.getName();
- return userService.findByEmail(name);
- }
- // Service
- @Service
- public class TicketServiceImpl implements TicketService {
- @Autowired
- private TicketRepository ticketRepository;
- @Transactional(readOnly = true)
- public List<TicketDto> findAllTickets(User user) {
- List<Ticket> ticketList = new ArrayList<>();
- if (user.getRole().equals(Role.EMPLOYEE)) {
- ticketList = ticketRepository.findAllTicketsByEmployee(user.getId());
- } else if (user.getRole().equals(Role.MANAGER)) {
- ticketList = ticketRepository.findAllTicketsByManager(user.getId());
- } else if (user.getRole().equals(Role.ENGINEER)) {
- ticketList = ticketRepository.findAllTicketsByEngineer(user.getId());
- }
- TicketConverter ticketConverter = new TicketConverter();
- List<TicketDto> ticketListDto = ticketConverter.convertEntityListToDtoList(ticketList);
- return ticketListDto;
- }
- // ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement