This commit is contained in:
@@ -86,6 +86,9 @@ func GetPost(w http.ResponseWriter, r *http.Request) {
|
||||
dto.Attachments = []AttachmentDTO{}
|
||||
}
|
||||
tags, _ := loadPostTagNames(r.Context(), pool, id, requestLangCode(r))
|
||||
if tags == nil {
|
||||
tags = []string{}
|
||||
}
|
||||
dto.Tags = tags
|
||||
writeJSON(w, dto)
|
||||
}
|
||||
@@ -198,6 +201,7 @@ func collectPostRows(r *http.Request, rows pgx.Rows) ([]PostDTO, error) {
|
||||
uid, _ := uuid.Parse(dto.ID)
|
||||
ids = append(ids, uid)
|
||||
dto.Attachments = []AttachmentDTO{}
|
||||
dto.Tags = []string{}
|
||||
list = append(list, dto)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
@@ -207,11 +211,21 @@ func collectPostRows(r *http.Request, rows pgx.Rows) ([]PostDTO, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lang := requestLangCode(r)
|
||||
tagsByPost, err := loadPostTagNamesByPostIDs(r.Context(), poolFrom(r), ids, lang)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range list {
|
||||
uid, _ := uuid.Parse(list[i].ID)
|
||||
if a, ok := atts[uid]; ok {
|
||||
list[i].Attachments = a
|
||||
}
|
||||
if t, ok := tagsByPost[uid]; ok {
|
||||
list[i].Tags = t
|
||||
} else {
|
||||
list[i].Tags = []string{}
|
||||
}
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user