lab2: postgres, sessions, redis, persistence, stale read
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-09 21:30:36 +03:00
parent 65003b6119
commit d8842a3de4
54 changed files with 3205 additions and 19 deletions
+30
View File
@@ -0,0 +1,30 @@
package domain
import (
"encoding/json"
"time"
)
type Chat struct {
ID string `json:"id"`
Title string `json:"title"`
MemberIDs []string `json:"member_ids"`
CreatedAt time.Time `json:"created_at"`
}
func (c Chat) MarshalJSON() ([]byte, error) {
type Alias Chat
members := c.MemberIDs
if members == nil {
members = []string{}
}
return json.Marshal(&struct {
Alias
MemberIDs []string `json:"member_ids"`
CreatedAt string `json:"created_at"`
}{
Alias: Alias(c),
MemberIDs: members,
CreatedAt: c.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
})
}
+25
View File
@@ -0,0 +1,25 @@
package domain
import (
"encoding/json"
"time"
)
type Message struct {
ID string `json:"id"`
ChatID string `json:"chat_id"`
SenderID string `json:"sender_id"`
Text string `json:"text"`
CreatedAt time.Time `json:"created_at"`
}
func (m Message) MarshalJSON() ([]byte, error) {
type Alias Message
return json.Marshal(&struct {
Alias
CreatedAt string `json:"created_at"`
}{
Alias: Alias(m),
CreatedAt: m.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
})
}
+10
View File
@@ -0,0 +1,10 @@
package domain
import "time"
type Session struct {
Token string `json:"token"`
UserID string `json:"-"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"-"`
}
+25
View File
@@ -0,0 +1,25 @@
package domain
import (
"encoding/json"
"time"
)
type User struct {
ID string `json:"id"`
Username string `json:"username"`
DisplayName string `json:"display_name"`
CreatedAt time.Time `json:"created_at"`
}
// MarshalJSON форматирует CreatedAt в RFC3339 без микросекунд.
func (u User) MarshalJSON() ([]byte, error) {
type Alias User
return json.Marshal(&struct {
Alias
CreatedAt string `json:"created_at"`
}{
Alias: Alias(u),
CreatedAt: u.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
})
}