forked from mtusi2026/mtusi2026lab3
Перенести актуальную lab2 как базу lab3
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
// Package dto defines the transport-independent data shared by service and store.
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// UserDTO is the public account profile without credentials.
|
||||
type UserDTO struct {
|
||||
// ID is the server-generated user identifier.
|
||||
ID uuid.UUID
|
||||
// Username is the unique lowercase ASCII account name.
|
||||
Username string
|
||||
// DisplayName is the display label, limited to 100 Unicode code points.
|
||||
DisplayName string
|
||||
// CreatedAt is the server-assigned UTC creation time.
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// ChatDTO is a chat with immutable membership.
|
||||
type ChatDTO struct {
|
||||
// ID is the server-generated chat identifier.
|
||||
ID uuid.UUID
|
||||
// Title is the nonblank title, limited to 100 Unicode code points.
|
||||
Title string
|
||||
// MemberIDs contains the fixed set of users allowed to read and write the chat.
|
||||
MemberIDs []uuid.UUID
|
||||
// CreatedAt is the server-assigned UTC creation time.
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// MessageDTO is an immutable message stored in a chat.
|
||||
type MessageDTO struct {
|
||||
// ID is the server-generated message identifier.
|
||||
ID uuid.UUID
|
||||
// ChatID identifies the owning chat.
|
||||
ChatID uuid.UUID
|
||||
// SenderID identifies the user resolved from the request identity.
|
||||
SenderID uuid.UUID
|
||||
// Text contains the original text, limited to 4000 Unicode code points.
|
||||
Text string
|
||||
// CreatedAt is the server-assigned UTC ordering timestamp.
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// UsersCreateRequestDTO carries untrusted registration values into the service.
|
||||
type UsersCreateRequestDTO struct {
|
||||
// Username is the raw requested account name.
|
||||
Username string
|
||||
// DisplayName is the raw requested display label.
|
||||
DisplayName string
|
||||
}
|
||||
|
||||
// ChatsCreateRequestDTO carries untrusted chat creation input.
|
||||
type ChatsCreateRequestDTO struct {
|
||||
// UserID is the caller identifier resolved from a validated session.
|
||||
UserID string
|
||||
// Title is the raw requested chat title.
|
||||
Title string
|
||||
// MemberIDs contains raw user UUIDs; the service checks uniqueness and membership.
|
||||
MemberIDs []string
|
||||
}
|
||||
|
||||
// MessagesCreateRequestDTO carries untrusted message creation input.
|
||||
type MessagesCreateRequestDTO struct {
|
||||
// UserID is the authenticated caller identifier, never a supplied sender field.
|
||||
UserID string
|
||||
// ChatID is the raw chat UUID from the route.
|
||||
ChatID string
|
||||
// Text is the unmodified message text to validate.
|
||||
Text string
|
||||
}
|
||||
|
||||
// PageRequestDTO carries raw pagination values for service-level validation.
|
||||
type PageRequestDTO struct {
|
||||
// UserID is the caller identifier resolved from a validated session.
|
||||
UserID string
|
||||
// ChatID is the requested chat UUID; it is unused when listing chats.
|
||||
ChatID string
|
||||
// Limit is the raw page size; empty selects the contract default.
|
||||
Limit string
|
||||
// Cursor is the opaque continuation token; empty starts at the beginning.
|
||||
Cursor string
|
||||
}
|
||||
|
||||
// PositionDTO is a validated keyset boundary; its zero value starts a history.
|
||||
type PositionDTO struct {
|
||||
// CreatedAt is the timestamp of the last record already returned.
|
||||
CreatedAt time.Time
|
||||
// ID is the tie-breaking identifier of the last record already returned.
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
// ChatPageDTO contains an ordered page of accessible chats.
|
||||
type ChatPageDTO struct {
|
||||
// Items contains at most the requested number of chats.
|
||||
Items []ChatDTO
|
||||
// NextCursor continues the same user-specific list; nil marks its current end.
|
||||
NextCursor *string
|
||||
}
|
||||
|
||||
// MessagePageDTO contains an ordered page of chat history.
|
||||
type MessagePageDTO struct {
|
||||
// Items contains at most the requested number of messages.
|
||||
Items []MessageDTO
|
||||
// NextCursor continues the same chat history; nil marks its current end.
|
||||
NextCursor *string
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dto
|
||||
|
||||
import "time"
|
||||
|
||||
// SessionDTO is an issued session, exposing the raw token only at creation.
|
||||
type SessionDTO struct {
|
||||
// Token contains 256 random bits encoded for a Bearer header.
|
||||
Token string
|
||||
// ExpiresAt is an absolute UTC deadline which is not extended by reads.
|
||||
ExpiresAt time.Time
|
||||
// User is the authenticated account without credentials.
|
||||
User UserDTO
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
// Package http defines the public JSON boundary, separate from DTOs.
|
||||
package http
|
||||
|
||||
import "time"
|
||||
|
||||
// UsersCreateRequest is the registration payload.
|
||||
type UsersCreateRequest struct {
|
||||
// Password is the unmodified Unicode registration secret.
|
||||
Password string `json:"password"`
|
||||
// Username is the unique lowercase ASCII username.
|
||||
Username string `json:"username"`
|
||||
// DisplayName is the user-visible name, limited to 100 Unicode code points.
|
||||
DisplayName string `json:"display_name"`
|
||||
}
|
||||
|
||||
// ChatsCreateRequest is the chat payload.
|
||||
type ChatsCreateRequest struct {
|
||||
// Title is the nonblank chat title, limited to 100 Unicode code points.
|
||||
Title string `json:"title"`
|
||||
// MemberIDs contains unique user UUIDs, including the caller when creating a chat.
|
||||
MemberIDs []string `json:"member_ids"`
|
||||
}
|
||||
|
||||
// MessagesCreateRequest is the message payload.
|
||||
type MessagesCreateRequest struct {
|
||||
// Text contains nonblank text, limited to 4000 Unicode code points.
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
// UserResponse is the public user model.
|
||||
type UserResponse struct {
|
||||
// ID is the canonical server-generated UUID.
|
||||
ID string `json:"id"`
|
||||
// Username is the unique lowercase ASCII username.
|
||||
Username string `json:"username"`
|
||||
// DisplayName is the user-visible name, limited to 100 Unicode code points.
|
||||
DisplayName string `json:"display_name"`
|
||||
// CreatedAt is the UTC creation time serialized as RFC 3339.
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// ChatResponse is the public chat model.
|
||||
type ChatResponse struct {
|
||||
// ID is the canonical server-generated UUID.
|
||||
ID string `json:"id"`
|
||||
// Title is the nonblank chat title, limited to 100 Unicode code points.
|
||||
Title string `json:"title"`
|
||||
// MemberIDs contains unique user UUIDs, including the caller when creating a chat.
|
||||
MemberIDs []string `json:"member_ids"`
|
||||
// CreatedAt is the UTC creation time serialized as RFC 3339.
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// MessageResponse is the public message model.
|
||||
type MessageResponse struct {
|
||||
// ID is the canonical server-generated UUID.
|
||||
ID string `json:"id"`
|
||||
// ChatID is the canonical UUID of the chat containing the message.
|
||||
ChatID string `json:"chat_id"`
|
||||
// SenderID is derived from the request identity, never from a client-supplied sender.
|
||||
SenderID string `json:"sender_id"`
|
||||
// Text contains nonblank text, limited to 4000 Unicode code points.
|
||||
Text string `json:"text"`
|
||||
// CreatedAt is the UTC creation time serialized as RFC 3339.
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// ChatPageResponse contains visible chats.
|
||||
type ChatPageResponse struct {
|
||||
// Items contains the ordered page records; an empty page is serialized as an empty array.
|
||||
Items []ChatResponse `json:"items"`
|
||||
// NextCursor is the opaque continuation token or null when the current page is last.
|
||||
NextCursor *string `json:"next_cursor"`
|
||||
}
|
||||
|
||||
// MessagePageResponse contains the requested history page.
|
||||
type MessagePageResponse struct {
|
||||
// Items contains the ordered page records; an empty page is serialized as an empty array.
|
||||
Items []MessageResponse `json:"items"`
|
||||
// NextCursor is the opaque continuation token or null when the current page is last.
|
||||
NextCursor *string `json:"next_cursor"`
|
||||
}
|
||||
|
||||
// ErrorResponse is the mandatory error envelope.
|
||||
type ErrorResponse struct {
|
||||
// Error contains the safe public error details.
|
||||
Error ErrorDetail `json:"error"`
|
||||
}
|
||||
|
||||
// ErrorDetail never exposes internal errors or input contents.
|
||||
type ErrorDetail struct {
|
||||
// Code is one of the machine-readable error codes declared by the API contract.
|
||||
Code string `json:"code"`
|
||||
// Message is a safe public explanation without internal errors or input contents.
|
||||
Message string `json:"message"`
|
||||
// RequestID matches the X-Request-Id response header for log correlation.
|
||||
RequestID string `json:"request_id"`
|
||||
}
|
||||
Reference in New Issue
Block a user