1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sourceforge.mystique.application;
22
23 import java.util.List;
24
25 import net.sourceforge.mystique.domain.entity.Attachment;
26 import net.sourceforge.mystique.domain.entity.Ticket;
27 import net.sourceforge.mystique.domain.repository.AttachmentRepository;
28 import net.sourceforge.mystique.domain.repository.Repository;
29 import net.sourceforge.mystique.domain.repository.RepositoryException;
30 import net.sourceforge.mystique.domain.repository.TicketRepository;
31
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Controller;
34 import org.springframework.ui.Model;
35 import org.springframework.web.bind.annotation.RequestMapping;
36 import org.springframework.web.bind.annotation.RequestParam;
37
38
39
40
41 @Controller
42 public class AttachmentController {
43
44 @Autowired
45 private TicketRepository ticketRepository;
46
47 @Autowired
48 private AttachmentRepository attachmentRepository;
49
50 @RequestMapping("/ticket/attachment/list.xhtml")
51 public String handleList(@RequestParam("ticketId") Long ticketId, Model model) throws RepositoryException {
52
53 Ticket ticket = ticketRepository.findById(ticketId);
54 List<Attachment> list = attachmentRepository.findByTicket(ticket, 0, Repository.SMALL_RESULT);
55
56 model.addAttribute("ticket", ticket);
57 model.addAttribute("list", list);
58
59 return "ticket.attachment.list";
60
61 }
62
63 @RequestMapping("/ticket/attachment/remove.xhtml")
64
65 public String handleRemove(@RequestParam("attachmentId") Long attachmentId) throws RepositoryException {
66
67 Attachment attachment = attachmentRepository.findById(attachmentId);
68 Long ticketId = attachment.getTicket().getId();
69 attachmentRepository.remove(attachment);
70
71 return "redirect:list.xhtml?ticketId=" + ticketId;
72
73 }
74
75 }