♻️ Replaced Content domain usage in entry HTTP delivery

This commit is contained in:
Maxim Lebedev 2023-10-26 12:18:52 +06:00
parent 2485f65747
commit 281afb0987
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 14 additions and 6 deletions

View File

@ -327,7 +327,12 @@ func (h *Handler) handleUpdate(w http.ResponseWriter, r *http.Request) {
req.populate(in) req.populate(in)
out, err := h.entries.Update(r.Context(), req.URL.URL, *in) out, err := h.entries.Update(r.Context(), req.URL.URL, entry.UpdateOptions{
// TODO(toby3d)
// Add: req.Add,
// Replace: req.Replace,
// Delete: req.Delete,
})
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
@ -481,7 +486,8 @@ func (r *RequestCreate) bind(req *http.Request) error {
func (r *RequestCreate) populate(dst *domain.Entry) { func (r *RequestCreate) populate(dst *domain.Entry) {
if len(r.Properties.Content) > 0 { if len(r.Properties.Content) > 0 {
dst.Content = []byte(r.Properties.Content[0].Value) dst.Content.HTML = r.Properties.Content[0].HTML
dst.Content.Text = r.Properties.Content[0].Value
} }
if len(r.Properties.Summary) > 0 { if len(r.Properties.Summary) > 0 {
@ -698,12 +704,13 @@ func NewResponseSource(src *domain.Entry, properties ...string) *ResponseSource
}) })
} }
case "content": case "content":
if len(src.Content) == 0 { if src.Content.Text == "" && src.Content.HTML == nil {
continue continue
} }
out.Properties.Content = append(out.Properties.Content, Content{ out.Properties.Content = append(out.Properties.Content, Content{
Value: string(src.Content), Value: src.Content.Text,
HTML: src.Content.HTML,
}) })
case "category": case "category":
out.Properties.Category = append(out.Properties.Category, src.Tags...) out.Properties.Category = append(out.Properties.Category, src.Tags...)
@ -735,7 +742,8 @@ func (p Properties) CopyTo(dst *domain.Entry) {
} }
if len(p.Content) > 0 { if len(p.Content) > 0 {
dst.Content = []byte(p.Content[0].Value) dst.Content.HTML = p.Content[0].HTML
dst.Content.Text = p.Content[0].Value
} }
if len(p.Name) > 0 { if len(p.Name) > 0 {
@ -796,7 +804,7 @@ func (d Delete) CopyTo(dst *domain.Entry) {
case "category": case "category":
dst.Tags = make([]string, 0) dst.Tags = make([]string, 0)
case "content": case "content":
dst.Content = make([]byte, 0) dst.Content = domain.Content{}
case "name": case "name":
dst.Title = "" dst.Title = ""
case "photo": case "photo":