1 | package com.example.skychasemk.controller;
|
---|
2 |
|
---|
3 | import ch.qos.logback.core.status.Status;
|
---|
4 | import com.example.skychasemk.dto.SupportTicketDTO;
|
---|
5 | import com.example.skychasemk.model.SupportTicket;
|
---|
6 | import com.example.skychasemk.services.SupportTicketService;
|
---|
7 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
8 | import org.springframework.http.ResponseEntity;
|
---|
9 | import org.springframework.web.bind.annotation.*;
|
---|
10 |
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.Optional;
|
---|
13 |
|
---|
14 | @RestController
|
---|
15 | @RequestMapping("/api/support-tickets")
|
---|
16 | public class SupportTicketController {
|
---|
17 |
|
---|
18 | @Autowired
|
---|
19 | private SupportTicketService supportTicketService;
|
---|
20 |
|
---|
21 | @GetMapping
|
---|
22 | public List<SupportTicket> getAllTickets() {
|
---|
23 | return supportTicketService.getAllTickets();
|
---|
24 | }
|
---|
25 | @GetMapping("/resolved")
|
---|
26 | public List<SupportTicket> getResolvedTickets() {
|
---|
27 | return supportTicketService.getResolvedTickets();
|
---|
28 | }
|
---|
29 |
|
---|
30 | @GetMapping("/{id}")
|
---|
31 | public Optional<SupportTicket> getTicketById(@PathVariable("id") Integer ticketID) {
|
---|
32 | return supportTicketService.getTicketById(ticketID);
|
---|
33 | }
|
---|
34 |
|
---|
35 | @PostMapping
|
---|
36 | public ResponseEntity<SupportTicket> submitTicket(@RequestBody SupportTicketDTO dto) {
|
---|
37 | SupportTicket ticket = supportTicketService.createTicket(dto);
|
---|
38 | return ResponseEntity.ok(ticket);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @PutMapping("/{ticketID}/status")
|
---|
42 | public ResponseEntity<SupportTicket> updateTicket(@PathVariable("ticketID") Integer ticketID, @RequestBody String status) {
|
---|
43 | try {
|
---|
44 | SupportTicket.TicketStatus newStatus = SupportTicket.TicketStatus.valueOf(status.toUpperCase());
|
---|
45 | return ResponseEntity.ok(supportTicketService.updateTicket(ticketID, newStatus));
|
---|
46 | } catch (IllegalArgumentException e) {
|
---|
47 | return ResponseEntity.badRequest().build();
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | }
|
---|