mercury/web/api/post.go

35 lines
767 B
Go

package api
import (
"git.sleepycat.moe/sam/mercury/internal/database"
"github.com/oklog/ulid/v2"
)
type Post struct {
ID ulid.ULID `json:"id"`
Content *string `json:"content"`
Source *string `json:"source"`
Visibility database.PostVisibility `json:"visibility"`
Blog postPartialBlog `json:"blog"`
}
type postPartialBlog struct {
ID ulid.ULID `json:"id"`
Name string `json:"name"`
Domain *string `json:"domain"`
}
func DBPostToPost(p database.Post, b database.Blog) Post {
return Post{
ID: p.ID,
Content: p.Content,
Source: p.Source,
Visibility: p.Visibility,
Blog: postPartialBlog{
ID: p.BlogID,
Name: b.Name,
Domain: b.Domain,
},
}
}