mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
7.0 KiB
7.0 KiB
description
| description |
|---|
| Controller for loading chat messages for users and groups with pagination. |
ChatLoadController
Controller Description
- Route:
api/chats - Authorize: Requires authenticated user with roles "Admin" or "User" (
[Authorize(Roles = "Admin, User")]).
Endpoints
GetGroupMessages
- Description: Retrieves messages from a specified group chat with pagination.
- Route:
[GET] api/chats/group-messages - HTTP Method:
GET - Request:
- Path Parameter:
chatId(Guid, required): ID of the group chat. - Query Parameter:
query(MessageQuery, required) with:startMessageId(Guid?, optional): ID of the starting message.before(int, default=20): Number of messages before the start.after(int, default=2): Number of messages after the start.
- Path Parameter:
- Responses:
-
200 OK: Returns a list of group chat messages.
[ { "id": "Guid", "senderId": "Guid", "recipientId": "Guid", "recipientType": "string", "encryptedContent": "string", "sentAt": "DateTime", "isEdited": "boolean", "editedAt": "DateTime?", "replyToMessageId": "Guid?", "mediaAttachments": [ { "id": "Guid", "messageId": "Guid", "mediaFileId": "Guid" } ], "reactions": [ { "id": "Guid", "messageId": "Guid", "userId": "Guid", "reactionCode": "string", "reactedAt": "DateTime" } ], "messageViews": [ { "id": "Guid", "messageId": "Guid", "userId": "Guid", "viewedAt": "DateTime" } ] } ] -
400 Bad Request:
- If
beforeorafteris negative or total exceeds 100:"Values must be non-negative and total must not exceed 100." - If an argument or resource is invalid:
"string"
- If
-
403 Forbidden: If user lacks authorization.
"string" -
500 Internal Server Error: Indicates an unexpected error.
"Unexpected Error! Please try again later."
-
GetUserMessages
- Description: Retrieves messages from a specified user chat with pagination.
- Route:
[GET] api/chats/user-messages - HTTP Method:
GET - Request:
- Path Parameter:
userId(Guid, required): ID of the target user. - Query Parameter:
query(MessageQuery, required) with:startMessageId(Guid?, optional): ID of the starting message.before(int, default=20): Number of messages before the start.after(int, default=2): Number of messages after the start.
- Path Parameter:
- Responses:
-
200 OK: Returns a list of user chat messages.
[ { "id": "Guid", "senderId": "Guid", "recipientId": "Guid", "recipientType": "string", "encryptedContent": "string", "sentAt": "DateTime", "isEdited": "boolean", "editedAt": "DateTime?", "replyToMessageId": "Guid?", "mediaAttachments": [ { "id": "Guid", "messageId": "Guid", "mediaFileId": "Guid" } ], "reactions": [ { "id": "Guid", "messageId": "Guid", "userId": "Guid", "reactionCode": "string", "reactedAt": "DateTime" } ], "messageViews": [ { "id": "Guid", "messageId": "Guid", "userId": "Guid", "viewedAt": "DateTime" } ] } ] -
400 Bad Request:
- If
beforeorafteris negative or total exceeds 100:"Values must be non-negative and total must not exceed 100." - If an operation or resource is invalid:
"string"
- If
-
403 Forbidden: If user lacks authorization.
"string" -
500 Internal Server Error: Indicates an unexpected error.
"Unexpected Error! Please try again later."
-
Data Models
MessageQuery
-
Description: Model for pagination query parameters.
-
Structure:
{ "startMessageId": "Guid?", "before": "int", "after": "int" }
MessageResponse
-
Description: Data transfer object for chat message details.
-
Structure:
{ "id": "Guid", "senderId": "Guid", "recipientId": "Guid", "recipientType": "string", "encryptedContent": "string", "sentAt": "DateTime", "isEdited": "boolean", "editedAt": "DateTime?", "replyToMessageId": "Guid?", "mediaAttachments": [ { "id": "Guid", "messageId": "Guid", "mediaFileId": "Guid" } ], "reactions": [ { "id": "Guid", "messageId": "Guid", "userId": "Guid", "reactionCode": "string", "reactedAt": "DateTime" } ], "messageViews": [ { "id": "Guid", "messageId": "Guid", "userId": "Guid", "viewedAt": "DateTime" } ] }
MediaAttachmentResponse
-
Description: Data transfer object for media attachments in messages.
-
Structure:
{ "id": "Guid", "messageId": "Guid", "mediaFileId": "Guid" }
MessageReactionResponse
-
Description: Data transfer object for message reactions.
-
Structure:
{ "id": "Guid", "messageId": "Guid", "userId": "Guid", "reactionCode": "string", "reactedAt": "DateTime" }
MessageViewResponse
-
Description: Data transfer object for message view tracking.
-
Structure:
{ "id": "Guid", "messageId": "Guid", "userId": "Guid", "viewedAt": "DateTime" }
Error Handling
- Invalid User ID: Handled by
ICurrentUserService, aborts if invalid. - Invalid Operations: Returns
400 Bad Requestfor negative values, total exceeding 100, orInvalidOperationException. - Unauthorized Access: Returns
403 ForbiddenforUnauthorizedAccessException. - Resource Not Found: Returns
400 Bad RequestforNotFoundException. - Unexpected Errors: Caught and returned as
500 Internal Server Error.
Logging
- Logs warnings for
UnauthorizedAccessException,NotFoundException,ArgumentException, andInvalidOperationException. - Logs errors for unexpected exceptions.