source: src/main/java/com/example/skychasemk/controller/SupportTicketController.java@ c064a42

Last change on this file since c064a42 was c064a42, checked in by ste08 <sjovanoska@…>, 3 months ago

Support ticket working!

  • Property mode set to 100644
File size: 1.8 KB
Line 
1package com.example.skychasemk.controller;
2
3import ch.qos.logback.core.status.Status;
4import com.example.skychasemk.dto.SupportTicketDTO;
5import com.example.skychasemk.model.SupportTicket;
6import com.example.skychasemk.services.SupportTicketService;
7import org.springframework.beans.factory.annotation.Autowired;
8import org.springframework.http.ResponseEntity;
9import org.springframework.web.bind.annotation.*;
10
11import java.util.List;
12import java.util.Optional;
13
14@RestController
15@RequestMapping("/api/support-tickets")
16public 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, @PathVariable 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}
Note: See TracBrowser for help on using the repository browser.