···
"Coves/internal/core/posts"
type postgresPostRepo struct {
···
39
-
// Convert content labels to PostgreSQL array
40
-
var labelsArray pq.StringArray
36
+
// Store content labels as JSONB
37
+
// post.ContentLabels contains com.atproto.label.defs#selfLabels JSON: {"values":[{"val":"nsfw","neg":false}]}
38
+
// Store the full JSON blob to preserve the 'neg' field and future extensions
39
+
var labelsJSON sql.NullString
if post.ContentLabels != nil {
42
-
// Parse JSON array string to []string
44
-
if err := json.Unmarshal([]byte(*post.ContentLabels), &labels); err == nil {
45
-
labelsArray = labels
41
+
labelsJSON.String = *post.ContentLabels
42
+
labelsJSON.Valid = true
···
err := r.db.QueryRowContext(
post.URI, post.CID, post.RKey, post.AuthorDID, post.CommunityDID,
65
-
post.Title, post.Content, facetsJSON, embedJSON, labelsArray,
61
+
post.Title, post.Content, facetsJSON, embedJSON, labelsJSON,
).Scan(&post.ID, &post.IndexedAt)
···
104
-
var facetsJSON, embedJSON sql.NullString
105
-
var contentLabels pq.StringArray
100
+
var facetsJSON, embedJSON, labelsJSON sql.NullString
err := r.db.QueryRowContext(ctx, query, uri).Scan(
&post.ID, &post.URI, &post.CID, &post.RKey,
&post.AuthorDID, &post.CommunityDID,
110
-
&post.Title, &post.Content, &facetsJSON, &embedJSON, &contentLabels,
105
+
&post.Title, &post.Content, &facetsJSON, &embedJSON, &labelsJSON,
&post.CreatedAt, &post.EditedAt, &post.IndexedAt, &post.DeletedAt,
&post.UpvoteCount, &post.DownvoteCount, &post.Score, &post.CommentCount,
···
post.Embed = &embedJSON.String
129
-
if len(contentLabels) > 0 {
130
-
labelsJSON, marshalErr := json.Marshal(contentLabels)
131
-
if marshalErr == nil {
132
-
labelsStr := string(labelsJSON)
133
-
post.ContentLabels = &labelsStr
124
+
if labelsJSON.Valid {
125
+
// Labels are stored as JSONB containing full com.atproto.label.defs#selfLabels structure
126
+
post.ContentLabels = &labelsJSON.String