| 1 | package edu.ucsb.cs156.gauchoride.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.gauchoride.entities.ChatMessage; | |
| 4 | import edu.ucsb.cs156.gauchoride.models.ChatMessageWithUserInfo; | |
| 5 | import edu.ucsb.cs156.gauchoride.repositories.ChatMessageRepository; | |
| 6 | ||
| 7 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | ||
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.data.domain.Page; | |
| 13 | import org.springframework.data.domain.PageRequest; | |
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.web.bind.annotation.GetMapping; | |
| 16 | import org.springframework.web.bind.annotation.PostMapping; | |
| 17 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestParam; | |
| 19 | import org.springframework.web.bind.annotation.RestController; | |
| 20 | import org.springframework.data.domain.Sort; | |
| 21 | ||
| 22 | @Tag(name = "Chat Message") | |
| 23 | @RequestMapping("/api/chat") | |
| 24 | @RestController | |
| 25 | ||
| 26 | public class ChatMessageController extends ApiController { | |
| 27 | ||
| 28 | @Autowired | |
| 29 | ChatMessageRepository chatMessageRepository; | |
| 30 | ||
| 31 | @Operation(summary = "Create a new message") | |
| 32 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
| 33 | @PostMapping("/post") | |
| 34 | public ChatMessage postMessage( | |
| 35 | @Parameter(name="content", description="The message you want to send", example="Hi", required = true) | |
| 36 | @RequestParam String content | |
| 37 | ) | |
| 38 | { | |
| 39 | ||
| 40 | ChatMessage message = new ChatMessage(); | |
| 41 | | |
| 42 |
1
1. postMessage : removed call to edu/ucsb/cs156/gauchoride/entities/ChatMessage::setUserId → KILLED |
message.setUserId(getCurrentUser().getUser().getId()); |
| 43 |
1
1. postMessage : removed call to edu/ucsb/cs156/gauchoride/entities/ChatMessage::setPayload → KILLED |
message.setPayload(content); |
| 44 | ||
| 45 | ChatMessage savedMessage = chatMessageRepository.save(message); | |
| 46 | ||
| 47 |
1
1. postMessage : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ChatMessageController::postMessage → KILLED |
return savedMessage; |
| 48 | } | |
| 49 | ||
| 50 | @Operation(summary = "List all messages with user info") | |
| 51 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
| 52 | @GetMapping("/get") | |
| 53 | public Page<ChatMessageWithUserInfo> allMessagesNewWay( | |
| 54 | @Parameter(name="page") @RequestParam int page, | |
| 55 | @Parameter(name="size") @RequestParam int size | |
| 56 | ) { | |
| 57 | Page<ChatMessageWithUserInfo> messages = chatMessageRepository.findAllWithUserInfo(PageRequest.of(page, size, Sort.by("timestamp").descending())); | |
| 58 |
1
1. allMessagesNewWay : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ChatMessageController::allMessagesNewWay → KILLED |
return messages; |
| 59 | } | |
| 60 | } | |
Mutations | ||
| 42 |
1.1 |
|
| 43 |
1.1 |
|
| 47 |
1.1 |
|
| 58 |
1.1 |