на оценку 4

This commit is contained in:
2026-11-22 23:33:11 +03:00
parent 20afc2c790
commit cc41f601e3
207 changed files with 22098 additions and 120 deletions
+59
View File
@@ -0,0 +1,59 @@
package dto
import (
"time"
"mtusi2026lab7/internal/domain"
)
type AttachmentVariantResponse struct {
Name string `json:"name"`
ContentType string `json:"content_type"`
SizeBytes int64 `json:"size_bytes"`
Width int `json:"width"`
Height int `json:"height"`
SHA256 string `json:"sha256"`
}
type AttachmentResponse struct {
ID string `json:"id"`
ChatID string `json:"chat_id"`
OwnerID string `json:"owner_id"`
Filename string `json:"filename"`
ContentType string `json:"content_type"`
SizeBytes int64 `json:"size_bytes"`
SHA256 string `json:"sha256"`
Status domain.AttachmentStatus `json:"status"`
Variants []AttachmentVariantResponse `json:"variants"`
ErrorCode *string `json:"error_code"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func AttachmentFromDomain(attachment domain.Attachment) AttachmentResponse {
variants := make([]AttachmentVariantResponse, 0, len(attachment.Variants))
for _, variant := range attachment.Variants {
variants = append(variants, AttachmentVariantResponse{
Name: variant.Name,
ContentType: variant.ContentType,
SizeBytes: variant.SizeBytes,
Width: variant.Width,
Height: variant.Height,
SHA256: variant.SHA256,
})
}
return AttachmentResponse{
ID: attachment.ID,
ChatID: attachment.ChatID,
OwnerID: attachment.OwnerID,
Filename: attachment.Filename,
ContentType: attachment.ContentType,
SizeBytes: attachment.SizeBytes,
SHA256: attachment.SHA256,
Status: attachment.Status,
Variants: variants,
ErrorCode: attachment.ErrorCode,
CreatedAt: attachment.CreatedAt,
UpdatedAt: attachment.UpdatedAt,
}
}
+38
View File
@@ -0,0 +1,38 @@
package dto
import (
"time"
"mtusi2026lab7/internal/domain"
)
type CreateChatRequest struct {
Title string `json:"title"`
MemberIDs []string `json:"member_ids"`
}
type ChatResponse struct {
ID string `json:"id"`
Title string `json:"title"`
MemberIDs []string `json:"member_ids"`
CreatedAt time.Time `json:"created_at"`
}
type ChatPageResponse struct {
Items []ChatResponse `json:"items"`
NextCursor *string `json:"next_cursor"`
}
func ChatFromDomain(chat domain.Chat) ChatResponse {
return ChatResponse{
ID: chat.ID, Title: chat.Title, MemberIDs: chat.MemberIDs, CreatedAt: chat.CreatedAt,
}
}
func ChatPageFromDomain(page domain.ChatPage) ChatPageResponse {
items := make([]ChatResponse, len(page.Items))
for index, chat := range page.Items {
items[index] = ChatFromDomain(chat)
}
return ChatPageResponse{Items: items, NextCursor: page.NextCursor}
}
+46
View File
@@ -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}
}
+21
View File
@@ -0,0 +1,21 @@
package dto
import (
"time"
"mtusi2026lab7/internal/domain"
)
type SessionResponse struct {
Token string `json:"token"`
TokenType string `json:"token_type"`
ExpiresAt time.Time `json:"expires_at"`
User UserResponse `json:"user"`
}
func SessionFromDomain(session domain.Session) SessionResponse {
return SessionResponse{
Token: session.Token, TokenType: session.TokenType, ExpiresAt: session.ExpiresAt,
User: UserFromDomain(session.User),
}
}
+26
View File
@@ -0,0 +1,26 @@
package dto
import (
"time"
"mtusi2026lab7/internal/domain"
)
type CreateUserRequest struct {
Username string `json:"username"`
DisplayName string `json:"display_name"`
Password string `json:"password"`
}
type UserResponse struct {
ID string `json:"id"`
Username string `json:"username"`
DisplayName string `json:"display_name"`
CreatedAt time.Time `json:"created_at"`
}
func UserFromDomain(user domain.User) UserResponse {
return UserResponse{
ID: user.ID, Username: user.Username, DisplayName: user.DisplayName, CreatedAt: user.CreatedAt,
}
}