Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new API endpoint to retrieve the count of unread messages in a user's inbox. The feature enables clients to display unread message counts without fetching all messages.
- Adds
/inbox/unread_countGET endpoint to query unread message count for the current user - Includes comprehensive test coverage verifying the count updates correctly when messages are sent and read
- Implements SQL query filtering on user ID, read status, and delete status
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| muyun-platform/src/main/java/net/ximatai/muyun/platform/controller/InboxController.java | Adds getUnreadCount() method with necessary imports to support the unread message count API endpoint |
| muyun-boot/src/test/java/net/ximatai/muyun/test/plaform/TestMessage.java | Extends existing message flow test to validate unread count returns 1 after sending and 0 after reading |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public Map<String, Object> getUnreadCount() { | ||
| String userId = getUser().getId(); | ||
|
|
||
| List<Map<String, Object>> result = getDB().query( | ||
| "SELECT COUNT(*) as count FROM %s.app_message_person WHERE id_at_auth_user__to = ? AND b_read = false AND b_delete = false" | ||
| .formatted(getSchemaName()), | ||
| userId | ||
| ); | ||
|
|
||
| long count = result.isEmpty() ? 0 : ((Number) result.getFirst().get("count")).longValue(); | ||
| return Map.of("count", count); | ||
| } |
There was a problem hiding this comment.
The return type and API design is inconsistent with the similar ReceiveController.unreadCount() method which returns long directly instead of wrapping it in a Map. Consider returning long directly to maintain consistency:
@GET
@Path("/unread_count")
@Operation(summary = "查询当前用户未读消息数量")
public long getUnreadCount() {
String userId = getUser().getId();
List<Map<String, Object>> result = getDB().query(
"SELECT COUNT(*) as count FROM %s.app_message_person WHERE id_at_auth_user__to = ? AND b_read = false AND b_delete = false"
.formatted(getSchemaName()),
userId
);
return result.isEmpty() ? 0L : ((Number) result.getFirst().get("count")).longValue();
}This would also simplify the test assertions to Assertions.assertEquals(1L, inboxCount); instead of Assertions.assertEquals(1, inboxCount.get("count"));
|
可以考虑 提供 count 接口,然后通过参数过滤是要查询什么条件下的 count |
No description provided.