Add message history

This commit is contained in:
2026-01-02 01:14:42 +01:00
parent 08afaa19ee
commit a4c72098b3
9 changed files with 366 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
package be.naaturel.boardmateapi.controllers;
import be.naaturel.boardmateapi.common.exceptions.ServiceException;
import be.naaturel.boardmateapi.common.models.Message;
import be.naaturel.boardmateapi.controllers.dtos.MessageDto;
import be.naaturel.boardmateapi.controllers.dtos.MessagePostRequestDto;
import be.naaturel.boardmateapi.controllers.dtos.ResponseBody;
import be.naaturel.boardmateapi.services.MessageService;
@@ -8,10 +10,9 @@ import be.naaturel.boardmateapi.services.WebexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class ChatController {
@@ -44,7 +45,7 @@ public class ChatController {
return ResponseEntity.
status(HttpStatus.OK)
.body(result);
} catch (Exception e){
} catch (ServiceException e){
result.setMessage(e.getMessage());
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
@@ -52,9 +53,32 @@ public class ChatController {
}
}
@GetMapping("/message/history")
public void history(){
@GetMapping("/message/history/{clientId}")
public ResponseEntity<ResponseBody<List<MessageDto>>> history(
@PathVariable String clientId,
@RequestParam(value = "$top", required = false, defaultValue = "20") int top
) {
ResponseBody<List<MessageDto>> result = ResponseBody.createEmpty();
try {
List<Message> messages = this.messageService.getHistory(clientId, top);
List<MessageDto> dtos = messages.stream()
.map(m -> {
MessageDto dto = new MessageDto();
dto.setContent(m.getContent());
dto.setTimestamp(m.getTimeStamp());
return dto;
})
.toList();
result.setSuccess(true);
result.setData(dtos);
return ResponseEntity.status(HttpStatus.OK).body(result);
} catch (ServiceException e) {
result.setMessage(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
}
}
}