forked from mtusi2026/mtusi2026lab7
на оценку 4
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"mtusi2026lab7/internal/domain"
|
||||
)
|
||||
|
||||
type CreateMessageRequest struct {
|
||||
Text string `json:"text"`
|
||||
AttachmentIDs []string `json:"attachment_ids"`
|
||||
}
|
||||
|
||||
type MessageResponse struct {
|
||||
ID string `json:"id"`
|
||||
ChatID string `json:"chat_id"`
|
||||
SenderID string `json:"sender_id"`
|
||||
Text string `json:"text"`
|
||||
AttachmentIDs []string `json:"attachment_ids"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type MessagePageResponse struct {
|
||||
Items []MessageResponse `json:"items"`
|
||||
NextCursor *string `json:"next_cursor"`
|
||||
}
|
||||
|
||||
func MessageFromDomain(message domain.Message) MessageResponse {
|
||||
attachmentIDs := append([]string(nil), message.AttachmentIDs...)
|
||||
if attachmentIDs == nil {
|
||||
attachmentIDs = make([]string, 0)
|
||||
}
|
||||
|
||||
return MessageResponse{
|
||||
ID: message.ID, ChatID: message.ChatID, SenderID: message.SenderID,
|
||||
Text: message.Text, AttachmentIDs: attachmentIDs, CreatedAt: message.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func MessagePageFromDomain(page domain.MessagePage) MessagePageResponse {
|
||||
items := make([]MessageResponse, len(page.Items))
|
||||
for index, message := range page.Items {
|
||||
items[index] = MessageFromDomain(message)
|
||||
}
|
||||
return MessagePageResponse{Items: items, NextCursor: page.NextCursor}
|
||||
}
|
||||
Reference in New Issue
Block a user