forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Attachment contains private persistence metadata and the public file description.
|
||||
type Attachment struct {
|
||||
// Variants contains generated immutable objects.
|
||||
Variants []Variant
|
||||
// ErrorCode is a safe terminal failure category.
|
||||
ErrorCode *string
|
||||
// PipelineVersion fences older processing jobs.
|
||||
PipelineVersion int
|
||||
// ID identifies the immutable upload.
|
||||
ID uuid.UUID
|
||||
// ChatID defines the authorization scope.
|
||||
ChatID uuid.UUID
|
||||
// OwnerID identifies the uploader.
|
||||
OwnerID uuid.UUID
|
||||
// Filename is display-only and never an object path.
|
||||
Filename string
|
||||
// ContentType is validated against decoded bytes.
|
||||
ContentType string
|
||||
// SizeBytes is the original encoded length.
|
||||
SizeBytes int64
|
||||
// SHA256 is the lowercase original checksum.
|
||||
SHA256 string
|
||||
// Status is the durable upload state.
|
||||
Status string
|
||||
// ObjectKey is private and must not reach HTTP responses.
|
||||
ObjectKey string
|
||||
// CreatedAt is the reservation timestamp.
|
||||
CreatedAt time.Time
|
||||
// UpdatedAt is the latest durable transition.
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// Variant describes a generated object; ObjectKey is persistence-only.
|
||||
type Variant struct {
|
||||
// Name is the contract variant name.
|
||||
Name string `json:"name"`
|
||||
// ContentType identifies the actual encoding.
|
||||
ContentType string `json:"content_type"`
|
||||
// Width is the decoded pixel width.
|
||||
Width int `json:"width"`
|
||||
// Height is the decoded pixel height.
|
||||
Height int `json:"height"`
|
||||
// SizeBytes is the encoded length.
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
// SHA256 is the encoded checksum.
|
||||
SHA256 string `json:"sha256"`
|
||||
// ObjectKey is not copied into HTTP responses.
|
||||
ObjectKey string `json:"object_key,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
// 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 {
|
||||
// AttachmentIDs references ordered immutable files in the same chat.
|
||||
AttachmentIDs []string
|
||||
// IdempotencyKey identifies a validated retry within the sender and chat scope.
|
||||
IdempotencyKey string
|
||||
// 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 {
|
||||
// AttachmentIDs references ordered immutable files in the same chat.
|
||||
AttachmentIDs []string
|
||||
// IdempotencyKey identifies a validated retry within the sender and chat scope.
|
||||
IdempotencyKey string
|
||||
// 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,102 @@
|
||||
// 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 {
|
||||
// AttachmentIDs references up to ten files of this chat.
|
||||
AttachmentIDs []string `json:"attachment_ids"`
|
||||
// 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 {
|
||||
// AttachmentIDs references up to ten files of this chat.
|
||||
AttachmentIDs []string `json:"attachment_ids"`
|
||||
// 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