diff --git a/api/models.go b/api/models.go new file mode 100644 index 0000000..c5395d2 --- /dev/null +++ b/api/models.go @@ -0,0 +1,68 @@ +package main + +import "time" + +// Author — human or agent, single identity model. +type Author struct { + ID string `json:"id"` + Kind string `json:"kind"` // "human" | "agent" | "system" + DisplayName string `json:"display_name"` + AvatarURL string `json:"avatar_url,omitempty"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + +// Channel — lightweight, optional, many-to-many with posts. +type Channel struct { + Slug string `json:"slug"` + Name string `json:"name"` + Description string `json:"description"` + CreatedAt time.Time `json:"created_at"` +} + +// Post — the primitive. Always lives in 0..N channels. +type Post struct { + ID string `json:"id"` + AuthorID string `json:"author_id"` + Title string `json:"title"` + Body string `json:"body"` + BumpedAt time.Time `json:"bumped_at"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + IsDeleted bool `json:"is_deleted,omitempty"` + ParentPost string `json:"parent_post,omitempty"` + Channels []string `json:"channels,omitempty"` +} + +// Comment — nested to arbitrary depth via path. +type Comment struct { + ID string `json:"id"` + PostID string `json:"post_id"` + ParentID string `json:"parent_id,omitempty"` + Path string `json:"path"` + Depth int `json:"depth"` + AuthorID string `json:"author_id"` + Body string `json:"body"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + IsDeleted bool `json:"is_deleted,omitempty"` +} + +// PostWithComments — for /api/posts/:id (the unit of rendering). +type PostWithComments struct { + Post Post `json:"post"` + Comments []Comment `json:"comments"` +} + +// CreatePostRequest — input shape. +type CreatePostRequest struct { + Title string `json:"title"` + Body string `json:"body"` + Channels []string `json:"channels,omitempty"` +} + +// CreateCommentRequest — input shape. +type CreateCommentRequest struct { + ParentID string `json:"parent_id,omitempty"` + Body string `json:"body"` +}