chore: port lab 1 solution

This commit is contained in:
kk10
2026-10-02 11:45:26 +03:00
parent 65003b6119
commit 2f279a1715
43 changed files with 2402 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
package dto
import (
"mtusi2026-messenger/internal/model"
"strings"
"time"
"unicode/utf8"
"github.com/google/uuid"
)
type CreateMessageRequest struct {
Text string `json:"text"`
}
type MessageResponse struct {
ID uuid.UUID `json:"id"`
ChatID uuid.UUID `json:"chat_id"`
SenderID uuid.UUID `json:"sender_id"`
Text string `json:"text"`
CreatedAt time.Time `json:"created_at"`
}
type MessagePageResponse struct {
Items []MessageResponse `json:"items"`
NextCursor *string `json:"next_cursor"`
}
func (r CreateMessageRequest) Validate() bool {
textLen := utf8.RuneCountInString(r.Text)
if strings.TrimSpace(r.Text) == "" || textLen > 4000 {
return false
}
return true
}
func ToMessageResponse(m model.Message) MessageResponse {
return MessageResponse{
ID: m.ID,
ChatID: m.ChatID,
SenderID: m.SenderID,
Text: m.Text,
CreatedAt: m.CreatedAt,
}
}