chore: import lab2 baseline
Skeleton contracts / contracts (push) Failing after 40s
Skeleton contracts / contracts (pull_request) Failing after 38s

This commit is contained in:
2026-10-02 15:50:49 +03:00
parent 0ab3a341aa
commit b5583a813e
39 changed files with 3405 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
package model
import (
"encoding/json"
"time"
)
const timestampLayout = "2006-01-02T15:04:05.000000Z"
type User struct {
ID string `json:"id"`
Username string `json:"username"`
DisplayName string `json:"display_name"`
CreatedAt time.Time `json:"created_at"`
}
type UserCredentials struct {
User
PasswordHash string `json:"-"`
}
type Chat struct {
ID string `json:"id"`
Title string `json:"title"`
MemberIDs []string `json:"member_ids"`
CreatedAt time.Time `json:"created_at"`
}
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"`
}
type Position struct {
CreatedAt time.Time
ID string
}
type userJSON struct {
ID string `json:"id"`
Username string `json:"username"`
DisplayName string `json:"display_name"`
CreatedAt string `json:"created_at"`
}
type chatJSON struct {
ID string `json:"id"`
Title string `json:"title"`
MemberIDs []string `json:"member_ids"`
CreatedAt string `json:"created_at"`
}
type messageJSON struct {
ID string `json:"id"`
ChatID string `json:"chat_id"`
SenderID string `json:"sender_id"`
Text string `json:"text"`
CreatedAt string `json:"created_at"`
}
func (u User) MarshalJSON() ([]byte, error) {
return json.Marshal(userJSON{u.ID, u.Username, u.DisplayName, formatTime(u.CreatedAt)})
}
func (c Chat) MarshalJSON() ([]byte, error) {
return json.Marshal(chatJSON{c.ID, c.Title, c.MemberIDs, formatTime(c.CreatedAt)})
}
func (m Message) MarshalJSON() ([]byte, error) {
return json.Marshal(messageJSON{m.ID, m.ChatID, m.SenderID, m.Text, formatTime(m.CreatedAt)})
}
func FormatTime(value time.Time) string {
return formatTime(value)
}
func formatTime(value time.Time) string {
return value.UTC().Format(timestampLayout)
}
+18
View File
@@ -0,0 +1,18 @@
package model
import (
"encoding/json"
"testing"
"time"
)
func TestUserTimestampHasFixedMicroseconds(t *testing.T) {
createdAt := time.Date(2026, time.September, 23, 21, 28, 15, 423030000, time.UTC)
data, err := json.Marshal(User{ID: "id", Username: "user", DisplayName: "User", CreatedAt: createdAt})
if err != nil {
t.Fatalf("Marshal() error = %v", err)
}
if string(data) != `{"id":"id","username":"user","display_name":"User","created_at":"2026-09-23T21:28:15.423030Z"}` {
t.Fatalf("Marshal() = %s", data)
}
}